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);
}
}
}
}
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;
}
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;
}
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;
}
Aggregations