Search in sources :

Example 6 with ArrowItem

use of net.minecraft.item.ArrowItem in project minecolonies by Minecolonies.

the class RangerCombatAI method calculateDamage.

/**
 * Calculates the ranged attack damage
 *
 * @param arrow
 * @return the attack damage
 */
private double calculateDamage(final AbstractArrowEntity arrow) {
    int damage = user.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Agility) / 5;
    final ItemStack heldItem = user.getItemInHand(Hand.MAIN_HAND);
    damage += EnchantmentHelper.getDamageBonus(heldItem, target.getMobType()) / 2.5;
    damage += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, heldItem);
    damage += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_DAMAGE);
    if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_USE_ARROWS) > 0) {
        int slot = InventoryUtils.findFirstSlotInItemHandlerWith(user.getInventoryCitizen(), item -> item.getItem() instanceof ArrowItem);
        if (slot != -1) {
            if (!ItemStackUtils.isEmpty(user.getInventoryCitizen().extractItem(slot, 1, true))) {
                damage += ARROW_EXTRA_DAMAGE;
                ((CustomArrowEntity) arrow).setOnHitCallback(entityRayTraceResult -> {
                    final int arrowSlot = InventoryUtils.findFirstSlotInItemHandlerWith(user.getInventoryCitizen(), item -> item.getItem() instanceof ArrowItem);
                    if (arrowSlot != -1) {
                        user.getInventoryCitizen().extractItem(arrowSlot, 1, false);
                    }
                    return true;
                });
            }
        }
    }
    if (user.getHealth() <= user.getMaxHealth() * 0.2D) {
        damage *= 2;
    }
    return (RANGER_BASE_DMG + damage) * MineColonies.getConfig().getServer().rangerDamageMult.get();
}
Also used : CustomArrowEntity(com.minecolonies.coremod.entity.CustomArrowEntity) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ArrowItem

use of net.minecraft.item.ArrowItem in project Arclight by IzzelAliz.

the class BowItemMixin method onPlayerStoppedUsing.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
    if (entityLiving instanceof PlayerEntity) {
        PlayerEntity playerentity = (PlayerEntity) entityLiving;
        boolean flag = playerentity.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemstack = playerentity.findAmmo(stack);
        int i = this.getUseDuration(stack) - timeLeft;
        i = ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, i, !itemstack.isEmpty() || flag);
        if (i < 0)
            return;
        if (!itemstack.isEmpty() || flag) {
            if (itemstack.isEmpty()) {
                itemstack = new ItemStack(Items.ARROW);
            }
            float f = getArrowVelocity(i);
            if (!((double) f < 0.1D)) {
                boolean flag1 = playerentity.abilities.isCreativeMode || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity));
                if (!worldIn.isRemote) {
                    ArrowItem arrowitem = (ArrowItem) (itemstack.getItem() instanceof ArrowItem ? itemstack.getItem() : Items.ARROW);
                    AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerentity);
                    abstractarrowentity = customeArrow(abstractarrowentity);
                    abstractarrowentity.shoot(playerentity, playerentity.rotationPitch, playerentity.rotationYaw, 0.0F, f * 3.0F, 1.0F);
                    if (f == 1.0F) {
                        abstractarrowentity.setIsCritical(true);
                    }
                    int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
                    if (j > 0) {
                        abstractarrowentity.setDamage(abstractarrowentity.getDamage() + (double) j * 0.5D + 0.5D);
                    }
                    int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
                    if (k > 0) {
                        abstractarrowentity.setKnockbackStrength(k);
                    }
                    if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
                        abstractarrowentity.setFire(100);
                    }
                    EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(playerentity, itemstack, abstractarrowentity, f);
                    if (event.isCancelled()) {
                        event.getProjectile().remove();
                        return;
                    }
                    stack.damageItem(1, playerentity, (p_220009_1_) -> {
                        p_220009_1_.sendBreakAnimation(playerentity.getActiveHand());
                    });
                    if (flag1 || playerentity.abilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) {
                        abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
                    }
                    if (event.getProjectile() == ((EntityBridge) abstractarrowentity).bridge$getBukkitEntity()) {
                        if (!worldIn.addEntity(abstractarrowentity)) {
                            if (playerentity instanceof ServerPlayerEntityBridge) {
                                ((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity().updateInventory();
                            }
                            return;
                        }
                    }
                }
                worldIn.playSound((PlayerEntity) null, playerentity.posX, playerentity.posY, playerentity.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
                if (!flag1 && !playerentity.abilities.isCreativeMode) {
                    itemstack.shrink(1);
                    if (itemstack.isEmpty()) {
                        playerentity.inventory.deleteStack(itemstack);
                    }
                }
                playerentity.addStat(Stats.ITEM_USED.get(this));
            }
        }
    }
}
Also used : EntityShootBowEvent(org.bukkit.event.entity.EntityShootBowEvent) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 8 with ArrowItem

