Jump to content

Recommended Posts

Posted

I've been trying to make an entity that sits around the player like a shield and pushes any other entity away, however, although I got the push part, it pushes the player too. I've tried messing around for a while, but have not figured anything out, so help would be highly appreciated.

This is the code I'm using in the tick() method:

        for(LivingEntity livingentity : this.level.getEntitiesOfClass(LivingEntity.class, this.getBoundingBox())) {
                if(livingentity != this.getOwner()) {
                    this.push(livingentity);
                    this.push(livingentity);
                    this.push(livingentity);
                    this.push(livingentity);
                }

        }

Sanity is for losers. -Felix

Posted

I also tried using this method:

    private void pushEntity(LivingEntity entity) {
        LivingEntity livingentity = this.getOwner();
        if (entity.isAlive() && entity != livingentity) {
            if (livingentity.isAlliedTo(entity)) {
                return;
            }
            this.push(entity);
            this.push(entity);
            this.push(entity);
            this.push(entity);
        }
    }

and calling it in tick():

        for(LivingEntity livingentity : this.level.getEntitiesOfClass(LivingEntity.class, this.getBoundingBox())) {
                if(livingentity != this.getOwner()) {
                    this.pushEntity(livingentity);
                }

but it just says that livingentity is null.

Sanity is for losers. -Felix

Posted

Like this?:

        for(LivingEntity livingentity : this.level.getEntitiesOfClass(LivingEntity.class, this.getBoundingBox())) {
                if(!(livingentity instanceof ServerPlayer)) {
                    this.push(livingentity);
                }
        }

Because that didn't work (although I feel I executed what you said wrong).

Sanity is for losers. -Felix

Posted (edited)

Even then it would just not push any player instead of specifically the owner.

(Also for some reason continue; didn't work. So that's wack:

        for(LivingEntity livingentity : this.level.getEntitiesOfClass(LivingEntity.class, this.getBoundingBox())) {
                if(livingentity == this.getOwner()) {
                    continue;
                }
            this.push(livingentity);
            this.push(livingentity);
            this.push(livingentity);
            this.push(livingentity);
        }

)

Edited by xCrazyFeline

Sanity is for losers. -Felix

Posted

Yeah, so that worked:

        for(LivingEntity livingentity : this.level.getEntitiesOfClass(LivingEntity.class, this.getBoundingBox())) {
                if(!(livingentity instanceof Player)) {
                    this.push(livingentity);
                    this.push(livingentity);
                    this.push(livingentity);
                    this.push(livingentity);
                }
        }

I feel so stupid XD. Thanks for the help guys.

Sanity is for losers. -Felix

  • xCrazyFeline changed the title to [SOLVED] How to push every entity except the player.

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.