Files
Purpur/patches/server/0113-Configurable-daylight-cycle.patch
William Blake Galbreath 17368d1aa9 Updated Upstream (Paper & Tuinity)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
12dec20 Bump paerweight to 1.1.7
e33ed89 Get short commit ref using a more proper method
7d6147d Remove now unneeded patch due to paperweight 1.1.7
e72fa41 Update task dependency for includeMappings so the new task isn't skipped
0ad5526 Trim whitspace off of git hash (oops)

Tuinity Changes:
e878ba9 Update paper
2bd2849 Bring back fix codec spam patch
2021-06-27 00:42:39 -05:00

101 lines
5.6 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 13bee6ce45fd718484a9cf08645556717c9934e8..dbdaadfaeea555904556136a7cca02aa59b85369 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -55,6 +55,7 @@ import net.minecraft.network.protocol.game.ClientboundExplodePacket;
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
import net.minecraft.network.protocol.game.ClientboundSetDefaultSpawnPositionPacket;
+import net.minecraft.network.protocol.game.ClientboundSetTimePacket;
import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
import net.minecraft.network.protocol.game.DebugPackets;
@@ -205,6 +206,8 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
public long lastMidTickExecuteFailure;
// Tuinity end - execute chunk tasks mid tick
+ private double fakeTime; // Purpur
+
// CraftBukkit start
private int tickPosition;
public final LevelStorageSource.LevelStorageAccess convertable;
@@ -578,6 +581,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();
}
// Tuinity start - optimise collision
@@ -763,9 +767,20 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
// CraftBukkit start
long l = this.levelData.getDayTime() + 24000L;
TimeSkipEvent event = new TimeSkipEvent(this.getWorld(), TimeSkipEvent.SkipReason.NIGHT_SKIP, (l - l % 24000L) - this.getDayTime());
+ ServerLevel level = this.serverLevelData.world;
if (this.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)) {
getCraftServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
+ double incrementTimeBy = 12000.0D / (double) (level.isDay() ? level.purpurConfig.daytimeTicks : level.purpurConfig.nighttimeTicks);
+ if (incrementTimeBy != 1.0D) {
+ this.fakeTime += incrementTimeBy;
+ this.setDayTime(this.fakeTime);
+ ClientboundSetTimePacket packet = new ClientboundSetTimePacket(level.getGameTime(), level.getDayTime(), true);
+ for (ServerPlayer player : level.players) {
+ packet.setDayTime(player.getPlayerTime());
+ player.connection.send(packet);
+ }
+ } else
this.setDayTime(this.getDayTime() + event.getSkipAmount());
}
@@ -877,6 +892,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 2cf088cc750aad13001859bbc8b49343e5459567..71d3d41eab2fc5068f34e8e1b20b43a19caa958e 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -94,6 +94,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;