package com.choonster.testmod3.item;

import com.choonster.testmod3.TestMod3;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagLong;
import net.minecraft.world.World;

/**
 * Based on Vastatio's ARKSlingshot code.
 * <p>
 * http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2483633-custom-bow-animation-and-projectiles
 */
public class ItemSlingshot extends ItemTestMod3 {
	public ItemSlingshot() {
		super("slingshot");
	}

	@Override
	public ItemStack onItemRightClick(ItemStack stack, World w, EntityPlayer p) {
		if (p.capabilities.isCreativeMode
				|| p.inventory
				.consumeInventoryItem(Items.snowball)) {
			setLastUseTime(stack, w.getTotalWorldTime());
			w.playSoundAtEntity(p, "random.bow", 0.5F,
					0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
			if (!w.isRemote)
				w.spawnEntityInWorld(new EntitySnowball(w, p));
		}
		return super.onItemRightClick(stack, w, p);
	}

	@Override
	public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player,
										  int useRemaining) {
		long ticksSinceLastUse = player.worldObj.getTotalWorldTime() - getLastUseTime(stack);
		if (ticksSinceLastUse < 20)
			return new ModelResourceLocation(TestMod3.MODID + ":slingshot_pulled",
					"inventory");
		else return null;
	}

	private void setLastUseTime(ItemStack stack, long time) {
		stack.setTagInfo("LastUse", new NBTTagLong(time));
	}

	private long getLastUseTime(ItemStack stack) {
		return stack.hasTagCompound() ? stack.getTagCompound().getLong(
				"LastUse") : 0;
	}
}

@@ -758,16 +758,20 @@
  World w
+orld
 , Entity
@@ -778,16 +778,21 @@
 Player p
+layer
 ) %7B%0A%09%09if
@@ -794,16 +794,21 @@
 %0A%09%09if (p
+layer
 .capabil
@@ -831,17 +831,18 @@
 Mode
-%0A%09%09%09%09%7C%7C p
+ %7C%7C player
 .inv
@@ -847,21 +847,16 @@
 nventory
-%0A%09%09%09%09
 .consume
@@ -914,16 +914,20 @@
 stack, w
+orld
 .getTota
@@ -945,16 +945,20 @@
 ));%0A%09%09%09w
+orld
 .playSou
@@ -969,16 +969,21 @@
 Entity(p
+layer
 , %22rando
@@ -995,22 +995,17 @@
 %22, 0.5F,
-%0A%09%09%09%09%09
+ 
 0.4F / (
@@ -1042,16 +1042,17 @@
 0.8F));%0A
+%0A
 %09%09%09if (!
@@ -1052,16 +1052,20 @@
 %09%09if (!w
+orld
 .isRemot
@@ -1070,14 +1070,20 @@
 ote)
+ %7B
 %0A%09%09%09%09w
+orld
 .spa
@@ -1122,19 +1122,34 @@
 ll(w
-, p
+orld, player
 ));%0A
+%09
 %09%09%7D%0A
+%09%09%7D%0A%0A
 %09%09re
@@ -1184,19 +1184,28 @@
 stack, w
-, p
+orld, player
 );%0A%09%7D%0A%0A%09
@@ -1294,20 +1294,8 @@
 yer,
-%0A%09%09%09%09%09%09%09%09%09%09 
  int
@@ -1399,16 +1399,17 @@
 stack);%0A
+%0A
 %09%09if (ti
@@ -1429,16 +1429,18 @@
 se %3C 20)
+ %7B
 %0A%09%09%09retu
@@ -1509,14 +1509,9 @@
 ed%22,
-%0A%09%09%09%09%09
+ 
 %22inv
@@ -1526,13 +1526,13 @@
 ;%0A%09%09
-else 
+%7D%0A%0A%09%09
 retu
@@ -1773,21 +1773,16 @@
 getLong(
-%0A%09%09%09%09
 %22LastUse

Clean up code