Laseph Posted February 5, 2016 Share Posted February 5, 2016 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? Quote Link to comment Share on other sites More sharing options...
yooksi Posted February 5, 2016 Share Posted February 5, 2016 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; } Quote 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 More sharing options...
Recommended Posts
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.