9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 19:39:17 +00:00

Update changes from ver/1.21.4 branch

This commit is contained in:
Dreeam
2025-06-10 12:34:55 +08:00
155 changed files with 2833 additions and 1026 deletions

View File

@@ -22,7 +22,7 @@ and, in my opinion, worth the low risk of minor mob-spawning-related
inconsistencies.
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 99e9fe7562520e37f8b0fa938b53a973b23c65c3..ff1f5943cb99353df6069060c67da86516c9c956 100644
index c1b3d2b4c56b657ff51c8b27b4b80e0c0d01ddbe..18a0bf81562f61fd6ede72d51d836ae28e9226c3 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -285,6 +285,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -33,6 +33,14 @@ index 99e9fe7562520e37f8b0fa938b53a973b23c65c3..ff1f5943cb99353df6069060c67da865
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
AtomicReference<S> atomicReference = new AtomicReference<>();
@@ -1046,6 +1047,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end - rewrite chunk system
// Paper start - Improved watchdog support - move final shutdown items here
Util.shutdownExecutors();
+ org.dreeam.leaf.async.ShutdownExecutors.shutdown(this); // Leaf
try {
net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
} catch (final Exception ignored) {
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index cd266af35c7b8455af19adc9b0874cdd7572217f..349eafa321c955c6bda7a5aa6931311d85867565 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
@@ -47,7 +55,7 @@ index cd266af35c7b8455af19adc9b0874cdd7572217f..349eafa321c955c6bda7a5aa6931311d
}
}
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 52cef9fed4a68d16d89eabacbad073ead0685972..229e115447b06db3e3b440ee8ea0505979656846 100644
index 3d7d336c2043b533012ee390e6da02ac4f64e1f2..e67196b815dad6baa823822285cff83848e549ce 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -182,6 +182,8 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon

View File

