Jump to content

TileEntity loading


Nauktis

Recommended Posts

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.

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.