Files
Purpur/patches/server/0114-Configurable-daylight-cycle.patch
William Blake Galbreath 89c9c902b1 Add axe actionable options
2021-07-06 01:01:33 -05: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 7620030f795604c49596ce972c0b39438341e4df..276fb2b9fc9d33dc2157903e799178168c69bc88 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -201,6 +201,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
final Int2ObjectMap<EnderDragonPart> dragonParts;
private final StructureFeatureManager structureFeatureManager;
private final boolean tickTime;
+ private double fakeTime; // Purpur
// Tuinity start - execute chunk tasks mid tick
public long lastMidTickExecuteFailure;
// Tuinity end - execute chunk tasks mid tick
@@ -578,6 +579,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
this.asyncChunkTaskManager = new com.destroystokyo.paper.io.chunk.ChunkTaskManager(this); // Paper
+ this.fakeTime = this.serverLevelData.getDayTime(); // Purpur
}
// Tuinity start - optimise collision
@@ -869,6 +871,18 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
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);
}
@@ -877,6 +891,12 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
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 cddccb3329be99ce11ea30b651184fb9eea243b3..b91e2bda59fa82ab0d86f70a6d0185ae76126772 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;