• 0

    posted a message on Need help syncronizing a value between the client and server.

    This is a simple question that I'm sure will have a not-so-simple answer: Let's say I have an integer n saved to the player's NBT server-side. How can we make sure that the client's n is the same value as the server's n if n is changed server-side? Also, to make things complicated, is there a way to this in reverse, as in, the server's n is set to the client's n?

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.

    It worked! Now I just need to actually implement the code into my mod, but I can do that myself.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.
    Quote from coolAlias»

    Okay, first of all you do NOT want to write every single value as a String - if it's an int, write an int, if it's a boolean, write a boolean. For an Enum, write the ordinal, which is an int.


    NBTTagList will only store one type of data value. They either have to be all int or booleans, or whatever other data types are supported. I decided to go with strings because I figured I could easily parse them.


    Anyways, this

    state = state.withProperty(property, (int) nbtList.get(i++);

    is the missing piece to the puzzle. I think I can complete it from here. Thanks for all your help. I will let you know how this goes.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.

    The writer:

    NBTTagCompound nbt = playerIn.getEntityData();
    
    				NBTTagList nbtList = new NBTTagList();
    				int i = 0;
    
    				nbtList.appendTag(new NBTTagString(Block.getIdFromBlock(state.getBlock()) + ""));
    				
    				for(IProperty prop : (Set<IProperty>)state.getProperties().keySet())
    				{
    					nbtList.appendTag(new NBTTagString(prop.getName()));
    					nbtList.appendTag(new NBTTagString(state.getValue(prop) + ""));
    					nbtList.appendTag(new NBTTagString(prop.getValueClass() + ""));
    					i++;
    				}
    
    				nbt.setTag("state", nbtList);


    And the reader:

    IBlockState state1;
     NBTTagList nbtList = (NBTTagList)nbt.getTag("state");
     Block block = Block.getBlockById(Integer.parseInt(nbtList.get(0) + ""));
     IProperty[] props = new IProperty[nbtList.tagCount() - 1];
    
    props = ???

    This is where I get stuck. Sorry the code spacing is so derpy.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.
    Quote from coolAlias»

    It's different for every Block, since they all have different Properties. Your best bet is probably to use Reflection:
    1. Figure out the class of Block you are working with (simple)
    2. Use Reflection to retrieve all Property fields of that Block (not too hard)
    3. Set the IBlockState with each of those Property fields to each of the values you have (harder than steps 1 + 2, but still shouldn't be too difficult)

    However, most blocks store all of their pertinent data as a single metadata field, as Alpvax mentioned. All block orientation is converted back and forth between these values, the color of grass is determined by the current biome it is in regardless of what you set its block state to, etc.

    For the vast majority if not all cases, it should be sufficient to send the integer Block#getMetaFromState(IBlockState) and then set the state using Block#getStateFromMeta(int). For 99% of the other cases, they will involve a TileEntity which you will can send via NBT using the TileEntity's own read and write methods.

    There will be some outliers that are not handled by this, such as fire (it only stores AGE as metadata, but all of the orienations are determined when the block catches fire), but it will work flawlessly for probably 95% or more.


    It's number 3 that I got caught on. Setting each of the property fields to the stored NBT value isn't as straightforward as it sounds.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.

    I wrote the code that will turn the block state into an NBT list, but I am having trouble reading the list to turn it back into a block state. Does anyone happen to new how to create a block state from the base data?

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.
    Quote from Alpvax»

    Regarding my earlier post, I had misread the question as BlockPos rather than states. However the general idea is the same. You could always just save the metadata, then use the getstatefrommeta method (not sure if that is the correct name)


    That wouldn't quite work, because sideways logs would become upright, snowy grass would become normal, and all that stuff.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.
    Quote from coolAlias»

    Except a HashMap is not saved to disk. Once you exit the game *poof* it's gone. NBT already allows you to read and write to disk, whereas you will have to write your own file input/output code or use a library to write your HashMap to disk, which will eventually just be writing integers and booleans.

    Have we just misunderstood what you are trying to accomplish? Because the whole point of NBT is that it can be written to disk - it's not designed (primarily) as an in-memory storage system, so when you say 'besides NBT' I think you want to write to disk.


    Looking back, I think I may have miscommunicated my goals. If it helps you understand a bit better, this stuff is for my World Tools mod. It is currently very buggy in multiplayer, and I am trying to find a way to fix it. The things that need to be stored are the positions that have been selected, what block state has been set by the player, etc. It's fine if this goes *poof* when you leave a world or the server is shut down, because you probably don't need those things saved anyways. I am looking for a standardized method of keeping custom values consistent between server and client, and that these values are easily accessible by both client and server. So I don't need to write to the disk, I just figured that NBTs where the most viable option due to the fact that they were built-in and easy to use. But when they weren't working like how I needed them to, I came here looking for alternate solutions.


    So, forgetting everything I've said prior to this, do you have any solutions for saving these properties that doesn't use NBTs?

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.
    Quote from coolAlias»

    It is that simple, and yet it isn't. Writing your own data storage system certainly won't make it any easier, though, I can tell you that much with absolute certainty.

    Storing the data will literally boil down to integers and booleans, with possibly some extra information for TileEntities (which already write themselves to NBT anyway).

    The problem is restoring those integers and booleans into the exact BlockState that they represent, and for that you need to make sure to store them all in the same order that you will be putting them back in, so if a BlockState has 4 properties, store them in the order so that the 1st value belongs to the 1st property.


    In my current system, I use an object HashMap to store all values. This allows me to just take the IBlockState, assign it with

    map.put("state", state);

    and retrieve it with

    (IBlockState)map.get("state");

    This doesn't require me to do any sort of breaking down into integers and booleans, so I'm wondering why "writing [my] own data storage system won't make it any easier" if that storage system can store a IBlockState as a IBlockState, and not as a bunch of integers and booleans.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.
    Quote from TehNut»

    So an int, two booleans, and some other things that would also boil down to ints, bools, and strings? NBT can handle that just fine.


    It's just not that simple. Take a look at the BlockState class yourself to see what I mean.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.
    Quote from Darkhax»

    NBTTagCompounds can essentially store anything you want. The premise for NBT is that almost any Object can be converted into it's most essential data, and then this most essential data can be used to construct a new instance of that object. This is the main premise for many data types, you only save what you need.


    An example of this is an ItemStack, if you look at the writeToNBT method within ItemStack, you can see that it writes a short for the numeric id, a byte for the amount, and another short for the damge (metavalue/durability). It will also write any additional information from the ItemStack's NBTTagCompound to a new tag.


    If you then look at the readFromNBT method in the same class, it uses the id to create a new Item via Item.getItemById which is then used to construct a new ItemStack. From there, the stack size and meta/durability is set to the ItemStack, finally if there is a generic stack tag, it will also be added to the new ItemStack instance. By only using the most essential information, we can read/write an ItemStack. The reason we do this is to eliminate needing to handle all of the overhead, which allows us to keep the data size smaller, which is better for saving to disk, and sending via packets.


    While I haven't messed with 1.8 all that much, I believe that BlockState's are simply a wrapper for the meta value. If that is the case, the only thing you will need to write for a BlockState is a byte to represent 0-15 for the meta value. You can then use this byte value along with an instance of the Block (which can be retrieved from Blocks, Block.getBlockById, or from your own block handler) to get the IBlockState. You may also want to keep track of the Block's id value, so you can reliably get instances of it. I would highly suggest string ids over numeric ones though.


    Block states don't only store meta, they store things like block direction, if leaves should decay, if grass is snowy, and lots of other block-specific things that I didn't think I'd be able to handle with NBT data.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.
    Quote from Alpvax»

    Use a structure like this:


    NBTTagCompound parent

    - NBTTagList list

    - - NBTTagCompound list[0]

    - - - X: int

    - - - Y: int

    - - - Z: int

    - - NBTTagCompound list[n]

    - - - X: int

    - - - Y: int

    - - - Z: int


    That wouldn't exactly work for block states though.

    Posted in: Modification Development
  • 0

    posted a message on Need help saving data without the use of NBTs.

    So I am working on my mod, but I am having some issues with data storage. This mod requires each player to have multiple new values assigned to them. Unfortunately, the values in my current dysfunctional data storing method include things like lists of block states, but unfortunately there isn't an NBT type for that. Any idea on how I can go about storing data in a multiplayer-friendly way?

    Posted in: Modification Development
  • 0

    posted a message on [MC 1.10][v2.0] World Tools - A mod to speed up building in creative! • Version 2.0 released 2/5/2017

    World Tools v1.3.2 for Minecraft 1.8 has been released. See Changelog/Guide for details on what's new and how to use it.

    Posted in: Minecraft Mods
  • 0

    posted a message on [MC 1.10][v2.0] World Tools - A mod to speed up building in creative! • Version 2.0 released 2/5/2017

    World Tools v1.3.1 for Minecraft 1.8 has been released. See Changelog/Guide for details on what's new and how to use it.

    Posted in: Minecraft Mods
  • To post a comment, please or register a new account.