Search in sources :

Example 1 with WardenEntity

use of frozenblock.wild.mod.entity.WardenEntity in project wildmod by Osmiooo.

the class SculkShriekerBlock method findWarden.

public static boolean findWarden(World world, BlockPos pos) {
    double x1 = pos.getX();
    double y1 = pos.getY();
    double z1 = pos.getZ();
    BlockPos side1 = new BlockPos(x1 - 26, y1 - 26, z1 - 26);
    BlockPos side2 = new BlockPos(x1 + 26, y1 + 26, z1 + 26);
    Box box = (new Box(side1, side2));
    List<WardenEntity> list = world.getNonSpectatingEntities(WardenEntity.class, box);
    if (!list.isEmpty()) {
        Iterator<WardenEntity> var11 = list.iterator();
        WardenEntity warden;
        while (var11.hasNext()) {
            warden = var11.next();
            if (warden.getBlockPos().isWithinDistance(pos, (24))) {
                return true;
            }
        }
    }
    return false;
}
Also used : WardenEntity(frozenblock.wild.mod.entity.WardenEntity)

Example 2 with WardenEntity

use of frozenblock.wild.mod.entity.WardenEntity in project wildmod by Osmiooo.

the class SculkShriekerBlock method addShriek.

public static void addShriek(BlockPos pos, World world, int i) {
    if (world instanceof ServerWorld) {
        if (world.getTime() - timer < -90) {
            timer = 0;
            shrieks = 0;
        }
        if (world.getGameRules().getBoolean(WildMod.WARDEN_SPAWNING) && world.getTime() > timer) {
            timer = world.getTime() + 30;
            if (!findWarden(world, pos) || world.getGameRules().getBoolean(WildMod.NO_WARDEN_COOLDOWN)) {
                shrieks = shrieks + i;
                ArrayList<BlockPos> candidates = findBlock(pos, 9, false, world);
                if (!candidates.isEmpty()) {
                    timer = world.getTime() + 30;
                    if (shrieks >= 3) {
                        Iterator<BlockPos> var11 = candidates.iterator();
                        BlockPos currentCheck;
                        while (var11.hasNext()) {
                            currentCheck = var11.next();
                            if (world.isSkyVisible(currentCheck.up()) && !world.isNight()) {
                                world.playSound(null, currentCheck, RegisterSounds.ENTITY_WARDEN_AMBIENT, SoundCategory.HOSTILE, 0.4F, 0.8F);
                            }
                        }
                        currentCheck = getRandomSpawnable(candidates, world, new Random());
                        if (currentCheck != null) {
                            shrieks = 0;
                            WardenEntity warden = RegisterEntities.WARDEN.create(world);
                            assert warden != null;
                            warden.refreshPositionAndAngles(currentCheck.getX() + 0.5D, currentCheck.up(1).getY(), currentCheck.getZ() + 0.5D, 0.0F, 0.0F);
                            world.spawnEntity(warden);
                            warden.handleStatus((byte) 5);
                            warden.leaveTime = world.getTime() + 1200;
                            warden.setPersistent();
                            world.playSound(null, currentCheck, RegisterSounds.ENTITY_WARDEN_EMERGE, SoundCategory.HOSTILE, 1F, 1F);
                        }
                    }
                }
            }
        } else if (findWarden(world, pos)) {
            shrieks = 0;
        }
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) WardenEntity(frozenblock.wild.mod.entity.WardenEntity)

Example 3 with WardenEntity

use of frozenblock.wild.mod.entity.WardenEntity in project wildmod by Osmiooo.

the class SniffGoal method canStart.

public boolean canStart() {
    if (this.mob.roarTicksLeft1 > 0 || !this.mob.hasEmerged) {
        return false;
    }
    if (this.mob.hasDug || this.mob.emergeTicksLeft == -5) {
        return false;
    }
    if (this.mob.emergeTicksLeft > 0) {
        return false;
    }
    int r = this.mob.getRoarTicksLeft1();
    if (r > 0) {
        return false;
    }
    if (this.mob.emergeTicksLeft > 0) {
        return false;
    }
    if (this.mob.sniffCooldown > 0) {
        return false;
    }
    if (this.mob.world.getDifficulty().getId() == 0) {
        return false;
    }
    boolean exit = false;
    LivingEntity sniffEntity = null;
    if (this.mob.mostSuspiciousAround() != null) {
        sniffEntity = this.mob.mostSuspiciousAround();
    }
    if (sniffEntity == null) {
        LivingEntity closestPlayer = this.mob.world.getClosestPlayer(this.mob, 16);
        sniffEntity = closestPlayer;
        if (closestPlayer == null) {
            Box box = new Box(this.mob.getBlockPos().add(-16, -16, -16), this.mob.getBlockPos().add(16, 16, 16));
            List<LivingEntity> entities = this.mob.world.getNonSpectatingEntities(LivingEntity.class, box);
            LivingEntity chosen = this.mob.world.getClosestEntity(entities, TargetPredicate.DEFAULT, this.mob, this.mob.getX(), this.mob.getY(), this.mob.getZ());
            if (chosen != null && !(chosen instanceof WardenEntity) && MathAddon.distance(chosen.getX(), chosen.getY(), chosen.getZ(), this.mob.getX(), this.mob.getY(), this.mob.getZ()) <= 16 && chosen.getType() != RegisterEntities.WARDEN) {
                sniffEntity = chosen;
            }
        }
    }
    if (sniffEntity != null && this.mob.roarOtherCooldown <= 0 && this.mob.movementPriority == 0 && this.mob.wanderTicksLeft <= 0 && this.mob.canSniff) {
        exit = true;
    }
    if (exit && sniffEntity instanceof PlayerEntity) {
        exit = !((PlayerEntity) sniffEntity).getAbilities().creativeMode;
    }
    return exit;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) WardenEntity(frozenblock.wild.mod.entity.WardenEntity) Box(net.minecraft.util.math.Box) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 4 with WardenEntity

use of frozenblock.wild.mod.entity.WardenEntity in project wildmod by Osmiooo.

the class SniffGoal method start.

public void start() {
    LivingEntity sniffEntity = null;
    if (this.mob.mostSuspiciousAround() != null) {
        sniffEntity = this.mob.mostSuspiciousAround();
    }
    if (sniffEntity == null) {
        LivingEntity closestPlayer = this.mob.world.getClosestPlayer(this.mob, 16);
        sniffEntity = closestPlayer;
        if (closestPlayer == null) {
            Box box = new Box(this.mob.getBlockPos().add(-16, -16, -16), this.mob.getBlockPos().add(16, 16, 16));
            List<LivingEntity> entities = this.mob.world.getNonSpectatingEntities(LivingEntity.class, box);
            LivingEntity chosen = this.mob.world.getClosestEntity(entities, TargetPredicate.DEFAULT, this.mob, this.mob.getX(), this.mob.getY(), this.mob.getZ());
            if (chosen != null && !(chosen instanceof WardenEntity) && MathAddon.distance(chosen.getX(), chosen.getY(), chosen.getZ(), this.mob.getX(), this.mob.getY(), this.mob.getZ()) <= 16) {
                sniffEntity = chosen;
            }
        }
    }
    if (sniffEntity != null) {
        if (MathAddon.distance(sniffEntity.getX(), sniffEntity.getY(), sniffEntity.getZ(), this.mob.getX(), this.mob.getY(), this.mob.getZ()) <= 16) {
            this.mob.getNavigation().stop();
            this.mob.canSniff = false;
            this.mob.world.sendEntityStatus(this.mob, (byte) 10);
            this.mob.sniffTicksLeft = 53;
            this.mob.sniffCooldown = 163;
            this.mob.ticksToWander = 100;
            this.mob.wanderTicksLeft = 0;
            this.mob.movementPriority = 2;
            this.mob.sniffX = sniffEntity.getX();
            this.mob.sniffY = sniffEntity.getY();
            this.mob.sniffZ = sniffEntity.getZ();
            this.mob.sniffEntity = sniffEntity.getUuidAsString();
            this.mob.world.playSound(null, this.mob.getCameraBlockPos(), RegisterSounds.ENTITY_WARDEN_SNIFF, SoundCategory.HOSTILE, 1F, 1F);
            this.mob.leaveTime = this.mob.getWorld().getTime() + 1200;
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) WardenEntity(frozenblock.wild.mod.entity.WardenEntity) Box(net.minecraft.util.math.Box)

Example 5 with WardenEntity

use of frozenblock.wild.mod.entity.WardenEntity in project wildmod by Osmiooo.

the class SimpleGameEventDispatcherMixin method dispatch.

@Inject(at = @At("HEAD"), method = "dispatch")
private void dispatch(GameEvent event, Entity entity, BlockPos pos, CallbackInfo ci) {
    BlockPos eventpos;
    World eventworld;
    LivingEntity evententity;
    if (SculkSensorBlock.FREQUENCIES.containsKey(event)) {
        if (entity == null) {
            eventpos = pos;
            eventworld = this.world;
            evententity = null;
        } else {
            if (entity.getType() == EntityType.PLAYER) {
                if (event == GameEvent.STEP || event == GameEvent.HIT_GROUND || event == GameEvent.PROJECTILE_SHOOT) {
                    if (entity.isSneaking()) {
                        eventpos = null;
                        eventworld = null;
                        evententity = null;
                    } else {
                        PlayerEntity player = (PlayerEntity) entity;
                        Item booties = player.getEquippedStack(EquipmentSlot.FEET).getItem();
                        Identifier identity = Registry.ITEM.getId(booties);
                        if (new Identifier("wooledboots", "wooled_chainmail_boots").equals(identity) || new Identifier("wooledboots", "wooled_gold_boots").equals(identity) || new Identifier("wooledboots", "wooled_diamond_boots").equals(identity) || new Identifier("wooledboots", "wooled_netherite_boots").equals(identity) || new Identifier("wooledboots", "wooled_iron_boots").equals(identity)) {
                            eventpos = null;
                            eventworld = null;
                            evententity = null;
                        } else {
                            eventpos = pos;
                            eventworld = entity.getEntityWorld();
                            evententity = (LivingEntity) entity;
                        }
                    }
                } else {
                    eventpos = pos;
                    eventworld = entity.getEntityWorld();
                    evententity = (LivingEntity) entity;
                }
            } else if (entity.getType() != RegisterEntities.WARDEN) {
                eventpos = pos;
                eventworld = entity.getEntityWorld();
                if (entity.isLiving()) {
                    evententity = (LivingEntity) entity;
                } else {
                    evententity = null;
                }
            } else {
                eventpos = null;
                eventworld = null;
                evententity = null;
            }
        }
        boolean bl1 = evententity != null || event == GameEvent.EAT || event == GameEvent.HIT_GROUND;
        if (eventpos != null && eventworld != null && bl1) {
            List<WardenEntity> wardens = this.world.getNonSpectatingEntities(WardenEntity.class, new Box(eventpos.getX() - 18, eventpos.getY() - 18, eventpos.getZ() - 18, eventpos.getX() + 18, eventpos.getY() + 18, eventpos.getZ() + 18));
            Iterator<WardenEntity> var11 = wardens.iterator();
            WardenEntity wardie;
            while (var11.hasNext()) {
                wardie = var11.next();
                // System.out.println(Math.floor(Math.sqrt(wardie.getBlockPos().getSquaredDistance(eventpos, false))));
                if (wardie.getEntityWorld() == eventworld && Math.floor(Math.sqrt(wardie.getBlockPos().getSquaredDistance(eventpos, false))) <= 16) {
                    boolean bl2 = event == GameEvent.HIT_GROUND && evententity == null;
                    if (event != GameEvent.PROJECTILE_LAND && event != GameEvent.EAT && !bl2) {
                        wardie.listen(eventpos, eventworld, evententity, wardie.eventSuspicionValue(event, evententity), null);
                    } else {
                        wardie.listen(eventpos, eventworld, null, 0, null);
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Item(net.minecraft.item.Item) Identifier(net.minecraft.util.Identifier) WardenEntity(frozenblock.wild.mod.entity.WardenEntity) BlockPos(net.minecraft.util.math.BlockPos) Box(net.minecraft.util.math.Box) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

WardenEntity (frozenblock.wild.mod.entity.WardenEntity)9 LivingEntity (net.minecraft.entity.LivingEntity)7 BlockPos (net.minecraft.util.math.BlockPos)5 Box (net.minecraft.util.math.Box)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 Inject (org.spongepowered.asm.mixin.injection.Inject)3 World (net.minecraft.world.World)2 SculkShriekerBlock (frozenblock.wild.mod.blocks.SculkShriekerBlock)1 Item (net.minecraft.item.Item)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 Identifier (net.minecraft.util.Identifier)1 GameEvent (net.minecraft.world.event.GameEvent)1