Search in sources :

Example 1 with ArrowShootEvent

use of cc.hyperium.event.entity.ArrowShootEvent in project Hyperium by HyperiumClient.

the class MixinItemBow method onPlayerStoppedUsing.

/**
 * @author Amp
 * @reason Events
 */
@Overwrite
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer entity, int timeLeft) {
    boolean infiniteArrows = entity.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
    if (infiniteArrows || entity.inventory.hasItem(Items.arrow)) {
        int maxTime = getMaxItemUseDuration(stack) - timeLeft;
        float pullBackTime = (float) maxTime / 20.0F;
        pullBackTime = (pullBackTime * pullBackTime + pullBackTime * 2.0F) / 3.0F;
        if ((double) pullBackTime < 0.1D)
            return;
        if (pullBackTime > 1.0F)
            pullBackTime = 1.0F;
        EntityArrow arrow = new EntityArrow(world, entity, pullBackTime * 2.0F);
        if (pullBackTime == 1.0F)
            arrow.setIsCritical(true);
        int powerEnchantmentLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
        if (powerEnchantmentLevel > 0)
            arrow.setDamage(arrow.getDamage() + (double) powerEnchantmentLevel * 0.5D + 0.5D);
        int punchEnchantmentLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
        if (punchEnchantmentLevel > 0)
            arrow.setKnockbackStrength(punchEnchantmentLevel);
        if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) {
            arrow.setFire(100);
        }
        stack.damageItem(1, entity);
        world.playSoundAtEntity(entity, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + pullBackTime * 0.5F);
        if (infiniteArrows)
            arrow.canBePickedUp = 2;
        else
            entity.inventory.consumeInventoryItem(Items.arrow);
        entity.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem((ItemBow) (Object) this)]);
        if (!world.isRemote)
            world.spawnEntityInWorld(arrow);
        EventBus.INSTANCE.post(new ArrowShootEvent(arrow, maxTime, stack));
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) ArrowShootEvent(cc.hyperium.event.entity.ArrowShootEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

ArrowShootEvent (cc.hyperium.event.entity.ArrowShootEvent)1 EntityArrow (net.minecraft.entity.projectile.EntityArrow)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1