Fix sleep goal cleanup on bed break: validate bed existence in tick() and canContinueToUse() for non-sleeping state
This commit is contained in:
@@ -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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (bedPos == null) return false;
|
||||
|
||||
Reference in New Issue
Block a user