use of net.minecraft.item.ArrowItem in project Mekanism by mekanism.

the class ItemElectricBow method releaseUsing.

@Override
public void releaseUsing(@Nonnull ItemStack stack, @Nonnull World world, @Nonnull LivingEntity entityLiving, int timeLeft) {
    if (entityLiving instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) entityLiving;
        // Vanilla diff - Get the energy container, because if something went wrong, and we don't have one then we can exit early
        IEnergyContainer energyContainer = null;
        boolean fireState = getFireState(stack);
        if (!player.isCreative()) {
            energyContainer = StorageUtils.getEnergyContainer(stack, 0);
            FloatingLong energyNeeded = fireState ? MekanismConfig.gear.electricBowEnergyUsageFire.get() : MekanismConfig.gear.electricBowEnergyUsage.get();
            if (energyContainer == null || energyContainer.extract(energyNeeded, Action.SIMULATE, AutomationType.MANUAL).smallerThan(energyNeeded)) {
                return;
            }
        }
        boolean infinity = player.isCreative() || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, stack) > 0;
        ItemStack ammo = player.getProjectile(stack);
        int charge = ForgeEventFactory.onArrowLoose(stack, world, player, getUseDuration(stack) - timeLeft, !ammo.isEmpty() || infinity);
        if (charge < 0) {
            return;
        }
        if (!ammo.isEmpty() || infinity) {
            float velocity = getPowerForTime(charge);
            if (velocity < 0.1) {
                return;
            }
            if (ammo.isEmpty()) {
                ammo = new ItemStack(Items.ARROW);
            }
            boolean noConsume = player.isCreative() || (ammo.getItem() instanceof ArrowItem && ((ArrowItem) ammo.getItem()).isInfinite(ammo, stack, player));
            if (!world.isClientSide) {
                ArrowItem arrowitem = (ArrowItem) (ammo.getItem() instanceof ArrowItem ? ammo.getItem() : Items.ARROW);
                AbstractArrowEntity arrowEntity = arrowitem.createArrow(world, ammo, player);
                arrowEntity = customArrow(arrowEntity);
                arrowEntity.shootFromRotation(player, player.xRot, player.yRot, 0, 3 * velocity, 1);
                if (velocity == 1) {
                    arrowEntity.setCritArrow(true);
                }
                int power = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, stack);
                if (power > 0) {
                    arrowEntity.setBaseDamage(arrowEntity.getBaseDamage() + 0.5 * power + 0.5);
                }
                int punch = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, stack);
                if (punch > 0) {
                    arrowEntity.setKnockback(punch);
                }
                // Vanilla diff - set it on fire if the bow's mode is set to fire, even if there is no flame enchantment
                if (fireState || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) {
                    arrowEntity.setSecondsOnFire(100);
                }
                // Vanilla diff - Instead of damaging the item we remove energy from it
                if (!player.isCreative() && energyContainer != null) {
                    energyContainer.extract(fireState ? MekanismConfig.gear.electricBowEnergyUsageFire.get() : MekanismConfig.gear.electricBowEnergyUsage.get(), Action.EXECUTE, AutomationType.MANUAL);
                }
                if (noConsume || player.isCreative() && (ammo.getItem() == Items.SPECTRAL_ARROW || ammo.getItem() == Items.TIPPED_ARROW)) {
                    arrowEntity.pickup = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
                }
                world.addFreshEntity(arrowEntity);
            }
            world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ARROW_SHOOT, SoundCategory.PLAYERS, 1, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + velocity * 0.5F);
            if (!noConsume && !player.isCreative()) {
                ammo.shrink(1);
                if (ammo.isEmpty()) {
                    player.inventory.removeItem(ammo);
                }
            }
            player.awardStat(Stats.ITEM_USED.get(this));
        }
    }
}
Also used : FloatingLong(mekanism.api.math.FloatingLong) IEnergyContainer(mekanism.api.energy.IEnergyContainer) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 9 with ArrowItem

