Posted December 6, 20213 yr 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 December 6, 20213 yr by Spring
December 6, 20213 yr Author 8 minutes ago, diesieben07 said: Why would it return null? not null,bug size() is ZERO。I just want to know how to use it correctly Edited December 6, 20213 yr by Spring
December 6, 20213 yr Author 3 hours ago, diesieben07 said: WHAT? It’s weird that it doesn’t work sometimes,getNearbyEntities() return Empty collection
December 6, 20213 yr Author 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 December 6, 20213 yr by Spring
December 7, 20213 yr Author 11 hours ago, Luis_ST said: Use debugger to check which code is running and what the return values are He doesn't seem to work on Skeleton ? Zombies can
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.