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

Hi,

 

I am having some issues with my design regarding the way TileEntities are created.

 

As you know, there are basically two ways for a TileEntity to be created.

- The Block creates it upon placement using createNewTileEntity(). There we have all the freedom to pass any information we want.

- The TileEntity is created (using default constructor) when loading a game that had one already there.

 

My problem is the following:

My TileEntity needs some configuration values when it is created (lets say the size of its inventory).

I previously stored this value in the NBT tag of the TileEntity and had no problem.

 

But this value is actually configuration and never changes, so I though it is a bit silly that each TileEntity saves it.

 

Before continuing I need to precise that I can not store that config value statically (MyModConfiguration.getConfigValue()) because my TileEntity is used by different blocks that each have a different config value.

Lets say I have block1 that has an inventory size of 10 and block2 that has an inventory size of 20.

 

The way to work around this is to ask the block of the TileEntity its config value (worldObj.getBlock(x,y,z).getConfigValue()).

My problem is that when a TileEntity is loaded the readFromNBT is called immediately before anything else from the TileEntity is set (world object, position, etc.)

My TileEntity is therefore trying to restore the inventory content while the inventory is not yet created because I can not access its size.

 

Would you see a way to work around this? How do you typically handle loading of TileEntities?

I hope my explanations are clear enough and thanks a lot beforehand.

  • Author

Alright, thought I would save some space if I managed to find the value without the need to save it in the NBT tag.

I'm probably over-engineering the stuff again -.-

 

Thanks for pointing it out :P

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.