Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. package io.github.hsyyid.wilsonsmp.items;
  2.  
  3. import io.github.hsyyid.wilsonsmp.proxies.CommonProxy;
  4. import net.minecraft.entity.item.EntityFireworkRocket;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.item.Item;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.world.World;
  9.  
  10. public class ItemSignalGun extends Item
  11. {
  12.     public Item ammoItem;
  13.     public int remainingBullets;
  14.    
  15.     public ItemSignalGun(Item ammoItem)
  16.     {
  17.         this.ammoItem = ammoItem;
  18.         this.setCreativeTab(CommonProxy.wilsonSMPMisc);
  19.         this.setMaxStackSize(1);
  20.         this.setMaxDamage(1000);
  21.     }
  22.  
  23.     public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
  24.     {
  25.         if (playerIn.capabilities.isCreativeMode || this.canDamageAmmo(worldIn, playerIn))
  26.         {
  27.             worldIn.playSoundAtEntity(playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  28.  
  29.             if (!worldIn.isRemote)
  30.             {
  31.                 try
  32.                 {
  33.                     EntityFireworkRocket entity = new EntityFireworkRocket(worldIn);
  34.                     entity.setPosition(playerIn.posX, playerIn.posY + 4, playerIn.posZ);
  35.                     entity.motionY = 0.1d;
  36.                     worldIn.spawnEntityInWorld(entity);
  37.                     itemStackIn.damageItem(1, playerIn);
  38.                 }
  39.                 catch (Exception e)
  40.                 {
  41.                     e.printStackTrace();
  42.                 }
  43.             }
  44.  
  45.             return itemStackIn;
  46.         }
  47.  
  48.         return itemStackIn;
  49.     }
  50.  
  51.     public boolean canDamageAmmo(World worldIn, EntityPlayer playerIn)
  52.     {
  53.         if (!worldIn.isRemote)
  54.         {
  55.             if (this.remainingBullets > 0)
  56.             {
  57.                 this.remainingBullets--;
  58.                 return true;
  59.             }
  60.             else if (playerIn.inventory.hasItem(this.ammoItem))
  61.             {
  62.                 for (ItemStack itemStack : playerIn.inventory.mainInventory)
  63.                 {
  64.                     if (itemStack != null && itemStack.getItem() != null && Item.getIdFromItem(this.ammoItem) == Item.getIdFromItem(itemStack.getItem()))
  65.                     {
  66.                         playerIn.inventory.consumeInventoryItem(itemStack.getItem());
  67.                         this.remainingBullets = 32;
  68.                         this.remainingBullets--;
  69.                         return true;
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.        
  75.         return false;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement