Commit 552e5e33 by Jonathan Thomas

Fixing issues with setting attacker and not allowing entities to target or attack themselves

parent 437a3695
Pipeline #12564 passed with stages
in 2 minutes 11 seconds
......@@ -33,11 +33,6 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
this.attackerEntity = attackerEntity;
this.speed = speed;
this.setControls(EnumSet.of(Control.MOVE, Control.LOOK, Control.TARGET));
// Set the target
if (this.targetEntity != null) {
this.attackerEntity.setTarget(this.targetEntity);
}
}
@Override
......@@ -59,6 +54,11 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
return false;
}
// Set the attack target (if not self)
if (!this.attackerEntity.equals(this.targetEntity)) {
this.attackerEntity.setTarget(this.targetEntity);
}
// Is nearby to target
boolean isNearby = this.attackerEntity.squaredDistanceTo(this.targetEntity) < MOVE_DISTANCE;
......@@ -82,6 +82,11 @@ public class AttackPlayerGoal extends PlayerBaseGoal {
}
private void performAttack() {
// Track the attacker (needed for protect to work)
if (!this.attackerEntity.equals(this.targetEntity)) {
this.targetEntity.setAttacker(this.attackerEntity);
}
// For passive entities (or hostile in creative mode), apply minimal damage to simulate a 'leap' / 'melee' attack
this.targetEntity.damage(this.attackerEntity.getDamageSources().generic(), 1.0F);
......
......@@ -21,7 +21,7 @@ public class ProtectPlayerGoal extends AttackPlayerGoal {
public boolean canStart() {
MobEntity lastAttackedByEntity = (MobEntity)this.protectedEntity.getLastAttacker();
int i = this.protectedEntity.getLastAttackedTime();
if (i != this.lastAttackedTime && lastAttackedByEntity != null) {
if (i != this.lastAttackedTime && lastAttackedByEntity != null && !this.attackerEntity.equals(lastAttackedByEntity)) {
// Set target to attack
this.lastAttackedTime = i;
this.targetEntity = lastAttackedByEntity;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment