Posted June 25, 20169 yr I was wondering if there is a simple way of storing a BlockState within an NBTTagCompound.
June 25, 20169 yr Write it as registry name + metadata. You can eventually serialize TileEntity if such exists at x/y/z. As for registry names - you could go with block IDs but mind that those are assigned per-world so your save would have to be for specific world and no other use outside it. If you have a large amount of blocks to serialize you can make local dictionary - make registry name have prive ID inside your NBT structure and then all blocks saved would use that dictionary reference to deserialize. 1.7.10 is no longer supported by forge, you are on your own.
June 25, 20169 yr Author Okay, I can store the block now, but I cannot figure out how to get the BlockState back from the ID and metadata. I can either the block from getBlockById, or the BlockState with getStateById, but I cannot figure out how to place that block in the world. The only method I can find is world.setBlockState, but that doesn't use the block ID.
June 25, 20169 yr Don't use block IDs. Get the block registry from ForgeRegistries.BLOCKS , the Block from its registry name by calling IForgeRegistry#getValue and then the IBlockState from the metadata by calling Block#getStateFromMeta . Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 27, 20169 yr Author Ok, I have it all sorted out. I am currently using block IDs temporary until I can figure out a good way of storing the block registry in NBT as it is a ResourceLocation and cannot be simply casted to a string for easy storage. Once I figure out how to store the registry, I will use that instead.
June 27, 20169 yr Store the registry name (and any other ResourceLocation ) as a string, convert by calling toString . Use the ResourceLocation(String) constructor to convert the string back to a ResourceLocation . Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 27, 20169 yr Author I forgot that the constructor for a ResourceLocation just takes a string. Thanks.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.