mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-19 17:37:42 +01:00
Add sleep options
This commit is contained in:
@@ -425,6 +425,21 @@ limit-villager-iron-golem-spawns
|
|||||||
* **default**: 5
|
* **default**: 5
|
||||||
* **description**: Maximum amount of iron golems villagers can spawn in configured radius
|
* **description**: Maximum amount of iron golems villagers can spawn in configured radius
|
||||||
|
|
||||||
|
sleep
|
||||||
|
~~~~~
|
||||||
|
* only-at-night
|
||||||
|
- **default:** false
|
||||||
|
- **description:** Make players only sleep at night. Night times specified below. Rest of the sleep options are ignored if this is false
|
||||||
|
* night-start
|
||||||
|
- **default:** 12541
|
||||||
|
- **description:** The starting time of night (in ticks) when a player can first sleep
|
||||||
|
* night-end
|
||||||
|
- **default:** 23458
|
||||||
|
- **description:** The ending time of night (in ticks) when a player cannot sleep
|
||||||
|
* invert-condition
|
||||||
|
- **default:** false
|
||||||
|
- **description:** Invert the result of the time condition. Time condition is `!(time < start && time > end)`. Inverting it removes the `!`
|
||||||
|
|
||||||
idle-timeout
|
idle-timeout
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
* kick-if-idle
|
* kick-if-idle
|
||||||
|
|||||||
75
patches/server/0087-Add-sleep-options.patch
Normal file
75
patches/server/0087-Add-sleep-options.patch
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
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
|
||||||
|
|
||||||
Reference in New Issue
Block a user