Jump to content

Reading NBT from a block instance's tile entity


myoKun345

Recommended Posts

Hello everyone,

I am having some trouble reading an NBT value from a tile entity attached to instances of my blocks; I have it set temporarily that right clicking on the block will increment the value stored in NBT. This works, but every instance of the block also gets the resulting effects of the NBT change because while every block instance creates a new tile entity, they all are only checking the first one that was created. I am sure I just made a newbie mistake, but I haven't been able to determine what is wrong in the code.

 

Related code:

https://github.com/myoKun345/Ars-Herbologica/blob/master/herbologica_common/herbologica/block/crop/BlockHerbologicaBush.java

 

https://github.com/myoKun345/Ars-Herbologica/blob/master/herbologica_common/herbologica/tileentity/crop/TileEntityBush.java

 

 

Explanation:

I create an uninitialized variable for the tile entity to be accessed from, which is then initialized in createNewTileEntity(). From my understanding, this would create a new instance of the tile entity for each block and then reference/store it in the tileentity variable. Then I use the tileentity variable in setBlockBoundsBasedOnState() to grow the block based on the GrowthState NBT tag saved to the tile entity. I store the GrowthState NBT tag in-game using a variable inside the tile entity class. Then I increment that in onBlockActivated() so when it is right-clicked the growth state variable will be increased. I think that the problem is in either how I create and initialize the tile entity or how I read and write to the growth state.

 

 

The rest of the code is in the repository if you need to check something else.

 

Thanks in advance!

 

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.