9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-26 18:29:18 +00:00

final features and fixes

This commit is contained in:
NONPLAYT
2025-03-03 20:09:33 +03:00
parent fc0922d105
commit 58edc79952
8 changed files with 184 additions and 20 deletions

View File

@@ -5,14 +5,13 @@ Subject: [PATCH] Configuration
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 4f90ebcd86fba38dec313143e36614e992c7dbc7..959d87f4cd1efe8cf591e98c7d32728067f7117c 100644
index 1d9bf122c4c32c486a33d846c95afcab12560fd7..61eeec6a0d789e5e44abdeb5826d7ee2307301ba 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -243,6 +243,17 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -218,6 +218,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
}
org.purpurmc.purpur.PurpurConfig.registerCommands();
*/// Purpur end - Purpur config files // Purpur - Configurable void damage height and damage
+
// Purpur end - Configurable void damage height and damage
+ // DivineMC start - Configuration
+ try {
+ org.bxteam.divinemc.DivineConfig.init((java.io.File) options.valueOf("divinemc-settings"));
@@ -22,10 +21,9 @@ index 4f90ebcd86fba38dec313143e36614e992c7dbc7..959d87f4cd1efe8cf591e98c7d327280
+ }
+ org.bxteam.divinemc.command.DivineCommands.registerCommands(this);
+ // DivineMC end - Configuration
+
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
this.setPvpAllowed(properties.pvp);
// Paper start - initialize global and world-defaults configuration
this.paperConfigurations.initializeGlobalConfiguration(this.registryAccess());
this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index 0fe8f4601eedfa68c38ebadc7847ba7a07ff6fb6..b4c2602ecf6b943ab022866231f74b850269af8f 100644
--- a/net/minecraft/world/level/Level.java

View File

@@ -355,10 +355,10 @@ index 781030cb2e0316151c20351f04347c8db63f43e1..527547b98b70429830a3cf82fddba202
}
// CraftBukkit end
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index b3a2acd884a4bb2e84e6992c11dd16e513912616..217c857b8baf3f2aa7f75c7b0b33bba9dba35489 100644
index 61eeec6a0d789e5e44abdeb5826d7ee2307301ba..440824d74912f9cabe950b9b27386fbf715f7884 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -234,6 +234,10 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -243,6 +243,10 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
io.papermc.paper.command.PaperCommands.registerCommands(this); // Paper - setup /paper command
this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics

View File

