Posted June 18, 20178 yr Hi ! I'm currently saving data to my Block using a TileEntity and the ITileEntityProvider interface. But when a player breaks the block, the TileEntity is removed and the data is lost. I'd like to keep the data in the ItemStack dropped by the block, so when the player replaces it, it'll reload the data previously contained by the TileEntity. 1- Can I do it without using capabilities ? 2- If yes, how/when can I do the conversion from TE data to IS data ? 3- If not, how can I do it using capabilities ?
June 18, 20178 yr 12 minutes ago, Franckyi said: ITileEntityProvider interface Is outdated, Use Block::hasTileEntity and Block::createTileEntity. 1. Yes. 2. Vanilla has a great example of a tile entity that retains it's data when broken. See BlockShulkerBox. 3. If you so chose to you can store all the data of the tile in your item's capability. Capabilities are just means of storing/accessing data easily. Chosing to use them or not in this case is up to you. In general you would want to create a custom ItemStack as a drop that contains your tile's data in it's NBT/Capability. Upon the placement of that item you would either set the data in a newly created tile on your own using a custom ItemBlock or let vanilla handle it by saving your tile data into a NBTTagCompound and storing that tag in your ItemStack that gets dropped with a BlockEntityTag as a key(yet again, see BlockShulkerBox for more clarification)
June 18, 20178 yr Author Thanks for the answer ! I'll check that and update this topic if I'm in trouble
June 18, 20178 yr A better example of saving data in the ItemStack when the block is broken is Forge's patches to BlockFlowerPot. This delays the removal of the TileEntity until after Block#getDrops is called, allowing you to access it there and store the data. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 18, 20178 yr Author 20 minutes ago, Choonster said: A better example of saving data in the ItemStack when the block is broken is Forge's patches to BlockFlowerPot. This delays the removal of the TileEntity until after Block#getDrops is called, allowing you to access it there and store the data. Oh right I see! Thanks for the information
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.