Кулдаун

Версия Minecraft
1.7.10
У меня есть предмет Коса-Винтовка(Смена режима на шифт+пкм)
bandicam_2018-02-23_11-26-19-487.gif
При стрельбе можно натягивать как лук, но стреляет все-равно даже если флудить пкм:
Как сделать кулдаун а то у меня что-то не получается.
Java:
package ruby;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowNockEvent;

public class item_ruby_scythe extends ItemSword {

   private float weaponDamage;
   public float SwordATK;
   public float SPEFT;
   public float ENT;
   public Item DUST;
   public static float ItemMode;
   public static String ItemModeName;
   private final ToolMaterial toolMaterial;
   private Random rand;
   private IIcon itemIcon2;
   private IIcon itemIcon3;
   private IIcon itemIcon1;
   private static int ammo_hit;
   private int cooldown;


   public item_ruby_scythe(ToolMaterial par2EnumToolMaterial, float SwordAtk, float SpEft, Item Dust) {
      super(par2EnumToolMaterial);
      this.toolMaterial = par2EnumToolMaterial;
      super.maxStackSize = 1;
      this.setMaxDamage(par2EnumToolMaterial.getMaxUses());
      this.setCreativeTab(CreativeTabs.tabCombat);
      this.weaponDamage = this.SwordATK + 4.0F + par2EnumToolMaterial.getDamageVsEntity();
      SwordAtk = this.SwordATK;
      this.SPEFT = SpEft;
      this.DUST = Dust;
      ItemMode = 0.0F;
      ItemModeName = "Коса";
   }

   @SideOnly(Side.CLIENT)
   public void addInformation(ItemStack par1, EntityPlayer par2, List par3, boolean bool) {
      par3.add(EnumChatFormatting.RED + "Высоко калиберная Снайпер-Коса");
      ItemMode = get_Crescent_Rose_State(par1);
      if(ItemMode == 1.0F) {
         ItemModeName = "Оружие";
      } else if(ItemMode == 0.0F) {
         ItemModeName = "Коса";
      }
      par3.add(EnumChatFormatting.DARK_GRAY + "Режим: " + ItemModeName);
      ammo_hit = get_ammo(par1);
      par3.add(EnumChatFormatting.GRAY + "Патронов : " + ammo_hit);
   }

   public static int get_col(ItemStack itemstack) {
      return itemstack.hasTagCompound()?itemstack.getTagCompound().getInteger("col"):0;
   }

   public static void set_col(ItemStack itemstack, int flag) {
      if(!itemstack.hasTagCompound()) {
         itemstack.setTagCompound(new NBTTagCompound());
      }

      itemstack.getTagCompound().setInteger("col", flag);
   }

   public static int get_ammo(ItemStack itemstack) {
      return itemstack.hasTagCompound()?itemstack.getTagCompound().getInteger("Ammo"):0;
   }

   public static void set_ammo(ItemStack itemstack, int flag) {
      if(!itemstack.hasTagCompound()) {
         itemstack.setTagCompound(new NBTTagCompound());
      }

      itemstack.getTagCompound().setInteger("Ammo", flag);
   }

   public static float get_Crescent_Rose_State(ItemStack itemstack) {
      return itemstack.hasTagCompound()?itemstack.getTagCompound().getFloat("Crescent_Rose"):0.0F;
   }

   public static void set_Crescent_Rose_State(ItemStack itemstack, float flag) {
      if(!itemstack.hasTagCompound()) {
         itemstack.setTagCompound(new NBTTagCompound());
      }

      itemstack.getTagCompound().setFloat("Crescent_Rose", flag);
   }

   public float func_82803_g() {
      return this.toolMaterial.getDamageVsEntity();
   }

