package com.tehbeard.enchancedadv.items;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;

/**
 * Encodes location information to apply to a command block
 * @author James
 *
 */
public class ItemLocationEncoder extends Item{

	public ItemLocationEncoder(int par1) {
		super(par1);
		setUnlocalizedName("locationencoder");
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void onCreated(ItemStack par1ItemStack, World par2World,
			EntityPlayer par3EntityPlayer) {
		initTag(par1ItemStack);
		super.onCreated(par1ItemStack, par2World, par3EntityPlayer);
	}
	
	@Override
	public boolean onItemUseFirst(ItemStack stack, EntityPlayer player,
			World world, int x, int y, int z, int side, float hitX, float hitY,
			float hitZ) {
		initTag(stack);
		if(player.isSneaking()){
			ForgeDirection direction = ForgeDirection.getOrientation(side);
		}
		return true;
	}
	
	public NBTTagCompound getLocTag(ItemStack stack){
		return stack.stackTagCompound.getCompoundTag("loc");
	}
	
	public void initTag(ItemStack stack){
		if(stack.stackTagCompound==null){
	        stack.stackTagCompound = new NBTTagCompound();
	        stack.stackTagCompound.setCompoundTag("loc", new NBTTagCompound());
	        stack.stackTagCompound.getCompoundTag("loc").setInteger("x",0);
	        stack.stackTagCompound.getCompoundTag("loc").setInteger("y",0);
	        stack.stackTagCompound.getCompoundTag("loc").setInteger("z",0);
	        }
	}

}

@@ -1043,16 +1043,328 @@
 (side);%0A
+%09%09%09getLocTag(stack).setInteger(%22x%22,x + direction.offsetX);%0A%09%09%09getLocTag(stack).setInteger(%22y%22,y + direction.offsetY);%0A%09%09%09getLocTag(stack).setInteger(%22z%22,z + direction.offsetZ);%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09getLocTag(stack).setInteger(%22x%22, x);%0A%09%09%09getLocTag(stack).setInteger(%22y%22, y);%0A%09%09%09getLocTag(stack).setInteger(%22z%22, z);%0A
 %09%09%7D%0A%09%09re

Save to tag.