use of net.minecraft.item.ArrowItem in project minecolonies by ldtteam.

the class ItemPharaoScepter method releaseUsing.

@Override
public void releaseUsing(@NotNull final ItemStack stack, @NotNull final World worldIn, LivingEntity entityLiving, int timeLeft) {
    if (entityLiving instanceof PlayerEntity) {
        PlayerEntity playerentity = (PlayerEntity) entityLiving;
        int useDuration = this.getUseDuration(stack) - timeLeft;
        useDuration = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, useDuration, true);
        if (useDuration < 0) {
            return;
        }
        float speed = getPowerForTime(useDuration);
        if (!((double) speed < 0.1D)) {
            if (!worldIn.isClientSide) {
                ArrowItem arrowitem = (ArrowItem) Items.ARROW;
                AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, new ItemStack(arrowitem, 1), playerentity);
                abstractarrowentity = customArrow(abstractarrowentity);
                abstractarrowentity.shootFromRotation(playerentity, playerentity.xRot, playerentity.yRot, 0.0F, speed * 3.0F, 1.0F);
                if (speed == 1.0F) {
                    abstractarrowentity.setCritArrow(true);
                }
                int j = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, stack);
                if (j > 0) {
                    abstractarrowentity.setBaseDamage(abstractarrowentity.getBaseDamage() + (double) j * 0.5D + 0.5D);
                }
                int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, stack);
                if (k > 0) {
                    abstractarrowentity.setKnockback(k);
                }
                if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) {
                    abstractarrowentity.setSecondsOnFire(100);
                }
                stack.hurtAndBreak(1, playerentity, new Consumer<PlayerEntity>() {

                    @Override
                    public void accept(final PlayerEntity player) {
                        player.broadcastBreakEvent(playerentity.getUsedItemHand());
                    }
                });
                abstractarrowentity.pickup = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
                worldIn.addFreshEntity(abstractarrowentity);
            }
            worldIn.playSound(null, playerentity.getX(), playerentity.getY(), playerentity.getZ(), SoundEvents.ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + speed * 0.5F);
            playerentity.awardStat(Stats.ITEM_USED.get(this));
        }
    }
}
Also used : ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Aggregations

ArrowItem (net.minecraft.item.ArrowItem)9 ItemStack (net.minecraft.item.ItemStack)9 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)7 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 CustomArrowEntity (com.minecolonies.coremod.entity.CustomArrowEntity)2 NotNull (org.jetbrains.annotations.NotNull)2 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)1 IEnergyContainer (mekanism.api.energy.IEnergyContainer)1 FloatingLong (mekanism.api.math.FloatingLong)1 BowItem (net.minecraft.item.BowItem)1 Item (net.minecraft.item.Item)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 EntityShootBowEvent (org.bukkit.event.entity.EntityShootBowEvent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 IRangedWeapon (team.cqr.cqrepoured.item.IRangedWeapon)1