From 88699fb548db9d3832694463be1e4859a3bea28a Mon Sep 17 00:00:00 2001 From: hayanesuru Date: Sun, 24 Aug 2025 20:57:16 +0900 Subject: [PATCH] fix: ensure goal selector plugin compatibility (#477) closes: #475 --- .../0282-optimize-goal-selector.patch | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/leaf-server/minecraft-patches/features/0282-optimize-goal-selector.patch b/leaf-server/minecraft-patches/features/0282-optimize-goal-selector.patch index a2ce63af..441a6926 100644 --- a/leaf-server/minecraft-patches/features/0282-optimize-goal-selector.patch +++ b/leaf-server/minecraft-patches/features/0282-optimize-goal-selector.patch @@ -22,15 +22,16 @@ index f54bbe2e65b18f214266769c7a64144baafa9a58..40d53e4469a71b33949ee2bd7b01783d } } diff --git a/net/minecraft/world/entity/ai/goal/GoalSelector.java b/net/minecraft/world/entity/ai/goal/GoalSelector.java -index 653c58c7637c46c8b46a5082f671324a2221d431..5148bed6cc991afc6f0e3de34bc19703295262e3 100644 +index 653c58c7637c46c8b46a5082f671324a2221d431..15b6781d110b7dc95c6dfb576e5258e7457b5e2f 100644 --- a/net/minecraft/world/entity/ai/goal/GoalSelector.java +++ b/net/minecraft/world/entity/ai/goal/GoalSelector.java -@@ -20,10 +20,11 @@ public class GoalSelector { +@@ -20,10 +20,12 @@ public class GoalSelector { } }; private final Map lockedFlags = new EnumMap<>(Goal.Flag.class); - private final Set availableGoals = new ObjectLinkedOpenHashSet<>(); -+ private final org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = new org.dreeam.leaf.util.map.BinaryGoalSet(); // Leaf - optimize goal selector ++ private final org.dreeam.leaf.util.map.BinaryGoalSet leaf$availableGoals = new org.dreeam.leaf.util.map.BinaryGoalSet(); // Leaf - optimize goal selector ++ private final Set availableGoals = leaf$availableGoals; // Leaf - optimize goal selector private static final Goal.Flag[] GOAL_FLAG_VALUES = Goal.Flag.values(); // Paper - remove streams from GoalSelector private final ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet goalTypes = new ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from GoalSelector private int curRate; // Paper - EAR 2 @@ -38,13 +39,13 @@ index 653c58c7637c46c8b46a5082f671324a2221d431..5148bed6cc991afc6f0e3de34bc19703 public void addGoal(int priority, Goal goal) { this.availableGoals.add(new WrappedGoal(priority, goal)); -@@ -40,7 +41,12 @@ public class GoalSelector { +@@ -40,7 +42,12 @@ public class GoalSelector { } public boolean hasTasks() { - for (WrappedGoal task : this.availableGoals) { + // Leaf start - optimize goal selector -+ org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.availableGoals; ++ org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.leaf$availableGoals; + WrappedGoal[] elements = availableGoals.elements(); + for (int i = 0, j = availableGoals.size(); i < j; i++) { + WrappedGoal task = elements[i]; @@ -52,13 +53,13 @@ index 653c58c7637c46c8b46a5082f671324a2221d431..5148bed6cc991afc6f0e3de34bc19703 if (task.isRunning()) { return true; } -@@ -50,7 +56,12 @@ public class GoalSelector { +@@ -50,7 +57,12 @@ public class GoalSelector { // Paper end - EAR 2 public void removeGoal(Goal goal) { - for (WrappedGoal wrappedGoal : this.availableGoals) { + // Leaf start - optimize goal selector -+ org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.availableGoals; ++ org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.leaf$availableGoals; + WrappedGoal[] elements = availableGoals.elements(); + for (int i = 0, j = availableGoals.size(); i < j; i++) { + WrappedGoal wrappedGoal = elements[i]; @@ -66,7 +67,7 @@ index 653c58c7637c46c8b46a5082f671324a2221d431..5148bed6cc991afc6f0e3de34bc19703 if (wrappedGoal.getGoal() == goal && wrappedGoal.isRunning()) { wrappedGoal.stop(); } -@@ -80,37 +91,81 @@ public class GoalSelector { +@@ -80,37 +92,81 @@ public class GoalSelector { } public void tick() { @@ -74,7 +75,7 @@ index 653c58c7637c46c8b46a5082f671324a2221d431..5148bed6cc991afc6f0e3de34bc19703 - if (wrappedGoal.isRunning() && (goalContainsAnyFlags(wrappedGoal, this.goalTypes) || !wrappedGoal.canContinueToUse())) { // Paper - Perf: optimize goal types by removing streams - wrappedGoal.stop(); + // Leaf start - optimize goal selector -+ final org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.availableGoals; ++ final org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.leaf$availableGoals; + final WrappedGoal[] elements = availableGoals.elements(); + final long disabled = this.goalTypes.getBackingSet(); + final int elemSize = availableGoals.size(); @@ -161,7 +162,7 @@ index 653c58c7637c46c8b46a5082f671324a2221d431..5148bed6cc991afc6f0e3de34bc19703 public void tickRunningGoals(boolean tickAllRunning) { - for (WrappedGoal wrappedGoal : this.availableGoals) { + // Leaf start - optimize goal selector -+ org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.availableGoals; ++ org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.leaf$availableGoals; + WrappedGoal[] elements = availableGoals.elements(); + for (int i = 0, j = availableGoals.size(); i < j; i++) { + WrappedGoal wrappedGoal = elements[i];