use of io.github.bioplethora.item.functionals.SwervingTotemItem 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);
}
}
}
Aggregations