Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package io.github.hsyyid.wilsonsmp.items;
- import io.github.hsyyid.wilsonsmp.proxies.CommonProxy;
- import net.minecraft.entity.item.EntityFireworkRocket;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- public class ItemSignalGun extends Item
- {
- public Item ammoItem;
- public int remainingBullets;
- public ItemSignalGun(Item ammoItem)
- {
- this.ammoItem = ammoItem;
- this.setCreativeTab(CommonProxy.wilsonSMPMisc);
- this.setMaxStackSize(1);
- this.setMaxDamage(1000);
- }
- public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
- {
- if (playerIn.capabilities.isCreativeMode || this.canDamageAmmo(worldIn, playerIn))
- {
- worldIn.playSoundAtEntity(playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
- if (!worldIn.isRemote)
- {
- try
- {
- EntityFireworkRocket entity = new EntityFireworkRocket(worldIn);
- entity.setPosition(playerIn.posX, playerIn.posY + 4, playerIn.posZ);
- entity.motionY = 0.1d;
- worldIn.spawnEntityInWorld(entity);
- itemStackIn.damageItem(1, playerIn);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- return itemStackIn;
- }
- return itemStackIn;
- }
- public boolean canDamageAmmo(World worldIn, EntityPlayer playerIn)
- {
- if (!worldIn.isRemote)
- {
- if (this.remainingBullets > 0)
- {
- this.remainingBullets--;
- return true;
- }
- else if (playerIn.inventory.hasItem(this.ammoItem))
- {
- for (ItemStack itemStack : playerIn.inventory.mainInventory)
- {
- if (itemStack != null && itemStack.getItem() != null && Item.getIdFromItem(this.ammoItem) == Item.getIdFromItem(itemStack.getItem()))
- {
- playerIn.inventory.consumeInventoryItem(itemStack.getItem());
- this.remainingBullets = 32;
- this.remainingBullets--;
- return true;
- }
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement