Fixed attack goals, and fixed disguises hurting themselves

This commit is contained in:
Sollace 2020-09-30 20:53:23 +02:00
parent 96e5af9743
commit 0059e92c2e

View file

@ -8,11 +8,27 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
public class MobBehaviour extends EntityBehaviour<MobEntity> {
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.<LivingEntity>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;
}
}