From a43adb0de29ed7c82051b4840fec5906dc949505 Mon Sep 17 00:00:00 2001 From: sasheg Date: Sun, 14 Jun 2026 01:37:22 +0300 Subject: [PATCH] Fix sleep goal cleanup on bed break: validate bed existence in tick() and canContinueToUse() for non-sleeping state --- .../fabled_hearts/ai/EllieSleepGoal.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/sashegdev/fabled_hearts/ai/EllieSleepGoal.java b/src/main/java/me/sashegdev/fabled_hearts/ai/EllieSleepGoal.java index 65ee3b8..cee7bf8 100644 --- a/src/main/java/me/sashegdev/fabled_hearts/ai/EllieSleepGoal.java +++ b/src/main/java/me/sashegdev/fabled_hearts/ai/EllieSleepGoal.java @@ -54,6 +54,12 @@ public class EllieSleepGoal extends Goal { public void tick() { if (bedPos == null) return; + BlockState currentState = ellie.level().getBlockState(bedPos); + if (!(currentState.getBlock() instanceof BedBlock)) { + bedPos = null; + return; + } + tryOpenDoor(); double distSqr = ellie.distanceToSqr(Vec3.atCenterOf(bedPos)); @@ -104,15 +110,16 @@ public class EllieSleepGoal extends Goal { @Override public boolean canContinueToUse() { + if (bedPos != null) { + BlockState state = ellie.level().getBlockState(bedPos); + if (!state.isBed(ellie.level(), bedPos, null)) return false; + } + if (ellie.isSleeping()) { if (sleepTimer >= MAX_SLEEP_TICKS) return false; if (ellie.level().isDay()) return false; if (ellie.hurtTime > 10) return false; - if (bedPos != null) { - BlockState state = ellie.level().getBlockState(bedPos); - if (!state.isBed(ellie.level(), bedPos, null)) return false; - if (ellie.distanceToSqr(Vec3.atCenterOf(bedPos)) > 16.0) return false; - } + if (ellie.distanceToSqr(Vec3.atCenterOf(bedPos)) > 16.0) return false; return true; } if (bedPos == null) return false;