mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 10:35:38 +01:00
77a5779e24
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2ec53f49 PR-1050: Fix empty result check for Complex Recipes 10671012 PR-1044: Add CrafterCraftEvent 4d87ffe0 Use correct method in JavaDoc ae5e5817 SPIGOT-7850: Add API for Bogged shear state 46b6d445 SPIGOT-7837: Support data pack banner patterns d5d0cefc Fix JavaDoc error b3c2b83d PR-1036: Add API for InventoryView derivatives 1fe2c75a SPIGOT-7809: Add ShieldMeta CraftBukkit Changes: 8ee6fd1b8 SPIGOT-7857: Improve ItemMeta block data deserialization 8f26c30c6 SPIGOT-7857: Fix spurious internal NBT tag when deserializing BlockStateMeta 759061b93 SPIGOT-7855: Fire does not spread or burn blocks 00fc9fb64 SPIGOT-7853: AnvilInventory#getRepairCost() always returns 0 7501e2e04 PR-1450: Add CrafterCraftEvent 8c51673e7 SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel d53d0d0b1 PR-1456: Fix inverted logic in CraftCrafterView#setSlotDisabled 682a678c8 SPIGOT-7850: Add API for Bogged shear state fccf5243a SPIGOT-7837: Support data pack banner patterns 9c3bd4390 PR-1431: Add API for InventoryView derivatives 0cc6acbc4 SPIGOT-7849: Fix FoodComponent serialize with "using-converts-to" using null 2c5474952 Don't rely on tags for CraftItemMetas 20d107e46 SPIGOT-7846: Fix ItemMeta for hanging signs 76f59e315 Remove redundant clone in Dropper InventoryMoveItemEvent e61a53d25 SPIGOT-7817: Call InventoryMoveItemEvent for Crafters 894682e2d SPIGOT-7839: Remove redundant Java version checks 2c12b2187 SPIGOT-7809: Add ShieldMeta and fix setting shield base colours Spigot Changes: fb8fb722 Rebuild patches 34bd42b7 SPIGOT-7835: Fix issue with custom hopper settings
161 lines
8.5 KiB
Diff
161 lines
8.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
Date: Mon, 6 Apr 2020 17:53:29 -0700
|
|
Subject: [PATCH] Optimize GoalSelector Goal.Flag Set operations
|
|
|
|
Optimise the stream.anyMatch statement to move to a bitset
|
|
where we can replace the call with a single bitwise operation.
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/Goal.java b/src/main/java/net/minecraft/world/entity/ai/goal/Goal.java
|
|
index 16f9a98b8a939e5ca7e2dc04f87134a7ed66736b..47741efa48258c3c30b1d59504bf3121c236cadb 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/goal/Goal.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/Goal.java
|
|
@@ -4,7 +4,16 @@ import java.util.EnumSet;
|
|
import net.minecraft.util.Mth;
|
|
|
|
public abstract class Goal {
|
|
- private final EnumSet<Goal.Flag> flags = EnumSet.noneOf(Goal.Flag.class);
|
|
+ private final EnumSet<Goal.Flag> flags = EnumSet.noneOf(Goal.Flag.class); // Paper unused, but dummy to prevent plugins from crashing as hard. Theyll need to support paper in a special case if this is super important, but really doesn't seem like it would be.
|
|
+ private final ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<net.minecraft.world.entity.ai.goal.Goal.Flag> goalTypes = new ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from pathfindergoalselector
|
|
+
|
|
+ // Paper start - remove streams from pathfindergoalselector; make sure types are not empty
|
|
+ public Goal() {
|
|
+ if (this.goalTypes.size() == 0) {
|
|
+ this.goalTypes.addUnchecked(Flag.UNKNOWN_BEHAVIOR);
|
|
+ }
|
|
+ }
|
|
+ // Paper end - remove streams from pathfindergoalselector
|
|
|
|
public abstract boolean canUse();
|
|
|
|
@@ -30,8 +39,13 @@ public abstract class Goal {
|
|
}
|
|
|
|
public void setFlags(EnumSet<Goal.Flag> controls) {
|
|
- this.flags.clear();
|
|
- this.flags.addAll(controls);
|
|
+ // Paper start - remove streams from pathfindergoalselector
|
|
+ this.goalTypes.clear();
|
|
+ this.goalTypes.addAllUnchecked(controls);
|
|
+ if (this.goalTypes.size() == 0) {
|
|
+ this.goalTypes.addUnchecked(Flag.UNKNOWN_BEHAVIOR);
|
|
+ }
|
|
+ // Paper end - remove streams from pathfindergoalselector
|
|
}
|
|
|
|
@Override
|
|
@@ -39,8 +53,10 @@ public abstract class Goal {
|
|
return this.getClass().getSimpleName();
|
|
}
|
|
|
|
- public EnumSet<Goal.Flag> getFlags() {
|
|
- return this.flags;
|
|
+ // Paper start - remove streams from pathfindergoalselector
|
|
+ public ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<Goal.Flag> getFlags() {
|
|
+ return this.goalTypes;
|
|
+ // Paper end - remove streams from pathfindergoalselector
|
|
}
|
|
|
|
protected int adjustedTickDelay(int ticks) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
index 074ef807258139f818e30494126585262c2f33c0..9bdbf3e9453bc3ce96d52d04b8cde0d05f7356d8 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
@@ -25,7 +25,8 @@ public class GoalSelector {
|
|
private final Map<Goal.Flag, WrappedGoal> lockedFlags = new EnumMap<>(Goal.Flag.class);
|
|
private final Set<WrappedGoal> availableGoals = new ObjectLinkedOpenHashSet<>();
|
|
private final Supplier<ProfilerFiller> profiler;
|
|
- private final EnumSet<Goal.Flag> disabledFlags = EnumSet.noneOf(Goal.Flag.class);
|
|
+ private static final Goal.Flag[] GOAL_FLAG_VALUES = Goal.Flag.values(); // Paper - remove streams from pathfindergoalselector
|
|
+ private final ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<net.minecraft.world.entity.ai.goal.Goal.Flag> goalTypes = new ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from pathfindergoalselector
|
|
private int curRate;
|
|
|
|
public GoalSelector(Supplier<ProfilerFiller> profiler) {
|
|
@@ -65,18 +66,18 @@ public class GoalSelector {
|
|
this.availableGoals.removeIf(wrappedGoalx -> wrappedGoalx.getGoal() == goal);
|
|
}
|
|
|
|
- private static boolean goalContainsAnyFlags(WrappedGoal goal, EnumSet<Goal.Flag> controls) {
|
|
- for (Goal.Flag flag : goal.getFlags()) {
|
|
- if (controls.contains(flag)) {
|
|
- return true;
|
|
- }
|
|
- }
|
|
-
|
|
- return false;
|
|
+ // Paper start
|
|
+ private static boolean goalContainsAnyFlags(WrappedGoal goal, ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<Goal.Flag> controls) {
|
|
+ return goal.getFlags().hasCommonElements(controls);
|
|
}
|
|
|
|
private static boolean goalCanBeReplacedForAllFlags(WrappedGoal goal, Map<Goal.Flag, WrappedGoal> goalsByControl) {
|
|
- for (Goal.Flag flag : goal.getFlags()) {
|
|
+ long flagIterator = goal.getFlags().getBackingSet();
|
|
+ int wrappedGoalSize = goal.getFlags().size();
|
|
+ for (int i = 0; i < wrappedGoalSize; ++i) {
|
|
+ final Goal.Flag flag = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)];
|
|
+ flagIterator ^= ca.spottedleaf.concurrentutil.util.IntegerUtil.getTrailingBit(flagIterator);
|
|
+ // Paper end
|
|
if (!goalsByControl.getOrDefault(flag, NO_GOAL).canBeReplacedBy(goal)) {
|
|
return false;
|
|
}
|
|
@@ -90,7 +91,7 @@ public class GoalSelector {
|
|
profilerFiller.push("goalCleanup");
|
|
|
|
for (WrappedGoal wrappedGoal : this.availableGoals) {
|
|
- if (wrappedGoal.isRunning() && (goalContainsAnyFlags(wrappedGoal, this.disabledFlags) || !wrappedGoal.canContinueToUse())) {
|
|
+ if (wrappedGoal.isRunning() && (goalContainsAnyFlags(wrappedGoal, this.goalTypes) || !wrappedGoal.canContinueToUse())) { // Paper - Perf: optimize goal types by removing streams
|
|
wrappedGoal.stop();
|
|
}
|
|
}
|
|
@@ -100,11 +101,14 @@ public class GoalSelector {
|
|
profilerFiller.push("goalUpdate");
|
|
|
|
for (WrappedGoal wrappedGoal2 : this.availableGoals) {
|
|
- if (!wrappedGoal2.isRunning()
|
|
- && !goalContainsAnyFlags(wrappedGoal2, this.disabledFlags)
|
|
- && goalCanBeReplacedForAllFlags(wrappedGoal2, this.lockedFlags)
|
|
- && wrappedGoal2.canUse()) {
|
|
- for (Goal.Flag flag : wrappedGoal2.getFlags()) {
|
|
+ // Paper start
|
|
+ if (!wrappedGoal2.isRunning() && !goalContainsAnyFlags(wrappedGoal2, this.goalTypes) && goalCanBeReplacedForAllFlags(wrappedGoal2, this.lockedFlags) && wrappedGoal2.canUse()) {
|
|
+ long flagIterator = wrappedGoal2.getFlags().getBackingSet();
|
|
+ int wrappedGoalSize = wrappedGoal2.getFlags().size();
|
|
+ for (int i = 0; i < wrappedGoalSize; ++i) {
|
|
+ final Goal.Flag flag = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)];
|
|
+ flagIterator ^= ca.spottedleaf.concurrentutil.util.IntegerUtil.getTrailingBit(flagIterator);
|
|
+ // Paper end
|
|
WrappedGoal wrappedGoal3 = this.lockedFlags.getOrDefault(flag, NO_GOAL);
|
|
wrappedGoal3.stop();
|
|
this.lockedFlags.put(flag, wrappedGoal2);
|
|
@@ -136,11 +140,11 @@ public class GoalSelector {
|
|
}
|
|
|
|
public void disableControlFlag(Goal.Flag control) {
|
|
- this.disabledFlags.add(control);
|
|
+ this.goalTypes.addUnchecked(control); // Paper - remove streams from pathfindergoalselector
|
|
}
|
|
|
|
public void enableControlFlag(Goal.Flag control) {
|
|
- this.disabledFlags.remove(control);
|
|
+ this.goalTypes.removeUnchecked(control); // Paper - remove streams from pathfindergoalselector
|
|
}
|
|
|
|
public void setControlFlag(Goal.Flag control, boolean enabled) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/WrappedGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/WrappedGoal.java
|
|
index b02d3deb550830245c8945ef17d3073ea930fdda..8cf2e0db6b2f7d3a50f2ac1c3f4f0c6c2434b5ba 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/goal/WrappedGoal.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/WrappedGoal.java
|
|
@@ -69,8 +69,10 @@ public class WrappedGoal extends Goal {
|
|
}
|
|
|
|
@Override
|
|
- public EnumSet<Goal.Flag> getFlags() {
|
|
+ // Paper start - remove streams from pathfindergoalselector
|
|
+ public ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<Goal.Flag> getFlags() {
|
|
return this.goal.getFlags();
|
|
+ // Paper end - remove streams from pathfindergoalselector
|
|
}
|
|
|
|
public boolean isRunning() {
|