Files
Purpur/patches/server/0114-Configurable-daylight-cycle.patch
Ben Kerllenevich 5ae3e94dec Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly
2021-08-28 08:20:37 -04:00

90 lines
4.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Sat, 10 Oct 2020 14:29:55 -0500
Subject: [PATCH] Configurable daylight cycle
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTimePacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTimePacket.java
index 689ad22925b2561f7c8db961743eb1f821dbb25f..fa3c960992cc240161817e54659d83fed259f2fe 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTimePacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTimePacket.java
@@ -5,7 +5,7 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundSetTimePacket implements Packet<ClientGamePacketListener> {
private final long gameTime;
- private final long dayTime;
+ private long dayTime; public void setDayTime(long dayTime) { this.dayTime = dayTime; } // Purpur
public ClientboundSetTimePacket(long time, long timeOfDay, boolean doDaylightCycle) {
this.gameTime = time % 192000; // Paper - fix guardian beam
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index f959fab7c941505fcb39b116c05a9e9cd401b090..f0b62a3ec03cdbba853be815834e56c4d136197c 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -196,6 +196,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
final Int2ObjectMap<EnderDragonPart> dragonParts;
private final StructureFeatureManager structureFeatureManager;
private final boolean tickTime;
+ private double fakeTime; // Purpur
// Paper start - execute chunk tasks mid tick
public long lastMidTickExecuteFailure;
// Paper end - execute chunk tasks mid tick
@@ -573,6 +574,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
this.asyncChunkTaskManager = new com.destroystokyo.paper.io.chunk.ChunkTaskManager(this); // Paper
+ this.fakeTime = this.serverLevelData.getDayTime(); // Purpur
}
public void setWeatherParameters(int clearDuration, int rainDuration, boolean raining, boolean thundering) {
@@ -838,6 +840,18 @@ public class ServerLevel extends Level implements WorldGenLevel {
this.liquidTicks.nextTick(); // Paper
this.serverLevelData.getScheduledEvents().tick(this.server, i);
if (this.levelData.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)) {
+ // Purpur start
+ double incrementTimeBy = 12000.0D / (double) (isDay() ? this.purpurConfig.daytimeTicks : this.purpurConfig.nighttimeTicks);
+ if (incrementTimeBy != 1.0D) {
+ this.fakeTime += incrementTimeBy;
+ this.setDayTime(this.fakeTime);
+ net.minecraft.network.protocol.game.ClientboundSetTimePacket packet = new net.minecraft.network.protocol.game.ClientboundSetTimePacket(getGameTime(), getDayTime(), true);
+ for (ServerPlayer player : this.players) {
+ packet.setDayTime(player.getPlayerTime());
+ player.connection.send(packet);
+ }
+ } else
+ // Purpur end
this.setDayTime(this.levelData.getDayTime() + 1L);
}
@@ -846,6 +860,12 @@ public class ServerLevel extends Level implements WorldGenLevel {
public void setDayTime(long timeOfDay) {
this.serverLevelData.setDayTime(timeOfDay);
+ // Purpur start
+ this.fakeTime = timeOfDay;
+ }
+ public void setDayTime(double i) {
+ this.serverLevelData.setDayTime((long) i);
+ // Purpur end
}
public void tickCustomSpawners(boolean spawnMonsters, boolean spawnAnimals) {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 05556f2d9f414a8718a616afcb1d15b2b97e2717..fd8430ad5419655f9d53f532e0f5c3d8391425f2 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -104,6 +104,13 @@ public class PurpurWorldConfig {
armorstandStepHeight = (float) getDouble("gameplay-mechanics.armorstand.step-height", armorstandStepHeight);
}
+ public int daytimeTicks = 12000;
+ public int nighttimeTicks = 12000;
+ private void daytimeCycleSettings() {
+ daytimeTicks = getInt("gameplay-mechanics.daylight-cycle-ticks.daytime", daytimeTicks);
+ nighttimeTicks = getInt("gameplay-mechanics.daylight-cycle-ticks.nighttime", nighttimeTicks);
+ }
+
public int elytraDamagePerSecond = 1;
public double elytraDamageMultiplyBySpeed = 0;
public boolean elytraIgnoreUnbreaking = false;