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

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

  • Author

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

  • Author

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

  • Author

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

  • Author

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

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.