Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I was wondering if there is a simple way of storing a BlockState within an NBTTagCompound.

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.

  • 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.

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.

  • 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.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.