   public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
      EntityPlayer Player = (EntityPlayer)par3Entity;
      ItemStack item = Player.getCurrentEquippedItem();
      if(par1ItemStack == item) {
         Player.addPotionEffect(new PotionEffect(Potion.jump.id, 0, 1));
         Player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 0, 1));
         Player.fallDistance = 0.0F;
      }
      cooldown++;
      if(cooldown == 1000) {
          cooldown = 100;
      }
   }

   public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) {
      Vec3 look = par3EntityLivingBase.getLookVec();
      par3EntityLivingBase.motionX = look.xCoord;
      par3EntityLivingBase.motionZ = look.zCoord;
      par3EntityLivingBase.motionY = look.yCoord;
      par3EntityLivingBase.lastTickPosZ = look.xCoord;
      par3EntityLivingBase.lastTickPosX = look.zCoord;
      set_Crescent_Rose_State(par1ItemStack, 0.0F);
      par1ItemStack.damageItem(1, par3EntityLivingBase);
      return true;
   }



   public EnumAction getItemUseAction(ItemStack par1ItemStack) {
          ItemMode = get_Crescent_Rose_State(par1ItemStack);
          return ItemMode == 1.0F?EnumAction.bow:EnumAction.block;
       }

   public int getMaxItemUseDuration(ItemStack par1ItemStack) {
      return 72000;
   }

   public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) {
      ItemMode = get_Crescent_Rose_State(par1ItemStack);
      ammo_hit = get_ammo(par1ItemStack);
      if(ItemMode == 1.0F) {
          if(par3EntityPlayer.isSneaking()) {
              set_Crescent_Rose_State(par1ItemStack, 0.0F);
      }else if(par3EntityPlayer.capabilities.isCreativeMode || get_ammo(par1ItemStack) > 0 || par3EntityPlayer.inventory.hasItem(Main.fire_dust_ammo)) {
          par2World.playSoundAtEntity(par3EntityPlayer, "serega:rose.gun", 1.0F, 1.0F);
         Vec3 look;
         EntityArrow fireball;
         if(par3EntityPlayer.isSneaking()) {
            look = par3EntityPlayer.getLookVec();
            par3EntityPlayer.motionX = -look.xCoord / 4.0D;
            par3EntityPlayer.motionZ = -look.zCoord / 4.0D;
            par3EntityPlayer.motionY = -look.yCoord / 4.0D;
            par3EntityPlayer.lastTickPosZ = -look.xCoord / 4.0D;
            par3EntityPlayer.lastTickPosX = -look.zCoord / 4.0D;
            if(!par2World.isRemote) {
               fireball = new EntityArrow(par2World, par3EntityPlayer, 5.0F);
               fireball.canBePickedUp = 0;
               par2World.spawnEntityInWorld(fireball);
               par1ItemStack.damageItem(2, par3EntityPlayer);
            }

            par1ItemStack.damageItem(2, par3EntityPlayer);
         } else {
            look = par3EntityPlayer.getLookVec();
            par3EntityPlayer.motionX = -look.xCoord;
            par3EntityPlayer.motionZ = -look.zCoord;
            par3EntityPlayer.motionY = -look.yCoord / 2.0D;
            par3EntityPlayer.lastTickPosZ = -look.xCoord;
            par3EntityPlayer.lastTickPosX = -look.zCoord;
            if(!par2World.isRemote) {
               fireball = new EntityArrow(par2World, par3EntityPlayer, 5.0F);
               fireball.canBePickedUp = 0;

               par2World.spawnEntityInWorld(fireball);
               par1ItemStack.damageItem(2, par3EntityPlayer);
            }

            par1ItemStack.damageItem(2, par3EntityPlayer);
         }

         if(!par3EntityPlayer.capabilities.isCreativeMode) {
            if(get_ammo(par1ItemStack) > 0) {
               set_ammo(par1ItemStack, get_ammo(par1ItemStack) - 1);
            } else {
               set_ammo(par1ItemStack, get_ammo(par1ItemStack) + 7);
               par3EntityPlayer.inventory.consumeInventoryItem(Main.fire_dust_ammo);
               if(!par2World.isRemote) {
                  par3EntityPlayer.dropItem(Main.fire_dust_ammo_out, 1);
               }
            }
         }
      }
   }else if(ItemMode == 0.0F && par3EntityPlayer.isSneaking()) {
       set_Crescent_Rose_State(par1ItemStack, 1.0F);
    }
   }

   public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
          ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
          MinecraftForge.EVENT_BUS.post(event);
          if(event.isCanceled()) {
             return event.result;
          } else {
             if (cooldown > 80) {
                  par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
              }
              cooldown = 0;
             return par1ItemStack;
          }
   }

   public void registerIcons(IIconRegister par1IconRegister) {
      super.itemIcon = par1IconRegister.registerIcon("ruby:" + this.getUnlocalizedName());
      this.itemIcon1 = par1IconRegister.registerIcon("ruby:" + this.getUnlocalizedName() + "_gr");
      this.itemIcon2 = par1IconRegister.registerIcon("ruby:" + this.getUnlocalizedName() + "_d_gr");
      this.itemIcon3 = par1IconRegister.registerIcon("ruby:" + this.getUnlocalizedName() + "_ye");
   }

   public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
      return this.getIcon(stack, renderPass);
   }

   @SideOnly(Side.CLIENT)
   public boolean requiresMultipleRenderPasses() {
      return true;
   }

   public IIcon getIcon(ItemStack stack, int renderPass) {
      return get_col(stack) == 0?super.itemIcon:(get_col(stack) == 1?this.itemIcon1:(get_col(stack) == 2?this.itemIcon2:this.itemIcon3));
   }
}
 
Решение
Java:
public int getMaxItemUseDuration(ItemStack itemstack) {
      return 40;//время в тиках
   }


public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
         
             entityplayer.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
         

          return itemstack;
       }
public ItemStack onEaten(ItemStack itemstack, World world, EntityPlayer entityplayer) {
     
         //твой код
        return itemstack;
      }
Вместо метода onEaten можно использовать какой-то другой, но у меня был только такой пример
1,007
36
206
Java:
public int getMaxItemUseDuration(ItemStack itemstack) {
      return 40;//время в тиках
   }


public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
         
             entityplayer.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
         

          return itemstack;
       }
public ItemStack onEaten(ItemStack itemstack, World world, EntityPlayer entityplayer) {
     
         //твой код
        return itemstack;
      }
Вместо метода onEaten можно использовать какой-то другой, но у меня был только такой пример
 
Сверху