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

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!

 

This is because you are using a reference to your tileentity within the block.

Prefer world.getBlockTileEntity(x,y,z);

  • Author

Ah, ok. I now have it so the tileentity variable is defined with world.getBlockTileEntity(x,y,z) cast to TileEntityBush whenever setBlockBoundsBasedOnState and onBlockActivated are called. It works now, thank you!

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.