Pass wander pause through to wander goal, fix SleepTrait

This commit is contained in:
fullwall 2022-11-12 12:51:40 +08:00
parent ce1f306b08
commit 102630a5e0
2 changed files with 18 additions and 7 deletions

View File

@ -25,12 +25,16 @@ public class SleepTrait extends Trait {
public void run() {
if (!npc.isSpawned())
return;
if (sleeping && at != null) {
return;
} else if (sleeping && at == null) {
stopSleeping();
if (sleeping) {
if (at == null) {
wakeup();
}
return;
}
if (at == null)
return;
npc.teleport(at, TeleportCause.PLUGIN);
if (npc.getEntity() instanceof Player) {
Player player = (Player) npc.getEntity();
if (at.getBlock().getBlockData() instanceof Bed || at.getBlock().getState() instanceof Bed) {
@ -46,15 +50,15 @@ public class SleepTrait extends Trait {
public void setSleeping(Location at) {
this.at = at != null ? at.clone() : null;
stopSleeping();
npc.teleport(at, TeleportCause.PLUGIN);
wakeup();
}
private void stopSleeping() {
private void wakeup() {
if (npc.getEntity() instanceof Player) {
NMS.sleep((Player) npc.getEntity(), false);
} else if (npc.getEntity() instanceof Villager) {
((Villager) npc.getEntity()).wakeup();
}
sleeping = false;
}
}

View File

@ -345,6 +345,13 @@ public class WanderWaypointProvider
@Override
public void setPaused(boolean paused) {
this.paused = paused;
if (currentGoal != null) {
if (paused) {
currentGoal.pause();
} else {
currentGoal.unpause();
}
}
}
public void setXYRange(int xrange, int yrange) {