Jump to content

Can I make a creeper a LivingEntity?


TheMajorN

Recommended Posts

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

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.

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

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

Announcements



×
×
  • Create New...

Important Information

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