Jump to content

[1.9+] Store BlockState in NBT


Selim_042

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.