Posted September 12, 20232 yr 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
September 12, 20232 yr 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
September 12, 20232 yr Wrap it all in a block if(!livingentity instanseof ServerPlayer){ } Edited September 12, 20232 yr by andreybadrey
September 12, 20232 yr 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
September 13, 20232 yr 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 September 13, 20232 yr by xCrazyFeline Sanity is for losers. -Felix
September 13, 20232 yr 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
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.