From b08756b4b345802d56375a0b9039834d2cbe57c5 Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Sun, 28 Sep 2025 14:44:04 +0800 Subject: [PATCH] fix: fixes #64 --- .../0009-Re-add-tick-count-support.patch | 59 +++++++++++++++++++ ...h => 0010-Leaves-Base-Protocol-Core.patch} | 43 +------------- ... => 0011-Leaves-Item-overstack-util.patch} | 0 ...ves-Old-Explosion-Damage-Calculator.patch} | 0 ...ch => 0013-Leaves-Old-raid-behavior.patch} | 0 ... 0014-Leaves-Redstone-Shears-Wrench.patch} | 0 ...atch => 0015-Leaves-Servux-Protocol.patch} | 0 ...rpur-Barrels-and-enderchests-6-rows.patch} | 0 ...-for-Raid-Revert-and-Cross-Region-D.patch} | 0 ...18-Disable-some-check-for-operators.patch} | 0 ...-support.patch => 0019-I18n-support.patch} | 0 ...ch => 0020-Old-zombie-reinforcement.patch} | 0 ...tch => 0021-Spawn-invulnerable-time.patch} | 0 ...ch => 0022-Leaves-Leaves-Fakeplayer.patch} | 12 ++-- ...lConfig.java => ServuxProtocolConfig.java} | 22 +++++-- .../org/leavesmc/leaves/bot/ServerBot.java | 2 +- .../servux/ServuxEntityDataProtocol.java | 4 +- .../servux/ServuxHudDataProtocol.java | 14 ++--- .../servux/ServuxStructuresProtocol.java | 14 ++--- .../litematics/ServuxLitematicsProtocol.java | 6 +- .../placement/SchematicPlacement.java | 4 +- 21 files changed, 105 insertions(+), 75 deletions(-) create mode 100644 lophine-server/minecraft-patches/features/0009-Re-add-tick-count-support.patch rename lophine-server/minecraft-patches/features/{0009-Leaves-Base-Protocol-Core.patch => 0010-Leaves-Base-Protocol-Core.patch} (83%) rename lophine-server/minecraft-patches/features/{0010-Leaves-Item-overstack-util.patch => 0011-Leaves-Item-overstack-util.patch} (100%) rename lophine-server/minecraft-patches/features/{0011-Leaves-Old-Explosion-Damage-Calculator.patch => 0012-Leaves-Old-Explosion-Damage-Calculator.patch} (100%) rename lophine-server/minecraft-patches/features/{0012-Leaves-Old-raid-behavior.patch => 0013-Leaves-Old-raid-behavior.patch} (100%) rename lophine-server/minecraft-patches/features/{0013-Leaves-Redstone-Shears-Wrench.patch => 0014-Leaves-Redstone-Shears-Wrench.patch} (100%) rename lophine-server/minecraft-patches/features/{0014-Leaves-Servux-Protocol.patch => 0015-Leaves-Servux-Protocol.patch} (100%) rename lophine-server/minecraft-patches/features/{0015-Purpur-Barrels-and-enderchests-6-rows.patch => 0016-Purpur-Barrels-and-enderchests-6-rows.patch} (100%) rename lophine-server/minecraft-patches/features/{0016-Compatibility-fix-for-Raid-Revert-and-Cross-Region-D.patch => 0017-Compatibility-fix-for-Raid-Revert-and-Cross-Region-D.patch} (100%) rename lophine-server/minecraft-patches/features/{0017-Disable-some-check-for-operators.patch => 0018-Disable-some-check-for-operators.patch} (100%) rename lophine-server/minecraft-patches/features/{0018-I18n-support.patch => 0019-I18n-support.patch} (100%) rename lophine-server/minecraft-patches/features/{0019-Old-zombie-reinforcement.patch => 0020-Old-zombie-reinforcement.patch} (100%) rename lophine-server/minecraft-patches/features/{0020-Spawn-invulnerable-time.patch => 0021-Spawn-invulnerable-time.patch} (100%) rename lophine-server/minecraft-patches/features/{0021-Leaves-Leaves-Fakeplayer.patch => 0022-Leaves-Leaves-Fakeplayer.patch} (99%) rename lophine-server/src/main/java/fun/bm/lophine/config/modules/function/{SurvuxProtocolConfig.java => ServuxProtocolConfig.java} (60%) diff --git a/lophine-server/minecraft-patches/features/0009-Re-add-tick-count-support.patch b/lophine-server/minecraft-patches/features/0009-Re-add-tick-count-support.patch new file mode 100644 index 0000000..b304d1f --- /dev/null +++ b/lophine-server/minecraft-patches/features/0009-Re-add-tick-count-support.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Helvetica Volubi +Date: Sun, 28 Sep 2025 13:21:30 +0800 +Subject: [PATCH] Re-add tick count support + + +diff --git a/io/papermc/paper/threadedregions/TickRegionScheduler.java b/io/papermc/paper/threadedregions/TickRegionScheduler.java +index b957585cf7cf7f845e20f59c7b355722880f3b4e..9b279d003eb9f780ed2723c98b28d9f4d6e3a281 100644 +--- a/io/papermc/paper/threadedregions/TickRegionScheduler.java ++++ b/io/papermc/paper/threadedregions/TickRegionScheduler.java +@@ -412,6 +412,8 @@ public final class TickRegionScheduler { + } + // Luminol end - Add tick command support + ++ MinecraftServer.getServer().handleTickCount(tickCount); // Lophine - reuse tick count ++ + if (!this.tryMarkTicking()) { + if (!this.cancelled.get()) { + throw new IllegalStateException("Scheduled region should be acquirable"); +diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java +index b156b5c635f931a3d4abc0584591f90476d011a6..ef0b401affa58077e8dd32b52063202a1c7e0bb6 100644 +--- a/net/minecraft/server/MinecraftServer.java ++++ b/net/minecraft/server/MinecraftServer.java +@@ -305,6 +305,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop CompletableFuture submit(java.util.function.Supplier task) { +@@ -2227,9 +2229,25 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop CompletableFuture submit(java.util.function.Supplier task) { -@@ -2227,9 +2228,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop S spin(Function threadFunction) { ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system AtomicReference atomicReference = new AtomicReference<>(); -@@ -1039,6 +1041,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0) { // Folia - region threading - this is complicated to implement, and even if done correctly is messy @@ -62,7 +62,7 @@ index 0b7c014114f1f8648824fe7c9b75fde3ea79162a..384b121df8bfc72b21b607e8fa4ae90e this.emptyTicks++; } else { this.emptyTicks = 0; -@@ -1913,6 +1916,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop hudEnabledLoggers = List.of("tps", "mob_caps"); + @TransformedConfig(name = "hud-update-interval", directory = {"function", "survux-protocol"}) @TransformedConfig(name = "hud-update-interval", directory = {"misc", "survux-protocol"}) @ConfigInfo(name = "hud-update-interval") public static int hudUpdateInterval = 1; + @TransformedConfig(name = "litematics-enabled", directory = {"function", "survux-protocol"}) @TransformedConfig(name = "litematics-enabled", directory = {"misc", "survux-protocol"}) - @ConfigInfo(name = "litematics-enabled") + @ConfigInfo(name = "litematics-enabled", directory = {"litematics"}) public static boolean litematicsEnabled = false; + @TransformedConfig(name = "litematics-max-nbt-size", directory = {"function", "survux-protocol"}) @TransformedConfig(name = "litematics-max-nbt-size", directory = {"misc", "survux-protocol"}) @CommandSuggestions(suggest = {"-1", "2097152"}) - @ConfigInfo(name = "litematics-max-nbt-size") + @ConfigInfo(name = "litematics-max-nbt-size", directory = {"litematics"}) public static int litematicsMaxNbtSize = 2097152; + @TransformedConfig(name = "litematics-print-max-delay-ticks", directory = {"function", "survux-protocol"}) @CommandSuggestions(suggest = {"-1", "1200"}) - @ConfigInfo(name = "litematics-print-max-delay-ticks", comments = "The max delay ticks for printing litematics, -1 to disable") + @ConfigInfo(name = "litematics-print-max-delay-ticks", directory = {"litematics"}, comments = "The max delay ticks for printing litematics, -1 to disable") public static int maxDelay = 1200; } diff --git a/lophine-server/src/main/java/org/leavesmc/leaves/bot/ServerBot.java b/lophine-server/src/main/java/org/leavesmc/leaves/bot/ServerBot.java index 0cec7fe..2409306 100644 --- a/lophine-server/src/main/java/org/leavesmc/leaves/bot/ServerBot.java +++ b/lophine-server/src/main/java/org/leavesmc/leaves/bot/ServerBot.java @@ -154,7 +154,7 @@ public class ServerBot extends ServerPlayer { this.notSleepTicks++; } - if (FakeplayerConfig.regenAmount > 0.0 && getServer().getTickCount() % 20 == 0) { + if (FakeplayerConfig.regenAmount > 0.0 && getServer().checkTickCount(20)) { float regenAmount = (float) (FakeplayerConfig.regenAmount * 20); this.setHealth(Math.min(this.getHealth() + regenAmount, this.getMaxHealth())); } diff --git a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxEntityDataProtocol.java b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxEntityDataProtocol.java index c9d9271..cd6c83f 100644 --- a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxEntityDataProtocol.java +++ b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxEntityDataProtocol.java @@ -18,7 +18,7 @@ package org.leavesmc.leaves.protocol.servux; import com.mojang.logging.LogUtils; -import fun.bm.lophine.config.modules.function.SurvuxProtocolConfig; +import fun.bm.lophine.config.modules.function.ServuxProtocolConfig; import io.netty.buffer.Unpooled; import net.minecraft.Util; import net.minecraft.core.BlockPos; @@ -144,7 +144,7 @@ public class ServuxEntityDataProtocol implements LeavesProtocol { @Override public boolean isActive() { - return SurvuxProtocolConfig.entityProtocol; + return ServuxProtocolConfig.entityProtocol; } public enum EntityDataPayloadType { diff --git a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxHudDataProtocol.java b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxHudDataProtocol.java index c548291..c5eca86 100644 --- a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxHudDataProtocol.java +++ b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxHudDataProtocol.java @@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.servux; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import com.mojang.serialization.DataResult; -import fun.bm.lophine.config.modules.function.SurvuxProtocolConfig; +import fun.bm.lophine.config.modules.function.ServuxProtocolConfig; import io.netty.buffer.Unpooled; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -104,7 +104,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol { metadata.putString("id", HudDataPayload.CHANNEL.toString()); metadata.putInt("version", PROTOCOL_VERSION); metadata.putString("servux", ServuxProtocol.SERVUX_STRING); - if (SurvuxProtocolConfig.hudLoggerProtocol) { + if (ServuxProtocolConfig.hudLoggerProtocol) { CompoundTag nbt = new CompoundTag(); for (DataLogger.Type type : DataLogger.Type.VALUES) { nbt.putBoolean(type.getSerializedName(), isLoggerTypeEnabled(type)); @@ -185,7 +185,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol { metadata.putInt("spawnPosZ", spawnPos.getZ()); metadata.putInt("spawnChunkRadius", level.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS)); - if (SurvuxProtocolConfig.hudMetadataShareSeed) { + if (ServuxProtocolConfig.hudMetadataShareSeed) { metadata.putLong("worldSeed", level.getSeed()); } } @@ -217,7 +217,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol { } private static boolean isLoggerTypeEnabled(DataLogger.Type type) { - return SurvuxProtocolConfig.hudEnabledLoggers.contains(type.getSerializedName()); + return ServuxProtocolConfig.hudEnabledLoggers.contains(type.getSerializedName()); } @ProtocolHandler.Ticker @@ -233,13 +233,13 @@ public class ServuxHudDataProtocol implements LeavesProtocol { @ProtocolHandler.Ticker(tickerId = "logger") public void loggerTick() { - if (!SurvuxProtocolConfig.hudLoggerProtocol) { + if (!ServuxProtocolConfig.hudLoggerProtocol) { return; } MinecraftServer server = MinecraftServer.getServer(); - if (server.getTickCount() % SurvuxProtocolConfig.hudUpdateInterval == 0) { + if (server.checkTickCount(ServuxProtocolConfig.hudUpdateInterval)) { LOGGERS.forEach((type, logger) -> { if (!isLoggerTypeEnabled(type)) { return; @@ -277,7 +277,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol { @Override public boolean isActive() { - return SurvuxProtocolConfig.hudMetadataProtocol; + return ServuxProtocolConfig.hudMetadataProtocol; } @Override diff --git a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxStructuresProtocol.java b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxStructuresProtocol.java index dce95e6..4b9a913 100644 --- a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxStructuresProtocol.java +++ b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxStructuresProtocol.java @@ -18,7 +18,7 @@ package org.leavesmc.leaves.protocol.servux; import com.mojang.logging.LogUtils; -import fun.bm.lophine.config.modules.function.SurvuxProtocolConfig; +import fun.bm.lophine.config.modules.function.ServuxProtocolConfig; import io.netty.buffer.Unpooled; import it.unimi.dsi.fastutil.longs.LongIterator; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; @@ -57,7 +57,6 @@ public class ServuxStructuresProtocol implements LeavesProtocol { public static final int PROTOCOL_VERSION = 2; private static final int updateInterval = 40; - private static final int timeout = 30 * 20; private static final Map players = new ConcurrentHashMap<>(); private static final Map> timeouts = new HashMap<>(); private static int retainDistance; @@ -105,7 +104,7 @@ public class ServuxStructuresProtocol implements LeavesProtocol { if (chunkHasStructureReferences(pos.x, pos.z, chunk.getLevel())) { final Map map = timeouts.computeIfAbsent(uuid, (u) -> new HashMap<>()); - map.computeIfAbsent(pos, (p) -> new Timeout(tickCounter - timeout)); + map.computeIfAbsent(pos, (p) -> new Timeout(tickCounter - ServuxProtocolConfig.maxDelay)); } } @@ -145,7 +144,7 @@ public class ServuxStructuresProtocol implements LeavesProtocol { tag.putString("id", StructuresPayload.CHANNEL.toString()); tag.putInt("version", PROTOCOL_VERSION); tag.putString("servux", ServuxProtocol.SERVUX_STRING); - tag.putInt("timeout", timeout); + tag.putInt("timeout", ServuxProtocolConfig.maxDelay); sendPacket(player, new StructuresPayload(StructuresPayloadType.PACKET_S2C_METADATA, tag)); } @@ -270,7 +269,7 @@ public class ServuxStructuresProtocol implements LeavesProtocol { for (Map.Entry entry : map.entrySet()) { Timeout out = entry.getValue(); - if (out.needsUpdate(tickCounter, timeout)) { + if (out.needsUpdate(ServuxProtocolConfig.maxDelay, tickCounter)) { positionsToUpdate.add(entry.getKey()); } } @@ -336,7 +335,7 @@ public class ServuxStructuresProtocol implements LeavesProtocol { @Override public boolean isActive() { - return SurvuxProtocolConfig.structureProtocol; + return ServuxProtocolConfig.structureProtocol; } public enum StructuresPayloadType { @@ -410,7 +409,8 @@ public class ServuxStructuresProtocol implements LeavesProtocol { } public boolean needsUpdate(int currentTick, int timeout) { - return currentTick - this.lastSync >= timeout; + if (timeout == -1 || currentTick - this.lastSync >= timeout) return true; + return MinecraftServer.getServer().checkTickCount(timeout); } public void setLastSync(int tickCounter) { diff --git a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/litematics/ServuxLitematicsProtocol.java b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/litematics/ServuxLitematicsProtocol.java index ec1b4a2..a1175ef 100644 --- a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/litematics/ServuxLitematicsProtocol.java +++ b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/litematics/ServuxLitematicsProtocol.java @@ -17,7 +17,7 @@ package org.leavesmc.leaves.protocol.servux.litematics; -import fun.bm.lophine.config.modules.function.SurvuxProtocolConfig; +import fun.bm.lophine.config.modules.function.ServuxProtocolConfig; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -133,7 +133,7 @@ public class ServuxLitematicsProtocol implements LeavesProtocol { } playerSession.remove(uuid); fullPacket.readVarInt(); - Tag tag = FriendlyByteBuf.readNbt(fullPacket, new NbtAccounter(SurvuxProtocolConfig.litematicsMaxNbtSize == -1 ? Long.MAX_VALUE : SurvuxProtocolConfig.litematicsMaxNbtSize, 512)); + Tag tag = FriendlyByteBuf.readNbt(fullPacket, new NbtAccounter(ServuxProtocolConfig.litematicsMaxNbtSize == -1 ? Long.MAX_VALUE : ServuxProtocolConfig.litematicsMaxNbtSize, 512)); if (!(tag instanceof CompoundTag)) { ServuxProtocol.LOGGER.error("cannot read nbt tag from packet"); return; @@ -275,7 +275,7 @@ public class ServuxLitematicsProtocol implements LeavesProtocol { @Override public boolean isActive() { - return SurvuxProtocolConfig.litematicsEnabled; + return ServuxProtocolConfig.litematicsEnabled; } public enum ServuxLitematicaPayloadType { diff --git a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/litematics/placement/SchematicPlacement.java b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/litematics/placement/SchematicPlacement.java index 0528abc..7652bf0 100644 --- a/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/litematics/placement/SchematicPlacement.java +++ b/lophine-server/src/main/java/org/leavesmc/leaves/protocol/servux/litematics/placement/SchematicPlacement.java @@ -18,7 +18,7 @@ package org.leavesmc.leaves.protocol.servux.litematics.placement; import com.google.common.collect.ImmutableMap; -import fun.bm.lophine.config.modules.function.SurvuxProtocolConfig; +import fun.bm.lophine.config.modules.function.ServuxProtocolConfig; import io.papermc.paper.threadedregions.RegionizedServer; import me.earthme.luminol.utils.NullPlugin; import net.kyori.adventure.text.Component; @@ -316,7 +316,7 @@ public class SchematicPlacement { ); final NullPlugin nullPlugin = new NullPlugin(); - scheduleTask(nullPlugin, serverWorld, count, count_full, player, timeStart, SurvuxProtocolConfig.maxDelay); + scheduleTask(nullPlugin, serverWorld, count, count_full, player, timeStart, ServuxProtocolConfig.maxDelay); } private void scheduleTask(Plugin plugin, ServerLevel serverWorld, AtomicInteger count1, AtomicInteger count2, ServerPlayer player, long timeStart, int retryCount) {