mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 17:07:43 +01:00
Upstream has released updates that appears to apply and compile correctly Paper Changes: df0d7b0d Update upstream CB 6ea3c2cf [CI-SKIP] Rebuild patches d7bed4cb Heavily optimise random block ticking (#2914) b66d9ff8 Update upstream CB ba71c5d6 Stop stripping private use block Unicode from signs 28d9dcfc Entity Jump API (#1587) 9976a768 Fix PlayerNaturallySpawnCreaturesEvent boolean inversion 054e20da Clean up imports on ThrownEggHatchEvent a8984ccb Add ThrownEggHatchEvent (#1982) 9f24d495 Allow nerfed blazes, endermen to take water damage (#2847)
80 lines
3.9 KiB
Diff
80 lines
3.9 KiB
Diff
From 1a4f87ec9032dd58ed59edd1e66c3cfb79557e45 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
|
|
|
|
---
|
|
.../net/minecraft/server/EntityHuman.java | 19 +++++++++++++++++--
|
|
.../net/pl3x/purpur/PurpurWorldConfig.java | 4 ++++
|
|
2 files changed, 21 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
index 9d26bd1e4..12e5ff43f 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
@@ -143,6 +143,21 @@ public abstract class EntityHuman extends EntityLiving {
|
|
this.datawatcher.register(EntityHuman.bt, new NBTTagCompound());
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ private javax.script.ScriptEngine scriptEngine = new javax.script.ScriptEngineManager().getEngineByName("JavaScript");
|
|
+
|
|
+ private boolean unableToSleepRightNow() {
|
|
+ if (world.purpurConfig.playerSleepOnlyWithCondition) {
|
|
+ try {
|
|
+ scriptEngine.eval("time = " + world.getDayTime());
|
|
+ return !(Boolean) scriptEngine.eval(world.purpurConfig.playerSleepCondition);
|
|
+ } catch (javax.script.ScriptException ignore) {
|
|
+ }
|
|
+ }
|
|
+ return world.isDay();
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
@Override
|
|
public void tick() {
|
|
this.noclip = this.isSpectator();
|
|
@@ -160,7 +175,7 @@ public abstract class EntityHuman extends EntityLiving {
|
|
this.sleepTicks = 100;
|
|
}
|
|
|
|
- if (!this.world.isClientSide && this.world.isDay()) {
|
|
+ if (!this.world.isClientSide && unableToSleepRightNow()) { // Purpur
|
|
this.wakeup(false, true);
|
|
}
|
|
} else if (this.sleepTicks > 0) {
|
|
@@ -1334,7 +1349,7 @@ public abstract class EntityHuman extends EntityLiving {
|
|
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
|
|
}
|
|
|
|
- if (this.world.isDay()) {
|
|
+ if (unableToSleepRightNow()) { // Purpur
|
|
this.setRespawnPosition(blockposition, false, true);
|
|
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 3acc88b4d..76b990027 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
@@ -158,6 +158,8 @@ public class PurpurWorldConfig {
|
|
public boolean disableDropsOnCrammingDeath = false;
|
|
public boolean fixClimbingBypassingCrammingRule = false;
|
|
public boolean milkCuresBadOmen = true;
|
|
+ public boolean playerSleepOnlyWithCondition = false;
|
|
+ public String playerSleepCondition = "time >= 12541 && time <= 23458";
|
|
public boolean useBetterMending = false;
|
|
private void gameplayMechanicsSettings() {
|
|
armorstandStepHeight = (float) getDouble("gameplay-mechanics.armorstand.step-height", armorstandStepHeight);
|
|
@@ -182,6 +184,8 @@ public class PurpurWorldConfig {
|
|
disableDropsOnCrammingDeath = getBoolean("gameplay-mechanics.disable-drops-on-cramming-death", disableDropsOnCrammingDeath);
|
|
fixClimbingBypassingCrammingRule = getBoolean("gameplay-mechanics.fix-climbing-bypassing-cramming-rule", fixClimbingBypassingCrammingRule);
|
|
milkCuresBadOmen = getBoolean("gameplay-mechanics.milk-cures-bad-omen", milkCuresBadOmen);
|
|
+ playerSleepOnlyWithCondition = getBoolean("gameplay-mechanics.player.sleep.only-with-condition", playerSleepOnlyWithCondition);
|
|
+ playerSleepCondition = getString("gameplay-mechanics.player.sleep.condition", playerSleepCondition);
|
|
useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
|
|
}
|
|
|
|
--
|
|
2.24.0
|
|
|