From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath 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 { 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 7944a33cf36878c9e4853637bfb9cba22ba8bc4d..3bc63f24bf8c07b89562887bdc8cf7569d7b33b4 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 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 @@ -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) { @@ -825,6 +827,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); } @@ -833,6 +847,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 02716d2cdaccb386bb84329dce02a175b03fd656..5d29dfbeefb325117c68d5a9dd8b97939a28c726 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;