mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 17:07:43 +01:00
76 lines
3.2 KiB
Diff
76 lines
3.2 KiB
Diff
From 7774dfe2612bbb0fb48b15bed689a11afbb11b89 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
|
Date: Sat, 30 Nov 2019 03:30:17 -0600
|
|
Subject: [PATCH] Add sleep options
|
|
|
|
---
|
|
.../java/net/minecraft/server/EntityHuman.java | 15 +++++++++++++--
|
|
.../java/net/pl3x/purpur/PurpurWorldConfig.java | 11 +++++++++++
|
|
2 files changed, 24 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
index 3610611299..2bb4ae2265 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
@@ -143,6 +143,17 @@ public abstract class EntityHuman extends EntityLiving {
|
|
this.datawatcher.register(EntityHuman.bw, new NBTTagCompound());
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ private boolean unableToSleepRightNow() {
|
|
+ if (world.purpurConfig.sleepOnlyAtNight) {
|
|
+ long time = world.getDayTime();
|
|
+ boolean wakeUp = time < world.purpurConfig.sleepStart && time > world.purpurConfig.sleepEnd;
|
|
+ return world.purpurConfig.sleepInvertCondition == wakeUp;
|
|
+ }
|
|
+ return world.isDayTime();
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
@Override
|
|
public void tick() {
|
|
this.noclip = this.isSpectator();
|
|
@@ -160,7 +171,7 @@ public abstract class EntityHuman extends EntityLiving {
|
|
this.sleepTicks = 100;
|
|
}
|
|
|
|
- if (!this.world.isClientSide && this.world.J()) {
|
|
+ if (!this.world.isClientSide && unableToSleepRightNow()) { // Purpur
|
|
this.wakeup(false, true, true);
|
|
}
|
|
} else if (this.sleepTicks > 0) {
|
|
@@ -1268,7 +1279,7 @@ public abstract class EntityHuman extends EntityLiving {
|
|
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
|
|
}
|
|
|
|
- if (this.world.J()) {
|
|
+ if (unableToSleepRightNow()) { // Purpur
|
|
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW);
|
|
}
|
|
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
index a1237c5b9d..8b62b0588a 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
@@ -161,6 +161,17 @@ public class PurpurWorldConfig {
|
|
limitVillagerIronGolemSpawns = getInt("limit-villager-iron-golem-spawns", limitVillagerIronGolemSpawns);
|
|
}
|
|
|
|
+ public boolean sleepOnlyAtNight = false;
|
|
+ public long sleepStart = 12541L;
|
|
+ public long sleepEnd = 23458L;
|
|
+ public boolean sleepInvertCondition = false;
|
|
+ private void sleepSettings() {
|
|
+ sleepOnlyAtNight = getBoolean("sleep.only-at-night", sleepOnlyAtNight);
|
|
+ sleepStart = getInt("sleep.night-start", (int) sleepStart);
|
|
+ sleepEnd = getInt("sleep.night-end", (int) sleepEnd);
|
|
+ sleepInvertCondition = getBoolean("sleep.invert-condition", sleepInvertCondition);
|
|
+ }
|
|
+
|
|
public boolean idleTimeoutKick = true;
|
|
public boolean idleTimeoutTickNearbyEntities = false;
|
|
public boolean idleTimeoutCountAsSleeping = false;
|
|
--
|
|
2.24.0.rc1
|
|
|