Posted June 11, 20169 yr I'm trying to create a wrench function for my blocks. I'm trying to retrieve the tile's NBT via getTileData(). getTileData() always returns an empty tag. The tile retains the NBT data so long as the block is placed. I can verify this because the block is a solar panel that generates RF. It retains the RF data through logging out and restarting the client. I have implemented packet handling to send the server data to the client as well. Following are the relevant methods: BlockSolarPanel#onBlockActivated public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntitySolarPanel te = getTE(worldIn, pos); if (te != null) { if (!playerIn.isSneaking()) { if (worldIn.isRemote) { GuiHandler.launchGui(Globals.GUINUM_SOLARPANEL, playerIn, worldIn, pos.getX(), pos.getY(), pos.getZ()); } } else { BlockUtils.wrenchBlock(worldIn, pos, state, te); } } return true; } BlockSolarPanel#getTE private TileEntitySolarPanel getTE(World worldIn, BlockPos pos) { return (TileEntitySolarPanel) BlockUtils.getTE(worldIn, pos); } BlockUtils#wrenchBlock public static void wrenchBlock(World worldIn, BlockPos pos, IBlockState state, TileEntity te) { if (!worldIn.isRemote) { ItemStack blockStack = new ItemStack(Item.getItemFromBlock(worldIn.getBlockState(pos).getBlock()), 1); if (te.getBlockMetadata() > 0) { blockStack.setItemDamage(te.getBlockMetadata()); } if (te.getTileData() != null) { NBTTagCompound nbt = te.getTileData(); blockStack.setTagCompound(nbt); } EntityItem entityItem = new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), blockStack); if (te != null) { worldIn.spawnEntityInWorld(entityItem); dropTEItems(worldIn, pos); worldIn.setBlockToAir(pos); } } } http://p455w0rd.net/images/forumsignature.png[/img]
June 11, 20169 yr TileEntity#getTileData is for storing external data on a TileEntity , it doesn't contain the TileEntity 's own data. Use INBTSerializable#serializeNBT (inherited by TileEntity ) to write an INBTSerializable object to NBT. 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.
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.