diff --git a/src/client/java/minicraft/entity/Entity.java b/src/client/java/minicraft/entity/Entity.java index 6dc8089da..861908abc 100644 --- a/src/client/java/minicraft/entity/Entity.java +++ b/src/client/java/minicraft/entity/Entity.java @@ -376,6 +376,7 @@ public boolean isWithin(int tileRadius, Entity other) { * * @return the closest player. */ + @Nullable protected Player getClosestPlayer() { return getClosestPlayer(true); } @@ -387,6 +388,7 @@ protected Player getClosestPlayer() { * @param returnSelf determines if the method can return itself. * @return The closest player to this entity. */ + @Nullable protected Player getClosestPlayer(boolean returnSelf) { if (this instanceof Player && returnSelf) return (Player) this; diff --git a/src/client/java/minicraft/entity/Spark.java b/src/client/java/minicraft/entity/Spark.java index f937abe67..10e25065f 100644 --- a/src/client/java/minicraft/entity/Spark.java +++ b/src/client/java/minicraft/entity/Spark.java @@ -51,7 +51,7 @@ public void tick() { y = (int) yy; Player player = getClosestPlayer(); - if (player.isWithin(0, this)) { + if (player != null && player.isWithin(0, this)) { player.hurt(owner, 1); } } diff --git a/src/client/java/minicraft/entity/mob/ObsidianKnight.java b/src/client/java/minicraft/entity/mob/ObsidianKnight.java index 16c5b1338..9c28558eb 100644 --- a/src/client/java/minicraft/entity/mob/ObsidianKnight.java +++ b/src/client/java/minicraft/entity/mob/ObsidianKnight.java @@ -74,11 +74,13 @@ public ObsidianKnight(int health) { @Override public void tick() { super.tick(); - if (getClosestPlayer().isRemoved()) { + Player player = getClosestPlayer(); + if (player == null || player.isRemoved()) { active = false; KnightStatue ks = new KnightStatue(health); level.add(ks, x, y, false); this.remove(); + return; } // Achieve phase 2 @@ -101,7 +103,6 @@ public void tick() { } if (attackPhase == AttackPhase.Attacking) { - Player player = getClosestPlayer(); if (attackDelay > 0) { xmov = ymov = 0; int dir = (attackDelay - 35) / 4 % 4; // The direction of attack.