package com.ForgeEssentials.util;

//Depreciated
import java.io.Serializable;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class BlockSaveable implements Serializable
{
	private int x;
	private int y;
	private int z;
	private short blockID;
	private byte metadata;
	private NBTTagCompound tile;

	/**
	 * generates the block from the world.
	 * 
	 * @param world
	 * @param x
	 * @param y
	 * @param z
	 */
	public BlockSaveable(World world, int x, int y, int z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
		blockID = (short) world.getBlockId(x, y, z);
		metadata = (byte) world.getBlockMetadata(x, y, z);

		TileEntity entity = world.getBlockTileEntity(x, y, z);
		if (entity != null)
		{
			NBTTagCompound compound = new NBTTagCompound();
			entity.writeToNBT(compound);
			tile = compound;
		}
	}

	@Override
	public boolean equals(Object object)
	{
		if (object instanceof BlockSaveable)
		{
			BlockSaveable block = (BlockSaveable) object;
			return x == block.x && y == block.y && z == block.z && blockID == block.blockID && metadata == block.metadata && tile.equals(block.tile);
		}
		return false;
	}

	/**
	 * @param world
	 * @return if the block was actually set.
	 */
	public boolean setinWorld(World world)
	{
		if (equals(new BlockSaveable(world, x, y, z)))
		{
			return false;
		}

		world.setBlockAndMetadata(x, y, z, blockID, metadata);
		TileEntity entity = world.getBlockTileEntity(x, y, z);
		if (entity != null && tile != null)
		{
			entity.readFromNBT(tile);
		}

		return true;
	}

	public boolean isAir()
	{
		return blockID == 0;
	}
}

@@ -768,16 +768,29 @@
 ll)%0A%09%09%7B%0A
+%09%09%09try%0A%09%09%09%7B%0A%09
 %09%09%09NBTTa
@@ -831,24 +831,25 @@
 pound();%0A%09%09%09
+%09
 entity.write
@@ -865,16 +865,17 @@
 pound);%0A
+%09
 %09%09%09tile 
@@ -886,16 +886,49 @@
 mpound;%0A
+%09%09%09%7D%0A%09%09%09catch(Exception e)%0A%09%09%09%7B%7D%0A
 %09%09%7D%0A%09%7D%0A%0A

fix #191