From 0059e92c2eed7b039a57208a93ed4b1b24cc131e Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 30 Sep 2020 20:53:23 +0200 Subject: [PATCH] Fixed attack goals, and fixed disguises hurting themselves --- .../entity/behaviour/MobBehaviour.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java index 9758e036..27acfbe2 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java @@ -8,11 +8,27 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.MobEntity; public class MobBehaviour extends EntityBehaviour { + + private MobEntity dummy; + @Override public void update(Pony player, MobEntity entity, DisguiseSpell spell) { if (player.sneakingChanged() && isSneakingOnGround(player)) { - entity.tryAttack(RayTraceHelper.findEntity(player.getEntity(), 6, 1, e -> e instanceof LivingEntity).orElse(entity)); + + LivingEntity target = RayTraceHelper.findEntity(player.getEntity(), 6, 1, + e -> e instanceof LivingEntity && e != entity && e != player.getOwner()) + .orElseGet(() -> getDummy(entity)); + + entity.tryAttack(target); + target.setAttacker(player.getOwner()); } } + + private MobEntity getDummy(MobEntity entity) { + if (dummy == null) { + dummy = (MobEntity)entity.getType().create(entity.world); + } + return dummy; + } }