Posted July 25, 201510 yr Hey guys, do you know how is the best way to store values from the tile entity in a block / itemstack, so they can be re-add when the block is placed again?
July 25, 201510 yr Author Well, currently I'm using that, but the player can still get the block when it is broke in creative. How can I check if it is creative or not? I mean, is there any problem by using !Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode in the breakBlock(World worldIn, BlockPos pos, IBlockState state) method?
July 25, 201510 yr Author In order to get the tile entity (!= null), I'm using the breakBlock(), instead of dropBlockAsItemWithChance(), or harvestBlock(), both return a null tile entity. So, I'm setting the tag in an itemstack and spawning it before the super.breakBlock(). When I do this, it will spawn an extra block, so I need to override the getItemDropped() to null. However, when I do that, it will always drop an item, even in creative.
July 25, 201510 yr Author Nice. But I still have a problem. When I destroy the tile entity in survival, it is not completely destroyed, I can still collide with it, and when I right click it, the block returns. Am I doing something wrong? @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return null; } @Override public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { if (willHarvest) return true; return super.removedByPlayer(world, pos, player, willHarvest); } @Override public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te) { super.harvestBlock(world, player, pos, state, te); world.setBlockToAir(pos); } @Override public List<ItemStack> getDrops(IBlockAccess worldIn, BlockPos pos, IBlockState state, int fortune) { List<ItemStack> drops = super.getDrops(worldIn, pos, state, fortune); TileEntity tileEntity = worldIn.getTileEntity(pos); if (tileEntity instanceof MyTile) { MyTile myTile= (MyTile) tileEntity; drops.add(this.getThisBlockWithTag(myTile, pos)); for (ItemStack itemStack : myTile.getInventory()) drops.add(itemStack); } return drops; } private ItemStack getThisBlockWithTag(MyTile myTile, BlockPos pos) { ItemStack stack = new ItemStack(BlockRegistry.myBlock); if (myTile != null) { NBTTagCompound compound = new NBTTagCompound(); compound.setByte("var1", (byte) myTile.getVar1()); [...] stack.setTagCompound(compound); } return stack; }
July 26, 201510 yr Author Thanks, that makes sense and I would not notice that, haha. Well, now it's working right. I was using debug, so I've closed mc and tried again. Weird
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.