Jump to content

Coping Tile Entity


alkinister

Recommended Posts

Hi so I am trying to make a item that can move a tile entity and blocks from a location to another which works with blocks however if I move a tile entity one of two things will happen if it is a furnace it will move but the items will pop out and fuel level gets removed so the furnace is no longer burning. The other thing is that if you move a chest all the items pop out and the chest is empty when it gets to the final location. Here is the code I have any help is appreciated.

 

	public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	if (stack.getTagCompound() == null) {
		stack.setTagCompound(new NBTTagCompound());
	}

	if (world.getBlockState(pos).getBlock().equals(ModBlocks.block_warper)) {
		stack.getTagCompound().setDouble("x", pos.getX());
		stack.getTagCompound().setDouble("y", pos.getY());
		stack.getTagCompound().setDouble("z", pos.getZ());
		stack.getTagCompound().setBoolean("linked", true);
	}

	if (!world.getBlockState(pos).getBlock().equals(ModBlocks.block_warper)) {
		BlockPos targetPos = new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ());
		IBlockState targetBlockState = world.getBlockState(new BlockPos(stack.getTagCompound().getDouble("x"), stack.getTagCompound().getDouble("y") + 1, stack.getTagCompound().getDouble("z")));
		if (world.getBlockState(targetPos).getBlock().equals(Blocks.air)) {
			world.setBlockState(targetPos, targetBlockState);
			if (!(world.getTileEntity(new BlockPos(stack.getTagCompound().getDouble("x"), stack.getTagCompound().getDouble("y") + 1, stack.getTagCompound().getDouble("z"))) == null)) {
				world.setTileEntity(targetPos, world.getTileEntity(new BlockPos(stack.getTagCompound().getDouble("x"), stack.getTagCompound().getDouble("y") + 1, stack.getTagCompound().getDouble("z"))));
			}
			world.setBlockToAir(new BlockPos(stack.getTagCompound().getDouble("x"), stack.getTagCompound().getDouble("y") + 1, stack.getTagCompound().getDouble("z")));
		}
	}
	return EnumActionResult.PASS;
}

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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