xCrazyFeline Posted September 12, 2023 Posted September 12, 2023 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); } } Quote Sanity is for losers. -Felix
xCrazyFeline Posted September 12, 2023 Author Posted September 12, 2023 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. Quote Sanity is for losers. -Felix
andreybadrey Posted September 12, 2023 Posted September 12, 2023 (edited) Wrap it all in a block if(!livingentity instanseof ServerPlayer){ } Edited September 12, 2023 by andreybadrey Quote
xCrazyFeline Posted September 12, 2023 Author Posted September 12, 2023 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). Quote Sanity is for losers. -Felix
xCrazyFeline Posted September 13, 2023 Author Posted September 13, 2023 (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 September 13, 2023 by xCrazyFeline Quote Sanity is for losers. -Felix
peuloom Posted September 13, 2023 Posted September 13, 2023 Did you try if(!(livingentity instanceof Player)){ } 1 Quote
xCrazyFeline Posted September 13, 2023 Author Posted September 13, 2023 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. Quote Sanity is for losers. -Felix
Recommended Posts
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.