12 juil. 2016, 11:40

Bonjour,

Je vous explique mon soucis, quand je met la fonction onUpdate dans la class de mon arc qui est extends Item mon arc bug complètement je vous met un exemple car c’est compliquer a expliqué.

vidéo:
 https://www.youtube.com/watch?v=wThsb3Fi4jU&feature=youtu.be

Je vous glisse ma classe juste la:


public class FlameBow extends Item {

public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};
   @SideOnly(Side.CLIENT)
   private IIcon[] iconArray;

   public FlameBow()
   {
       this.maxStackSize = 1;
       this.setCreativeTab(CreativeTabs.tabCombat);
   }

   /**
    * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
    */
   public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int p_77615_4_)
   {
       int j = this.getMaxItemUseDuration(stack) - p_77615_4_;

       ArrowLooseEvent event = new ArrowLooseEvent(player, stack, j);
       MinecraftForge.EVENT_BUS.post(event);
       if (event.isCanceled())
       {
           return;
       }
       j = event.charge;

       boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;

       if (flag || player.inventory.hasItem(Items.arrow))
       {
           float f = (float)j / 20.0F;
           f = (f * f + f * 2.0F) / 3.0F;

           if ((double)f < 0.1D)
           {
               return;
           }

           if (f > 1.0F)
           {
               f = 1.0F;
           }

           EntityArrow entityarrow = new EntityArrow(world, player, f * 2.0F);

           if (f == 1.0F)
           {
               entityarrow.setIsCritical(true);
           }

           int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);

           if (k > 0)
           {
               entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
           }

           int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);

           if (l > 0)
           {
               entityarrow.setKnockbackStrength(l);
           }

           if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
           {
               entityarrow.setFire(100);
           }

           stack.damageItem(1, player);
           world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

           if (flag)
           {
               entityarrow.canBePickedUp = 2;
           }
           else
           {
            player.inventory.consumeInventoryItem(Items.arrow);
           }

           if (!world.isRemote)
           {
            world.spawnEntityInWorld(entityarrow);
            entityarrow.setFire(1 * 10);
            entityarrow.setDamage(20);
           }
       }
   }

   public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_)
   {
       return p_77654_1_;
   }

   /**
    * How long it takes to use or consume an item
    */
   public int getMaxItemUseDuration(ItemStack p_77626_1_)
   {
       return 72000;
   }

   /**
    * returns the action that specifies what animation to play when the items is being used
    */
   public EnumAction getItemUseAction(ItemStack p_77661_1_)
   {
       return EnumAction.bow;
   }

   /**
    * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
    */
   public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
   {
       ArrowNockEvent event = new ArrowNockEvent(p_77659_3_, p_77659_1_);
       MinecraftForge.EVENT_BUS.post(event);
       if (event.isCanceled())
       {
           return event.result;
       }

       if (p_77659_3_.capabilities.isCreativeMode || p_77659_3_.inventory.hasItem(Items.arrow))
       {
           p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));
       }

       return p_77659_1_;
   }

   /**
    * Return the enchantability factor of the item, most of the time is based on material.
    */
   public int getItemEnchantability()
   {
       return 1;
   }

   @SideOnly(Side.CLIENT)
   public void registerIcons(IIconRegister p_94581_1_)
   {
       this.itemIcon = p_94581_1_.registerIcon(this.getIconString() + "_standby");
       this.iconArray = new IIcon[bowPullIconNameArray.length];

       for (int i = 0; i < this.iconArray.length; ++i)
       {
           this.iconArray* = p_94581_1_.registerIcon(this.getIconString() + "_" + bowPullIconNameArray*);
       }
   }

   /**
    * used to cycle through icons based on their used duration, i.e. for the bow
    */
   @SideOnly(Side.CLIENT)
   public IIcon getItemIconForUseDuration(int p_94599_1_)
   {
       return this.iconArray[p_94599_1_];
   }

public void onUpdate(ItemStack item, World world, Entity player,
int slotIndex, boolean inHand) {
if(!item.hasTagCompound()) {
      item.setTagCompound(new NBTTagCompound());
}
int timer = !item.getTagCompound().hasKey("timer") ? 0 : item.getTagCompound().getInteger("timer");
timer++;
item.getTagCompound().setInteger("timer", timer);

super.onUpdate(item, world, player, slotIndex, inHand);
}

}

Voilà:) merci d’avance.

PS: aussi j’ai un soucis regarder la vidéo j’ai pas de flèches qui s’affiche sur mon arc.