@@ -307,7 +307,7 @@ index 6c65122fe15e08c352885c7dfd3ddf496f0c00c4..bff3da0fba99532889976281dba70d65
io.papermc.paper.plugin.PluginInitializerManager.load(optionSet); // Paper
Bootstrap.bootStrap();
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index af17193fde9d4c13e84fb7952521430299f2cfec..5c0e7804555f9b789a96a98008dd1edf0be68104 100644
index 18a0bf81562f61fd6ede72d51d836ae28e9226c3..271233087ad8a0ef8e90e1d518907e166f8235a2 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -265,6 +265,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -343,7 +343,7 @@ index af17193fde9d4c13e84fb7952521430299f2cfec..5c0e7804555f9b789a96a98008dd1edf
// CraftBukkit start
if (this.server != null) {
this.server.spark.disable(); // Paper - spark
@@ -1073,6 +1085,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1074,6 +1086,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.safeShutdown(waitForServer, false);
}
public void safeShutdown(boolean waitForServer, boolean isRestarting) {
@@ -352,7 +352,7 @@ index af17193fde9d4c13e84fb7952521430299f2cfec..5c0e7804555f9b789a96a98008dd1edf
this.isRestarting = isRestarting;
this.hasLoggedStop = true; // Paper - Debugging
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
@@ -1184,6 +1198,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1185,6 +1199,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// Paper end - Add onboarding message for initial server start
@@ -369,7 +369,7 @@ index af17193fde9d4c13e84fb7952521430299f2cfec..5c0e7804555f9b789a96a98008dd1edf
while (this.running) {
long l;
if (!this.isPaused() && this.tickRateManager.isSprinting() && this.tickRateManager.checkShouldSprintThisTick()) {
@@ -1217,6 +1241,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1218,6 +1242,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.recentTps[0] = tps1.getAverage();
this.recentTps[1] = tps5.getAverage();
this.recentTps[2] = tps15.getAverage();
@@ -377,7 +377,7 @@ index af17193fde9d4c13e84fb7952521430299f2cfec..5c0e7804555f9b789a96a98008dd1edf
tickSection = currentTime;
}
// Paper end - further improve server tick loop
@@ -1242,6 +1267,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1243,6 +1268,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.tickFrame.end();
this.mayHaveDelayedTasks = true;
this.delayedTasksMaxNextTickTimeNanos = Math.max(Util.getNanos() + l, this.nextTickTimeNanos);
@@ -390,7 +390,7 @@ index af17193fde9d4c13e84fb7952521430299f2cfec..5c0e7804555f9b789a96a98008dd1edf
this.startMeasuringTaskExecutionTime();
this.waitUntilNextTick();
this.finishMeasuringTaskExecutionTime();
@@ -1657,7 +1688,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1658,7 +1689,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
long worldTime = level.getGameTime();
final ClientboundSetTimePacket worldPacket = new ClientboundSetTimePacket(worldTime, dayTime, doDaylight);
for (Player entityhuman : level.players()) {
@@ -399,7 +399,7 @@ index af17193fde9d4c13e84fb7952521430299f2cfec..5c0e7804555f9b789a96a98008dd1edf
continue;
}
ServerPlayer entityplayer = (ServerPlayer) entityhuman;
@@ -1676,6 +1707,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1677,6 +1708,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
serverLevel.updateLagCompensationTick(); // Paper - lag compensation
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = serverLevel.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper - Perf: Optimize Hoppers

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Fix Pufferfish and Purpur patches
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 5c0e7804555f9b789a96a98008dd1edf0be68104..62b82b753c36b5400e371952e0685115453bd953 100644
index 271233087ad8a0ef8e90e1d518907e166f8235a2..ecf1e794c78962440da02aadfbe78d9782df2cf0 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -276,7 +276,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -26,7 +26,7 @@ index 5c0e7804555f9b789a96a98008dd1edf0be68104..62b82b753c36b5400e371952e0685115
public boolean lagging = false; // Purpur - Lagging threshold
protected boolean upnp = false; // Purpur - UPnP Port Forwarding
@@ -1238,9 +1238,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1239,9 +1239,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
tps15.add(currentTps, diff);
// Backwards compat with bad plugins
@@ -42,7 +42,7 @@ index 5c0e7804555f9b789a96a98008dd1edf0be68104..62b82b753c36b5400e371952e0685115
lagging = recentTps[0] < org.purpurmc.purpur.PurpurConfig.laggingThreshold; // Purpur - Lagging threshold
tickSection = currentTime;
}
@@ -1268,7 +1271,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1269,7 +1272,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.mayHaveDelayedTasks = true;
this.delayedTasksMaxNextTickTimeNanos = Math.max(Util.getNanos() + l, this.nextTickTimeNanos);
// Purpur start - Configurable TPS Catchup

View File

@@ -7,10 +7,10 @@ Original license: MIT
Original project: https://github.com/PurpurMC/Purpur
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 62b82b753c36b5400e371952e0685115453bd953..3190ed2171b0de32aeb8761aa3e510c968c45448 100644
index ecf1e794c78962440da02aadfbe78d9782df2cf0..cf958bb871137dc88a8c36be867f2192acba2687 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1837,7 +1837,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1838,7 +1838,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@DontObfuscate
public String getServerModName() {

View File

@@ -59,10 +59,10 @@ index 62b9d9486c15a1ec6527f786df4e9fc483390bcb..5384bbc6bb3dbe5481f9d8cb10282551
int i = buffer.readableBytes();
if (i >= 0 && i <= maxSize) {
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 3190ed2171b0de32aeb8761aa3e510c968c45448..58c52eabba725be9fa5fde06be5cf69d0281ce5b 100644
index cf958bb871137dc88a8c36be867f2192acba2687..2c50bde56da7174dcea828feedecb92c98347a45 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1735,6 +1735,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1736,6 +1736,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
GameTestTicker.SINGLETON.tick();
}

View File

@@ -87,10 +87,10 @@ index b305ba9bab617bf4e52d0e6ddf160bacc5751a94..853933618e67d7597c23b3099ea7a7a1
if (players.size() >= resultLimit) {
return players;
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 58c52eabba725be9fa5fde06be5cf69d0281ce5b..83cbf865d83edcb4caea59a1a2b4932a915414be 100644
index 2c50bde56da7174dcea828feedecb92c98347a45..ee07832a92b3f73bd85d13388276cf224743c0ed 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1638,7 +1638,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1639,7 +1639,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
private ServerStatus.Players buildPlayerStatus() {

View File

@@ -13,7 +13,7 @@ To avoid the hefty ArrayDeque's size() call, we check if we *really* need to exe
Most entities won't have any scheduled tasks, so this is a nice performance bonus. These optimizations, however, wouldn't work in a Folia environment, but because in SparklyPaper executeTick is always executed on the main thread, it ain't an issue for us (yay).
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 83cbf865d83edcb4caea59a1a2b4932a915414be..3a86960729e23c7a5028dd64538d08428afd2b01 100644
index ee07832a92b3f73bd85d13388276cf224743c0ed..2ecda6d2af7721113384c11d4a96a3b3cb082232 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -289,6 +289,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -24,7 +24,7 @@ index 83cbf865d83edcb4caea59a1a2b4932a915414be..3a86960729e23c7a5028dd64538d0842
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
AtomicReference<S> atomicReference = new AtomicReference<>();
@@ -1662,6 +1663,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1663,6 +1664,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
// Paper start - Folia scheduler API
((io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler) org.bukkit.Bukkit.getGlobalRegionScheduler()).tick();
@@ -47,7 +47,7 @@ index 83cbf865d83edcb4caea59a1a2b4932a915414be..3a86960729e23c7a5028dd64538d0842
getAllLevels().forEach(level -> {
for (final net.minecraft.world.entity.Entity entity : level.getEntities().getAll()) {
if (entity.isRemoved()) {
@@ -1673,6 +1690,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1674,6 +1691,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}
});

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Virtual thread for chat executor
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 3a86960729e23c7a5028dd64538d08428afd2b01..3ca7405318a4076000250203be4b91dbde95191b 100644
index 2ecda6d2af7721113384c11d4a96a3b3cb082232..7f6dac89c98132645799b7976b972bf43f475fe8 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -2662,7 +2662,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2663,7 +2663,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Cache player profileResult
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 9dce1d22c7de3a3dd0e0e8f117cfbb54d1b15042..405b62c082017024abae7ccc1db5f74caab1eabf 100644
index 9dce1d22c7de3a3dd0e0e8f117cfbb54d1b15042..6b0b0ccc18a5da05685867656705e1fcf94b5891 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -70,6 +70,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -70,6 +70,14 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
private net.minecraft.server.level.ServerPlayer player; // CraftBukkit
public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
private int velocityLoginMessageId = -1; // Paper - Add Velocity IP Forwarding Support
@@ -16,11 +16,14 @@ index 9dce1d22c7de3a3dd0e0e8f117cfbb54d1b15042..405b62c082017024abae7ccc1db5f74c
+ private static final com.github.benmanes.caffeine.cache.Cache<String, ProfileResult> playerProfileResultCache = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
+ .expireAfterWrite(org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResultTimeout, java.util.concurrent.TimeUnit.MINUTES)
+ .build();
+ private static final com.github.benmanes.caffeine.cache.Cache<String, InetAddress> playerSession = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
+ .expireAfterWrite(org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResultTimeout, java.util.concurrent.TimeUnit.MINUTES)
+ .build();
+ // Leaf end - Cache player profileResult
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
this.server = server;
@@ -303,9 +308,25 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -303,9 +311,30 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
String string1 = Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized");
try {
@@ -29,15 +32,20 @@ index 9dce1d22c7de3a3dd0e0e8f117cfbb54d1b15042..405b62c082017024abae7ccc1db5f74c
- .hasJoinedServer(string1, string, this.getAddress());
+ // Leaf start - Cache player profileResult
+ ProfileResult profileResult;
+ if (false) { // TODO
+ if (org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResult) {
+ profileResult = playerProfileResultCache.getIfPresent(string1);
+
+ if (profileResult == null) {
+ InetAddress address = this.getAddress();
+ InetAddress lastAddress = playerSession.getIfPresent(string1);
+ if (isInvalidSession(address, lastAddress)) {
+ // Send request to mojang server to verify session
+ // Result will be null if is invalid and will do disconnect logic below
+ profileResult = ServerLoginPacketListenerImpl.this.server
+ .getSessionService()
+ .hasJoinedServer(string1, string, this.getAddress());
+ if (profileResult != null) {
+ .hasJoinedServer(string1, string, address);
+ if (profileResult != null && address != null) {
+ playerProfileResultCache.put(string1, profileResult);
+ playerSession.put(string1, address);
+ }
+ }
+ } else {
@@ -49,3 +57,24 @@ index 9dce1d22c7de3a3dd0e0e8f117cfbb54d1b15042..405b62c082017024abae7ccc1db5f74c
if (profileResult != null) {
GameProfile gameProfile = profileResult.profile();
// CraftBukkit start - fire PlayerPreLoginEvent
@@ -350,6 +379,20 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
// Paper end - Cache authenticator threads
}
+ // Leaf start - Cache player profileResult
+ private static boolean isInvalidSession(@org.jetbrains.annotations.Nullable InetAddress currAddress, @org.jetbrains.annotations.Nullable InetAddress lastAddress) {
+ // Invalid address or non-public IP address
+ if (currAddress == null ||
+ currAddress.isAnyLocalAddress() ||
+ currAddress.isLinkLocalAddress() ||
+ currAddress.isLoopbackAddress() ||
+ currAddress.isSiteLocalAddress()) {
+ return true;
+ }
+ return !currAddress.equals(lastAddress);
+ }
+ // Leaf end - Cache player profileResult
+
// CraftBukkit start
private GameProfile callPlayerPreLoginEvents(GameProfile gameprofile) throws Exception { // Paper - Add more fields to AsyncPlayerPreLoginEvent
// Paper start - Add Velocity IP Forwarding Support

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Replace brain maps with optimized collection
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
index 29fdf94db0308031edfe7915fc587a2aa5a1a18a..b946faf899561b9e4f8399e16600eede54bb55a5 100644
index 29fdf94db0308031edfe7915fc587a2aa5a1a18a..4a0faaedacd7b925c5adad0280870e674cf7ab46 100644
--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -45,14 +45,18 @@ public class Brain<E extends LivingEntity> {
@@ -14,11 +14,12 @@ index 29fdf94db0308031edfe7915fc587a2aa5a1a18a..b946faf899561b9e4f8399e16600eede
private static final int SCHEDULE_UPDATE_DELAY = 20;
- private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newHashMap();
- private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
- private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
+ // Leaf start - Replace brain maps with optimized collection
+ private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
+ private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>();
+ private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = new it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap<>();
+ private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = new it.unimi.dsi.fastutil.objects.Reference2ReferenceLinkedOpenHashMap<>();
+ private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = new it.unimi.dsi.fastutil.objects.Object2ObjectRBTreeMap<>();
+ // Leaf end - Replace brain maps with optimized collection
private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
private Schedule schedule = Schedule.EMPTY;
- private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
- private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = Maps.newHashMap();

View File

@@ -71,7 +71,7 @@ index 9c0c99b936b4a82ebfe924866e53ec71f7bbe9ad..2ccff968cb2065d34fad4d27573f9e30
.add(
new ClientboundUpdateAttributesPacket.AttributeSnapshot(
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe29a2d6f8b 100644
index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..38a43e143906f2727025696a2895eafa8a77deb6 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -255,6 +255,15 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -104,26 +104,51 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
// Paper start - optimise entity tracker
if (true) {
this.newTrackerTick();
@@ -1135,7 +1151,17 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1135,7 +1151,42 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
final Entity entity;
private final int range;
SectionPos lastSectionPos;
- public final Set<ServerPlayerConnection> seenBy = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - Perf: optimise map impl
+ // Leaf start - Multithreaded tracker
+ public static final ServerPlayerConnection[] EMPTY_OBJECT_ARRAY = new ServerPlayerConnection[0];
+ public final Set<ServerPlayerConnection> seenBy = org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled ? it.unimi.dsi.fastutil.objects.ReferenceSets.synchronize(new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>()) : new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - Perf: optimise map impl
+ private final it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<ServerPlayerConnection> nonSyncSeenBy = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>() {
+ @Override
+ public boolean add(ServerPlayerConnection serverPlayerConnection) {
+ seenByUpdated = true;
+ return super.add(serverPlayerConnection);
+ }
+
+ @Override
+ public boolean remove(Object k) {
+ seenByUpdated = true;
+ return super.remove(k);
+ }
+
+ @Override
+ public void clear() {
+ seenByUpdated = true;
+ super.clear();
+ }
+ };
+ public final Set<ServerPlayerConnection> seenBy = org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled ? it.unimi.dsi.fastutil.objects.ReferenceSets.synchronize(nonSyncSeenBy) : nonSyncSeenBy; // Paper - Perf: optimise map impl
+ private volatile boolean seenByUpdated = true;
+ private volatile ServerPlayerConnection[] seenByArray = EMPTY_OBJECT_ARRAY;
+ public ServerPlayerConnection[] seenBy() {
+ return seenByArray;
+ if (!seenByUpdated) {
+ return seenByArray;
+ } else {
+ return seenBy.toArray(EMPTY_OBJECT_ARRAY);
+ }
+ }
+ public void seenByUpdated() {
+ this.seenByArray = this.seenBy.toArray(EMPTY_OBJECT_ARRAY);
+ seenByUpdated = false;
+ }
+ // Leaf end - Multithreaded tracker
// Paper start - optimise entity tracker
private long lastChunkUpdate = -1L;
@@ -1162,27 +1188,95 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1162,27 +1213,95 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
this.lastTrackedChunk = chunk;
final ServerPlayer[] playersRaw = players.getRawDataUnchecked();
@@ -145,13 +170,13 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
if (!players.contains(player)) {
- this.removePlayer(player);
+ removed |= this.removePlayerMulti(player);
}
}
+ }
+ }
+ if (removed) {
+ this.seenByUpdated();
+ }
}
}
+ }
+ }
+ // Leaf end - Multithreaded tracker
+
+ // Leaf start - Multithreaded tracker
@@ -199,8 +224,8 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
+ }
+ if (removed) {
+ this.seenByUpdated();
+ }
+ }
}
}
+ };
+
+ // Only update asynchronously for real player, and sync update for fake players
@@ -212,8 +237,8 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
+ } else {
+ updatePlayerTasks.run();
+ return null;
+ }
+ }
}
}
+ // Leaf end - Multithreaded tracker
@Override
@@ -224,7 +249,7 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(conn.getPlayer())) {
foundToRemove = true;
break;
@@ -1193,12 +1287,13 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1193,12 +1312,13 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
return;
}
@@ -240,7 +265,7 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
}
@Override
@@ -1208,10 +1303,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1208,10 +1328,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
if (this.seenBy.isEmpty()) {
return;
}
@@ -254,7 +279,7 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
}
@Override
@@ -1238,7 +1334,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1238,7 +1359,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
}
public void broadcast(Packet<?> packet) {
@@ -263,7 +288,7 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
serverPlayerConnection.send(packet);
}
}
@@ -1259,21 +1355,34 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1259,21 +1380,34 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
}
public void broadcastRemoved() {
@@ -301,7 +326,7 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
// Paper start - remove allocation of Vec3D here
// Vec3 vec3 = player.position().subtract(this.entity.position());
double vec3_dx = player.getX() - this.entity.getX();
@@ -1301,6 +1410,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1301,6 +1435,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
// CraftBukkit end
if (flag) {
if (this.seenBy.add(player.connection)) {
@@ -309,7 +334,7 @@ index c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a..ae0a7c9b95f4f2561769e0d661fadbe2
// Paper start - entity tracking events
if (io.papermc.paper.event.player.PlayerTrackEntityEvent.getHandlerList().getRegisteredListeners().length == 0 || new io.papermc.paper.event.player.PlayerTrackEntityEvent(player.getBukkitEntity(), this.entity.getBukkitEntity()).callEvent()) {
this.serverEntity.addPairing(player);
@@ -1309,6 +1419,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1309,6 +1444,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
this.serverEntity.onPlayerAdd(); // Paper - fix desync when a player is added to the tracker
}
} else if (this.seenBy.remove(player.connection)) {

View File

@@ -6,23 +6,6 @@ Subject: [PATCH] Nitori: Async playerdata saving
Original license: GPL v3
Original project: https://github.com/Gensokyo-Reimagined/Nitori
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 3ca7405318a4076000250203be4b91dbde95191b..2aed6f594c73bea5e8919e65cf04bc7eb6775c3e 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1067,6 +1067,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
io.papermc.paper.log.CustomLogManager.forceReset(); // Paper - Reset loggers after shutdown
this.onServerExit();
// Paper end - Improved watchdog support - move final shutdown items here
+ // Leaf start - Async playerdata saving
+ org.dreeam.leaf.async.AsyncPlayerDataSaving.IO_POOL.shutdown();
+ try {
+ org.dreeam.leaf.async.AsyncPlayerDataSaving.IO_POOL.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS);
+ } catch (java.lang.InterruptedException ignored) {}
+ // Leaf end - Async playerdata saving
}
public String getLocalIp() {
diff --git a/net/minecraft/world/level/storage/LevelStorageSource.java b/net/minecraft/world/level/storage/LevelStorageSource.java
index 8104f71c30c1fa46c83acdf0b2e58483df9d89cc..169b4544ab3d0e8515a2d7020a23ae0e2e0c952d 100644
--- a/net/minecraft/world/level/storage/LevelStorageSource.java

View File

@@ -7,10 +7,10 @@ Original license: AGPL-3.0
Original project: https://github.com/snackbag/TT20
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 2aed6f594c73bea5e8919e65cf04bc7eb6775c3e..bbd2b327c658b56a1fcf30c8b77cab987d688fcc 100644
index 7f6dac89c98132645799b7976b972bf43f475fe8..4bf840705bec251aa7e5595fa16bf8e1a9a7d2e9 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1544,6 +1544,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1539,6 +1539,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.server.spark.tickStart(); // Paper - spark
new com.destroystokyo.paper.event.server.ServerTickStartEvent(this.tickCount+1).callEvent(); // Paper - Server Tick Events

View File

@@ -1,49 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Smooth teleport config
This abuses some of how Minecraft works and attempts to teleport a player to another world without
triggering typical respawn packets. All of natural state of chunk resends, entity adds/removes, etc still
happen but the visual "refresh" of a world change is hidden. Depending on the destination location/world,
this can act as a "smooth teleport" to a world if the new world is very similar looking to the old one.
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 18125ed336c3425f123232b405a8af9ee3a2ba7d..e97a93c97e1822f969dce2d30dd915db5d3d14cf 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -1419,6 +1419,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
LevelData worlddata = level.getLevelData();
this.connection.send(new ClientboundRespawnPacket(this.createCommonSpawnInfo(level), (byte) 3));
+ if (!org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled || !PlayerList.isSameLogicalHeight(serverLevel, level)) this.connection.send(new ClientboundRespawnPacket(this.createCommonSpawnInfo(level), (byte) 3)); // Leaf - Smooth teleport
this.connection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
PlayerList playerList = this.server.getPlayerList();
@@ -1428,7 +1429,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
// CraftBukkit end
this.portalPos = org.bukkit.craftbukkit.util.CraftLocation.toBlockPosition(exit); // Purpur - Fix stuck in portals
this.setServerLevel(level);
- this.connection.internalTeleport(PositionMoveRotation.of(teleportTransition), teleportTransition.relatives()); // CraftBukkit - use internal teleport without event
+ if (!org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled || !PlayerList.isSameLogicalHeight(serverLevel, level)) this.connection.internalTeleport(PositionMoveRotation.of(teleportTransition), teleportTransition.relatives()); // CraftBukkit - use internal teleport without event // Leaf - Smooth teleport
this.connection.resetPosition();
level.addDuringTeleport(this);
this.triggerDimensionChangeTriggers(serverLevel);
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 34c5c2e3d6b0706cb91ec0171969cf81e94741a4..8b1652805a2ac9ebae9c99dd77e81c7a484a7abb 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -956,11 +956,11 @@ public abstract class PlayerList {
byte b = (byte)(keepInventory ? 1 : 0);
ServerLevel serverLevel = serverPlayer.serverLevel();
LevelData levelData = serverLevel.getLevelData();
- if (!serverPlayer.smoothWorldTeleport || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.send(new ClientboundRespawnPacket(serverPlayer.createCommonSpawnInfo(serverLevel), b)); // Leaf - Slice
+ if ((!serverPlayer.smoothWorldTeleport && !org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled) || b != 1 || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.send(new ClientboundRespawnPacket(serverPlayer.createCommonSpawnInfo(serverLevel), b)); // Leaf - Slice // Leaf - Smooth teleport
// serverPlayer.connection.teleport(serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), serverPlayer.getYRot(), serverPlayer.getXRot());
serverPlayer.connection.send(new ClientboundSetChunkCacheRadiusPacket(serverLevel.spigotConfig.viewDistance)); // Spigot
serverPlayer.connection.send(new ClientboundSetSimulationDistancePacket(serverLevel.spigotConfig.simulationDistance)); // Spigot
- if (!serverPlayer.smoothWorldTeleport || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.teleport(org.bukkit.craftbukkit.util.CraftLocation.toBukkit(serverPlayer.position(), serverLevel.getWorld(), serverPlayer.getYRot(), serverPlayer.getXRot())); // CraftBukkit // Leaf - Slice
+ if ((!serverPlayer.smoothWorldTeleport && !org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled) || b != 1 || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.teleport(org.bukkit.craftbukkit.util.CraftLocation.toBukkit(serverPlayer.position(), serverLevel.getWorld(), serverPlayer.getYRot(), serverPlayer.getXRot())); // CraftBukkit // Leaf - Slice // Leaf - Smooth teleport
serverPlayer.connection.send(new ClientboundSetDefaultSpawnPositionPacket(level.getSharedSpawnPos(), level.getSharedSpawnAngle()));
serverPlayer.connection.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked()));
serverPlayer.connection

View File

@@ -1,47 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Collect then startEachNonRunningBehavior in Brain
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
index b946faf899561b9e4f8399e16600eede54bb55a5..b2e17d387558875f45a8458cf874a5b056820432 100644
--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -462,20 +462,29 @@ public class Brain<E extends LivingEntity> {
}
private void startEachNonRunningBehavior(ServerLevel level, E entity) {
- long gameTime = level.getGameTime();
+ // Leaf start - Collect then startEachNonRunningBehavior in Brain
+ final long gameTime = level.getGameTime();
+ List<BehaviorControl<? super E>> behaviorsToStart = new ObjectArrayList<>();
- for (Map<Activity, Set<BehaviorControl<? super E>>> map : this.availableBehaviorsByPriority.values()) {
- for (Entry<Activity, Set<BehaviorControl<? super E>>> entry : map.entrySet()) {
- Activity activity = entry.getKey();
- if (this.activeActivities.contains(activity)) {
- for (BehaviorControl<? super E> behaviorControl : entry.getValue()) {
+ for (Activity activeActivity : this.activeActivities) {
+ for (Map<Activity, Set<BehaviorControl<? super E>>> priorityMap : this.availableBehaviorsByPriority.values()) {
+ Set<BehaviorControl<? super E>> behaviors = priorityMap.get(activeActivity);
+
+ if (behaviors != null && !behaviors.isEmpty()) {
+ for (BehaviorControl<? super E> behaviorControl : behaviors) {
if (behaviorControl.getStatus() == Behavior.Status.STOPPED) {
- behaviorControl.tryStart(level, entity, gameTime);
+ behaviorsToStart.add(behaviorControl);
}
}
}
}
}
+ if (!behaviorsToStart.isEmpty()) {
+ for (BehaviorControl<? super E> behaviorControl : behaviorsToStart) {
+ behaviorControl.tryStart(level, entity, gameTime);
+ }
+ }
+ // Leaf end - Collect then startEachNonRunningBehavior in Brain
}
private void tickEachRunningBehavior(ServerLevel level, E entity) {

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Optimize checking nearby players for spawning
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index ae0a7c9b95f4f2561769e0d661fadbe29a2d6f8b..14b2abc51fa5d2caa56adfaf50784296c5668ae6 100644
index 38a43e143906f2727025696a2895eafa8a77deb6..083b49c8fbdbde96b5be3e5531c21b2c96371b60 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -773,7 +773,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Replace brain activity maps with optimized collection
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
index b2e17d387558875f45a8458cf874a5b056820432..e78cef4c0ee6cff7ec2f27ced12c96be67dc7a0e 100644
index 4a0faaedacd7b925c5adad0280870e674cf7ab46..655c3028440e62bcc01d8f1b3e808fd68484128e 100644
--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -399,8 +399,8 @@ public class Brain<E extends LivingEntity> {

View File

@@ -38,10 +38,10 @@ index ccd6f16e244745ee0702504dbea710485037a3e3..2ecb73fc7b6754ade93bf16b48c623e6
.forEach(
entity -> {
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index e97a93c97e1822f969dce2d30dd915db5d3d14cf..ccd442b24693bc9269cc8ab3e44887d0ad3eadbd 100644
index 18125ed336c3425f123232b405a8af9ee3a2ba7d..d507544efafe74ecaffd6a063eff152d349ec76a 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -1519,6 +1519,13 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -1518,6 +1518,13 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
this.containerMenu.broadcastChanges();
}

View File

@@ -20,10 +20,10 @@ One-time operation: Convert distance to squared distance
Total operations: ~3 × n (in the no-predicate case) or ~4 × n (with predicate)
diff --git a/net/minecraft/world/level/EntityGetter.java b/net/minecraft/world/level/EntityGetter.java
index 670860df81a3abfc1b8b53be505fce0ee32ee2c4..083a2b5da246113913bcd5d0b2b9be42cf0554d9 100644
index 670860df81a3abfc1b8b53be505fce0ee32ee2c4..308e00947da3fe4888fb1b1b9fa11ac5da46663b 100644
--- a/net/minecraft/world/level/EntityGetter.java
+++ b/net/minecraft/world/level/EntityGetter.java
@@ -201,23 +201,42 @@ public interface EntityGetter extends ca.spottedleaf.moonrise.patches.chunk_syst
@@ -201,23 +201,43 @@ public interface EntityGetter extends ca.spottedleaf.moonrise.patches.chunk_syst
}
// Paper end - Affects Spawning API
@@ -41,9 +41,10 @@ index 670860df81a3abfc1b8b53be505fce0ee32ee2c4..083a2b5da246113913bcd5d0b2b9be42
- for (Player player1 : this.players()) {
- if (predicate == null || predicate.test(player1)) {
+ List<? extends Player> players = this.players();
+ if (predicate == null) {
+ for (int i = 0; i < this.players().size(); i++) {
+ Player player1 = this.players().get(i);
+ for (int i = 0, playersSize = players.size(); i < playersSize; i++) {
+ Player player1 = players.get(i);
double d1 = player1.distanceToSqr(x, y, z);
- if ((distance < 0.0 || d1 < distance * distance) && (d == -1.0 || d1 < d)) {
- d = d1;
@@ -53,8 +54,8 @@ index 670860df81a3abfc1b8b53be505fce0ee32ee2c4..083a2b5da246113913bcd5d0b2b9be42
}
}
+ } else {
+ for (int i = 0; i < this.players().size(); i++) {
+ Player player1 = this.players().get(i);
+ for (int i = 0, playersSize = players.size(); i < playersSize; i++) {
+ Player player1 = players.get(i);
+ if (predicate.test(player1)) {
+ double d1 = player1.distanceToSqr(x, y, z);
+ if (d1 < distance) {

View File

@@ -1,72 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Fri, 14 Feb 2025 14:58:59 +0100
Subject: [PATCH] Alternative Brain Behaviour
In the test, this can give ~54.87% improvement (~25712ms -> ~11604ms),
under 1024 villagers situation.
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
index e78cef4c0ee6cff7ec2f27ced12c96be67dc7a0e..e3d0186e681168840836690acd402b774bc464b5 100644
--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -268,23 +268,52 @@ public class Brain<E extends LivingEntity> {
return this.activeActivities;
}
+ // Leaf start - Alternative Brain Behaviour
+ private ObjectArrayList<BehaviorControl<? super E>> runningBehaviorsCache;
+ private long lastRunningBehaviorCheck = -1;
+ // Leaf end - Alternative Brain Behaviour
+
@Deprecated
@VisibleForDebug
public List<BehaviorControl<? super E>> getRunningBehaviors() {
- List<BehaviorControl<? super E>> list = new ObjectArrayList<>();
+ // Leaf start - Alternative Brain Behaviour
+ long currentTick = getCurrentTick();
+
+ // Use cached result if within update interval
+ if (runningBehaviorsCache != null && (currentTick - lastRunningBehaviorCheck) < org.dreeam.leaf.config.modules.opt.BrainRunningBehaviorCacheUpdate.interval) {
+ return runningBehaviorsCache;
+ }
+
+ // Initialize or reuse cache list
+ if (runningBehaviorsCache == null) {
+ runningBehaviorsCache = new ObjectArrayList<>(32);
+ } else {
+ runningBehaviorsCache.clear();
+ }
+
+ for (Map<Activity, Set<BehaviorControl<? super E>>> activityMap : availableBehaviorsByPriority.values()) {
+ for (Set<BehaviorControl<? super E>> behaviors : activityMap.values()) {
+ if (behaviors.isEmpty()) continue;
- for (Map<Activity, Set<BehaviorControl<? super E>>> map : this.availableBehaviorsByPriority.values()) {
- for (Set<BehaviorControl<? super E>> set : map.values()) {
- for (BehaviorControl<? super E> behaviorControl : set) {
- if (behaviorControl.getStatus() == Behavior.Status.RUNNING) {
- list.add(behaviorControl);
+ for (BehaviorControl<? super E> behavior : behaviors) {
+ if (behavior.getStatus() == Behavior.Status.RUNNING) {
+ runningBehaviorsCache.add(behavior);
}
}
}
}
- return list;
+ lastRunningBehaviorCheck = currentTick;
+
+ return runningBehaviorsCache;
+ }
+
+ // Helper method to get current tick
+ private long getCurrentTick() {
+ // This should be implemented to return the current game tick
+ return System.nanoTime() / 50_000_000; // Approximate tick time of 50ms
}
+ // Leaf end - Alternative Brain Behaviour
public void useDefaultActivity() {
this.setActiveActivity(this.defaultActivity);

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Use ensureCapacity to pre-populate the size of ticking chunks
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index 14b2abc51fa5d2caa56adfaf50784296c5668ae6..0813505f96a1a6bb2cbfb05a97c90241f0c5b1c8 100644
index 083b49c8fbdbde96b5be3e5531c21b2c96371b60..d77197ff56bd7acd7747af7d0dc937c31fa86a17 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -733,6 +733,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider

View File

@@ -7,7 +7,7 @@ Subject: [PATCH] Directly use the pre-filtered ticking chunks list as the
This patch uses already pre filtered chunks, which completely skips the isChunkNearPlayer check
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index 0813505f96a1a6bb2cbfb05a97c90241f0c5b1c8..051d839fece06cac8ad79d8d936237a66cd01ae4 100644
index d77197ff56bd7acd7747af7d0dc937c31fa86a17..b0a5ded4012e892631f20829166e86fac8491339 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -739,13 +739,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider

View File

@@ -41,6 +41,29 @@ index ea4010df54dbd17cdae22d671ea1e4bd7b685b3e..8d53cb917e9f623a67aba066c6a21f27
boolean ret = false;
final boolean canProcessFullUpdates = processFullUpdates & isTickThread;
diff --git a/io/papermc/paper/redstone/RedstoneWireTurbo.java b/io/papermc/paper/redstone/RedstoneWireTurbo.java
index ff747a1ecdf3c888bca0d69de4f85dcd810b6139..b288d57d9f7bd0ccf1877cf9920bd67288ff22f7 100644
--- a/io/papermc/paper/redstone/RedstoneWireTurbo.java
+++ b/io/papermc/paper/redstone/RedstoneWireTurbo.java
@@ -829,14 +829,10 @@ public final class RedstoneWireTurbo {
j = getMaxCurrentStrength(upd, j);
int l = 0;
- wire.shouldSignal = false;
- // Unfortunately, World.isBlockIndirectlyGettingPowered is complicated,
- // and I'm not ready to try to replicate even more functionality from
- // elsewhere in Minecraft into this accelerator. So sadly, we must
- // suffer the performance hit of this very expensive call. If there
- // is consistency to what this call returns, we may be able to cache it.
- final int k = worldIn.getBestNeighborSignal(upd.self);
- wire.shouldSignal = true;
+ // Leaf start - SparklyPaper - parallel world ticking
+ // This now correctly calls the (conditionally) thread-safe method in RedStoneWireBlock
+ final int k = wire.getBlockSignal(worldIn, upd.self);
+ // Leaf end - SparklyPaper - parallel world ticking
// The variable 'k' holds the maximum redstone power value of any adjacent blocks.
// If 'k' has the highest level of all neighbors, then the power level of this
diff --git a/net/minecraft/core/dispenser/DispenseItemBehavior.java b/net/minecraft/core/dispenser/DispenseItemBehavior.java
index 582e012222123e5001c34153f2ee1ab1d08935fd..c0bce2293d07ca58cc5bc9e036ab8dcac06c1566 100644
--- a/net/minecraft/core/dispenser/DispenseItemBehavior.java
@@ -57,7 +80,7 @@ index 582e012222123e5001c34153f2ee1ab1d08935fd..c0bce2293d07ca58cc5bc9e036ab8dca
List<org.bukkit.block.BlockState> states = new java.util.ArrayList<>(level.capturedBlockStates.values());
level.capturedBlockStates.clear();
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index bbd2b327c658b56a1fcf30c8b77cab987d688fcc..c9b8bc9592d5fce77750de89fa886db383d92a89 100644
index 4bf840705bec251aa7e5595fa16bf8e1a9a7d2e9..543bdb926426bfd5be01d0c23e8c9e274b94485c 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -290,6 +290,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -131,7 +154,7 @@ index bbd2b327c658b56a1fcf30c8b77cab987d688fcc..c9b8bc9592d5fce77750de89fa886db3
flag = true;
}
@@ -1665,6 +1684,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1660,6 +1679,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}
@@ -150,7 +173,7 @@ index bbd2b327c658b56a1fcf30c8b77cab987d688fcc..c9b8bc9592d5fce77750de89fa886db3
protected void tickChildren(BooleanSupplier hasTimeLeft) {
this.getPlayerList().getPlayers().forEach(serverPlayer1 -> serverPlayer1.connection.suspendFlushing());
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
@@ -1731,28 +1762,50 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1726,28 +1757,50 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
this.isIteratingOverLevels = true; // Paper - Throw exception on world create while being ticked
@@ -219,7 +242,7 @@ index bbd2b327c658b56a1fcf30c8b77cab987d688fcc..c9b8bc9592d5fce77750de89fa886db3
this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
this.tickConnection();
@@ -1832,6 +1885,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1827,6 +1880,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
newLevels.remove(level.dimension());
@@ -373,7 +396,7 @@ index 54910c2e1d6e6bb556e536fda060bd09402e04e8..72e871b8c7fee9b5cbd567e03baee80e
// Gale start - Pufferfish - SIMD support
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 0f9d18dd29e210ad656da211a3cb1cb25cd4efb1..b3acfc7e00797ea16cc2c1793452f3ed97b9c61a 100644
index 6d5a15122079f2d1568ceb7086db21ad454f58e6..9dd6205e1cdd2124ab9d91f0a1e344eb6aa1fb2e 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -175,7 +175,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -617,7 +640,7 @@ index 2ecb73fc7b6754ade93bf16b48c623e6b3a955a9..85bfc91ff163a2a564b7b610e27ff90e
// Paper start - extra debug info
if (entity.valid) {
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index ccd442b24693bc9269cc8ab3e44887d0ad3eadbd..ac7ac519ecc58a31c4b9efc24f054ec014851fb4 100644
index d507544efafe74ecaffd6a063eff152d349ec76a..bc955da0dff79262dace84d255f27b3271a91ca5 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -456,6 +456,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -645,7 +668,7 @@ index ccd442b24693bc9269cc8ab3e44887d0ad3eadbd..ac7ac519ecc58a31c4b9efc24f054ec0
// CraftBukkit start
/*
this.isChangingDimension = true;
@@ -1748,6 +1752,12 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -1747,6 +1751,12 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
return OptionalInt.empty();
} else {
// CraftBukkit start
@@ -658,7 +681,7 @@ index ccd442b24693bc9269cc8ab3e44887d0ad3eadbd..ac7ac519ecc58a31c4b9efc24f054ec0
this.containerMenu = abstractContainerMenu; // Moved up
if (!this.isImmobile())
this.connection
@@ -1812,6 +1822,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -1811,6 +1821,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
}
@Override
public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
@@ -671,7 +694,7 @@ index ccd442b24693bc9269cc8ab3e44887d0ad3eadbd..ac7ac519ecc58a31c4b9efc24f054ec0
// Paper end - Inventory close reason
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 8b1652805a2ac9ebae9c99dd77e81c7a484a7abb..e4bccc642abe15b0ec4b1cf2634801065a27e11a 100644
index 34c5c2e3d6b0706cb91ec0171969cf81e94741a4..a1249d66c3693374b0f57c83302d05a7cbc2a306 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -252,6 +252,8 @@ public abstract class PlayerList {
@@ -688,12 +711,12 @@ index 8b1652805a2ac9ebae9c99dd77e81c7a484a7abb..e4bccc642abe15b0ec4b1cf263480106
public ServerPlayer respawn(ServerPlayer player, boolean keepInventory, Entity.RemovalReason reason, @Nullable org.bukkit.event.player.PlayerRespawnEvent.RespawnReason eventReason, @Nullable org.bukkit.Location location) {
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) {
+ if (location != null) // Leaf - THIS CAN BE NULL; see PlayerList::respawn(ServerPlayer, boolean, Entity.RemovalReason, PlayerRespawnEvent.RespawnReason)
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureOnlyTickThread("Cannot respawn player off-main, from world " + player.serverLevel().getWorld().getName() + " to world " + location.getWorld().getName());
+ else
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureOnlyTickThread("Cannot respawn player off-main, respawning in world " + player.serverLevel().getWorld().getName());
+ // SparklyPaper end - parallel world ticking (additional concurrency issues logs)
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled && !this.server.isSameThread()) {
+ // Respawning is a complex operation that modifies global player lists and can interact with multiple
+ // worlds. It must be executed on the main server thread to ensure thread safety. We block the
+ // calling (world) thread to wait for the result, preserving the synchronous API contract of this method.
+ org.bukkit.Location finalLocation = location;
+ return this.server.submit(() -> this.respawn(player, keepInventory, reason, eventReason, finalLocation)).join();
+ }
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
player.stopRiding(); // CraftBukkit
@@ -1104,10 +1127,21 @@ index d306f5f524dc64618df94c9783c2168dc561a5e3..2e0aec5327d92f89f38bbc393b3ba705
return true;
} else {
diff --git a/net/minecraft/world/level/block/RedStoneWireBlock.java b/net/minecraft/world/level/block/RedStoneWireBlock.java
index 1943a6aad888647953e2d9dbbeedb0bd81c6f9df..3902c21a0a4f456a4e1b966a0301c15f8c20a298 100644
index 1943a6aad888647953e2d9dbbeedb0bd81c6f9df..ccc98d71da3c1150878f96801fbf65bfa1a64472 100644
--- a/net/minecraft/world/level/block/RedStoneWireBlock.java
+++ b/net/minecraft/world/level/block/RedStoneWireBlock.java
@@ -283,7 +283,12 @@ public class RedStoneWireBlock extends Block {
@@ -65,7 +65,10 @@ public class RedStoneWireBlock extends Block {
private final Function<BlockState, VoxelShape> shapes;
private final BlockState crossState;
private final RedstoneWireEvaluator evaluator = new DefaultRedstoneWireEvaluator(this);
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
public boolean shouldSignal = true;
+ private final ThreadLocal<Boolean> shouldSignalTL = ThreadLocal.withInitial(() -> true);
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
@Override
public MapCodec<RedStoneWireBlock> codec() {
@@ -283,7 +286,12 @@ public class RedStoneWireBlock extends Block {
if (orientation != null) {
source = pos.relative(orientation.getFront().getOpposite());
}
@@ -1121,7 +1155,7 @@ index 1943a6aad888647953e2d9dbbeedb0bd81c6f9df..3902c21a0a4f456a4e1b966a0301c15f
return;
}
updatePowerStrength(worldIn, pos, state, orientation, blockAdded);
@@ -311,7 +316,12 @@ public class RedStoneWireBlock extends Block {
@@ -311,7 +319,12 @@ public class RedStoneWireBlock extends Block {
// [Space Walker] suppress shape updates and emit those manually to
// bypass the new neighbor update stack.
if (level.setBlock(pos, state, Block.UPDATE_KNOWN_SHAPE | Block.UPDATE_CLIENTS)) {
@@ -1135,6 +1169,76 @@ index 1943a6aad888647953e2d9dbbeedb0bd81c6f9df..3902c21a0a4f456a4e1b966a0301c15f
}
}
}
@@ -328,10 +341,19 @@ public class RedStoneWireBlock extends Block {
}
public int getBlockSignal(Level level, BlockPos pos) {
- this.shouldSignal = false;
- int bestNeighborSignal = level.getBestNeighborSignal(pos);
- this.shouldSignal = true;
- return bestNeighborSignal;
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) {
+ this.shouldSignalTL.set(false);
+ int bestNeighborSignal = level.getBestNeighborSignal(pos);
+ this.shouldSignalTL.set(true);
+ return bestNeighborSignal;
+ } else {
+ this.shouldSignal = false;
+ int bestNeighborSignal = level.getBestNeighborSignal(pos);
+ this.shouldSignal = true;
+ return bestNeighborSignal;
+ }
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
private void checkCornerChangeAt(Level level, BlockPos pos) {
@@ -422,12 +444,21 @@ public class RedStoneWireBlock extends Block {
@Override
protected int getDirectSignal(BlockState blockState, BlockGetter blockAccess, BlockPos pos, Direction side) {
- return !this.shouldSignal ? 0 : blockState.getSignal(blockAccess, pos, side);
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ boolean signal = org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled ? this.shouldSignalTL.get() : this.shouldSignal;
+ return !signal ? 0 : blockState.getSignal(blockAccess, pos, side);
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
@Override
protected int getSignal(BlockState blockState, BlockGetter blockAccess, BlockPos pos, Direction side) {
- if (this.shouldSignal && side != Direction.DOWN) {
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ boolean signal;
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled)
+ signal = this.shouldSignalTL.get();
+ else
+ signal = this.shouldSignal;
+ if (signal && side != Direction.DOWN) {
int powerValue = blockState.getValue(POWER);
if (powerValue == 0) {
return 0;
@@ -441,6 +472,7 @@ public class RedStoneWireBlock extends Block {
return 0;
}
}
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
protected static boolean shouldConnectTo(BlockState state) {
return shouldConnectTo(state, null);
@@ -459,7 +491,12 @@ public class RedStoneWireBlock extends Block {
@Override
protected boolean isSignalSource(BlockState state) {
- return this.shouldSignal;
+ // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
+ if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled)
+ return this.shouldSignalTL.get();
+ else
+ return this.shouldSignal;
+ // Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
public static int getColorForPower(int power) {
diff --git a/net/minecraft/world/level/block/SaplingBlock.java b/net/minecraft/world/level/block/SaplingBlock.java
index a22cb810622e0ae97bc2a0d6390d026d9482b783..3e7478e959da3a0191de6c76b80cbb9b625b6898 100644
--- a/net/minecraft/world/level/block/SaplingBlock.java

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] SparklyPaper: Track each world MSPT
Original project: https://github.com/SparklyPower/SparklyPaper
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index c9b8bc9592d5fce77750de89fa886db383d92a89..1dc599e28682b59c8389ff2ada100b405bf97240 100644
index 543bdb926426bfd5be01d0c23e8c9e274b94485c..9933a60db91d68f76df33ccddea0852fd59b8983 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1687,7 +1687,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1682,7 +1682,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Leaf start - SparklyPaper - parallel world ticking mod (move level ticking logic out for branch convergence)
private void tickLevel(ServerLevel serverLevel, BooleanSupplier hasTimeLeft) {
try {

View File

@@ -0,0 +1,52 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 6 Apr 2025 11:22:35 +0200
Subject: [PATCH] More virtual threads
diff --git a/net/minecraft/Util.java b/net/minecraft/Util.java
index 9918572306e983281d05c6d28c8a5d843348ad2d..2491ca5bcabcf8ae99ef990eed4e1fd94f799991 100644
--- a/net/minecraft/Util.java
+++ b/net/minecraft/Util.java
@@ -98,7 +98,8 @@ public class Util {
public static final TracingExecutor DIMENSION_DATA_IO_POOL = makeExtraIoExecutor("Dimension-Data-IO-Worker-"); // Paper - Separate dimension data IO pool
private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true);
// Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
- public static final ExecutorService PROFILE_EXECUTOR = Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
+ // Leaf start - More virtual threads
+ public static final ExecutorService PROFILE_EXECUTOR = createProfileExecutor(); /* new Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
private final AtomicInteger count = new AtomicInteger();
@@ -111,7 +112,30 @@ public class Util {
});
return ret;
}
- });
+ }); */
+
+ private static ExecutorService createProfileExecutor() {
+ final java.util.concurrent.ThreadFactory factory;
+ if (org.dreeam.leaf.config.modules.opt.VT4ProfileExecutor.enabled && org.galemc.gale.virtualthread.VirtualThreadService.isSupported()) {
+ factory = org.galemc.gale.virtualthread.VirtualThreadService.get().createFactory();
+ } else {
+ factory = new java.util.concurrent.ThreadFactory() {
+ private final AtomicInteger count = new AtomicInteger();
+
+ @Override
+ public Thread newThread(Runnable run) {
+ Thread ret = new Thread(run);
+ ret.setName("Profile Lookup Executor #" + this.count.getAndIncrement());
+ ret.setUncaughtExceptionHandler((Thread thread, Throwable throwable) -> {
+ LOGGER.error("Uncaught exception in thread " + thread.getName(), throwable);
+ });
+ return ret;
+ }
+ };
+ }
+ return Executors.newFixedThreadPool(2, factory);
+ }
+ // Leaf end - More virtual threads
// Paper end - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
private static final DateTimeFormatter FILENAME_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss", Locale.ROOT);
public static final int LINEAR_LOOKUP_THRESHOLD = 8;

View File

@@ -106,7 +106,7 @@ index 7b686d834e4eb36be5758b0e0a846a70d1e2294b..956d48fb7146b9eb2a5b5b4e23a83f60
final EntityCollectionBySection byType = this.entitiesByType.get(entity.getType());
byType.removeEntity(entity, sectionIndex);
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 1dc599e28682b59c8389ff2ada100b405bf97240..c2c904565df5fb320b98307a4d451066286ad726 100644
index 9933a60db91d68f76df33ccddea0852fd59b8983..14c4dfb497ab050adfffebb8d75e6fe89c38effc 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -291,6 +291,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -117,21 +117,6 @@ index 1dc599e28682b59c8389ff2ada100b405bf97240..c2c904565df5fb320b98307a4d451066
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
AtomicReference<S> atomicReference = new AtomicReference<>();
@@ -1092,6 +1093,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
org.dreeam.leaf.async.AsyncPlayerDataSaving.IO_POOL.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS);
} catch (java.lang.InterruptedException ignored) {}
// Leaf end - Async playerdata saving
+ // Leaf start - Async target finding
+ if (this.asyncGoalThread != null) {
+ try {
+ this.asyncGoalThread.join();
+ } catch (java.lang.InterruptedException ignored) {
+ }
+ }
+ // Leaf end - Async target finding
}
public String getLocalIp() {
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 72e871b8c7fee9b5cbd567e03baee80ee4b9c82e..574765713c194a6cf3eb7c125e78ed77c82aba2e 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java

View File

@@ -1,112 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 6 Apr 2025 11:22:35 +0200
Subject: [PATCH] More virtual threads
diff --git a/net/minecraft/Util.java b/net/minecraft/Util.java
index 9918572306e983281d05c6d28c8a5d843348ad2d..1d4ad1370ca041753ce765b1a2feddae59f1f8ca 100644
--- a/net/minecraft/Util.java
+++ b/net/minecraft/Util.java
@@ -98,7 +98,8 @@ public class Util {
public static final TracingExecutor DIMENSION_DATA_IO_POOL = makeExtraIoExecutor("Dimension-Data-IO-Worker-"); // Paper - Separate dimension data IO pool
private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true);
// Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
- public static final ExecutorService PROFILE_EXECUTOR = Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
+ // Leaf start - More virtual threads
+ public static final ExecutorService PROFILE_EXECUTOR = createProfileExecutor(); /* new Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
private final AtomicInteger count = new AtomicInteger();
@@ -111,7 +112,30 @@ public class Util {
});
return ret;
}
- });
+ }); */
+
+ private static ExecutorService createProfileExecutor() {
+ final java.util.concurrent.ThreadFactory factory;
+ if (org.dreeam.leaf.config.modules.opt.VT4ProfileExecutor.enabled && org.galemc.gale.virtualthread.VirtualThreadService.isSupported()) {
+ factory = org.galemc.gale.virtualthread.VirtualThreadService.get().createFactory();
+ } else {
+ factory = new java.util.concurrent.ThreadFactory() {
+ private final AtomicInteger count = new AtomicInteger();
+
+ @Override
+ public Thread newThread(Runnable run) {
+ Thread ret = new Thread(run);
+ ret.setName("Profile Lookup Executor #" + this.count.getAndIncrement());
+ ret.setUncaughtExceptionHandler((Thread thread, Throwable throwable) -> {
+ LOGGER.error("Uncaught exception in thread " + thread.getName(), throwable);
+ });
+ return ret;
+ }
+ };
+ }
+ return Executors.newFixedThreadPool(2, factory);
+ }
+ // Leaf end - More virtual threads
// Paper end - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
private static final DateTimeFormatter FILENAME_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss", Locale.ROOT);
public static final int LINEAR_LOOKUP_THRESHOLD = 8;
@@ -255,16 +279,31 @@ public class Util {
}
private static TracingExecutor makeIoExecutor(String name, boolean daemon) {
- AtomicInteger atomicInteger = new AtomicInteger(1);
- return new TracingExecutor(Executors.newCachedThreadPool(task -> {
- Thread thread = new Thread(task);
- String string = name + atomicInteger.getAndIncrement();
- TracyClient.setThreadName(string, name.hashCode());
- thread.setName(string);
- thread.setDaemon(daemon);
- thread.setUncaughtExceptionHandler(Util::onThreadException);
- return thread;
- }));
+ // Leaf start - More virtual threads
+ final java.util.concurrent.ThreadFactory factory;
+ final boolean useVirtualThreads; // Gale - virtual thread support
+ if (name.startsWith("Download-")) { // Gale - virtual thread support
+ useVirtualThreads = org.dreeam.leaf.config.modules.opt.VT4DownloadPool.enabled && org.galemc.gale.virtualthread.VirtualThreadService.isSupported(); // Gale - virtual thread support
+ } else {
+ useVirtualThreads = false;
+ }
+
+ if (useVirtualThreads) {
+ factory = org.galemc.gale.virtualthread.VirtualThreadService.get().createFactory();
+ } else {
+ AtomicInteger atomicInteger = new AtomicInteger(1);
+ factory = task -> {
+ Thread thread = new Thread(task);
+ String string = name + atomicInteger.getAndIncrement();
+ TracyClient.setThreadName(string, name.hashCode());
+ thread.setName(string);
+ thread.setDaemon(daemon);
+ thread.setUncaughtExceptionHandler(Util::onThreadException);
+ return thread;
+ };
+ }
+ return new TracingExecutor(Executors.newCachedThreadPool(factory));
+ // Leaf end - More virtual threads
}
// Paper start - Separate dimension data IO pool
@@ -1109,7 +1148,7 @@ public class Util {
}
public static <T> Typed<T> readTypedOrThrow(Type<T> type, Dynamic<?> data, boolean partial) {
- DataResult<Typed<T>> dataResult = type.readTyped(data).map(Pair::getFirst);
+ DataResult<Typed<T>> dataResult = type.readTyped(data).map(Pair::getFirst); // Paper - Fix generics issue // Gale - Fix generics issue
try {
return partial ? dataResult.getPartialOrThrow(IllegalStateException::new) : dataResult.getOrThrow(IllegalStateException::new);
@@ -1158,7 +1197,7 @@ public class Util {
}
public void openUri(URI uri) {
- throw new IllegalStateException("This method is not useful on dedicated servers."); // Paper - Fix warnings on build by removing client-only code
+ // throw new IllegalStateException("This method is not useful on dedicated servers."); // Paper - Fix warnings on build by removing client-only code // Leaf - More virtual threads - This method is not useful on dedicated servers
}
public void openFile(File file) {

View File

@@ -27,7 +27,7 @@ index 3a78e7512772fd3f7cf8f221e3a72474def14bea..ba52af914e9e231caa0ac50562e9a692
public static final int GENERATED_TICKET_LEVEL = ChunkHolderManager.FULL_LOADED_TICKET_LEVEL;
public static final int LOADED_TICKET_LEVEL = ChunkTaskScheduler.getTicketLevel(ChunkStatus.EMPTY);
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index e4bccc642abe15b0ec4b1cf2634801065a27e11a..6a9aa085956ddd27e8910dd524ecb79caf9ae0ba 100644
index a1249d66c3693374b0f57c83302d05a7cbc2a306..2ea112ed64d5dc7c5eb365e7a518cf0e8dd4927f 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -434,6 +434,13 @@ public abstract class PlayerList {

View File

@@ -22,10 +22,10 @@ index 56fd1ed7ccaf96e7eedea60fbdbf7f934939d563..d2f522ea6d0a209496848af073c9af1c
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index c2c904565df5fb320b98307a4d451066286ad726..84b90f496e5ab59d43503301fe935627af123e3f 100644
index 14c4dfb497ab050adfffebb8d75e6fe89c38effc..54f5336b5bb56cb9dfda2b75fff07bae0b27cfd3 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1833,6 +1833,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1820,6 +1820,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleTick(tickCount); // Leaves - protocol
@@ -33,20 +33,8 @@ index c2c904565df5fb320b98307a4d451066286ad726..84b90f496e5ab59d43503301fe935627
for (int i = 0; i < this.tickables.size(); i++) {
this.tickables.get(i).run();
diff --git a/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java
index 16b2ca8c96e9561aa57e0903d1e98e6441044b6d..939400c18eb4e87e0bf1b131e1601f4dcaa4885c 100644
--- a/net/minecraft/server/level/ServerEntity.java
+++ b/net/minecraft/server/level/ServerEntity.java
@@ -297,6 +297,7 @@ public class ServerEntity {
this.entity.hurtMarked = false;
this.broadcastAndSend(new ClientboundSetEntityMotionPacket(this.entity));
}
+ if (entity instanceof ServerPlayer serverPlayer) org.dreeam.leaf.protocol.Protocols.tickTracker(serverPlayer); // Leaf - Protocol core
}
private Stream<Entity> mountedOrDismounted(List<Entity> entities) {
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index ac7ac519ecc58a31c4b9efc24f054ec014851fb4..59a61ac969e79966484a839b7d9ca0ac50e80994 100644
index bc955da0dff79262dace84d255f27b3271a91ca5..7abc297d91d6e1b21b855424b345dba4f4df37b6 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -805,6 +805,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -71,7 +59,7 @@ index 18f0d486c478087f404d8bb6cd840079e2c8d239..1a6f1c5f4cf13ee50bc8445845cbb973
final byte[] data = discardedPayload.data();
try {
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 6a9aa085956ddd27e8910dd524ecb79caf9ae0ba..e0f6b82d9836cb73f6fe631071bb1a0c5ec77eab 100644
index 2ea112ed64d5dc7c5eb365e7a518cf0e8dd4927f..24a5fd508e36238aade92fcae1c97cb38159506a 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -686,6 +686,7 @@ public abstract class PlayerList {

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Async switch connection state
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index f3e9de8716f5e1a72ec465ee897c8f0413f7b1c3..c83ee2137a57e62003b1d20c3ceea9f569350a53 100644
index f3e9de8716f5e1a72ec465ee897c8f0413f7b1c3..3dce0665e7438d2994a86450e31fb2a10431df9b 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -342,6 +342,11 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -36,22 +36,11 @@ index f3e9de8716f5e1a72ec465ee897c8f0413f7b1c3..c83ee2137a57e62003b1d20c3ceea9f5
}
}
@@ -369,7 +381,38 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
}
@@ -373,6 +385,31 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
}
}
boolean flag = protocolInfo.id() == ConnectionProtocol.LOGIN;
- syncAfterConfigurationChange(this.channel.writeAndFlush(outboundConfigurationTask.andThen(context -> this.sendLoginDisconnect = flag)));
+ var cf = this.channel.writeAndFlush(outboundConfigurationTask.andThen(context -> this.sendLoginDisconnect = flag));
+ // Leaf start - Async switch connection state
+ if (org.dreeam.leaf.config.modules.network.AlternativeJoin.enabled) {
+ if (ca.spottedleaf.moonrise.common.util.TickThread.isTickThread()) {
+ throw new IllegalStateException("Thread failed netty thread check: Switching outbound protocol state use setupOutboundProtocolAsync instead");
+ }
+ }
+ syncAfterConfigurationChange(cf);
+ }
+ }
+
+ // Leaf start - Async switch connection state
+ public @Nullable ChannelFuture setupOutboundProtocolAsync(ProtocolInfo<?> protocolInfo) {
+ if (protocolInfo.flow() != this.getSending()) {
+ throw new IllegalStateException("Invalid outbound protocol: " + protocolInfo.id());
@@ -72,10 +61,13 @@ index f3e9de8716f5e1a72ec465ee897c8f0413f7b1c3..c83ee2137a57e62003b1d20c3ceea9f5
+ return cf;
+ }
+ return null;
+ // Leaf end - Async switch connection state
}
}
+ }
+ }
+ // Leaf end - Async switch connection state
+
public void setListenerForServerboundHandshake(PacketListener packetListener) {
if (this.packetListener != null) {
throw new IllegalStateException("Listener already set");
diff --git a/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java b/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
index 2e9eb04c7c4342393c05339906c267bca9ff29b1..53b9daa909c2b89046d5af515e17afe09ea7015a 100644
--- a/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
@@ -118,10 +110,10 @@ index 2e9eb04c7c4342393c05339906c267bca9ff29b1..53b9daa909c2b89046d5af515e17afe0
try {
PlayerList playerList = this.server.getPlayerList();
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 405b62c082017024abae7ccc1db5f74caab1eabf..1ad1fc46775a473e6f7fd97eac4b8c7110c7332b 100644
index 6b0b0ccc18a5da05685867656705e1fcf94b5891..889bab9613fb32d239bb0613db4a900a442116a3 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -471,11 +471,31 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -493,11 +493,31 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
}
@@ -150,7 +142,7 @@ index 405b62c082017024abae7ccc1db5f74caab1eabf..1ad1fc46775a473e6f7fd97eac4b8c71
net.minecraft.network.protocol.PacketUtils.ensureRunningOnSameThread(packet, this, this.server); // CraftBukkit
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.PROTOCOL_SWITCHING, "Unexpected login acknowledgement packet");
- this.connection.setupOutboundProtocol(ConfigurationProtocols.CLIENTBOUND);
+ if (!org.dreeam.leaf.config.modules.network.AlternativeJoin.enabled) this.connection.setupOutboundProtocol(ConfigurationProtocols.CLIENTBOUND); // Leaf - Async switch connection state
+ if (!org.dreeam.leaf.config.modules.network.AlternativeJoin.enabled) this.connection.setupOutboundProtocol(ConfigurationProtocols.CLIENTBOUND); // Leaf - Async switch connection state
CommonListenerCookie commonListenerCookie = CommonListenerCookie.createInitial(Objects.requireNonNull(this.authenticatedProfile), this.transferred);
ServerConfigurationPacketListenerImpl serverConfigurationPacketListenerImpl = new ServerConfigurationPacketListenerImpl(
this.server, this.connection, commonListenerCookie, this.player // CraftBukkit

View File

@@ -1,11 +1,11 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Thu, 8 May 2025 13:30:07 +0200
Subject: [PATCH] Optimise BlockEntities tickersInLevel
Subject: [PATCH] Optimize BlockEntities tickersInLevel
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
index e82e55ec400c5e338502ed7ce433372a88d4acff..155e9b807a61ab1212ee25cc79a386821596dedc 100644
index e82e55ec400c5e338502ed7ce433372a88d4acff..31f19dfe16e270b55f3b44754c97ed8d9fa422cf 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -73,7 +73,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
@@ -13,7 +13,7 @@ index e82e55ec400c5e338502ed7ce433372a88d4acff..155e9b807a61ab1212ee25cc79a38682
}
};
- private final Map<BlockPos, LevelChunk.RebindableTickingBlockEntityWrapper> tickersInLevel = Maps.newHashMap();
+ private final Map<BlockPos, LevelChunk.RebindableTickingBlockEntityWrapper> tickersInLevel = org.dreeam.leaf.config.modules.opt.OptimiseBlockEntities.enabled ? new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>() : Maps.newHashMap(); // Leaf - Optimise BlockEntities tickersInLevel
+ private final Map<BlockPos, LevelChunk.RebindableTickingBlockEntityWrapper> tickersInLevel = org.dreeam.leaf.config.modules.opt.OptimizeBlockEntities.enabled ? new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>() : Maps.newHashMap(); // Leaf - Optimise BlockEntities tickersInLevel
public boolean loaded;
public final ServerLevel level; // CraftBukkit - type
@Nullable

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Only tick items at hand
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 59a61ac969e79966484a839b7d9ca0ac50e80994..82ac99c3c5b374482f3ff18f5d20bf888091e539 100644
index 7abc297d91d6e1b21b855424b345dba4f4df37b6..0c81dca5905c2d4c166661dc3473b0c1e9aa5265 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -834,12 +834,19 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Add configurable death item drop knockback settings
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 82ac99c3c5b374482f3ff18f5d20bf888091e539..c9fbbbef8d006a90023c70419b5be7220602ee3b 100644
index 0c81dca5905c2d4c166661dc3473b0c1e9aa5265..373059fcccdab0a918aa1d1a4a613fb62fef8a18 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -1053,7 +1053,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] optimize getEntityStatus
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..11f4f2f3bc4c9f9f6a1f83b90f3de34c8edb9819 100644
index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..703bf9c2a56b262e2719a1787584de537b8f12e0 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
@@ -93,8 +93,14 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
@@ -14,14 +14,14 @@ index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..11f4f2f3bc4c9f9f6a1f83b90f3de34c
}
- final Visibility visibility = EntityLookup.getEntityStatus(entity);
- return visibility.isAccessible() ? entity : null;
+ // Leaf start
+ // Leaf start - optimize getEntityStatus
+ final FullChunkStatus entityStatus = ((ChunkSystemEntity) entity).moonrise$getChunkStatus();
+ return switch (entityStatus) {
+ case INACCESSIBLE -> null;
+ case FULL, BLOCK_TICKING, ENTITY_TICKING -> entity;
+ case null -> null;
+ };
+ // Leaf end
+ // Leaf end - optimize getEntityStatus
}
@Override
@@ -30,26 +30,26 @@ index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..11f4f2f3bc4c9f9f6a1f83b90f3de34c
}
final FullChunkStatus entityStatus = ((ChunkSystemEntity)entity).moonrise$getChunkStatus();
- return Visibility.fromFullChunkStatus(entityStatus == null ? FullChunkStatus.INACCESSIBLE : entityStatus);
+ // Leaf start
+ // Leaf start - optimize getEntityStatus
+ return switch (entityStatus) {
+ case INACCESSIBLE -> Visibility.HIDDEN;
+ case FULL, BLOCK_TICKING -> Visibility.TRACKED;
+ case ENTITY_TICKING -> Visibility.TICKING;
+ case null -> Visibility.HIDDEN;
+ };
+ // Leaf end
+ // Leaf end - optimize getEntityStatus
}
protected boolean addEntity(final Entity entity, final boolean fromDisk, final boolean event) {
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 5fda5eadd37ec52ca6470d4aeb18a20c192811be..35fdc9863598755ece1dcc53b4b42c0d5d5e882d 100644
index e1a722c3ec74c0967d089ad469d7b3305bf66195..74794efea55ce1874730c8a2de5fdd9277065d10 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -374,6 +374,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// Paper end
// Paper start - rewrite chunk system
private final boolean isHardColliding = this.moonrise$isHardCollidingUncached();
+ @org.jetbrains.annotations.Nullable // Leaf
+ @org.jetbrains.annotations.Nullable // Leaf - optimize getEntityStatus
private net.minecraft.server.level.FullChunkStatus chunkStatus;
private ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkData chunkData;
private int sectionX = Integer.MIN_VALUE;
@@ -57,7 +57,7 @@ index 5fda5eadd37ec52ca6470d4aeb18a20c192811be..35fdc9863598755ece1dcc53b4b42c0d
}
@Override
+ @org.jetbrains.annotations.Nullable // Leaf
+ @org.jetbrains.annotations.Nullable // Leaf - optimize getEntityStatus
public final net.minecraft.server.level.FullChunkStatus moonrise$getChunkStatus() {
return this.chunkStatus;
}

View File

@@ -32327,7 +32327,7 @@ index 175647d57e59e838ea7b4680fbf22c161100c513..a7b772cfc89161414469cd7da374d6c7
return structureTemplate.save(new CompoundTag());
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 84b90f496e5ab59d43503301fe935627af123e3f..54e31a239d6563abe56435ee8de03e55548ead29 100644
index 54f5336b5bb56cb9dfda2b75fff07bae0b27cfd3..60ec95c72506afe5cc58c15fef8749f96222c318 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -294,6 +294,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

View File

@@ -1,212 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Thu, 24 Apr 2025 16:36:16 -0400
Subject: [PATCH] Paw optimization
Some random optimizations
- Remove Paper's dead code
- Only set shuffle random seed if is really used
- Secret patches (WIP)
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index c83ee2137a57e62003b1d20c3ceea9f569350a53..de1f271d36c7daa10c398e146386b51e2622df9a 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -660,13 +660,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|| loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
|| Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
- // Paper start - detailed watchdog information
- net.minecraft.network.protocol.PacketUtils.packetProcessing.push(this.packetListener);
- try {
tickablePacketListener.tick();
- } finally {
- net.minecraft.network.protocol.PacketUtils.packetProcessing.pop();
- } // Paper end - detailed watchdog information
} // Paper end - Buffer joins to world
}
diff --git a/net/minecraft/network/protocol/PacketUtils.java b/net/minecraft/network/protocol/PacketUtils.java
index 4535858701b2bb232b9d2feb2af6551526232ddc..e65c62dbe4c1560ae153e4c4344e9194c783a2f4 100644
--- a/net/minecraft/network/protocol/PacketUtils.java
+++ b/net/minecraft/network/protocol/PacketUtils.java
@@ -21,8 +21,6 @@ public class PacketUtils {
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packet, T processor, BlockableEventLoop<?> executor) throws RunningOnDifferentThreadException {
if (!executor.isSameThread()) {
executor.executeIfPossible(() -> {
- packetProcessing.push(processor); // Paper - detailed watchdog information
- try { // Paper - detailed watchdog information
if (processor instanceof net.minecraft.server.network.ServerCommonPacketListenerImpl serverCommonPacketListener && serverCommonPacketListener.processedDisconnect) return; // Paper - Don't handle sync packets for kicked players
if (processor.shouldHandleMessage(packet)) {
try {
@@ -37,12 +35,6 @@ public class PacketUtils {
} else {
LOGGER.debug("Ignoring packet due to disconnection: {}", packet);
}
- // Paper start - detailed watchdog information
- } finally {
- totalMainThreadPacketsProcessed.getAndIncrement();
- packetProcessing.pop();
- }
- // Paper end - detailed watchdog information
});
throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD;
}
@@ -69,22 +61,4 @@ public class PacketUtils {
packetListener.fillCrashReport(crashReport);
}
-
- // Paper start - detailed watchdog information
- public static final java.util.concurrent.ConcurrentLinkedDeque<PacketListener> packetProcessing = new java.util.concurrent.ConcurrentLinkedDeque<>();
- static final java.util.concurrent.atomic.AtomicLong totalMainThreadPacketsProcessed = new java.util.concurrent.atomic.AtomicLong();
-
- public static long getTotalProcessedPackets() {
- return totalMainThreadPacketsProcessed.get();
- }
-
- public static java.util.List<PacketListener> getCurrentPacketProcessors() {
- java.util.List<PacketListener> listeners = new java.util.ArrayList<>(4);
- for (PacketListener listener : packetProcessing) {
- listeners.add(listener);
- }
-
- return listeners;
- }
- // Paper end - detailed watchdog information
}
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index b3acfc7e00797ea16cc2c1793452f3ed97b9c61a..17c1b05f520145b84e90fc359dca4523191f08cd 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -622,8 +622,10 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
try {
this.chunkMap.collectSpawningChunks(list);
// Paper start - chunk tick iteration optimisation
- this.shuffleRandom.setSeed(this.level.random.nextLong());
- if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
+ if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) {
+ this.shuffleRandom.setSeed(this.level.random.nextLong()); // Leaf - paw optimization - Only set seed if is really used
+ Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
+ }
// Paper end - chunk tick iteration optimisation
for (LevelChunk levelChunk : list) {
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index c0044f4013520fd617ec365012b10862571744f3..14d23006d3ec15bb3ec6f976bff6c0975662c69d 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -1518,13 +1518,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// Paper end - log detailed entity tick information
public void tickNonPassenger(Entity entity) {
- // Paper start - log detailed entity tick information
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot tick an entity off-main");
- try {
- if (currentlyTickingEntity.get() == null) {
- currentlyTickingEntity.lazySet(entity);
- }
- // Paper end - log detailed entity tick information
entity.setOldPosAndRot();
entity.tickCount++;
entity.totalEntityAge++; // Paper - age-like counter for all entities
@@ -1537,13 +1531,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
for (Entity entity1 : entity.getPassengers()) {
this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2
}
- // Paper start - log detailed entity tick information
- } finally {
- if (currentlyTickingEntity.get() == entity) {
- currentlyTickingEntity.lazySet(null);
- }
- }
- // Paper end - log detailed entity tick information
}
private void tickPassenger(Entity ridingEntity, Entity passengerEntity, final boolean isActive) { // Paper - EAR 2
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index e1a722c3ec74c0967d089ad469d7b3305bf66195..5fda5eadd37ec52ca6470d4aeb18a20c192811be 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1144,16 +1144,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.onGround;
}
- // Paper start - detailed watchdog information
- public final Object posLock = new Object(); // Paper - log detailed entity tick information
-
- @Nullable
- private Vec3 moveVector;
- private double moveStartX;
- private double moveStartY;
- private double moveStartZ;
- // Paper end - detailed watchdog information
-
public void move(MoverType type, Vec3 movement) {
// Gale start - VMP - skip entity move if movement is zero
if (!this.boundingBoxChanged && movement.equals(Vec3.ZERO)) {
@@ -1161,16 +1151,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Gale end - VMP - skip entity move if movement is zero
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
- // Paper start - detailed watchdog information
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot move an entity off-main");
- synchronized (this.posLock) {
- this.moveStartX = this.getX();
- this.moveStartY = this.getY();
- this.moveStartZ = this.getZ();
- this.moveVector = movement;
- }
- try {
- // Paper end - detailed watchdog information
if (this.noPhysics) {
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
@@ -1304,13 +1285,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// Gale end - skip negligible planar movement multiplication
}
}
- // Paper start - detailed watchdog information
- } finally {
- synchronized (this.posLock) { // Paper
- this.moveVector = null;
- } // Paper
- }
- // Paper end - detailed watchdog information
}
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission movementEmission, Vec3 movement, BlockPos pos, BlockState state) {
@@ -4862,9 +4836,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public void setDeltaMovement(Vec3 deltaMovement) {
- synchronized (this.posLock) { // Paper - detailed watchdog information
this.deltaMovement = deltaMovement;
- } // Paper - detailed watchdog information
}
public void addDeltaMovement(Vec3 addend) {
@@ -4972,9 +4944,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Paper end - Fix MC-4
if (this.position.x != x || this.position.y != y || this.position.z != z) {
- synchronized (this.posLock) { // Paper - detailed watchdog information
this.position = new Vec3(x, y, z);
- } // Paper - detailed watchdog information
int floor = Mth.floor(x);
int floor1 = Mth.floor(y);
int floor2 = Mth.floor(z);
diff --git a/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java b/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java
index ef9c2c0a665a1acf490affd9cd4496ae9d677410..27e7c1bb585f30165bd501bb8f8aab0dd147ca5b 100644
--- a/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java
@@ -48,7 +48,7 @@ public class DesertPyramidStructure extends SinglePieceStructure {
}
}
- ObjectArrayList<BlockPos> list = new ObjectArrayList<>(set.stream().toList());
+ ObjectArrayList<BlockPos> list = new ObjectArrayList<>(set); // Leaf - paw optimization - TODO: use array
RandomSource randomSource = RandomSource.create(level.getSeed()).forkPositional().at(pieces.calculateBoundingBox().getCenter());
Util.shuffle(list, randomSource);
int min = Math.min(set.size(), randomSource.nextInt(5, 8));

View File

@@ -0,0 +1,66 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Tue, 3 Jun 2025 15:16:32 +0900
Subject: [PATCH] optimise ChunkGenerator#getMobsAt
inline fillStartsForStructure
diff --git a/net/minecraft/world/level/StructureManager.java b/net/minecraft/world/level/StructureManager.java
index 3399922d79a713484e16beb6e4e9985c284ddfb5..fbe93098ce0366054a6da857cd808af1431b6612 100644
--- a/net/minecraft/world/level/StructureManager.java
+++ b/net/minecraft/world/level/StructureManager.java
@@ -78,7 +78,7 @@ public class StructureManager {
public void fillStartsForStructure(Structure structure, LongSet structureRefs, Consumer<StructureStart> startConsumer) {
for (long l : structureRefs) {
- SectionPos sectionPos = SectionPos.of(new ChunkPos(l), this.level.getMinSectionY());
+ SectionPos sectionPos = SectionPos.of(ChunkPos.getX(l), this.level.getMinSectionY(), ChunkPos.getZ(l)); // Leaf - optimise ChunkGenerator#getMobsAt
StructureStart startForStructure = this.getStartForStructure(
sectionPos, structure, this.level.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_STARTS)
);
@@ -178,8 +178,8 @@ public class StructureManager {
}
public Map<Structure, LongSet> getAllStructuresAt(BlockPos pos) {
- SectionPos sectionPos = SectionPos.of(pos);
- return this.level.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
+ //SectionPos sectionPos = SectionPos.of(pos); // Leaf - optimise ChunkGenerator#getMobsAt
+ return this.level.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences(); // Leaf - optimise ChunkGenerator#getMobsAt
}
public StructureCheckResult checkStructurePresence(ChunkPos chunkPos, Structure structure, StructurePlacement placement, boolean skipKnownStructures) {
diff --git a/net/minecraft/world/level/chunk/ChunkGenerator.java b/net/minecraft/world/level/chunk/ChunkGenerator.java
index e1ebbfab87aed9cc633f2fedb1e6edeca4ddc2ec..11c7c299d4affb9e78488590e7db939efe6e3dd9 100644
--- a/net/minecraft/world/level/chunk/ChunkGenerator.java
+++ b/net/minecraft/world/level/chunk/ChunkGenerator.java
@@ -496,18 +496,20 @@ public abstract class ChunkGenerator {
Structure structure = entry.getKey();
StructureSpawnOverride structureSpawnOverride = structure.spawnOverrides().get(category);
if (structureSpawnOverride != null) {
- MutableBoolean mutableBoolean = new MutableBoolean(false);
- Predicate<StructureStart> predicate = structureSpawnOverride.boundingBox() == StructureSpawnOverride.BoundingBoxType.PIECE
- ? structureStart -> structureManager.structureHasPieceAt(pos, structureStart)
- : structureStart -> structureStart.getBoundingBox().isInside(pos);
- structureManager.fillStartsForStructure(structure, entry.getValue(), structureStart -> {
- if (mutableBoolean.isFalse() && predicate.test(structureStart)) {
- mutableBoolean.setTrue();
+ // Leaf start - optimise ChunkGenerator#getMobsAt
+ for (long l : entry.getValue()) {
+ StructureStart startForStructure = structureManager.getStartForStructure(
+ null, structure, structureManager.level.getChunk(ChunkPos.getX(l), ChunkPos.getZ(l), ChunkStatus.STRUCTURE_STARTS)
+ );
+ if (startForStructure != null && startForStructure.isValid()) {
+ if (structureSpawnOverride.boundingBox() == StructureSpawnOverride.BoundingBoxType.PIECE
+ ? structureManager.structureHasPieceAt(pos, startForStructure)
+ : startForStructure.getBoundingBox().isInside(pos)) {
+ return structureSpawnOverride.spawns();
+ }
}
- });
- if (mutableBoolean.isTrue()) {
- return structureSpawnOverride.spawns();
}
+ // Leaf end - optimise ChunkGenerator#getMobsAt
}
}

View File

@@ -0,0 +1,147 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Tue, 3 Jun 2025 15:20:40 +0900
Subject: [PATCH] optimise getBiome
diff --git a/net/minecraft/advancements/critereon/LocationPredicate.java b/net/minecraft/advancements/critereon/LocationPredicate.java
index a26a5311f87873e0d4d26fda9cb8956a32ee81e8..65e4315cce35814c60b21bbd5baea2ffac82162c 100644
--- a/net/minecraft/advancements/critereon/LocationPredicate.java
+++ b/net/minecraft/advancements/critereon/LocationPredicate.java
@@ -49,7 +49,7 @@ public record LocationPredicate(
} else {
BlockPos blockPos = BlockPos.containing(x, y, z);
boolean isLoaded = level.isLoaded(blockPos);
- return (!this.biomes.isPresent() || isLoaded && this.biomes.get().contains(level.getBiome(blockPos)))
+ return (!this.biomes.isPresent() || isLoaded && this.biomes.get().contains(org.dreeam.leaf.config.modules.opt.OptimizeBiome.advancement ? level.getBiomeCached(blockPos) : level.getBiome(blockPos))) // Leaf - cache getBiome
&& (!this.structures.isPresent() || isLoaded && level.structureManager().getStructureWithPieceAt(blockPos, this.structures.get()).isValid())
&& (!this.smokey.isPresent() || isLoaded && this.smokey.get() == CampfireBlock.isSmokeyPos(level, blockPos))
&& (!this.light.isPresent() || this.light.get().matches(level, blockPos))
diff --git a/net/minecraft/world/level/LevelReader.java b/net/minecraft/world/level/LevelReader.java
index 0842fd6488c8b27d98c4344e1244996b4c0e9912..c6ddb49648c55443ae880c1adba9887ab0681c82 100644
--- a/net/minecraft/world/level/LevelReader.java
+++ b/net/minecraft/world/level/LevelReader.java
@@ -57,6 +57,12 @@ public interface LevelReader extends ca.spottedleaf.moonrise.patches.chunk_syste
return this.getBiomeManager().getBiome(pos);
}
+ // Leaf start - cache getBiome
+ default Holder<Biome> getBiomeCached(BlockPos pos) {
+ return this.getBiomeManager().getBiomeCached(pos);
+ }
+ // Leaf end - cache getBiome
+
default Stream<BlockState> getBlockStatesIfLoaded(AABB aabb) {
int floor = Mth.floor(aabb.minX);
int floor1 = Mth.floor(aabb.maxX);
diff --git a/net/minecraft/world/level/NaturalSpawner.java b/net/minecraft/world/level/NaturalSpawner.java
index a2da4fce50f31d56036d04041c4f80ed90c18b27..f242941ce06d356a025e306efe78c688e9b755c4 100644
--- a/net/minecraft/world/level/NaturalSpawner.java
+++ b/net/minecraft/world/level/NaturalSpawner.java
@@ -443,7 +443,7 @@ public final class NaturalSpawner {
private static Optional<MobSpawnSettings.SpawnerData> getRandomSpawnMobAt(
ServerLevel level, StructureManager structureManager, ChunkGenerator generator, MobCategory category, RandomSource random, BlockPos pos
) {
- Holder<Biome> biome = level.getBiome(pos);
+ Holder<Biome> biome = org.dreeam.leaf.config.modules.opt.OptimizeBiome.mobSpawn ? level.getBiomeCached(pos) : level.getBiome(pos); // Leaf - cache getBiome
return category == MobCategory.WATER_AMBIENT && biome.is(BiomeTags.REDUCED_WATER_AMBIENT_SPAWNS) && random.nextFloat() < 0.98F
? Optional.empty()
: mobsAt(level, structureManager, generator, category, pos, biome).getRandom(random);
@@ -460,7 +460,7 @@ public final class NaturalSpawner {
) {
return isInNetherFortressBounds(pos, level, cetagory, structureManager)
? NetherFortressStructure.FORTRESS_ENEMIES
- : generator.getMobsAt(biome != null ? biome : level.getBiome(pos), structureManager, cetagory, pos);
+ : generator.getMobsAt(biome != null ? biome : (org.dreeam.leaf.config.modules.opt.OptimizeBiome.mobSpawn ? level.getBiomeCached(pos) : level.getBiome(pos)), structureManager, cetagory, pos); // Leaf - cache getBiome
}
public static boolean isInNetherFortressBounds(BlockPos pos, ServerLevel level, MobCategory category, StructureManager structureManager) {
diff --git a/net/minecraft/world/level/biome/BiomeManager.java b/net/minecraft/world/level/biome/BiomeManager.java
index a48175a7ebb1788ace46395621ed78d910178a53..00122472991ba0c1a0ea77053aad71cdfa92a7bd 100644
--- a/net/minecraft/world/level/biome/BiomeManager.java
+++ b/net/minecraft/world/level/biome/BiomeManager.java
@@ -15,10 +15,23 @@ public class BiomeManager {
private final BiomeManager.NoiseBiomeSource noiseBiomeSource;
private final long biomeZoomSeed;
private static final double maxOffset = 0.4500000001D; // Leaf - Carpet-Fixes - Optimized getBiome method
+ // Leaf start - cache getBiome
+ private final Holder<Biome>[] biomeCache;
+ private final long[] biomeCachePos;
+ // Leaf end - cache getBiome
public BiomeManager(BiomeManager.NoiseBiomeSource noiseBiomeSource, long biomeZoomSeed) {
this.noiseBiomeSource = noiseBiomeSource;
this.biomeZoomSeed = biomeZoomSeed;
+ // Leaf start - cache getBiome
+ if (org.dreeam.leaf.config.modules.opt.OptimizeBiome.enabled) {
+ biomeCache = new Holder[65536];
+ biomeCachePos = new long[65536];
+ } else {
+ biomeCache = null;
+ biomeCachePos = null;
+ }
+ // Leaf end - cache getBiome
}
public static long obfuscateSeed(long seed) {
@@ -29,6 +42,40 @@ public class BiomeManager {
return new BiomeManager(newSource, this.biomeZoomSeed);
}
+ // Leaf start - cache getBiome
+ public Holder<Biome> getBiomeCached(BlockPos pos) {
+ if (biomeCache == null) {
+ return getBiome(pos);
+ }
+ int xMinus2 = pos.getX() - 2;
+ int yMinus2 = pos.getY() - 2;
+ int zMinus2 = pos.getZ() - 2;
+ int x = xMinus2 >> 2;
+ int y = yMinus2 >> 2;
+ int z = zMinus2 >> 2;
+ long packedPos = BlockPos.asLong(x, y, z);
+ long hash = packedPos;
+ hash = (hash ^ (hash >>> 32)) * 0xff51afd7ed558ccdL;
+ hash = (hash ^ (hash >>> 32)) * 0xc4ceb9fe1a85ec53L;
+ hash = (hash ^ (hash >>> 32)) & 65535L;
+
+ long pos1 = biomeCachePos[(int) hash];
+ if (pos1 == packedPos) {
+ Holder<Biome> biome = biomeCache[(int) hash];
+ if (biome != null) {
+ return biome;
+ }
+ }
+
+ Holder<Biome> biome = getBiome(pos);
+
+ biomeCache[(int) hash] = biome;
+ biomeCachePos[(int) hash] = packedPos;
+
+ return biome;
+ }
+ // Leaf end - cache getBiome
+
public Holder<Biome> getBiome(BlockPos pos) {
// Leaf start - Carpet-Fixes - Optimized getBiome method
int xMinus2 = pos.getX() - 2;
@@ -126,9 +173,18 @@ public class BiomeManager {
return Mth.square(zNoise + fiddle2) + Mth.square(yNoise + fiddle1) + Mth.square(xNoise + fiddle);
}
+ // Leaf start - optimise getBiome
+ private static final double[] FIDDLE_TABLE = new double[1024];
+ static {
+ for (int i = 0; i < 1024; i++) {
+ FIDDLE_TABLE[i] = (i - 512) * (0.9 / 1024.0);
+ }
+ }
private static double getFiddle(long seed) {
- return (double)(((seed >> 24) & (1024 - 1)) - (1024/2)) * (0.9 / 1024.0); // Paper - avoid floorMod, fp division, and fp subtraction
+ return FIDDLE_TABLE[(int)(seed >>> 24) & 1023];
+ //return (double)(((seed >> 24) & (1024 - 1)) - (1024/2)) * (0.9 / 1024.0); // Paper - avoid floorMod, fp division, and fp subtraction
}
+ // Leaf end - optimise getBiome
public interface NoiseBiomeSource {
Holder<Biome> getNoiseBiome(int x, int y, int z);

View File

@@ -0,0 +1,28 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Tue, 3 Jun 2025 15:20:59 +0900
Subject: [PATCH] optimize mob spawning
diff --git a/net/minecraft/world/level/NaturalSpawner.java b/net/minecraft/world/level/NaturalSpawner.java
index f242941ce06d356a025e306efe78c688e9b755c4..38a6a11c05c0a0a2f59c1477e516431263dce101 100644
--- a/net/minecraft/world/level/NaturalSpawner.java
+++ b/net/minecraft/world/level/NaturalSpawner.java
@@ -472,6 +472,17 @@ public final class NaturalSpawner {
}
}
+ // Leaf start - optimize mob spawning
+ private static void mutableRandomPosWithin(BlockPos.MutableBlockPos pos1, Level level, LevelChunk chunk) {
+ ChunkPos pos = chunk.getPos();
+ int randomX = pos.getMinBlockX() + level.random.nextInt(16);
+ int randomZ = pos.getMinBlockZ() + level.random.nextInt(16);
+ int surfaceY = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, randomX, randomZ) + 1;
+ int randomY = Mth.randomBetweenInclusive(level.random, level.getMinY(), surfaceY);
+ pos1.set(randomX, randomY, randomZ);
+ }
+ // Leaf end - optimize mob spawning
+
private static BlockPos getRandomPosWithin(Level level, LevelChunk chunk) {
ChunkPos pos = chunk.getPos();
int i = pos.getMinBlockX() + level.random.nextInt(16);

View File

@@ -0,0 +1,46 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Tue, 3 Jun 2025 15:41:12 +0900
Subject: [PATCH] optimize structure map
diff --git a/net/minecraft/world/level/chunk/ChunkAccess.java b/net/minecraft/world/level/chunk/ChunkAccess.java
index 4fd9313ce2c87383685d80e2533b93d5b85a9f41..c9655ab6faf33fca2971629cd819f66da7024240 100644
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -76,8 +76,8 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
protected BlendingData blendingData;
public final Map<Heightmap.Types, Heightmap> heightmaps = Maps.newEnumMap(Heightmap.Types.class);
// Paper - rewrite chunk system
- private final Map<Structure, StructureStart> structureStarts = Maps.newHashMap();
- private final Map<Structure, LongSet> structuresRefences = Maps.newHashMap();
+ private final Map<Structure, StructureStart> structureStarts = new it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap<>(); // Leaf - optimize structure map
+ private final Map<Structure, LongSet> structuresRefences = new it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap<>(); // Leaf - optimize structure map
protected final Map<BlockPos, CompoundTag> pendingBlockEntities = Maps.newHashMap();
public final Map<BlockPos, BlockEntity> blockEntities = new Object2ObjectOpenHashMap<>();
protected final LevelHeightAccessor levelHeightAccessor;
@@ -303,7 +303,7 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
}
public Map<Structure, StructureStart> getAllStarts() {
- return Collections.unmodifiableMap(this.structureStarts);
+ return this.structureStarts; // Leaf - optimize structure map
}
public void setAllStarts(Map<Structure, StructureStart> structureStarts) {
@@ -319,13 +319,13 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
@Override
public void addReferenceForStructure(Structure structure, long reference) {
- this.structuresRefences.computeIfAbsent(structure, key -> new LongOpenHashSet()).add(reference);
+ this.structuresRefences.computeIfAbsent(structure, key -> new it.unimi.dsi.fastutil.longs.LongArraySet()).add(reference); // Leaf - optimize structure map
this.markUnsaved();
}
@Override
public Map<Structure, LongSet> getAllReferences() {
- return Collections.unmodifiableMap(this.structuresRefences);
+ return this.structuresRefences; // Leaf - optimize structure map
}
@Override

Some files were not shown because too many files have changed in this diff Show More