package com.choonster.testmod3.item;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;

// http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2451199-1-8-iteminteractionforentity-with-nbt-bug
public class ItemEntityInteractionTest extends ItemTestMod3 {
	public ItemEntityInteractionTest() {
		super("entityInteractionTest");
	}

	private int getInteractCount(ItemStack stack) {
		if (!stack.hasTagCompound()) {
			stack.setTagCompound(new NBTTagCompound());
		}

		NBTTagCompound tagCompound = stack.getTagCompound();

		if (!tagCompound.hasKey("Count", Constants.NBT.TAG_INT)) {
			tagCompound.setInteger("Count", 0);
		}

		return tagCompound.getInteger("Count");
	}

	@Override
	public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target) {
		int count = getInteractCount(stack) + 1;
		stack.getTagCompound().setInteger("Count", count);

		if (!playerIn.worldObj.isRemote) {
			playerIn.addChatComponentMessage(new ChatComponentTranslation("message.testmod3:entityInteractCount", count));
		}

		return true;
	}

	@Override
	public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
		if (!playerIn.worldObj.isRemote) {
			int count = getInteractCount(itemStackIn);

			playerIn.addChatComponentMessage(new ChatComponentTranslation("message.testmod3:entityInteractCount", count));
		}

		return super.onItemRightClick(itemStackIn, worldIn, playerIn);
	}
}

@@ -719,187 +719,37 @@
 %0A%0A%09%09
-NBTTagCompound tagCompound = stack.getTagCompound();%0A%0A%09%09if (!tagCompound.hasKey(%22Count%22, Constants.NBT.TAG_INT)) %7B%0A%09%09%09tagCompound.setInteger(%22Count%22, 0);%0A%09%09%7D%0A%0A%09%09return tagCompound
+return stack.getTagCompound()
 .get
@@ -889,16 +889,54 @@
 rget) %7B%0A
+%09%09if (!playerIn.worldObj.isRemote) %7B%0A%09
 %09%09int co
@@ -970,16 +970,17 @@
 k) + 1;%0A
+%09
 %09%09stack.
@@ -1029,45 +1029,8 @@
 );%0A%0A
-%09%09if (!playerIn.worldObj.isRemote) %7B%0A
 %09%09%09p

Clean up code