Jump to content

Take NBt of a block with tileentity and put it in again, makes chest can't open


Recommended Posts

How it sais in title, the chest can't get opened after putin nbt back in chest, but if you destroy the chest, it drops the correct items


public void takeBlock(World world, EntityPlayer player, BlockPos pos, float hitX, float hitY, float hitZ, int id){
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
	nfb.theBlock = world.getBlockState(pos);
	ItemStack stack = player.getCurrentEquippedItem();
	NBTTagCompound nbt = stack.getTagCompound();
		TileEntity tile = world.getTileEntity(pos);
		NBTTagCompound tileData = new NBTTagCompound();
		nbt.setTag("NBTBlock", tileData);
		nfb.tileEntityData = tileData;
	nbt.setInteger("ID", Block.getIdFromBlock(world.getBlockState(pos).getBlock()));
	nbt.setBoolean("IsBlock", true);
	nbt.setString("EntityIDClient", nfb.getUniqueID().toString());
	nbt.setInteger("EntityIDServer", nfb.getEntityId());
	Block block = nfb.fallTile != null ? nfb.fallTile.getBlock() : Blocks.air;
	ResourceLocation resourcelocation = (ResourceLocation)Block.blockRegistry.getNameForObject(block);
	nbt.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
	nbt.setByte("Data", (byte)block.getMetaFromState(nfb.fallTile));

	if (nfb.tileEntityData != null)
		nbt.setTag("TileEntityData", nfb.tileEntityData);
	entity = nfb;

public void placeBlock(World world, ItemStack stack){
	if(entity instanceof EntityNotFallingBlock){
		if(world.getBlockState(new BlockPos(entity)).getBlock() == Blocks.air){
			world.setBlockState(new BlockPos(entity), ((EntityNotFallingBlock) entity).getBlock());
			if(world.getBlockState(new BlockPos(entity)).getBlock().hasTileEntity((world.getBlockState(new BlockPos(entity))))){
				world.getTileEntity(new BlockPos(entity)).readFromNBT((NBTTagCompound) stack.getTagCompound().getTag("NBTBlock"));
			stack.getTagCompound().setInteger("ID", -1);
			stack.getTagCompound().setBoolean("IsBlock", false);
			entity = null;

Creator of Extra Shoes


Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Link to comment
Share on other sites

This topic is now closed to further replies.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.