Jump to content

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


Kloonder

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);
	world.spawnEntityInWorld(nfb);
	ItemStack stack = player.getCurrentEquippedItem();
	NBTTagCompound nbt = stack.getTagCompound();
	if(world.getBlockState(pos).getBlock().hasTileEntity(world.getBlockState(pos))){
		TileEntity tile = world.getTileEntity(pos);
		NBTTagCompound tileData = new NBTTagCompound();
		tile.writeToNBT(tileData);
		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;
	world.setBlockToAir(pos);
}

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.setDead();
			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

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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