diff --git a/leaf-server/minecraft-patches/features/0154-Async-target-finding.patch b/leaf-server/minecraft-patches/features/0154-Async-target-finding.patch index 41961c8e..fd386af4 100644 --- a/leaf-server/minecraft-patches/features/0154-Async-target-finding.patch +++ b/leaf-server/minecraft-patches/features/0154-Async-target-finding.patch @@ -5,28 +5,30 @@ Subject: [PATCH] Async target finding diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..635d6aabbbe9be5c81a71d5e5bf758211deec0cf 100644 +index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..561723eeb1dd80f7fdd9aff33f6e1c4c16def0ff 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -@@ -40,8 +40,8 @@ public final class ChunkEntitySlices { +@@ -40,8 +40,10 @@ public final class ChunkEntitySlices { private final EntityCollectionBySection allEntities; private final EntityCollectionBySection hardCollidingEntities; - private final Reference2ObjectOpenHashMap, EntityCollectionBySection> entitiesByClass; - private final Reference2ObjectOpenHashMap, EntityCollectionBySection> entitiesByType; -+ private final Reference2ObjectMap, EntityCollectionBySection> entitiesByClass; // Leaf -+ private final Reference2ObjectMap, EntityCollectionBySection> entitiesByType; // Leaf ++ // Leaf start - Async target finding ++ private final Reference2ObjectMap, EntityCollectionBySection> entitiesByClass; ++ private final Reference2ObjectMap, EntityCollectionBySection> entitiesByType; ++ // Leaf end - Async target finding private final EntityList entities = new EntityList(); public FullChunkStatus status; -@@ -67,9 +67,16 @@ public final class ChunkEntitySlices { +@@ -67,9 +69,15 @@ public final class ChunkEntitySlices { this.allEntities = new EntityCollectionBySection(this); this.hardCollidingEntities = new EntityCollectionBySection(this); - this.entitiesByClass = new Reference2ObjectOpenHashMap<>(); - this.entitiesByType = new Reference2ObjectOpenHashMap<>(); - -+ // Leaf start +- ++ // Leaf start - Async target finding + if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) { + this.entitiesByClass = it.unimi.dsi.fastutil.objects.Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>()); + this.entitiesByType = it.unimi.dsi.fastutil.objects.Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>()); @@ -34,18 +36,18 @@ index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..635d6aabbbe9be5c81a71d5e5bf75821 + this.entitiesByClass = new Reference2ObjectOpenHashMap<>(); + this.entitiesByType = new Reference2ObjectOpenHashMap<>(); + } -+ // Leaf end ++ // Leaf end - Async target finding this.status = status; this.chunkData = chunkData; } -@@ -248,14 +255,26 @@ public final class ChunkEntitySlices { +@@ -248,14 +256,26 @@ public final class ChunkEntitySlices { this.hardCollidingEntities.addEntity(entity, sectionIndex); } - for (final Iterator, EntityCollectionBySection>> iterator = - this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext();) { - final Reference2ObjectMap.Entry, EntityCollectionBySection> entry = iterator.next(); -+ // Leaf start ++ // Leaf start - Async target finding + if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) { + synchronized (this.entitiesByClass) { + for (final var entry : this.entitiesByClass.reference2ObjectEntrySet()) { @@ -66,18 +68,18 @@ index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..635d6aabbbe9be5c81a71d5e5bf75821 + } } } -+ // Leaf end ++ // Leaf end - Async target finding EntityCollectionBySection byType = this.entitiesByType.get(entity.getType()); if (byType != null) { -@@ -282,14 +301,27 @@ public final class ChunkEntitySlices { +@@ -282,14 +302,27 @@ public final class ChunkEntitySlices { this.hardCollidingEntities.removeEntity(entity, sectionIndex); } - for (final Iterator, EntityCollectionBySection>> iterator = - this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext();) { - final Reference2ObjectMap.Entry, EntityCollectionBySection> entry = iterator.next(); -+ // Leaf start ++ // Leaf start - Async target finding + if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) { + synchronized (this.entitiesByClass) { + for (final var entry : this.entitiesByClass.reference2ObjectEntrySet()) { @@ -98,7 +100,7 @@ index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..635d6aabbbe9be5c81a71d5e5bf75821 + } } } -+ // Leaf end ++ // Leaf end - Async target finding + final EntityCollectionBySection byType = this.entitiesByType.get(entity.getType()); @@ -667,7 +669,7 @@ index 3093f03d4f298bf39fec8bad2b6c22518774aea8..0a41797fd7beddce0b93d42bac6e0270 } else { this.parent = animal; diff --git a/net/minecraft/world/entity/ai/goal/GoalSelector.java b/net/minecraft/world/entity/ai/goal/GoalSelector.java -index e82e32407cec6109b9c3b0106295217f4a3f4aa2..a177505c84697b93d828db9f111bdeb14f57de43 100644 +index e82e32407cec6109b9c3b0106295217f4a3f4aa2..3c24382a3cced8dcea103ccc87cb506310de8461 100644 --- a/net/minecraft/world/entity/ai/goal/GoalSelector.java +++ b/net/minecraft/world/entity/ai/goal/GoalSelector.java @@ -26,13 +26,23 @@ public class GoalSelector { @@ -684,37 +686,39 @@ index e82e32407cec6109b9c3b0106295217f4a3f4aa2..a177505c84697b93d828db9f111bdeb1 + public void addGoal(int priority, Goal goal) { this.availableGoals.add(new WrappedGoal(priority, goal)); -+ availableGoalsDirty = true; // Leaf ++ availableGoalsDirty = true; // Leaf - Async target finding } @VisibleForTesting public void removeAllGoals(Predicate filter) { this.availableGoals.removeIf(wrappedGoal -> filter.test(wrappedGoal.getGoal())); -+ availableGoalsDirty = true; // Leaf ++ availableGoalsDirty = true; // Leaf - Async target finding } // Paper start - EAR 2 -@@ -63,16 +73,19 @@ public class GoalSelector { +@@ -63,18 +73,19 @@ public class GoalSelector { } this.availableGoals.removeIf(wrappedGoal1 -> wrappedGoal1.getGoal() == goal); -+ availableGoalsDirty = true; // Leaf ++ availableGoalsDirty = true; // Leaf - Async target finding } // Paper start - Perf: optimize goal types private static boolean goalContainsAnyFlags(WrappedGoal goal, ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet flags) { -+ // Leaf - inline diff - return goal.getFlags().hasCommonElements(flags); +- return goal.getFlags().hasCommonElements(flags); ++ return goal.getFlags().hasCommonElements(flags); // Leaf - Async target finding - inline diff } private static boolean goalCanBeReplacedForAllFlags(WrappedGoal goal, Map flag) { long flagIterator = goal.getFlags().getBackingSet(); int wrappedGoalSize = goal.getFlags().size(); -+ // Leaf - inline diff for (int i = 0; i < wrappedGoalSize; ++i) { - final Goal.Flag flag1 = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)]; +- final Goal.Flag flag1 = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)]; ++ final Goal.Flag flag1 = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)]; // Leaf - Async target finding - inline diff flagIterator ^= ca.spottedleaf.concurrentutil.util.IntegerUtil.getTrailingBit(flagIterator); -@@ -85,7 +98,131 @@ public class GoalSelector { + // Paper end - Perf: optimize goal types + if (!flag.getOrDefault(flag1, NO_GOAL).canBeReplacedBy(goal)) { +@@ -85,7 +96,131 @@ public class GoalSelector { return true; } @@ -846,7 +850,7 @@ index e82e32407cec6109b9c3b0106295217f4a3f4aa2..a177505c84697b93d828db9f111bdeb1 for (WrappedGoal wrappedGoal : this.availableGoals) { if (wrappedGoal.isRunning() && (goalContainsAnyFlags(wrappedGoal, this.goalTypes) || !wrappedGoal.canContinueToUse())) { // Paper - Perf: optimize goal types by removing streams wrappedGoal.stop(); -@@ -116,6 +253,18 @@ public class GoalSelector { +@@ -116,6 +251,18 @@ public class GoalSelector { } public void tickRunningGoals(boolean tickAllRunning) { diff --git a/leaf-server/minecraft-patches/features/0162-Sakura-copy-EntityList-implementation-to-BasicEntity.patch b/leaf-server/minecraft-patches/features/0162-Sakura-copy-EntityList-implementation-to-BasicEntity.patch index 3f1d986d..e38ae491 100644 --- a/leaf-server/minecraft-patches/features/0162-Sakura-copy-EntityList-implementation-to-BasicEntity.patch +++ b/leaf-server/minecraft-patches/features/0162-Sakura-copy-EntityList-implementation-to-BasicEntity.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Sakura: copy-EntityList-implementation-to-BasicEntityList diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -index 635d6aabbbe9be5c81a71d5e5bf758211deec0cf..a45f4eb235a7823fce84948ad556c36d9fc6fdd8 100644 +index 561723eeb1dd80f7fdd9aff33f6e1c4c16def0ff..1acf552d915f72929e1a68d9c769dd8a9026514f 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -@@ -414,6 +414,13 @@ public final class ChunkEntitySlices { +@@ -415,6 +415,13 @@ public final class ChunkEntitySlices { private E[] storage; private int size; @@ -22,7 +22,7 @@ index 635d6aabbbe9be5c81a71d5e5bf758211deec0cf..a45f4eb235a7823fce84948ad556c36d public BasicEntityList() { this(0); -@@ -434,6 +441,7 @@ public final class ChunkEntitySlices { +@@ -435,6 +442,7 @@ public final class ChunkEntitySlices { private void resize() { if (this.storage == me.titaniumtown.ArrayConstants.emptyEntityArray) { // Gale - JettPack - reduce array allocations this.storage = (E[])new Entity[DEFAULT_CAPACITY]; @@ -30,7 +30,7 @@ index 635d6aabbbe9be5c81a71d5e5bf758211deec0cf..a45f4eb235a7823fce84948ad556c36d } else { this.storage = Arrays.copyOf(this.storage, this.storage.length * 2); } -@@ -447,6 +455,7 @@ public final class ChunkEntitySlices { +@@ -448,6 +456,7 @@ public final class ChunkEntitySlices { } else { this.storage[idx] = entity; } @@ -38,7 +38,7 @@ index 635d6aabbbe9be5c81a71d5e5bf758211deec0cf..a45f4eb235a7823fce84948ad556c36d } public int indexOf(final E entity) { -@@ -462,24 +471,32 @@ public final class ChunkEntitySlices { +@@ -463,24 +472,32 @@ public final class ChunkEntitySlices { } public boolean remove(final E entity) { diff --git a/leaf-server/minecraft-patches/features/0164-Protocol-Core.patch b/leaf-server/minecraft-patches/features/0164-Protocol-Core.patch index b322df76..a28bedcc 100644 --- a/leaf-server/minecraft-patches/features/0164-Protocol-Core.patch +++ b/leaf-server/minecraft-patches/features/0164-Protocol-Core.patch @@ -5,80 +5,80 @@ Subject: [PATCH] Protocol Core diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java -index 7e19dfe90a63ff26f03b95891dacb7360bba5a3c..d20ffa172227f85b9fd6ac5e2766f6ebd2d07638 100644 +index 7e19dfe90a63ff26f03b95891dacb7360bba5a3c..5d0961f06c23121883c4f0b889ccdf32f06e8a35 100644 --- a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java +++ b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java @@ -47,6 +47,12 @@ public interface CustomPacketPayload { return; } // Leaves end - protocol core -+ // Leaf start - protocol ++ // Leaf start - Protocol core + if (value instanceof org.dreeam.leaf.protocol.LeafCustomPayload payload) { + org.dreeam.leaf.protocol.Protocols.write(buffer, payload); + return; + } -+ // Leaf end - protocol ++ // Leaf end - Protocol core this.writeCap(buffer, value.type(), value); } diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java -index 98af1ad020a003db66d7319f33d43deec315aec5..e04a6db55d936277f2a852374f11d483d79a90ed 100644 +index 98af1ad020a003db66d7319f33d43deec315aec5..9669036e6b7f1830888e48c99acb01d443f4e9f0 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -1839,6 +1839,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop