use of io.github.bioplethora.entity.others.PrimordialRingEntity 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 io.github.bioplethora.entity.others.PrimordialRingEntity in project bioplethora by AquexTheSeal.
the class PrimordialStaffItem method releaseUsing.
public void releaseUsing(ItemStack stack, World worldIn, LivingEntity entity, int value) {
super.releaseUsing(stack, worldIn, entity, value);
if (entity instanceof PlayerEntity) {
PlayerEntity playerIn = (PlayerEntity) entity;
BlockPos blockpos = playerIn.blockPosition().offset(worldIn.getRandom().nextBoolean() ? -2 : 2, 0, worldIn.getRandom().nextBoolean() ? 2 : -2);
int i = this.getUseDuration(stack) - value;
if (i >= 10) {
if (worldIn instanceof ServerWorld) {
PrimordialRingEntity ring = BioplethoraEntities.PRIMORDIAL_RING.get().create(worldIn);
ring.moveTo(blockpos, 0.0F, 0.0F);
ring.setOwner(playerIn);
ring.finalizeSpawn((IServerWorld) worldIn, worldIn.getCurrentDifficultyAt(blockpos), SpawnReason.MOB_SUMMONED, null, null);
ring.setHasLimitedLife(true);
ring.setLifeLimitBeforeDeath(hellConfig ? 1000 : 850 + playerIn.getRandom().nextInt(200));
worldIn.addFreshEntity(ring);
PrimordialRingEntity ring2 = BioplethoraEntities.PRIMORDIAL_RING.get().create(worldIn);
ring2.moveTo(blockpos, 0.0F, 0.0F);
ring2.setOwner(playerIn);
ring2.finalizeSpawn((IServerWorld) worldIn, worldIn.getCurrentDifficultyAt(blockpos), SpawnReason.MOB_SUMMONED, null, null);
ring2.setHasLimitedLife(true);
ring2.setLifeLimitBeforeDeath(hellConfig ? 1000 : 850 + playerIn.getRandom().nextInt(200));
worldIn.addFreshEntity(ring2);
}
worldIn.playSound(null, blockpos, SoundEvents.GHAST_SHOOT, SoundCategory.PLAYERS, 1, 1);
if (worldIn instanceof ServerWorld) {
((ServerWorld) worldIn).sendParticles(ParticleTypes.POOF, (playerIn.getX()), (playerIn.getY()), (playerIn.getZ()), 100, 0.65, 0.65, 0.65, 0.01);
}
if (!playerIn.isCreative()) {
playerIn.getCooldowns().addCooldown(stack.getItem(), hellConfig ? 500 : 450 + playerIn.getRandom().nextInt(200));
}
}
}
}
Aggregations