Skip to content

Commit 188517a

Browse files
Merge pull request CloudburstMC#1044 from AntonPPDS/fix-exporb-target
Fix target choose logic for EntityXPOrb
2 parents 030cc24 + dfeb031 commit 188517a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/cn/nukkit/entity/item/EntityXPOrb.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,20 @@ public boolean onUpdate(int currentTick) {
143143
}
144144

145145
if (this.closestPlayer == null || this.closestPlayer.distanceSquared(this) > 64.0D) {
146+
this.closestPlayer = null;
147+
double closestDistance = 0.0D;
146148
for (Player p : this.getViewers().values()) {
147-
if (!p.isSpectator() && p.distance(this) <= 8) {
148-
this.closestPlayer = p;
149-
break;
149+
if (!p.isSpectator() && p.spawned && p.isAlive()) {
150+
double d = p.distanceSquared(this);
151+
if (d <= 64.0D && (this.closestPlayer == null || d < closestDistance)) {
152+
this.closestPlayer = p;
153+
closestDistance = d;
154+
}
150155
}
151156
}
152157
}
153158

154-
if (this.closestPlayer != null && this.closestPlayer.isSpectator()) {
159+
if (this.closestPlayer != null && (this.closestPlayer.isSpectator() || !this.closestPlayer.spawned || !this.closestPlayer.isAlive())) {
155160
this.closestPlayer = null;
156161
}
157162

0 commit comments

Comments
 (0)