Search in sources :

Example 1 with PrimordialRingEntity

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

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));
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IServerWorld(net.minecraft.world.IServerWorld) PrimordialRingEntity(io.github.bioplethora.entity.others.PrimordialRingEntity) BlockPos(net.minecraft.util.math.BlockPos) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

PrimordialRingEntity (io.github.bioplethora.entity.others.PrimordialRingEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 AlphemKingEntity (io.github.bioplethora.entity.creatures.AlphemKingEntity)1 AltyrusEntity (io.github.bioplethora.entity.creatures.AltyrusEntity)1 GrylynenEntity (io.github.bioplethora.entity.creatures.GrylynenEntity)1 HeliobladeEntity (io.github.bioplethora.entity.creatures.HeliobladeEntity)1 SwervingTotemItem (io.github.bioplethora.item.functionals.SwervingTotemItem)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)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 IServerWorld (net.minecraft.world.IServerWorld)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1