Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Find nearby monsters


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


        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())) {


Edited by Spring
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.