Jump to content

[1.7.10] Inconsistent TileEntity NBT

Izzy Axel

Recommended Posts

I have a block that you right click on to "store" a certain item in, when it's stored a boolean is made true, which is being written to NBT, when its taken out, the boolean is made false.  The issue is, when I put a stdout with the boolean variable in it, I found out that it's alternating between true and false every other tick, which is a huge problem, and I can't figure out why it's doing that.






Dummy Block

Link to comment
Share on other sites

Not sure why the boolean value would be switching, your code looks fine, but I've noticed a couple minor issues in your code:

1) When you get your TileEntity using (TEChaliceOfTheVoid)world.getTileEntity(x, y - 1, z) you don't check if the TileEntity returned by World#getTileEntity is actually an instance of TEChaliceOfTheVoid, which could cause ClassCastException(s). Check this using world.getTileEntity(x, y - 1, z) instanceof TEChaliceOfTheVoid and if that's true cast it like so:

if (world.getTileEntity(x, y - 1, z) instanceof TEChaliceOfTheVoid) {
    TEChaliceOfTheVoid chaliceTE = (TEChaliceOfTheVoid)world.getTileEntity(x, y - 1, z);


2) When you use world.getBlock(x, y - 1, z).setHardness(-1.0f); you not only set the hardness for block at the specified coordinates, you set the hardness for every instance of that block in the game, and I doubt this is the intended behavior. My suggestion is that you add an additional variable to your TileEntity that specifies whether the block can be broken or not and check that variable when someone attempts to break the block.


3) You decrease the stackSize of the ItemStack when you add the pendant to the TE, but you don't check if the stackSize is zero. If the stackSize does happen to be zero, there will be an ItemStack in the player's inventory that contains 0 of your item, this is not how MC works. Immediately after you decrease the stackSize, you should check if it's zero and if so, set the stack to null.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Link to comment
Share on other sites

You should never be able to separate the dummy block and the chalice block, and when one is destroyed, the other is too.  If I wanted to be completely safe, I could check that cast, but for now, it doesn't matter.


Whoops, missed that, I'll add that to the TE's NBT.


MaxStackSize is 1 on the pendant, but if I wanted to be safe, again I guess I could check that, but it doesn't affect anything right now.


Edit: but you could pickblock the dummy, so fixed that.

Link to comment
Share on other sites

Turns out that's exactly what it was, it seemed to be switching between the inventory TE/block and world TE/block every other frame, removing the ISBRH fixed it.  Now I need to figure out how to draw the model in the inventory...

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.

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.


  • Create New...

Important Information

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