Search in sources :

Example 1 with ArrowItem

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

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)

Example 2 with ArrowItem

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

the class ItemPharaoScepter method customArrow.

@NotNull
@Override
public AbstractArrowEntity customArrow(@NotNull AbstractArrowEntity arrow) {
    AbstractArrowEntity entity = ((ArrowItem) ModItems.firearrow).createArrow(arrow.level, new ItemStack(ModItems.firearrow, 1), (LivingEntity) arrow.getOwner());
    entity.pickup = AbstractArrowEntity.PickupStatus.DISALLOWED;
    entity.setSecondsOnFire(3);
    return entity;
}
Also used : ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ArrowItem

use of net.minecraft.item.ArrowItem in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIAttackRanged method checkAndPerformAttack.

protected void checkAndPerformAttack(LivingEntity attackTarget) {
    if (this.entity.tickCount > this.prevTimeAttacked + this.getAttackCooldown()) {
        if (this.getAttackChargeTicks() > 0) {
            this.entity.startUsingItem(Hand.MAIN_HAND);
            this.entity.swinging = true;
        }
        if (this.entity.getUseItemRemainingTicks() >= this.getAttackChargeTicks()) {
            ItemStack stack = this.getEquippedWeapon();
            Item item = stack.getItem();
            if (item instanceof BowItem) {
                ItemStack arrowItem = this.entity.getItemStackFromExtraSlot(EntityEquipmentExtraSlot.ARROW);
                if (arrowItem.isEmpty() || !(arrowItem.getItem() instanceof ArrowItem)) {
                    arrowItem = new ItemStack(Items.ARROW);
                }
                AbstractArrowEntity arrow = ((ArrowItem) arrowItem.getItem()).createArrow(this.world, arrowItem, this.entity);
                // arrowItem.shrink(1);
                double x = attackTarget.getX() - this.entity.getX();
                double y = attackTarget.getY() + attackTarget.getBbHeight() * 0.5D - arrow.getY();
                double z = attackTarget.getZ() - this.entity.getZ();
                double distance = Math.sqrt(x * x + z * z);
                arrow.shoot(x, y + distance * distance * 0.0045D, z, 2.4F, this.getInaccuracy());
                /*arrow.motionX += this.entity.motionX;
					arrow.motionZ += this.entity.motionZ;
					if (!this.entity.onGround) {
						arrow.motionY += this.entity.motionY;
					}*/
                Vector3d shooterVec = this.entity.getDeltaMovement();
                arrow.setDeltaMovement(arrow.getDeltaMovement().add(shooterVec.x(), this.entity.isOnGround() ? 0 : shooterVec.y(), shooterVec.z()));
                this.world.addFreshEntity(arrow);
                this.entity.playSound(SoundEvents.ARROW_SHOOT, 1.0F, 0.8F + this.random.nextFloat() * 0.4F);
            } else if (item instanceof IRangedWeapon) {
                ((IRangedWeapon) item).shoot(this.world, this.entity, attackTarget, Hand.MAIN_HAND);
                if (((IRangedWeapon) item).getShootSound() != null) {
                    this.entity.playSound(((IRangedWeapon) item).getShootSound(), 1.0F, 0.8F + this.random.nextFloat() * 0.4F);
                }
            }
            this.prevTimeAttacked = this.entity.tickCount;
            if (this.getAttackChargeTicks() > 0) {
                this.entity.stopUsingItem();
                this.entity.swinging = false;
            } else {
                this.entity.startUsingItem(Hand.MAIN_HAND);
            }
        }
    }
}
Also used : Item(net.minecraft.item.Item) ArrowItem(net.minecraft.item.ArrowItem) BowItem(net.minecraft.item.BowItem) Vector3d(net.minecraft.util.math.vector.Vector3d) IRangedWeapon(team.cqr.cqrepoured.item.IRangedWeapon) BowItem(net.minecraft.item.BowItem) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 4 with ArrowItem

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

the class ItemPharaoScepter method customArrow.

@NotNull
@Override
public AbstractArrowEntity customArrow(@NotNull AbstractArrowEntity arrow) {
    AbstractArrowEntity entity = ((ArrowItem) ModItems.firearrow).createArrow(arrow.level, new ItemStack(ModItems.firearrow, 1), (LivingEntity) arrow.getOwner());
    entity.pickup = AbstractArrowEntity.PickupStatus.DISALLOWED;
    entity.setSecondsOnFire(3);
    return entity;
}
Also used : ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ArrowItem

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

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)

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