Search in sources :

Example 1 with IRangedWeapon

use of team.cqr.cqrepoured.item.IRangedWeapon 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 2 with IRangedWeapon

use of team.cqr.cqrepoured.item.IRangedWeapon in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIAttackRanged method getAttackChargeTicks.

protected int getAttackChargeTicks() {
    ItemStack stack = this.getEquippedWeapon();
    Item item = stack.getItem();
    if (item instanceof BowItem) {
        return 20;
    } else if (item instanceof IRangedWeapon) {
        return ((IRangedWeapon) item).getChargeTicks();
    }
    return 40;
}
Also used : Item(net.minecraft.item.Item) ArrowItem(net.minecraft.item.ArrowItem) BowItem(net.minecraft.item.BowItem) IRangedWeapon(team.cqr.cqrepoured.item.IRangedWeapon) BowItem(net.minecraft.item.BowItem) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IRangedWeapon

use of team.cqr.cqrepoured.item.IRangedWeapon in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIAttackRanged method getAttackCooldown.

protected int getAttackCooldown() {
    ItemStack stack = this.getEquippedWeapon();
    Item item = stack.getItem();
    if (item instanceof BowItem) {
        switch(this.world.getDifficulty()) {
            case HARD:
                return 20;
            case NORMAL:
                return 30;
            default:
                return 40;
        }
    } else if (item instanceof IRangedWeapon) {
        return ((IRangedWeapon) item).getCooldown();
    }
    return 40;
}
Also used : Item(net.minecraft.item.Item) ArrowItem(net.minecraft.item.ArrowItem) BowItem(net.minecraft.item.BowItem) IRangedWeapon(team.cqr.cqrepoured.item.IRangedWeapon) BowItem(net.minecraft.item.BowItem) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IRangedWeapon

use of team.cqr.cqrepoured.item.IRangedWeapon in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIAttackRanged method getAttackRange.

protected double getAttackRange() {
    ItemStack stack = this.getEquippedWeapon();
    Item item = stack.getItem();
    if (item instanceof BowItem) {
        return 32.0D;
    } else if (item instanceof IRangedWeapon) {
        return ((IRangedWeapon) item).getRange();
    }
    return 32.0D;
}
Also used : Item(net.minecraft.item.Item) ArrowItem(net.minecraft.item.ArrowItem) BowItem(net.minecraft.item.BowItem) IRangedWeapon(team.cqr.cqrepoured.item.IRangedWeapon) BowItem(net.minecraft.item.BowItem) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ArrowItem (net.minecraft.item.ArrowItem)4 BowItem (net.minecraft.item.BowItem)4 Item (net.minecraft.item.Item)4 ItemStack (net.minecraft.item.ItemStack)4 IRangedWeapon (team.cqr.cqrepoured.item.IRangedWeapon)4 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1