package janluca.quidditch.items;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.resources.Language;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.Sys;


/**
 * Created by Jan-Luca on 16.08.2016.
 */
public class BroomItem extends Item {

    public BroomItem(){
        setRegistryName("quidditch", "broom");
        setUnlocalizedName("broom");
        GameRegistry.register(this);

    }

    @Override
    public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {

        if(entityIn instanceof EntityPlayer){
            EntityPlayer player = (EntityPlayer) entityIn;
            if(!worldIn.isRemote && player.inventory.getStackInSlot(40).getUnlocalizedName().equals(this.getUnlocalizedName())){
                throwSnowball(worldIn, (EntityPlayer) entityIn);
            }
        }


    }

    @Override
    @SideOnly(Side.CLIENT)
    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
    {
        if(!worldIn.isRemote) {
            throwSnowball(worldIn, playerIn);
        }

        return new ActionResult(EnumActionResult.PASS, itemStackIn);
    }

    public void throwSnowball(World worldIn, EntityPlayer playerIn){

        EntityThrowable z = new EntitySnowball(worldIn);
        Vec3d lookDir = playerIn.getLookVec();
        z.setPosition(playerIn.posX+lookDir.xCoord, playerIn.posY + (double)playerIn.getEyeHeight() - 0.10000000149011612D, playerIn.posZ+lookDir.zCoord);
        z.setThrowableHeading(lookDir.xCoord, lookDir.yCoord, lookDir.zCoord, 1, 0);
        worldIn.spawnEntityInWorld(z);

    }

    @SideOnly(Side.CLIENT)
    public void initModel(){
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }

}

@@ -103,56 +103,8 @@
 on;%0A
-import net.minecraft.client.resources.Language;%0A
 impo
@@ -135,16 +135,16 @@
 Entity;%0A
+
 import n
@@ -299,55 +299,8 @@
 le;%0A
-import net.minecraft.inventory.InventoryBasic;%0A
 impo
@@ -770,26 +770,30 @@
 ly;%0A
+%0A
 import 
-org.lwjgl.S
+java.util.Arra
 ys;%0A
@@ -1167,16 +1167,53 @@
       if
+(!worldIn.isRemote) %7B%0A            if 
 (entityI
@@ -1238,16 +1238,17 @@
 yPlayer)
+ 
 %7B%0A      
@@ -1249,24 +1249,28 @@
             
+   
+ 
 EntityPlayer
@@ -1316,36 +1316,67 @@
         
-if(!worldIn.isRemote
+    if(player.inventory.offHandInventory%5B0%5D != null
  && play
@@ -1392,26 +1392,27 @@
 ory.
-getStackInSlot(40)
+offHandInventory%5B0%5D
 .get
@@ -1463,16 +1463,17 @@
 Name()))
+ 
 %7B%0A      
@@ -1474,32 +1474,36 @@
                 
+ 
+   
 throwSnowball(wo
@@ -1513,33 +1513,34 @@
 In, 
-(EntityPlayer) entityIn);
+player);%0A                %7D
 %0A   
@@ -1560,25 +1560,22 @@
       %7D%0A
-%0A%0A
     %7D%0A
-%0A
     @Ove
@@ -2119,23 +2119,8 @@
 posX
-+lookDir.xCoord
 , pl
@@ -2206,23 +2206,8 @@
 posZ
-+lookDir.zCoord
 );%0A 
@@ -2523,7 +2523,5 @@
   %7D%0A
-%0A%7D%0A
+%7D

Add files via upload