Jump to content

Find nearby monsters


Spring

Recommended Posts

i try use 

    private static final EntityPredicate PREDICATE = (new EntityPredicate()).allowUnseeable().ignoreInvisibilityTesting();
private static List<MobEntity> getNearbyEntities(PlayerEntity player) {
            double x = player.getX();
            double y = player.getY();
            double z = player.getZ();
            return player.level.getNearbyEntities(MobEntity.class, PREDICATE, player,
                    new AxisAlignedBB(x, y, z, x + 50, y + 50, z + 50));
        }

but it never return null       。size() is ZERO

Edited by Spring
Link to comment
Share on other sites

12 minutes ago, Spring said:

It’s weird that it doesn’t work sometimes,getNearbyEntities() return Empty collection

Maybe the method is not suitable for onArmorTick

I want to set the monster not to attack the player

 

        @Override
        public void onArmorTick(ItemStack stack, World world, PlayerEntity player) {

            List<MobEntity> mobEntities = getNearbyEntities(player);
            for (MobEntity mobEntity : mobEntities) {
                Optional<LivingEntity> target = Optional.ofNullable(mobEntity.getTarget());
                target.ifPresent(res -> {
                    if (res instanceof PlayerEntity) {
                        PlayerEntity targetPlayer = (PlayerEntity) res;
                        if (targetPlayer.getUUID().equals(player.getUUID())) {
                            mobEntity.setTarget(null);
                        }
                    }
                });
            }

 

Edited by Spring
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.