Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

  • 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

  • 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 by TheMajorN
Wording

  • 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.

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.