Search in sources :

Example 1 with MagmaCubeEntity

use of net.minecraft.entity.mob.MagmaCubeEntity in project wildmod by Osmiooo.

the class FrogGoal method tick.

public void tick() {
    World world = this.mob.getEntityWorld();
    Box box2 = new Box(this.mob.getBlockPos().add(-12, -4, -12), this.mob.getBlockPos().add(12, 6, 12));
    if (this.mob.isSubmergedInWater() && this.mob.isTouchingWater()) {
        if (world.getBlockState(this.mob.getBlockPos().up()) != Blocks.AIR.getDefaultState() && world.getBlockState(this.mob.getBlockPos().up()) != Blocks.WATER.getDefaultState()) {
            double angle = Math.random() * 360;
            double radius = Math.random() * 0.3;
            this.mob.setYaw((float) angle);
            this.mob.updateVelocity(2F, new Vec3d(-Math.sin(angle) * radius, 0, -Math.cos(angle) * radius));
            this.mob.getLookControl().lookAt(new Vec3d(-Math.sin(angle) * radius, 0, -Math.cos(angle) * radius));
        }
        if (Math.random() < 0.5) {
            double result;
            int radius = 3;
            BlockPos targetPos = null;
            ArrayList<BlockPos> targetList = checkforSafePlaceToGo(world, this.mob.getBlockPos(), radius);
            if (targetList.size() > 0) {
                result = Math.round(Math.random() * (targetList.size() - 1));
                targetPos = targetList.get((int) result);
            }
            if (!(targetPos == null)) {
                double dx = targetPos.getX() - this.mob.getBlockPos().getX();
                double dy = targetPos.getY() - this.mob.getBlockPos().getY();
                double dz = targetPos.getZ() - this.mob.getBlockPos().getZ();
                if (dy < 0) {
                    dy = 0;
                }
                if (Math.sqrt(dx * dx) > 0 || Math.sqrt(dz * dz) > 0) {
                    this.mob.updateVelocity(2F, new Vec3d(dx / 15, 0.1 + dy / 10, dz / 15));
                    this.mob.getLookControl().lookAt(new Vec3d(dx / 15, 0.1 + dy / 10, dz / 15));
                }
            }
        }
    }
    if (this.mob.isSubmergedInWater()) {
        if (Math.random() < 0.05) {
            double jumpamount = Math.random() / 4;
            double angle = Math.random() * 360;
            double radius = Math.random() / 10;
            this.mob.setYaw((float) angle);
            this.mob.updateVelocity(2F, new Vec3d(-Math.sin(angle) * radius, jumpamount, -Math.cos(angle) * radius));
            this.mob.getLookControl().lookAt(new Vec3d(-Math.sin(angle) * radius, jumpamount, -Math.cos(angle) * radius));
        }
    }
    if (this.mob.isOnGround()) {
        this.mob.setBodyYaw((float) Math.random());
        if (this.mob.getTongue() < 1) {
            double d = 3;
            List<SlimeEntity> slimes = this.mob.getWorld().getNonSpectatingEntities(SlimeEntity.class, box2);
            // List<FireflyEntity> fireflies = this.mob.getWorld().getNonSpectatingEntities(FireflyEntity.class, box2);
            List<GoatEntity> goats = this.mob.getWorld().getNonSpectatingEntities(GoatEntity.class, box2);
            ArrayList<LivingEntity> allEntities = new ArrayList<>();
            if (slimes.size() > 0) {
                for (SlimeEntity target : slimes) {
                    if (target.getSize() == 1) {
                        allEntities.add(target);
                    }
                }
            }
            // allEntities.addAll(fireflies);
            LivingEntity chosen = this.mob.getWorld().getClosestEntity(allEntities, TargetPredicate.DEFAULT, this.mob, this.mob.getX(), this.mob.getY(), this.mob.getZ());
            if (chosen != null) {
                this.mob.getNavigation().startMovingTo(chosen, 1.8);
            }
        }
    }
    if (Math.random() < 0.025) {
        double jumpamount = Math.random() / 2;
        if (jumpamount < 0.25) {
            jumpamount = 0.25;
        }
        if (Math.random() < 0.25) {
            // RANDOM JUMP
            double angle = Math.random() * 360;
            double radius = Math.random() * 0.3;
            this.mob.updateVelocity(2F, new Vec3d(-Math.sin(angle) * radius, jumpamount, -Math.cos(angle) * radius));
            this.mob.getLookControl().lookAt(new Vec3d(-Math.sin(angle) * radius, jumpamount, -Math.cos(angle) * radius));
            this.mob.playSound(RegisterSounds.ENTITY_FROG_LONG_JUMP, 1.0f, 1.0f);
        } else {
            // LILYPAD/DRIPLEAF JUMP
            double result;
            int radius = 5;
            BlockPos targetPos = null;
            ArrayList<BlockPos> targetList = Sphere.checkSpherePos(Blocks.LILY_PAD.getDefaultState(), this.mob.getEntityWorld(), this.mob.getBlockPos(), radius, true);
            ArrayList<BlockPos> northDripleafList = Sphere.checkSpherePos(Blocks.BIG_DRIPLEAF.getDefaultState().with(BigDripleafBlock.FACING, Direction.NORTH), this.mob.getEntityWorld(), this.mob.getBlockPos(), radius, true);
            ArrayList<BlockPos> southDripleafList = Sphere.checkSpherePos(Blocks.BIG_DRIPLEAF.getDefaultState().with(BigDripleafBlock.FACING, Direction.SOUTH), this.mob.getEntityWorld(), this.mob.getBlockPos(), radius, true);
            ArrayList<BlockPos> eastDripleafList = Sphere.checkSpherePos(Blocks.BIG_DRIPLEAF.getDefaultState().with(BigDripleafBlock.FACING, Direction.EAST), this.mob.getEntityWorld(), this.mob.getBlockPos(), radius, true);
            ArrayList<BlockPos> westDripleafList = Sphere.checkSpherePos(Blocks.BIG_DRIPLEAF.getDefaultState().with(BigDripleafBlock.FACING, Direction.WEST), this.mob.getEntityWorld(), this.mob.getBlockPos(), radius, true);
            targetList.addAll(northDripleafList);
            targetList.addAll(southDripleafList);
            targetList.addAll(eastDripleafList);
            targetList.addAll(westDripleafList);
            if (targetList.size() > 0) {
                result = Math.round(Math.random() * (targetList.size() - 1));
                targetPos = targetList.get((int) result);
            }
            if (!(targetPos == null)) {
                double dx = targetPos.getX() - this.mob.getBlockPos().getX();
                double dy = targetPos.getY() - this.mob.getBlockPos().getY();
                double dz = targetPos.getZ() - this.mob.getBlockPos().getZ();
                if (dy < 0) {
                    dy = 0;
                }
                if (Math.sqrt(dx * dx) > 0 || Math.sqrt(dz * dz) > 0) {
                    this.mob.updateVelocity(2F, new Vec3d(dx / 10, jumpamount + dy / 10, dz / 10));
                    this.mob.playSound(RegisterSounds.ENTITY_FROG_LONG_JUMP, 1.0f, 1.0f);
                }
            }
        }
    }
    /*List<FireflyEntity> list = world.getNonSpectatingEntities(FireflyEntity.class, box2);
        if (list.size() > 0) {
            if (world.getTime()-this.mob.eatTimer>=50 && this.mob.getBlockPos().getSquaredDistance(list.get(0).getBlockPos())<=6) {
                FireflyEntity target = list.get(0);
                world.sendEntityStatus(this.mob, (byte) 4);
                target.teleport(this.mob.getX(), this.mob.getY(), this.mob.getZ());
                target.setInvulnerable(true);
                this.mob.playSound(RegisterSounds.ENTITY_FROG_TONGUE, 1.0F, 1.0F);
                this.mob.targetRemoveTimer=10;
                this.mob.targetID=target.getId();
                this.mob.eatTimer = world.getTime();
            }
        }*/
    List<GoatEntity> goatlist = world.getNonSpectatingEntities(GoatEntity.class, box2);
    String string = Formatting.strip(this.mob.getName().getString());
    if ("Osmiooo".equals(string)) {
        if (goatlist.size() > 0) {
            for (GoatEntity target : goatlist) {
                if (world.getTime() - this.mob.eatTimer >= 50 && this.mob.getBlockPos().getSquaredDistance(target.getBlockPos()) <= 6) {
                    world.sendEntityStatus(this.mob, (byte) 4);
                    target.teleport(this.mob.getX(), this.mob.getY(), this.mob.getZ());
                    target.setInvulnerable(true);
                    this.mob.playSound(RegisterSounds.ENTITY_FROG_TONGUE, 1.0F, 1.0F);
                    this.mob.targetRemoveTimer = 10;
                    this.mob.targetID = target.getId();
                    this.mob.eatTimer = world.getTime();
                }
            }
        }
    }
    List<SlimeEntity> slimelist = world.getNonSpectatingEntities(SlimeEntity.class, box2);
    if (slimelist.size() > 0) {
        for (SlimeEntity target : slimelist) {
            if (target.getSize() == 1 && target.getType() != EntityType.MAGMA_CUBE && target.isAlive()) {
                if (world.getTime() - this.mob.eatTimer >= 50 && this.mob.getBlockPos().getSquaredDistance(target.getBlockPos()) <= 6) {
                    world.sendEntityStatus(this.mob, (byte) 4);
                    target.teleport(this.mob.getX(), this.mob.getY(), this.mob.getZ());
                    target.setInvulnerable(true);
                    this.mob.playSound(RegisterSounds.ENTITY_FROG_TONGUE, 1.0F, 1.0F);
                    this.mob.targetRemoveTimer = 10;
                    this.mob.targetID = target.getId();
                    this.mob.eatTimer = world.getTime();
                }
            }
        }
    }
    List<MagmaCubeEntity> magmalist = world.getNonSpectatingEntities(MagmaCubeEntity.class, box2);
    if (magmalist.size() > 0) {
        for (MagmaCubeEntity target : magmalist) {
            if (target.getSize() == 1 && target.isAlive()) {
                if (world.getTime() - this.mob.eatTimer >= 50 && this.mob.getBlockPos().getSquaredDistance(target.getBlockPos()) <= 6) {
                    world.sendEntityStatus(this.mob, (byte) 4);
                    target.teleport(this.mob.getX(), this.mob.getY(), this.mob.getZ());
                    target.setInvulnerable(true);
                    this.mob.playSound(RegisterSounds.ENTITY_FROG_TONGUE, 1.0F, 1.0F);
                    this.mob.targetRemoveTimer = 10;
                    this.mob.targetID = target.getId();
                    this.mob.eatTimer = world.getTime();
                }
            }
        }
    }
}
Also used : SlimeEntity(net.minecraft.entity.mob.SlimeEntity) ArrayList(java.util.ArrayList) Box(net.minecraft.util.math.Box) MagmaCubeEntity(net.minecraft.entity.mob.MagmaCubeEntity) World(net.minecraft.world.World) GoatEntity(net.minecraft.entity.passive.GoatEntity) Vec3d(net.minecraft.util.math.Vec3d) LivingEntity(net.minecraft.entity.LivingEntity) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

ArrayList (java.util.ArrayList)1 LivingEntity (net.minecraft.entity.LivingEntity)1 MagmaCubeEntity (net.minecraft.entity.mob.MagmaCubeEntity)1 SlimeEntity (net.minecraft.entity.mob.SlimeEntity)1 GoatEntity (net.minecraft.entity.passive.GoatEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 Box (net.minecraft.util.math.Box)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1