Posted December 25, 20213 yr Heya, So I'm trying to call the getNearbyEntities method to check for creepers in an AABB radius, though one of the parameters requires a LivingEntity, and I can't seem to bend the rules around to making a creeper into one. For context, this is for the creeper proximity alarm. Here's the tick method in the tile entity so far: @Override public void tick() { BlockPos pos = getBlockPos().below(3); LivingEntity creeper = ???; AxisAlignedBB blockAABB = new AxisAlignedBB(pos); AxisAlignedBB creeperPos = EntityType.CREEPER.getAABB (5.0, 2.0, 5.0); assert level != null; List<MobEntity> entities = Objects.requireNonNull(Objects.requireNonNull(level .getBlockEntity(pos)).getLevel()).getNearbyEntities (MobEntity.class, EntityPredicate.DEFAULT, creeper, creeperPos); /* Also might need help comparing the entities to the position of the block to make it ring, but that's a problem for later. */ if (entities.equals(blockAABB)) { MagicItems.LOGGER.info("Creeper Alerted the bell!"); } } Unless the LivingEntity parameter is supposed to be the source of the radius? Which in that case how can I make it my block? Any help would be appreciated!
December 25, 20213 yr Author Oh I see, sorry I didn't see your reply to the last post. I'll use getEntities instead and see if that yields any better results
December 25, 20213 yr Author Sorry to continue pestering about this, but in the getEntities methods, there are two. I assume I'd have to use the one with 2 parameter, Entity and AABB because I don't see why I'd use a predicate if I'm not searching for some kind of condition in the creepers. If this is the case, is the Entity parameter the searcher or the searched? If it's the searcher, how can I set that to my block? If its the searched, I'm having trouble turning the creeper class to an Entity. Thanks for taking the time to help, I really do appreciate it. Edited December 25, 20213 yr by TheMajorN Wording
December 25, 20213 yr Author Alright so that works, thank you very much, but I'm still having some trouble with the comparing of the getEntities to the alarm block's AABB. I just tested with @Override public void tick() { BlockPos pos = getBlockPos().below(3); AxisAlignedBB blockAABB = new AxisAlignedBB(pos).inflate(5, 5, 5); assert level != null; List<CreeperEntity> entities = level.getEntities (EntityType.CREEPER, blockAABB, Predicates.alwaysTrue()); if (entities.equals(blockAABB)) { MagicItems.LOGGER.info("Creeper Alerted the bell!"); } } But that's not doing anything in-game. I'm gonna look through and make sure I have the tile entity correctly set up with my block, just to make sure it's not some dumb error, but I don't think that if statement is doing the job.
December 25, 20213 yr Author I got it to work with this! if (entities.size() > 0) { MagicItems.LOGGER.info("Creeper Alerted the bell!"); } Thanks so much for the help Diesie.
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.