@@ -4,6 +4,105 @@ Date: Sat, 1 Feb 2025 00:33:03 +0300
Subject: [PATCH] Chunk System optimization
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..8fa7b73b02434487fef495b92a33d24dcfa24c0b 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -301,7 +301,7 @@ public final class RegionizedPlayerChunkLoader {
return false;
}
- public void tick() {
+ public synchronized void tick() { // DivineMC - Chunk System optimization - synchronized
TickThread.ensureTickThread("Cannot tick player chunk loader async");
long currTime = System.nanoTime();
for (final ServerPlayer player : new java.util.ArrayList<>(this.world.players())) {
@@ -362,7 +362,7 @@ public final class RegionizedPlayerChunkLoader {
GENERATED_TICKET_LEVEL,
TICK_TICKET_LEVEL
};
- private final Long2ByteOpenHashMap chunkTicketStage = new Long2ByteOpenHashMap();
+ private final it.unimi.dsi.fastutil.longs.Long2ByteMap chunkTicketStage = it.unimi.dsi.fastutil.longs.Long2ByteMaps.synchronize(new Long2ByteOpenHashMap()); // DivineMC - Chunk System optimization
{
this.chunkTicketStage.defaultReturnValue(CHUNK_TICKET_STAGE_NONE);
}
@@ -492,7 +492,7 @@ public final class RegionizedPlayerChunkLoader {
}
@Override
- protected void removeCallback(final PlayerChunkLoaderData parameter, final int chunkX, final int chunkZ) {
+ protected synchronized void removeCallback(final PlayerChunkLoaderData parameter, final int chunkX, final int chunkZ) { // DivineMC - Chunk System optimization - synchronized
final long chunk = CoordinateUtils.getChunkKey(chunkX, chunkZ);
// note: by the time this is called, the tick cleanup should have ran - so, if the chunk is at
// the tick stage it was deemed in range for loading. Thus, we need to move it to generated
@@ -626,7 +626,7 @@ public final class RegionizedPlayerChunkLoader {
return Math.max(Math.abs(dx), Math.abs(dz)) <= this.lastTickDistance;
}
- private boolean areNeighboursGenerated(final int chunkX, final int chunkZ, final int radius) {
+ private synchronized boolean areNeighboursGenerated(final int chunkX, final int chunkZ, final int radius) { // DivineMC - Chunk System optimization - synchronized
for (int dz = -radius; dz <= radius; ++dz) {
for (int dx = -radius; dx <= radius; ++dx) {
if ((dx | dz) == 0) {
@@ -645,19 +645,11 @@ public final class RegionizedPlayerChunkLoader {
return true;
}
- void updateQueues(final long time) {
+ synchronized void updateQueues(final long time) { // DivineMC - Chunk System optimization - synchronized
TickThread.ensureTickThread(this.player, "Cannot tick player chunk loader async");
if (this.removed) {
throw new IllegalStateException("Ticking removed player chunk loader");
}
- // update rate limits
- final double loadRate = this.getMaxChunkLoadRate();
- final double genRate = this.getMaxChunkGenRate();
- final double sendRate = this.getMaxChunkSendRate();
-
- this.chunkLoadTicketLimiter.tickAllocation(time, loadRate, loadRate);
- this.chunkGenerateTicketLimiter.tickAllocation(time, genRate, genRate);
- this.chunkSendLimiter.tickAllocation(time, sendRate, sendRate);
// try to progress chunk loads
while (!this.loadingQueue.isEmpty()) {
@@ -684,8 +676,7 @@ public final class RegionizedPlayerChunkLoader {
}
// try to push more chunk loads
- final long maxLoads = Math.max(0L, Math.min(MAX_RATE, Math.min(this.loadQueue.size(), this.getMaxChunkLoads())));
- final int maxLoadsThisTick = (int)this.chunkLoadTicketLimiter.takeAllocation(time, loadRate, maxLoads);
+ final int maxLoadsThisTick = this.loadQueue.size(); // DivineMC - Chunk System optimization
if (maxLoadsThisTick > 0) {
final LongArrayList chunks = new LongArrayList(maxLoadsThisTick);
for (int i = 0; i < maxLoadsThisTick; ++i) {
@@ -760,9 +751,7 @@ public final class RegionizedPlayerChunkLoader {
}
// try to push more chunk generations
- final long maxGens = Math.max(0L, Math.min(MAX_RATE, Math.min(this.genQueue.size(), this.getMaxChunkGenerates())));
- // preview the allocations, as we may not actually utilise all of them
- final long maxGensThisTick = this.chunkGenerateTicketLimiter.previewAllocation(time, genRate, maxGens);
+ final long maxGensThisTick = this.genQueue.size(); // DivineMC - Chunk System optimization
long ratedGensThisTick = 0L;
while (!this.genQueue.isEmpty()) {
final long chunkKey = this.genQueue.firstLong();
@@ -792,8 +781,6 @@ public final class RegionizedPlayerChunkLoader {
);
this.generatingQueue.enqueue(chunkKey);
}
- // take the allocations we actually used
- this.chunkGenerateTicketLimiter.takeAllocation(time, genRate, ratedGensThisTick);
// try to pull ticking chunks
while (!this.tickingQueue.isEmpty()) {
@@ -827,6 +814,7 @@ public final class RegionizedPlayerChunkLoader {
final int maxSendsThisTick = Math.min((int)this.chunkSendLimiter.takeAllocation(time, sendRate, maxSends), this.sendQueue.size());
// we do not return sends that we took from the allocation back because we want to limit the max send rate, not target it
for (int i = 0; i < maxSendsThisTick; ++i) {
+ if (this.sendQueue.isEmpty()) break; // DivineMC - Chunk System optimization
final long pendingSend = this.sendQueue.firstLong();
final int pendingSendX = CoordinateUtils.getChunkX(pendingSend);
final int pendingSendZ = CoordinateUtils.getChunkZ(pendingSend);
diff --git a/net/minecraft/world/level/LevelReader.java b/net/minecraft/world/level/LevelReader.java
index 26c8c1e5598daf3550aef05b12218c47bda6618b..94c824ab1457939c425e1f99929d3222ee2c18a0 100644
--- a/net/minecraft/world/level/LevelReader.java

View File

@@ -206,10 +206,10 @@ index 30bd254542d631676494f349ff3f44f52d54ab2f..6c728ae3b58bc1b8449d34c6c7409161
private static final String PREFIX = "data:image/png;base64,";
public static final Codec<ServerStatus.Favicon> CODEC = Codec.STRING.comapFlatMap(string -> {
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 217c857b8baf3f2aa7f75c7b0b33bba9dba35489..573cbcccc7caf75002ba8b73460170bbdf72efa2 100644
index 440824d74912f9cabe950b9b27386fbf715f7884..374d74d459fb5548a47c0cb3adcf432ee83003d1 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -668,6 +668,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -666,6 +666,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@Override
public boolean enforceSecureProfile() {

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Async Chunk Sending
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..287bc85b80059fe5711cec25220d2d7bab472a16 100644
index 8fa7b73b02434487fef495b92a33d24dcfa24c0b..d11cd068a87eb263af9a5def8ea322374cc234dc 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -823,8 +823,11 @@ public final class RegionizedPlayerChunkLoader {
@@ -810,8 +810,11 @@ public final class RegionizedPlayerChunkLoader {
}
// try to pull sending chunks
@@ -21,7 +21,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..287bc85b80059fe5711cec25220d2d7b
+ // DivineMC end - Async Chunk Sending
// we do not return sends that we took from the allocation back because we want to limit the max send rate, not target it
for (int i = 0; i < maxSendsThisTick; ++i) {
final long pendingSend = this.sendQueue.firstLong();
if (this.sendQueue.isEmpty()) break; // DivineMC - Chunk System optimization
diff --git a/net/minecraft/server/network/PlayerChunkSender.java b/net/minecraft/server/network/PlayerChunkSender.java
index 14878690a88fd4de3e2c127086607e6c819c636c..4723ce85ebcd3740245607348a525f292ac1e2f3 100644
--- a/net/minecraft/server/network/PlayerChunkSender.java

View File

@@ -1,6 +1,16 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 3 Mar 2025 19:57:47 +0300
Subject: [PATCH] Leaf: Optimize Connection.flushQueue
Original author - Taiyou06
Original patch - https://github.com/Winds-Studio/Leaf/pull/235
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index 7b78c0af4a83bd39a5bc2d6554cc677bd4c0c822..515e90aca8ab1c3a9dce67784a360630ae7dd247 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -85,7 +_,7 @@
@@ -85,7 +85,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
private static final ProtocolInfo<ServerHandshakePacketListener> INITIAL_PROTOCOL = HandshakeProtocols.SERVERBOUND;
private final PacketFlow receiving;
private volatile boolean sendLoginDisconnect = true;
@@ -9,7 +19,7 @@
public Channel channel;
public SocketAddress address;
// Spigot start
@@ -541,10 +_,10 @@
@@ -541,10 +541,10 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
if (io.papermc.paper.util.MCUtil.isMainThread()) {
return this.processQueue();
} else if (this.isPending) {
@@ -24,7 +34,7 @@
}
return false;
}
@@ -554,29 +_,16 @@
@@ -554,29 +554,18 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
return true;
}
@@ -49,10 +59,11 @@
if (queued instanceof PacketSendAction packetSendAction) {
final Packet<?> packet = packetSendAction.packet;
if (!packet.isReady()) {
+ this.pendingActions.add(queued);
return false;
}
}
-
- iterator.remove();
+ // DivineMC end - Optimize Connection.flushQueue
if (queued.tryMarkConsumed()) {

View File

@@ -0,0 +1,53 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 3 Mar 2025 20:08:44 +0300
Subject: [PATCH] Option to disable disconnect.spam
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index d4e15d9295236fef5cbac3569cd37c1bd3c96d96..32f0648c72ec68f731340935a94105026206db6d 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -811,7 +811,7 @@ public class ServerGamePacketListenerImpl
public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) {
// PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // Paper - AsyncTabCompleteEvent; run this async
// CraftBukkit start
- if (!this.tabSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { // Paper - configurable tab spam limits
+ if (!this.tabSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile()) && !org.bxteam.divinemc.DivineConfig.disableDisconnectSpam) { // Paper - configurable tab spam limits // DivineMC - Option to disable disconnect.spam
this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - Kick event cause // Paper - add proper async disconnect
return;
}
@@ -823,7 +823,7 @@ public class ServerGamePacketListenerImpl
// Paper end - Don't suggest if tab-complete is disabled
// Paper start
final int index;
- if (packet.getCommand().length() > 64 && ((index = packet.getCommand().indexOf(' ')) == -1 || index >= 64)) {
+ if (packet.getCommand().length() > 64 && ((index = packet.getCommand().indexOf(' ')) == -1 || index >= 64) && !org.bxteam.divinemc.DivineConfig.disableDisconnectSpam) { // DivineMC - Option to disable disconnect.spam
this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - add proper async disconnect
return;
}
@@ -883,6 +883,7 @@ public class ServerGamePacketListenerImpl
ParseResults<CommandSourceStack> parseResults = this.server.getCommands().getDispatcher().parse(stringReader, this.player.createCommandSourceStack());
// Paper start - Handle non-recoverable exceptions
if (!parseResults.getExceptions().isEmpty()
+ && !org.bxteam.divinemc.DivineConfig.disableDisconnectSpam // DivineMC - Option to disable disconnect.spam
&& parseResults.getExceptions().values().stream().anyMatch(e -> e instanceof io.papermc.paper.brigadier.TagParseCommandSyntaxException)) {
this.disconnect(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM);
return;
@@ -2606,6 +2607,7 @@ public class ServerGamePacketListenerImpl
// this.chatSpamThrottler.increment();
if (!this.chatSpamThrottler.isIncrementAndUnderThreshold()
// CraftBukkit end
+ && !org.bxteam.divinemc.DivineConfig.disableDisconnectSpam // DivineMC - Option to disable disconnect.spam
&& !this.server.getPlayerList().isOp(this.player.getGameProfile())
&& !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - kick event cause & add proper async disconnect
@@ -3382,7 +3384,7 @@ public class ServerGamePacketListenerImpl
public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) {
// Paper start - auto recipe limit
if (!org.bukkit.Bukkit.isPrimaryThread()) {
- if (!this.recipeSpamPackets.isIncrementAndUnderThreshold()) {
+ if (!this.recipeSpamPackets.isIncrementAndUnderThreshold() && !org.bxteam.divinemc.DivineConfig.disableDisconnectSpam) { // DivineMC - Option to disable disconnect.spam
this.disconnectAsync(net.minecraft.network.chat.Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - kick event cause // Paper - add proper async disconnect
return;
}

View File

@@ -243,7 +243,7 @@ public class DivineConfig {
public static int asyncChunkSendingThreadCount = 1;
public static boolean asyncChunkSendingUseVirtualThreads = false;
public static int asyncChunkSendingRateLimitChunkSends = 50;
private void asyncChunkSending() {
private static void asyncChunkSending() {
asyncChunkSendingEnabled = getBoolean("settings.async-chunk-sending.enable", asyncChunkSendingEnabled,
"Enables chunk sending runs off-main thread.");
@@ -286,6 +286,7 @@ public class DivineConfig {
public static boolean ignoreMovedTooQuicklyWhenLagging = true;
public static boolean alwaysAllowWeirdMovement = true;
public static boolean updateSuppressionCrashFix = true;
public static boolean disableDisconnectSpam = false;
private static void miscSettings() {
skipUselessSecondaryPoiSensor = getBoolean("settings.misc.skip-useless-secondary-poi-sensor", skipUselessSecondaryPoiSensor);
clumpOrbs = getBoolean("settings.misc.clump-orbs", clumpOrbs,
@@ -295,6 +296,8 @@ public class DivineConfig {
alwaysAllowWeirdMovement = getBoolean("settings.misc.always-allow-weird-movement", alwaysAllowWeirdMovement,
"Means ignoring messages like 'moved too quickly' and 'moved wrongly'");
updateSuppressionCrashFix = getBoolean("settings.misc.update-suppression-crash-fix", updateSuppressionCrashFix);
disableDisconnectSpam = getBoolean("settings.misc.disable-disconnect-spam", disableDisconnectSpam,
"Prevents players being disconnected by 'disconnect.spam' when sending too many chat packets");
}
public static boolean enableFasterTntOptimization = true;