use of net.minecraft.entity.projectile.AbstractArrowEntity 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));
}
}
}
use of net.minecraft.entity.projectile.AbstractArrowEntity 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;
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project minecolonies by Minecolonies.
the class RangerCombatAI method doAttack.
@Override
protected void doAttack(final LivingEntity target) {
if (user.distanceToSqr(target) < RANGED_FLEE_SQDIST) {
if (user.getRandom().nextInt(FLEE_CHANCE) == 0 && !((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getTask().equals(GuardTaskSetting.GUARD)) {
user.getNavigation().moveAwayFromLivingEntity(target, getAttackDistance() / 2.0, getCombatMovementSpeed());
}
} else {
user.getNavigation().stop();
}
user.getCitizenData().setVisibleStatus(ARCHER_COMBAT);
user.swing(Hand.MAIN_HAND);
int amountOfArrows = 1;
if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS) > 0) {
if (user.getRandom().nextDouble() < user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS)) {
amountOfArrows++;
}
}
for (int i = 0; i < amountOfArrows; i++) {
final AbstractArrowEntity arrow = CombatUtils.createArrowForShooter(user);
if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARROW_PIERCE) > 0) {
arrow.setPierceLevel((byte) 2);
}
// Add bow enchant effects: Knocback and fire
final ItemStack bow = user.getItemInHand(Hand.MAIN_HAND);
if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, bow) > 0) {
arrow.setSecondsOnFire(100);
}
final int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, bow);
if (k > 0) {
arrow.setKnockback(k);
}
double damage = calculateDamage(arrow);
arrow.setBaseDamage(damage);
final float chance = HIT_CHANCE_DIVIDER / (user.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Adaptability) + 1);
CombatUtils.shootArrow(arrow, target, chance);
user.playSound(SoundEvents.SKELETON_SHOOT, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(user.getRandom()));
}
target.setLastHurtByMob(user);
user.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
user.stopUsingItem();
user.decreaseSaturationForContinuousAction();
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project bioplethora by AquexTheSeal.
the class ServerWorldEvents method onProjectileHit.
@SubscribeEvent
public static void onProjectileHit(ProjectileImpactEvent event) {
AlphemKingSpawnHelper.onProjectileImpact(event);
Entity projectile = event.getEntity();
RayTraceResult result = event.getRayTraceResult();
if (result instanceof EntityRayTraceResult) {
// =================================================
// Totem of Swerving Skill
// =================================================
boolean targetIsEntity = ((EntityRayTraceResult) result).getEntity() instanceof LivingEntity;
if (projectile instanceof AbstractArrowEntity) {
((AbstractArrowEntity) projectile).setPierceLevel((byte) 0);
}
if (!projectile.level.isClientSide && targetIsEntity) {
LivingEntity user = ((LivingEntity) ((EntityRayTraceResult) result).getEntity());
int shouldDodge = user.getRandom().nextInt(3);
if ((user.getOffhandItem().getItem() instanceof SwervingTotemItem) || (user.getMainHandItem().getItem() instanceof SwervingTotemItem)) {
if (shouldDodge == 1) {
boolean isNegVal = user.getRandom().nextBoolean();
int tpLoc = 1 + user.getRandom().nextInt(2);
user.level.playSound(null, user.getX(), user.getY(), user.getZ(), SoundEvents.GHAST_SHOOT, SoundCategory.PLAYERS, 1, 1);
if (user.level instanceof ServerWorld) {
((ServerWorld) user.level).sendParticles(ParticleTypes.POOF, user.getX(), user.getY(), user.getZ(), 50, 0.65, 0.65, 0.65, 0.01);
}
BlockPos blockpos = new BlockPos(user.getX() + (isNegVal ? tpLoc : -tpLoc), user.getY(), user.getZ() + (isNegVal ? tpLoc : -tpLoc));
if (!user.level.getBlockState(blockpos).getMaterial().blocksMotion()) {
user.teleportTo(blockpos.getX(), blockpos.getY(), blockpos.getZ());
event.setCanceled(true);
}
}
}
}
// =================================================
// Mob Special Skills
// =================================================
boolean targetIsAltyrus = ((EntityRayTraceResult) result).getEntity() instanceof AltyrusEntity;
if (projectile instanceof AbstractArrowEntity) {
((AbstractArrowEntity) projectile).setPierceLevel((byte) 0);
}
if (!projectile.level.isClientSide() && targetIsAltyrus) {
AltyrusEntity altyrus = ((AltyrusEntity) ((EntityRayTraceResult) result).getEntity());
int shouldDodge = altyrus.getRandom().nextInt(3);
if ((shouldDodge == 1) || (shouldDodge == 2)) {
Vector3d projectilePos = event.getEntity().position();
Vector3d rVec = altyrus.getLookAngle().yRot(0.5F + (float) Math.PI).add(altyrus.position());
Vector3d lVec = altyrus.getLookAngle().yRot(0.5F + (float) Math.PI).add(altyrus.position());
BlockPos pos = new BlockPos((int) altyrus.getX(), (int) altyrus.getY(), (int) altyrus.getZ());
boolean rDir;
if (projectilePos.distanceTo(rVec) < projectilePos.distanceTo(lVec)) {
rDir = true;
} else if (projectilePos.distanceTo(rVec) > projectilePos.distanceTo(lVec)) {
rDir = false;
} else {
rDir = altyrus.getRandom().nextBoolean();
}
Vector3d vectorThingy = event.getEntity().getDeltaMovement().yRot((float) ((rDir ? 0.5F : -0.5F) * Math.PI)).normalize();
altyrus.setDodging(true);
altyrus.level.playSound(null, pos, altyrus.getDodgeSound(), SoundCategory.HOSTILE, (float) 1, (float) 1);
altyrus.setDeltaMovement(altyrus.getDeltaMovement().add(vectorThingy.x() * 0.5F, 0, vectorThingy.z() * 0.5F));
event.setCanceled(true);
}
}
boolean targetIsHelioblade = ((EntityRayTraceResult) result).getEntity() instanceof HeliobladeEntity;
if (!projectile.level.isClientSide && targetIsHelioblade) {
HeliobladeEntity helioblade = ((HeliobladeEntity) ((EntityRayTraceResult) result).getEntity());
int shouldDodge = helioblade.getRandom().nextInt(3);
if (projectile instanceof AbstractArrowEntity) {
((AbstractArrowEntity) projectile).setPierceLevel((byte) 0);
}
if ((shouldDodge == 1) || (shouldDodge == 2)) {
Vector3d projectilePos = event.getEntity().position();
Vector3d rVec = helioblade.getLookAngle().yRot(0.5F + (float) Math.PI).add(helioblade.position());
Vector3d lVec = helioblade.getLookAngle().yRot(0.5F + (float) Math.PI).add(helioblade.position());
BlockPos pos = new BlockPos((int) helioblade.getX(), (int) helioblade.getY(), (int) helioblade.getZ());
boolean rDir;
if (projectilePos.distanceTo(rVec) < projectilePos.distanceTo(lVec)) {
rDir = true;
} else if (projectilePos.distanceTo(rVec) > projectilePos.distanceTo(lVec)) {
rDir = false;
} else {
rDir = helioblade.getRandom().nextBoolean();
}
Vector3d vectorThingy = event.getEntity().getDeltaMovement().yRot((float) ((rDir ? 0.5F : -0.5F) * Math.PI)).normalize();
helioblade.setDeltaMovement(helioblade.getDeltaMovement().add(vectorThingy.x() * 1F, 0, vectorThingy.z() * 1F));
event.setCanceled(true);
}
}
boolean targetIsPrimordialRing = ((EntityRayTraceResult) result).getEntity() instanceof PrimordialRingEntity;
if (!projectile.level.isClientSide && targetIsPrimordialRing) {
PrimordialRingEntity primordialRing = ((PrimordialRingEntity) ((EntityRayTraceResult) result).getEntity());
if (projectile instanceof AbstractArrowEntity) {
((AbstractArrowEntity) projectile).setPierceLevel((byte) 0);
}
Vector3d projectilePos = event.getEntity().position();
Vector3d rVec = primordialRing.getLookAngle().yRot(0.5F + (float) Math.PI).add(primordialRing.position());
Vector3d lVec = primordialRing.getLookAngle().yRot(0.5F + (float) Math.PI).add(primordialRing.position());
boolean rDir;
if (projectilePos.distanceTo(rVec) < projectilePos.distanceTo(lVec)) {
rDir = true;
} else if (projectilePos.distanceTo(rVec) > projectilePos.distanceTo(lVec)) {
rDir = false;
} else {
rDir = primordialRing.getRandom().nextBoolean();
}
Vector3d vectorThingy = event.getEntity().getDeltaMovement().yRot((float) ((rDir ? 0.5F : -0.5F) * Math.PI)).normalize();
primordialRing.setDeltaMovement(primordialRing.getDeltaMovement().add(vectorThingy.x() * 1F, 0, vectorThingy.z() * 1F));
event.setCanceled(true);
}
}
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project endergetic by team-abnormals.
the class BoofBlockEntity method tick.
@Override
public void tick() {
AxisAlignedBB bb = this.getBoundingBox().inflate(0, 0.25F, 0);
List<Entity> entities = this.level.getEntitiesOfClass(Entity.class, bb, (entity -> !entity.isPassenger()));
for (Entity entity : entities) {
if (!EETags.EntityTypes.BOOF_BLOCK_RESISTANT.contains(entity.getType())) {
if (entity instanceof AbstractArrowEntity) {
this.setForProjectile(true);
this.level.setBlockAndUpdate(getOrigin(), Blocks.AIR.defaultBlockState());
entity.push(MathHelper.sin((float) (entity.yRot * Math.PI / 180.0F)) * 3 * 0.1F, 0.55D, -MathHelper.cos((float) (entity.yRot * Math.PI / 180.0F)) * 3 * 0.1F);
} else {
if (entity.getY() - 0.45F >= this.getY()) {
entity.push(0, this.random.nextFloat() * 0.05D + 0.35D, 0);
} else if (entity.getY() < this.getY() - 1F) {
entity.push(0, this.random.nextFloat() * -0.05D - 0.35D, 0);
} else {
float amount = 0.5F;
Vector3d result = entity.position().subtract(this.position());
entity.push(result.x * amount, this.random.nextFloat() * 0.45D + 0.25D, result.z * amount);
}
}
if (!(entity instanceof PlayerEntity)) {
entity.hurtMarked = true;
}
}
}
if (this.tickCount >= 10) {
if (this.level.isAreaLoaded(this.getOrigin(), 1) && this.level.getBlockState(getOrigin()).getBlock() == EEBlocks.BOOF_BLOCK.get() && !this.isForProjectile()) {
this.level.setBlockAndUpdate(this.getOrigin(), EEBlocks.BOOF_BLOCK.get().defaultBlockState());
} else if (this.level.isAreaLoaded(this.getOrigin(), 1) && this.isForProjectile()) {
this.level.setBlockAndUpdate(this.getOrigin(), EEBlocks.BOOF_BLOCK.get().defaultBlockState());
}
this.remove();
}
}
Aggregations