Posted August 17, 201312 yr I'm trying to figure out how to maintain TileEntity data when breaking and placing a block. The OpenBlocks source code has some clues in it (spawning an EntityItem with the appropriate data stored in it), but when I place the block again, the data is lost. I'm assuming that there's something I need to do with the item is placed, but I'm not sure what. Any ideas?
August 17, 201312 yr Use the item values to change the tileentity state. Something like: onItemUse(world, itemstack,x,y,z...) { data = getData(itemstack.getTagCompound()); (MyTileEntity)world.getBlockTileEntity(x,y,z).changeState(data); }
August 17, 201312 yr Author I'm still kind of in the dark here. Block doesn't have an onItemUse function, so does that mean I need to create a custom Item class that, when placed, spawns the block and inserts the entity data? I don't see any way to get the itemstack from inside the Block class when the block is placed.
August 17, 201312 yr I'm assuming that there's something I need to do with the item is placed You said you had an item. The easy way is certainly to use an item to place the block. Which means you want noone to get the actual block, only the item. Then when block is broken, spawn an EntityItem which contains the item (again, not the block).
August 18, 201312 yr Author If I want the item to actually render like a block, is that going to be a huge ordeal of building a custom renderer or something, or is there some shortcut way to make it render the item as if it's an existing block?
August 18, 201312 yr You could use an IItemRenderer and use renderblocks i suppose...or use an ItemBlock.
August 18, 201312 yr Or you could just have the block... and the item... and the tileentity. All you have to do is, in the method that returns what the block drops, you create a new Item and give it all the data it needs, and then spawn the EntityItem with that item you spawned. And that item is the item etc, that you create *EDIT* Just relized that it wouldn't look like a block though, it would be the 2D item. But hey, it would be easier I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
August 18, 201312 yr you could tottally use the same code for the IItemRenderer as the TileEntitySpecialRenderer, nothign is stopping you to do it how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
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.