Jump to content

[1.8.9]TileEntity setting variable only once.


Laseph
 Share

Recommended Posts

So i have this variable i want to set when the TileEntity is created based on the metadata from the associated block. I first tried placing it in the constructor but i quickly found out the worldObj of the tileentity isn't created until later. Then i tried doing it in the onLoad method but it loops itself infinitely because of trying to get the blockstate via loading the chunk. Should i just do a check in the update event or is there a better way?

Link to comment
Share on other sites

You can store and later retrieve metadata from blockstate. Override this class in your custom block class, extract the metadata from blockstate and invoke the tile entity constructor with metadata as your argument:

/**
* Called throughout the code as a replacement for ITileEntityProvider.createNewTileEntity
* Return the same thing you would from that function.
* This will fall back to ITileEntityProvider.createNewTileEntity(World) if this block is a ITileEntityProvider
*
* @param metadata The Metadata of the current block
* @return A instance of a class extending TileEntity
*/
public TileEntity createTileEntity(World world, IBlockState state)
{
    if (isTileProvider)
    {
        return ((ITileEntityProvider)this).createNewTileEntity(world, getMetaFromState(state));
    }
    return null;
}

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

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
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.

 Share



×
×
  • Create New...

Important Information

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