9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00

Update patches from 1.21.4 branch

This commit is contained in:
Dreeam
2025-03-28 16:46:38 -04:00
parent 893ab16248
commit 45016fbaff
31 changed files with 537 additions and 348 deletions

View File

@@ -1,24 +1,33 @@
package org.dreeam.leaf.async;
import net.minecraft.Util;
import org.dreeam.leaf.config.modules.async.AsyncPlayerDataSave;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class AsyncPlayerDataSaving {
public static final ExecutorService IO_POOL = new ThreadPoolExecutor(
1, 1, 0, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
new com.google.common.util.concurrent.ThreadFactoryBuilder()
.setPriority(Thread.NORM_PRIORITY - 2)
.setNameFormat("Leaf IO Thread")
.setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER))
.build(),
new ThreadPoolExecutor.DiscardPolicy()
);
private AsyncPlayerDataSaving() {
}
public static void saveAsync(Runnable runnable) {
public static void save(Runnable runnable) {
if (!AsyncPlayerDataSave.enabled) {
runnable.run();
return;
} else {
IO_POOL.execute(runnable);
}
ExecutorService ioExecutor = Util.backgroundExecutor().service();
CompletableFuture.runAsync(runnable, ioExecutor);
}
}

View File

@@ -12,7 +12,6 @@ public class AsyncBlockFinding extends ConfigModules {
@Experimental
public static boolean enabled = false;
public static boolean asyncBlockFindingInitialized;
@Override

View File

@@ -27,7 +27,6 @@ public class SparklyPaperParallelWorldTicking extends ConfigModules {
**实验性功能**
启用并行世界处理以提高多核系统的性能.""");
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
threads = config.getInt(getBasePath() + ".threads", threads);
threads = enabled ? threads : 0;

View File

@@ -1,30 +0,0 @@
package org.dreeam.leaf.config.modules.network;
import org.dreeam.leaf.config.ConfigModules;
import org.dreeam.leaf.config.EnumConfigCategory;
public class ConnectionFlushQueueRewrite extends ConfigModules {
public String getBasePath() {
return EnumConfigCategory.NETWORK.getBaseKeyName();
}
public static boolean enabled = false;
@Override
public void onLoaded() {
enabled = config.getBoolean(getBasePath() + ".connection-flush-queue-rewrite", enabled, config.pickStringRegionBased("""
This replaces ConcurrentLinkedQueue with ArrayDeque for better performance
and uses the Netty event loop to ensure thread safety.
May increase the Netty thread usage and requires server restart to take effect
Default: false
""",
"""
此选项将 ConcurrentLinkedQueue 替换为 ArrayDeque 以提高性能,
并使用 Netty 事件循环以确保线程安全。
默认值: false
"""));
}
}

View File

@@ -0,0 +1,35 @@
package org.dreeam.leaf.config.modules.network;
import org.dreeam.leaf.config.ConfigModules;
import org.dreeam.leaf.config.EnumConfigCategory;
public class OptimizeNonFlushPacketSending extends ConfigModules {
public String getBasePath() {
return EnumConfigCategory.NETWORK.getBaseKeyName();
}
public static boolean enabled = false;
@Override
public void onLoaded() {
enabled = config.getBoolean(getBasePath() + ".OptimizeNonFlushPacketSending", enabled, config.pickStringRegionBased("""
WARNING: This option is NOT compatible with ProtocolLib and may cause
issues with other plugins that modify packet handling.
Optimizes non-flush packet sending by using Netty's lazyExecute method to avoid
expensive thread wakeup calls when scheduling packet operations.
Requires server restart to take effect.
""",
"""
警告: 此选项与 ProtocolLib 不兼容, 并可能导致与其他修改数据包
处理的插件出现问题.
通过使用 Netty 的 lazyExecute 方法来优化非刷新数据包的发送,
避免在调度数据包操作时进行昂贵的线程唤醒调用.
需要重启服务器才能生效.
"""));
}
}

View File

@@ -19,7 +19,9 @@ public class FastRNG extends ConfigModules {
public static boolean useLegacyForSlimeChunk = false;
public static boolean useDirectImpl = false;
public static boolean worldgenEnabled() {return enabled && enableForWorldgen;} // Helper function
public static boolean worldgenEnabled() {
return enabled && enableForWorldgen;
} // Helper function
@Override
public void onLoaded() {

View File

@@ -3,8 +3,8 @@ package org.dreeam.leaf.util.map;
import it.unimi.dsi.fastutil.longs.*;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
@@ -41,8 +41,8 @@ public final class ConcurrentLongHashSet extends LongOpenHashSet implements Long
/**
* Creates a new concurrent long set with the specified parameters.
*
* @param initialCapacity the initial capacity
* @param loadFactor the load factor
* @param initialCapacity the initial capacity
* @param loadFactor the load factor
* @param concurrencyLevel the concurrency level
*/
public ConcurrentLongHashSet(int initialCapacity, float loadFactor, int concurrencyLevel) {
@@ -465,9 +465,7 @@ public final class ConcurrentLongHashSet extends LongOpenHashSet implements Long
void clear() {
lock.lock();
try {
for (int i = 0; i < used.length; i++) {
used[i] = false;
}
Arrays.fill(used, false);
size = 0;
} finally {
lock.unlock();

View File

@@ -11,7 +11,6 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory;
public class FasterRandomSource implements BitRandomSource {
private static final int INT_BITS = 48;
@@ -42,6 +41,7 @@ public class FasterRandomSource implements BitRandomSource {
if (isSplittableGenerator) {
return new FasterRandomSource(seed, ((RandomGenerator.SplittableGenerator) this.randomGenerator).split());
}
return new FasterRandomSource(this.nextLong());
}
@@ -61,10 +61,9 @@ public class FasterRandomSource implements BitRandomSource {
if (useDirectImpl) {
// Direct
return (int) ((seed = seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> (INT_BITS - bits));
} else {
// old
return (int) ((seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> (INT_BITS - bits));
}
return (int) ((seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> (INT_BITS - bits));
}
public static class FasterRandomSourcePositionalRandomFactory implements PositionalRandomFactory {
@@ -104,9 +103,9 @@ public class FasterRandomSource implements BitRandomSource {
if (useDirectImpl) {
return (int) (((seed = seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> 16) ^
((seed = seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> 32));
} else {
return randomGenerator.nextInt();
}
return randomGenerator.nextInt();
}
@Override
@@ -121,45 +120,45 @@ public class FasterRandomSource implements BitRandomSource {
val = bits % bound;
} while (bits - val + (bound - 1) < 0);
return val;
} else {
return randomGenerator.nextInt(bound);
}
return randomGenerator.nextInt(bound);
}
@Override
public final long nextLong() {
if (useDirectImpl) {
return ((long) next(32) << 32) + next(32);
} else {
return randomGenerator.nextLong();
}
return randomGenerator.nextLong();
}
@Override
public final boolean nextBoolean() {
if (useDirectImpl) {
return next(1) != 0;
} else {
return randomGenerator.nextBoolean();
}
return randomGenerator.nextBoolean();
}
@Override
public final float nextFloat() {
if (useDirectImpl) {
return next(24) / ((float) (1 << 24));
} else {
return randomGenerator.nextFloat();
}
return randomGenerator.nextFloat();
}
@Override
public final double nextDouble() {
if (useDirectImpl) {
return (((long) next(26) << 27) + next(27)) / (double) (1L << 53);
} else {
return randomGenerator.nextDouble();
}
return randomGenerator.nextDouble();
}
@Override