Search in sources :

Example 1 with AltyrusEntity

use of io.github.bioplethora.entity.creatures.AltyrusEntity 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);
        }
    }
}
Also used : HeliobladeEntity(io.github.bioplethora.entity.creatures.HeliobladeEntity) PrimordialRingEntity(io.github.bioplethora.entity.others.PrimordialRingEntity) GrylynenEntity(io.github.bioplethora.entity.creatures.GrylynenEntity) Entity(net.minecraft.entity.Entity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AlphemKingEntity(io.github.bioplethora.entity.creatures.AlphemKingEntity) LivingEntity(net.minecraft.entity.LivingEntity) AltyrusEntity(io.github.bioplethora.entity.creatures.AltyrusEntity) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) AltyrusEntity(io.github.bioplethora.entity.creatures.AltyrusEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.world.server.ServerWorld) Vector3d(net.minecraft.util.math.vector.Vector3d) PrimordialRingEntity(io.github.bioplethora.entity.others.PrimordialRingEntity) HeliobladeEntity(io.github.bioplethora.entity.creatures.HeliobladeEntity) SwervingTotemItem(io.github.bioplethora.item.functionals.SwervingTotemItem) BlockPos(net.minecraft.util.math.BlockPos) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with AltyrusEntity

use of io.github.bioplethora.entity.creatures.AltyrusEntity in project bioplethora by AquexTheSeal.

the class AltyrusSummoningEntity method tick.

public void tick() {
    super.tick();
    ++birthTime;
    this.setDeltaMovement(this.getDeltaMovement().add(0, 0.5, 0));
    if (this.level instanceof ServerWorld) {
        ((ServerWorld) this.level).sendParticles(ParticleTypes.POOF, (this.getX()), (this.getY()), (this.getZ()), (int) 5, 1, 1, 1, 0.1);
    // this.summonParticleBarrier((ServerWorld) this.level);
    }
    if (this.birthTime >= 100) {
        if (!this.level.isClientSide) {
            this.level.explode(this, this.getX(), this.getY(0.0625D), this.getZ(), 5F, Explosion.Mode.BREAK);
            ServerWorld serverworld = (ServerWorld) this.level;
            BlockPos blockpos = (new BlockPos(this.getX(), this.getY(), this.getZ()));
            this.grantBirthAdvancement(32);
            AltyrusEntity altyrusEntity = BioplethoraEntities.ALTYRUS.get().create(this.level);
            altyrusEntity.moveTo(blockpos, 0.0F, 0.0F);
            altyrusEntity.finalizeSpawn(serverworld, this.level.getCurrentDifficultyAt(blockpos), SpawnReason.MOB_SUMMONED, (ILivingEntityData) null, (CompoundNBT) null);
            serverworld.addFreshEntity(altyrusEntity);
            this.remove();
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) AltyrusEntity(io.github.bioplethora.entity.creatures.AltyrusEntity) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

AltyrusEntity (io.github.bioplethora.entity.creatures.AltyrusEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 AlphemKingEntity (io.github.bioplethora.entity.creatures.AlphemKingEntity)1 GrylynenEntity (io.github.bioplethora.entity.creatures.GrylynenEntity)1 HeliobladeEntity (io.github.bioplethora.entity.creatures.HeliobladeEntity)1 PrimordialRingEntity (io.github.bioplethora.entity.others.PrimordialRingEntity)1 SwervingTotemItem (io.github.bioplethora.item.functionals.SwervingTotemItem)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)1 EntityRayTraceResult (net.minecraft.util.math.EntityRayTraceResult)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1