From 0358549f7bb732bab5a8ff6860c342dcadb010d0 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Wed, 24 Nov 2021 03:06:34 -0800 Subject: [PATCH] p a t c h e s --- .../0196-Add-Player-Client-Options-API.patch} | 0 ...No-Tick-view-distance-implementation.patch | 0 ...imise-TickListServer-by-rewriting-it.patch | 0 ...ptimize-Collision-to-not-load-chunks.patch | 0 ...0405-Remove-streams-from-PairedQueue.patch | 0 ...-teleport-command-to-valid-locations.patch | 0 patches/server/0006-MC-Utils.patch | 29 ++- ...oalSelector-Goal.Flag-Set-operations.patch | 175 ++++++++++++++ .../0392-Improved-Watchdog-Support.patch} | 74 +++--- .../0393-Optimize-Pathfinding.patch} | 4 +- ...4-Reduce-Either-Optional-allocation.patch} | 0 ...-memory-footprint-of-NBTTagCompound.patch} | 8 +- ...ent-opening-inventories-when-frozen.patch} | 8 +- ...97-Optimise-ArraySetSorted-removeIf.patch} | 0 ...entity-collision-code-if-not-needed.patch} | 6 +- ...Implement-Player-Client-Options-API.patch} | 14 +- ...ayer-is-attempted-to-be-removed-fro.patch} | 4 +- ...1-Broadcast-join-message-to-console.patch} | 4 +- ...00-Remove-streams-from-Mob-AI-System.patch | 223 ------------------ 19 files changed, 263 insertions(+), 286 deletions(-) rename patches/{unapplied/api/0197-Add-Player-Client-Options-API.patch => api/0196-Add-Player-Client-Options-API.patch} (100%) rename patches/{unapplied/server => removed/1.18}/0368-No-Tick-view-distance-implementation.patch (100%) rename patches/{unapplied/server => removed/1.18}/0388-Optimise-TickListServer-by-rewriting-it.patch (100%) rename patches/{unapplied/server => removed/1.18}/0393-Optimize-Collision-to-not-load-chunks.patch (100%) rename patches/{unapplied/server => removed/1.18/No longer needed}/0405-Remove-streams-from-PairedQueue.patch (100%) rename patches/{unapplied/server => removed/1.18/No longer needed}/0410-Restrict-vanilla-teleport-command-to-valid-locations.patch (100%) create mode 100644 patches/server/0391-Optimize-GoalSelector-Goal.Flag-Set-operations.patch rename patches/{unapplied/server/0402-Improved-Watchdog-Support.patch => server/0392-Improved-Watchdog-Support.patch} (92%) rename patches/{unapplied/server/0403-Optimize-Pathfinding.patch => server/0393-Optimize-Pathfinding.patch} (91%) rename patches/{unapplied/server/0404-Reduce-Either-Optional-allocation.patch => server/0394-Reduce-Either-Optional-allocation.patch} (100%) rename patches/{unapplied/server/0406-Reduce-memory-footprint-of-NBTTagCompound.patch => server/0395-Reduce-memory-footprint-of-NBTTagCompound.patch} (89%) rename patches/{unapplied/server/0407-Prevent-opening-inventories-when-frozen.patch => server/0396-Prevent-opening-inventories-when-frozen.patch} (92%) rename patches/{unapplied/server/0408-Optimise-ArraySetSorted-removeIf.patch => server/0397-Optimise-ArraySetSorted-removeIf.patch} (100%) rename patches/{unapplied/server/0409-Don-t-run-entity-collision-code-if-not-needed.patch => server/0398-Don-t-run-entity-collision-code-if-not-needed.patch} (82%) rename patches/{unapplied/server/0411-Implement-Player-Client-Options-API.patch => server/0399-Implement-Player-Client-Options-API.patch} (90%) rename patches/{unapplied/server/0413-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch => server/0400-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch} (88%) rename patches/{unapplied/server/0414-Broadcast-join-message-to-console.patch => server/0401-Broadcast-join-message-to-console.patch} (87%) delete mode 100644 patches/unapplied/server/0400-Remove-streams-from-Mob-AI-System.patch diff --git a/patches/unapplied/api/0197-Add-Player-Client-Options-API.patch b/patches/api/0196-Add-Player-Client-Options-API.patch similarity index 100% rename from patches/unapplied/api/0197-Add-Player-Client-Options-API.patch rename to patches/api/0196-Add-Player-Client-Options-API.patch diff --git a/patches/unapplied/server/0368-No-Tick-view-distance-implementation.patch b/patches/removed/1.18/0368-No-Tick-view-distance-implementation.patch similarity index 100% rename from patches/unapplied/server/0368-No-Tick-view-distance-implementation.patch rename to patches/removed/1.18/0368-No-Tick-view-distance-implementation.patch diff --git a/patches/unapplied/server/0388-Optimise-TickListServer-by-rewriting-it.patch b/patches/removed/1.18/0388-Optimise-TickListServer-by-rewriting-it.patch similarity index 100% rename from patches/unapplied/server/0388-Optimise-TickListServer-by-rewriting-it.patch rename to patches/removed/1.18/0388-Optimise-TickListServer-by-rewriting-it.patch diff --git a/patches/unapplied/server/0393-Optimize-Collision-to-not-load-chunks.patch b/patches/removed/1.18/0393-Optimize-Collision-to-not-load-chunks.patch similarity index 100% rename from patches/unapplied/server/0393-Optimize-Collision-to-not-load-chunks.patch rename to patches/removed/1.18/0393-Optimize-Collision-to-not-load-chunks.patch diff --git a/patches/unapplied/server/0405-Remove-streams-from-PairedQueue.patch b/patches/removed/1.18/No longer needed/0405-Remove-streams-from-PairedQueue.patch similarity index 100% rename from patches/unapplied/server/0405-Remove-streams-from-PairedQueue.patch rename to patches/removed/1.18/No longer needed/0405-Remove-streams-from-PairedQueue.patch diff --git a/patches/unapplied/server/0410-Restrict-vanilla-teleport-command-to-valid-locations.patch b/patches/removed/1.18/No longer needed/0410-Restrict-vanilla-teleport-command-to-valid-locations.patch similarity index 100% rename from patches/unapplied/server/0410-Restrict-vanilla-teleport-command-to-valid-locations.patch rename to patches/removed/1.18/No longer needed/0410-Restrict-vanilla-teleport-command-to-valid-locations.patch diff --git a/patches/server/0006-MC-Utils.patch b/patches/server/0006-MC-Utils.patch index ed5ecbfecc..2221c39a98 100644 --- a/patches/server/0006-MC-Utils.patch +++ b/patches/server/0006-MC-Utils.patch @@ -1950,13 +1950,15 @@ index 0000000000000000000000000000000000000000..d0c77068e9a53d1b8bbad0f3f6b420d6 +} diff --git a/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java b/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java new file mode 100644 -index 0000000000000000000000000000000000000000..9df0006c1a283f77c4d01d9fce9062fc1c9bbb1f +index 0000000000000000000000000000000000000000..66f6423d2732d23809fe86418537e35d40d24373 --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java -@@ -0,0 +1,67 @@ +@@ -0,0 +1,92 @@ +package com.destroystokyo.paper.util.set; + +import java.util.Collection; ++import java.util.function.Consumer; ++import java.util.function.Predicate; + +/** + * @author Spottedleaf @@ -2020,6 +2022,29 @@ index 0000000000000000000000000000000000000000..9df0006c1a283f77c4d01d9fce9062fc + public boolean hasCommonElements(final OptimizedSmallEnumSet other) { + return (other.backingSet & this.backingSet) != 0; + } ++ ++ public void forEach(final E[] values, final Consumer action) { ++ long iterator = this.getBackingSet(); ++ int wrappedGoalSize = this.size(); ++ for (int i = 0; i < wrappedGoalSize; ++i) { ++ final E type = values[Long.numberOfTrailingZeros(iterator)]; ++ iterator ^= io.papermc.paper.util.IntegerUtil.getTrailingBit(iterator); ++ action.accept(type); ++ } ++ } ++ ++ public boolean anyMatch(final E[] values, final Predicate predicate) { ++ long iterator = this.getBackingSet(); ++ int wrappedGoalSize = this.size(); ++ for (int i = 0; i < wrappedGoalSize; ++i) { ++ final E type = values[Long.numberOfTrailingZeros(iterator)]; ++ iterator ^= io.papermc.paper.util.IntegerUtil.getTrailingBit(iterator); ++ if (predicate.test(type)) { ++ return true; ++ } ++ } ++ return false; ++ } +} diff --git a/src/main/java/io/papermc/paper/chunk/SingleThreadChunkRegionManager.java b/src/main/java/io/papermc/paper/chunk/SingleThreadChunkRegionManager.java new file mode 100644 diff --git a/patches/server/0391-Optimize-GoalSelector-Goal.Flag-Set-operations.patch b/patches/server/0391-Optimize-GoalSelector-Goal.Flag-Set-operations.patch new file mode 100644 index 0000000000..3182a81862 --- /dev/null +++ b/patches/server/0391-Optimize-GoalSelector-Goal.Flag-Set-operations.patch @@ -0,0 +1,175 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf +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 6667ecc4b7eded4e20a415cef1e1b1179e6710b8..4379b9948f1eecfe6fd7dea98e298ad5f761019a 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,8 @@ import java.util.EnumSet; + import net.minecraft.util.Mth; + + public abstract class Goal { +- private final EnumSet flags = EnumSet.noneOf(Goal.Flag.class); ++ private final EnumSet 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 com.destroystokyo.paper.util.set.OptimizedSmallEnumSet goalTypes = new com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from pathfindergoalselector + + public abstract boolean canUse(); + +@@ -30,8 +31,10 @@ public abstract class Goal { + } + + public void setFlags(EnumSet controls) { +- this.flags.clear(); +- this.flags.addAll(controls); ++ // Paper start - remove streams from pathfindergoalselector ++ this.goalTypes.clear(); ++ this.goalTypes.addAllUnchecked(controls); ++ // Paper end - remove streams from pathfindergoalselector + } + + @Override +@@ -39,8 +42,10 @@ public abstract class Goal { + return this.getClass().getSimpleName(); + } + +- public EnumSet getFlags() { +- return this.flags; ++ // Paper start - remove streams from pathfindergoalselector ++ public com.destroystokyo.paper.util.set.OptimizedSmallEnumSet 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 2bb32378b19a21c94ff3ec8ed32fc9d6f0ad0fdb..ad82395c46943e91e7f65d8d67824cc0c965362b 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 +@@ -30,10 +30,12 @@ public class GoalSelector { + private final Map lockedFlags = new EnumMap<>(Goal.Flag.class); + public final Set availableGoals = Sets.newLinkedHashSet(); + private final Supplier profiler; +- private final EnumSet disabledFlags = EnumSet.noneOf(Goal.Flag.class); ++ private final EnumSet disabledFlags = 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 com.destroystokyo.paper.util.set.OptimizedSmallEnumSet goalTypes = new com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from pathfindergoalselector + private int tickCount; + private int newGoalRate = 3; + private int curRate; ++ private static final Goal.Flag[] GOAL_FLAG_VALUES = Goal.Flag.values(); // Paper - remove streams from pathfindergoalselector + + public GoalSelector(Supplier profiler) { + this.profiler = profiler; +@@ -63,32 +65,33 @@ public class GoalSelector { + } + // Paper end + public void removeGoal(Goal goal) { +- this.availableGoals.stream().filter((wrappedGoal) -> { +- return wrappedGoal.getGoal() == goal; +- }).filter(WrappedGoal::isRunning).forEach(WrappedGoal::stop); +- this.availableGoals.removeIf((wrappedGoal) -> { +- return wrappedGoal.getGoal() == goal; +- }); +- } +- +- private static boolean goalContainsAnyFlags(WrappedGoal goal, EnumSet controls) { +- for(Goal.Flag flag : goal.getFlags()) { +- if (controls.contains(flag)) { +- return true; ++ // Paper start - remove streams from pathfindergoalselector ++ for (java.util.Iterator iterator = this.availableGoals.iterator(); iterator.hasNext();) { ++ WrappedGoal goalWrapped = iterator.next(); ++ if (goalWrapped.getGoal() != goal) { ++ continue; ++ } ++ if (goalWrapped.isRunning()) { ++ goalWrapped.stop(); + } ++ iterator.remove(); + } ++ // Paper end - remove streams from pathfindergoalselector ++ } + +- return false; ++ private static boolean goalContainsAnyFlags(WrappedGoal goal, com.destroystokyo.paper.util.set.OptimizedSmallEnumSet controls) { ++ return goal.getFlags().hasCommonElements(controls); // Paper + } + + private static boolean goalCanBeReplacedForAllFlags(WrappedGoal goal, Map goalsByControl) { +- for(Goal.Flag flag : goal.getFlags()) { ++ // Paper start ++ return !goal.getFlags().anyMatch(GOAL_FLAG_VALUES, flag -> { + if (!goalsByControl.getOrDefault(flag, NO_GOAL).canBeReplacedBy(goal)) { +- return false; ++ return true; + } +- } +- +- return true; ++ return false; ++ }); ++ // Paper end + } + + public void tick() { +@@ -96,7 +99,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())) { + wrappedGoal.stop(); + } + } +@@ -114,12 +117,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()) { ++ wrappedGoal2.getFlags().forEach(GOAL_FLAG_VALUES, flag -> { ++ // Paper end + WrappedGoal wrappedGoal3 = this.lockedFlags.getOrDefault(flag, NO_GOAL); + wrappedGoal3.stop(); + this.lockedFlags.put(flag, wrappedGoal2); +- } ++ }); // Paper + + wrappedGoal2.start(); + } +@@ -155,11 +160,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 6665ce5f48316e626907e6937d5ef1bc398a7ebd..51deb4455cac055ffa455e4f34aa30858d2fb448 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 getFlags() { ++ // Paper start - remove streams from pathfindergoalselector ++ public com.destroystokyo.paper.util.set.OptimizedSmallEnumSet getFlags() { + return this.goal.getFlags(); ++ // Paper end - remove streams from pathfindergoalselector + } + + public boolean isRunning() { diff --git a/patches/unapplied/server/0402-Improved-Watchdog-Support.patch b/patches/server/0392-Improved-Watchdog-Support.patch similarity index 92% rename from patches/unapplied/server/0402-Improved-Watchdog-Support.patch rename to patches/server/0392-Improved-Watchdog-Support.patch index 466d96eea9..9fa6d06322 100644 --- a/patches/unapplied/server/0402-Improved-Watchdog-Support.patch +++ b/patches/server/0392-Improved-Watchdog-Support.patch @@ -71,10 +71,10 @@ index e3b605695e3b837246f72ccb364af06ea48bda45..62c3c597732e6fb30ed5367d902ea876 cause = cause.getCause(); } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048f4eb6705 100644 +index 56682365381d34784b63d36ab50a1deedfb73e74..77820cd4d464f2582b57f60d34bc0c2f3622e4ae 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -299,7 +299,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop processQueue = new java.util.concurrent.ConcurrentLinkedQueue(); public int autosavePeriod; public Commands vanillaCommandDispatcher; @@ -83,7 +83,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048 // CraftBukkit end // Spigot start public static final int TPS = 20; -@@ -310,6 +310,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop S spin(Function serverFactory) { AtomicReference atomicreference = new AtomicReference(); Thread thread = new Thread(() -> { -@@ -933,6 +936,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { CompletableFuture completablefuture; diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 0f2bfc82e715e18f1501da4d0e28b35f5d3faa77..d7e99d7dab0590cfa62ae450e93c600fd1ea4770 100644 +index af93692bb5cc232397cec69ce2bd836a956550ef..fd0aea068fe4bec0bd02a372afd7475314ceb88a 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java -@@ -513,7 +513,7 @@ public abstract class PlayerList { +@@ -512,7 +512,7 @@ public abstract class PlayerList { this.cserver.getPluginManager().callEvent(playerQuitEvent); entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage()); @@ -299,10 +299,10 @@ index 7bf4bf5cb2c1b54a7e2733091f48f3a824336d36..dcce05d2f4ab16424db4ab103a12188e } diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java -index 8306d6628c5b7507ee80cb2bff660e0badf84660..c1f545f48cea7afea53342e3053c669d295851f0 100644 +index 6ec5a6239b6144b2e3f9edcafdfd6fed6de6cbcd..46adef4de2f9e5888dce1e669619dd0386b90470 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java -@@ -839,6 +839,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -830,6 +830,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { try { tickConsumer.accept(entity); } catch (Throwable throwable) { @@ -311,10 +311,10 @@ index 8306d6628c5b7507ee80cb2bff660e0badf84660..c1f545f48cea7afea53342e3053c669d final String msg = String.format("Entity threw exception at %s:%s,%s,%s", entity.level.getWorld().getName(), entity.getX(), entity.getY(), entity.getZ()); MinecraftServer.LOGGER.error(msg, throwable); diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java -index 016c2302d8bcf121eafd1be7eb4f3b206dbdbeec..1de1566b76c73ddfaf7e022296068db02044d5f3 100644 +index fc0ac2a5ad24951f05a18607318e5b5edf4f3463..c76e46afa685fbaa5c83aff4ef72b5fe32bc6d10 100644 --- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java -@@ -1325,6 +1325,7 @@ public class LevelChunk implements ChunkAccess { +@@ -1067,6 +1067,7 @@ public class LevelChunk extends ChunkAccess { gameprofilerfiller.pop(); } catch (Throwable throwable) { @@ -323,10 +323,10 @@ index 016c2302d8bcf121eafd1be7eb4f3b206dbdbeec..1de1566b76c73ddfaf7e022296068db0 final String msg = String.format("BlockEntity threw exception at %s:%s,%s,%s", LevelChunk.this.getLevel().getWorld().getName(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ()); net.minecraft.server.MinecraftServer.LOGGER.error(msg, throwable); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index b0e4f6cb9fe7c199afdd29ea1cd80c93134df426..02f0c3bdf516638bcbcfa86cf71ab79a52c50b11 100644 +index b9b5c7c3d4e991dd62ed7acb33e02c2523fe5d46..c7e2ce7d2fa80c6c97ebe94ec5c36c9eb7356f45 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -@@ -2004,7 +2004,7 @@ public final class CraftServer implements Server { +@@ -2049,7 +2049,7 @@ public final class CraftServer implements Server { @Override public boolean isPrimaryThread() { @@ -336,7 +336,7 @@ index b0e4f6cb9fe7c199afdd29ea1cd80c93134df426..02f0c3bdf516638bcbcfa86cf71ab79a // Paper start diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java -index 33fb61c219f5356a40c4e6e47187a3a606402536..1d63b1da588ef8930133d4cf7ca541fe4d753a4b 100644 +index 867c0802557375b63e69907bdb3ccd66644f1418..1ade239c9aacf2334c6dee773e0b37f3969723da 100644 --- a/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java @@ -12,6 +12,8 @@ import java.util.logging.Level; @@ -348,7 +348,7 @@ index 33fb61c219f5356a40c4e6e47187a3a606402536..1d63b1da588ef8930133d4cf7ca541fe import net.minecrell.terminalconsole.TerminalConsoleAppender; // Paper public class Main { -@@ -156,6 +158,36 @@ public class Main { +@@ -162,6 +164,36 @@ public class Main { OptionSet options = null; @@ -385,7 +385,7 @@ index 33fb61c219f5356a40c4e6e47187a3a606402536..1d63b1da588ef8930133d4cf7ca541fe try { options = parser.parse(args); } catch (joptsimple.OptionException ex) { -@@ -255,8 +287,64 @@ public class Main { +@@ -261,8 +293,64 @@ public class Main { } catch (Throwable t) { t.printStackTrace(); } diff --git a/patches/unapplied/server/0403-Optimize-Pathfinding.patch b/patches/server/0393-Optimize-Pathfinding.patch similarity index 91% rename from patches/unapplied/server/0403-Optimize-Pathfinding.patch rename to patches/server/0393-Optimize-Pathfinding.patch index 5f0b3f1a77..cb063274e6 100644 --- a/patches/unapplied/server/0403-Optimize-Pathfinding.patch +++ b/patches/server/0393-Optimize-Pathfinding.patch @@ -7,10 +7,10 @@ Prevents pathfinding from spamming failures for things such as arrow attacks. diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java -index c7147605f0f2c57274e48ecee20a78efda84ddf9..61080352ef305a1f276dbc297aa680b3175a5da2 100644 +index e675eca77a0a1718cdaceefa20b026dffdcc5508..5884fb42f0880585dee843b98a6ea470a1508e46 100644 --- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java +++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java -@@ -191,9 +191,29 @@ public abstract class PathNavigation { +@@ -193,9 +193,29 @@ public abstract class PathNavigation { return this.moveTo(this.createPath(x, y, z, 1), speed); } diff --git a/patches/unapplied/server/0404-Reduce-Either-Optional-allocation.patch b/patches/server/0394-Reduce-Either-Optional-allocation.patch similarity index 100% rename from patches/unapplied/server/0404-Reduce-Either-Optional-allocation.patch rename to patches/server/0394-Reduce-Either-Optional-allocation.patch diff --git a/patches/unapplied/server/0406-Reduce-memory-footprint-of-NBTTagCompound.patch b/patches/server/0395-Reduce-memory-footprint-of-NBTTagCompound.patch similarity index 89% rename from patches/unapplied/server/0406-Reduce-memory-footprint-of-NBTTagCompound.patch rename to patches/server/0395-Reduce-memory-footprint-of-NBTTagCompound.patch index 3bc485c91d..a47c3ab7a6 100644 --- a/patches/unapplied/server/0406-Reduce-memory-footprint-of-NBTTagCompound.patch +++ b/patches/server/0395-Reduce-memory-footprint-of-NBTTagCompound.patch @@ -8,10 +8,10 @@ is important because we clone chunk data after reading it for safety. So, reduce the impact of the clone on GC. diff --git a/src/main/java/net/minecraft/nbt/CompoundTag.java b/src/main/java/net/minecraft/nbt/CompoundTag.java -index e59475b7bb3e000afece0033c5d3f112d643c4f2..5456387ade8932fb0d9804abe0fd66f1c565e1ae 100644 +index d0b523387a194d1649469e8d861b0b78a2f4e0b6..be2bd47a509a03e78c380cf749cd476f332ab03d 100644 --- a/src/main/java/net/minecraft/nbt/CompoundTag.java +++ b/src/main/java/net/minecraft/nbt/CompoundTag.java -@@ -34,7 +34,7 @@ public class CompoundTag implements Tag { +@@ -35,7 +35,7 @@ public class CompoundTag implements Tag { if (i > 512) { throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512"); } else { @@ -20,7 +20,7 @@ index e59475b7bb3e000afece0033c5d3f112d643c4f2..5456387ade8932fb0d9804abe0fd66f1 byte b; while((b = CompoundTag.readNamedTagType(dataInput, nbtAccounter)) != 0) { -@@ -67,7 +67,7 @@ public class CompoundTag implements Tag { +@@ -129,7 +129,7 @@ public class CompoundTag implements Tag { } public CompoundTag() { @@ -29,7 +29,7 @@ index e59475b7bb3e000afece0033c5d3f112d643c4f2..5456387ade8932fb0d9804abe0fd66f1 } @Override -@@ -373,8 +373,16 @@ public class CompoundTag implements Tag { +@@ -435,8 +435,16 @@ public class CompoundTag implements Tag { @Override public CompoundTag copy() { diff --git a/patches/unapplied/server/0407-Prevent-opening-inventories-when-frozen.patch b/patches/server/0396-Prevent-opening-inventories-when-frozen.patch similarity index 92% rename from patches/unapplied/server/0407-Prevent-opening-inventories-when-frozen.patch rename to patches/server/0396-Prevent-opening-inventories-when-frozen.patch index e9c771ae86..a16fd79371 100644 --- a/patches/unapplied/server/0407-Prevent-opening-inventories-when-frozen.patch +++ b/patches/server/0396-Prevent-opening-inventories-when-frozen.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Prevent opening inventories when frozen diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java -index 642ef5b0b6660f4fbee91c46c016125960bb9e9d..004b5f1e280304312f820eaeaa7ac6a3e89980ca 100644 +index d507adcb538933fcf36e9a4bfb561106d509c26f..9cbca14b0a111e57a1d01bcbcf2164ab8b53b1a5 100644 --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java -@@ -609,7 +609,7 @@ public class ServerPlayer extends Player { +@@ -612,7 +612,7 @@ public class ServerPlayer extends Player { containerUpdateDelay = level.paperConfig.containerUpdateTickRate; } // Paper end @@ -17,7 +17,7 @@ index 642ef5b0b6660f4fbee91c46c016125960bb9e9d..004b5f1e280304312f820eaeaa7ac6a3 this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper this.containerMenu = this.inventoryMenu; } -@@ -1455,7 +1455,7 @@ public class ServerPlayer extends Player { +@@ -1479,7 +1479,7 @@ public class ServerPlayer extends Player { } else { // CraftBukkit start this.containerMenu = container; @@ -27,7 +27,7 @@ index 642ef5b0b6660f4fbee91c46c016125960bb9e9d..004b5f1e280304312f820eaeaa7ac6a3 this.initMenu(container); return OptionalInt.of(this.containerCounter); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java -index 460828d29583ee21a7c5b716f9687a8243911a7e..8836e8cf912948199f0233c3ec22b079268db79d 100644 +index 76a08aaf5106a5e8d0a24e9d966817574ec26068..9ad94aea2959082dfd44edd63c0a5aa1cec1e655 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -322,7 +322,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { diff --git a/patches/unapplied/server/0408-Optimise-ArraySetSorted-removeIf.patch b/patches/server/0397-Optimise-ArraySetSorted-removeIf.patch similarity index 100% rename from patches/unapplied/server/0408-Optimise-ArraySetSorted-removeIf.patch rename to patches/server/0397-Optimise-ArraySetSorted-removeIf.patch diff --git a/patches/unapplied/server/0409-Don-t-run-entity-collision-code-if-not-needed.patch b/patches/server/0398-Don-t-run-entity-collision-code-if-not-needed.patch similarity index 82% rename from patches/unapplied/server/0409-Don-t-run-entity-collision-code-if-not-needed.patch rename to patches/server/0398-Don-t-run-entity-collision-code-if-not-needed.patch index 384947eab1..c41c482f70 100644 --- a/patches/unapplied/server/0409-Don-t-run-entity-collision-code-if-not-needed.patch +++ b/patches/server/0398-Don-t-run-entity-collision-code-if-not-needed.patch @@ -7,10 +7,10 @@ Will not run if max entity craming is disabled and the max collisions per entity is less than or equal to 0 diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java -index 64403a0a1bddeb1f126b8e315187ea79a859582a..478204aa91d33232f33708816fcc7ea2fe1b55d4 100644 +index 06c32d50d6672d2816c8cb1b4ef0dc038ffce817..ba3aae873c2bd23a1bb35bb7746907d0bcfd0dd3 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java -@@ -3262,10 +3262,16 @@ public abstract class LivingEntity extends Entity { +@@ -3261,10 +3261,16 @@ public abstract class LivingEntity extends Entity { protected void serverAiStep() {} protected void pushEntities() { @@ -20,7 +20,7 @@ index 64403a0a1bddeb1f126b8e315187ea79a859582a..478204aa91d33232f33708816fcc7ea2 + return; + } + // Paper end - don't run getEntities if we're not going to use its result - List list = this.level.getEntities(this, this.getBoundingBox(), EntitySelector.pushableBy(this)); + List list = this.level.getEntities((Entity) this, this.getBoundingBox(), EntitySelector.pushableBy(this)); if (!list.isEmpty()) { - int i = this.level.getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING); diff --git a/patches/unapplied/server/0411-Implement-Player-Client-Options-API.patch b/patches/server/0399-Implement-Player-Client-Options-API.patch similarity index 90% rename from patches/unapplied/server/0411-Implement-Player-Client-Options-API.patch rename to patches/server/0399-Implement-Player-Client-Options-API.patch index 38a6ef177b..dcf1849a64 100644 --- a/patches/unapplied/server/0411-Implement-Player-Client-Options-API.patch +++ b/patches/server/0399-Implement-Player-Client-Options-API.patch @@ -85,23 +85,23 @@ index 0000000000000000000000000000000000000000..b6f4400df3d8ec7e06a996de54f8cabb + } +} diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java -index 004b5f1e280304312f820eaeaa7ac6a3e89980ca..2f102c6160a01177820c3b82dce138c71a492526 100644 +index 9cbca14b0a111e57a1d01bcbcf2164ab8b53b1a5..cdb0eb8e21299ca70ed7ed5c1195d07f44e47838 100644 --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java -@@ -1807,6 +1807,7 @@ public class ServerPlayer extends Player { +@@ -1830,6 +1830,7 @@ public class ServerPlayer extends Player { public String locale = null; // CraftBukkit - add, lowercase // Paper - default to null public java.util.Locale adventure$locale = java.util.Locale.US; // Paper public void updateOptions(ServerboundClientInformationPacket packet) { -+ new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(getBukkitEntity(), packet.language, packet.viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(packet.getChatVisibility().name()), packet.getChatColors(), new com.destroystokyo.paper.PaperSkinParts(packet.getModelCustomisation()), packet.getMainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT).callEvent(); // Paper - settings event ++ new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(getBukkitEntity(), packet.language, packet.viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(packet.chatVisibility().name()), packet.chatColors(), new com.destroystokyo.paper.PaperSkinParts(packet.modelCustomisation()), packet.mainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT).callEvent(); // Paper - settings event // CraftBukkit start - if (getMainArm() != packet.getMainHand()) { + if (getMainArm() != packet.mainHand()) { PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -index c52101f871ca6ba45027964281516056775c4290..991e9afd16de706ddc62ab2c121a87bc775142db 100644 +index 131a8fcf8b0e9ddb5e9f456c494ddea27d4cb88e..ac535aef823ebe286847dafb8b0678de5d3128a1 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -@@ -521,6 +521,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player { - public void setViewDistance(int viewDistance) { +@@ -544,6 +544,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + public void setSendViewDistance(int viewDistance) { throw new NotImplementedException("Per-Player View Distance APIs need further understanding to properly implement (There are per world view distances though!)"); // TODO } + diff --git a/patches/unapplied/server/0413-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch b/patches/server/0400-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch similarity index 88% rename from patches/unapplied/server/0413-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch rename to patches/server/0400-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch index 324693d286..d450c95f78 100644 --- a/patches/unapplied/server/0413-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch +++ b/patches/server/0400-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch @@ -7,10 +7,10 @@ Subject: [PATCH] Don't crash if player is attempted to be removed from I suspect it deals with teleporting as it uses players current x/y/z diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java -index 38eebda226e007c8910e04f502ce218cdfe1d456..b49d380ef088aed3204ec71abc437c348ef004fa 100644 +index 975f1aab48f04a9f3cae04141b3fb65247f0ffaf..1a6c75a33c6dfec63eabef0b8a0a5d8812aeeb4c 100644 --- a/src/main/java/net/minecraft/server/level/DistanceManager.java +++ b/src/main/java/net/minecraft/server/level/DistanceManager.java -@@ -253,8 +253,8 @@ public abstract class DistanceManager { +@@ -281,8 +281,8 @@ public abstract class DistanceManager { ObjectSet objectset = (ObjectSet) this.playersPerChunk.get(i); if (objectset == null) return; // CraftBukkit - SPIGOT-6208 diff --git a/patches/unapplied/server/0414-Broadcast-join-message-to-console.patch b/patches/server/0401-Broadcast-join-message-to-console.patch similarity index 87% rename from patches/unapplied/server/0414-Broadcast-join-message-to-console.patch rename to patches/server/0401-Broadcast-join-message-to-console.patch index 1f8a36b70f..cf0692952f 100644 --- a/patches/unapplied/server/0414-Broadcast-join-message-to-console.patch +++ b/patches/server/0401-Broadcast-join-message-to-console.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Broadcast join message to console diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 11079851f8a375d987933b53409b789030b3220d..c6d7d546ca79f71aadafe92d5d91f7ace8a07a0d 100644 +index fd0aea068fe4bec0bd02a372afd7475314ceb88a..ccf03feb976d22f8c4ca4f60b6bc1d1d773c485f 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java -@@ -294,7 +294,9 @@ public abstract class PlayerList { +@@ -293,7 +293,9 @@ public abstract class PlayerList { if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure joinMessage = PaperAdventure.asVanilla(jm); // Paper - Adventure diff --git a/patches/unapplied/server/0400-Remove-streams-from-Mob-AI-System.patch b/patches/unapplied/server/0400-Remove-streams-from-Mob-AI-System.patch deleted file mode 100644 index f546485714..0000000000 --- a/patches/unapplied/server/0400-Remove-streams-from-Mob-AI-System.patch +++ /dev/null @@ -1,223 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Spottedleaf -Date: Mon, 6 Apr 2020 17:53:29 -0700 -Subject: [PATCH] Remove streams from Mob AI System - -The streams hurt performance and allocate tons of garbage, so -replace them with the standard iterator. - -Also 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 d92ddc8a4c0f5249b7ff4f97af1ea3db413b2983..fabd20265863751ad980ee4a697f3f0d47df101f 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 -@@ -3,7 +3,8 @@ package net.minecraft.world.entity.ai.goal; - import java.util.EnumSet; - - public abstract class Goal { -- private final EnumSet flags = EnumSet.noneOf(Goal.Flag.class); -+ private final EnumSet 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 com.destroystokyo.paper.util.set.OptimizedSmallEnumSet goalTypes = new com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from pathfindergoalselector - - public abstract boolean canUse(); - -@@ -25,8 +26,10 @@ public abstract class Goal { - } - - public void setFlags(EnumSet controls) { -- this.flags.clear(); -- this.flags.addAll(controls); -+ // Paper start - remove streams from pathfindergoalselector -+ this.goalTypes.clear(); -+ this.goalTypes.addAllUnchecked(controls); -+ // Paper end - remove streams from pathfindergoalselector - } - - @Override -@@ -34,8 +37,10 @@ public abstract class Goal { - return this.getClass().getSimpleName(); - } - -- public EnumSet getFlags() { -- return this.flags; -+ // Paper start - remove streams from pathfindergoalselector -+ public com.destroystokyo.paper.util.set.OptimizedSmallEnumSet getFlags() { -+ return this.goalTypes; -+ // Paper end - remove streams from pathfindergoalselector - } - - public static enum Flag { -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 69bf112655615337e0df3ea56b9e42fa5ff70430..a96831d5df2b88203aec8fe2a5909708764b38ee 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 -@@ -28,10 +28,12 @@ public class GoalSelector { - private final Map lockedFlags = new EnumMap<>(Goal.Flag.class); - public final Set availableGoals = Sets.newLinkedHashSet(); - private final Supplier profiler; -- private final EnumSet disabledFlags = EnumSet.noneOf(Goal.Flag.class); -+ private final EnumSet disabledFlags = 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 com.destroystokyo.paper.util.set.OptimizedSmallEnumSet goalTypes = new com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from pathfindergoalselector - private int tickCount; - private int newGoalRate = 3; - private int curRate; -+ private static final Goal.Flag[] PATHFINDER_GOAL_TYPES = Goal.Flag.values(); // Paper - remove streams from pathfindergoalselector - - public GoalSelector(Supplier profiler) { - this.profiler = profiler; -@@ -61,47 +63,95 @@ public class GoalSelector { - } - // Paper end - public void removeGoal(Goal goal) { -- this.availableGoals.stream().filter((wrappedGoal) -> { -- return wrappedGoal.getGoal() == goal; -- }).filter(WrappedGoal::isRunning).forEach(WrappedGoal::stop); -- this.availableGoals.removeIf((wrappedGoal) -> { -- return wrappedGoal.getGoal() == goal; -- }); -+ // Paper start - remove streams from pathfindergoalselector -+ for (java.util.Iterator iterator = this.availableGoals.iterator(); iterator.hasNext();) { -+ WrappedGoal goalWrapped = iterator.next(); -+ if (goalWrapped.getGoal() != goal) { -+ continue; -+ } -+ if (goalWrapped.isRunning()) { -+ goalWrapped.stop(); -+ } -+ iterator.remove(); -+ } -+ // Paper end - remove streams from pathfindergoalselector - } - - public void tick() { - ProfilerFiller profilerFiller = this.profiler.get(); - profilerFiller.push("goalCleanup"); -- this.getRunningGoals().filter((wrappedGoal) -> { -- return !wrappedGoal.isRunning() || wrappedGoal.getFlags().stream().anyMatch(this.disabledFlags::contains) || !wrappedGoal.canContinueToUse(); -- }).forEach(Goal::stop); -- this.lockedFlags.forEach((flag, wrappedGoal) -> { -+ // Paper start - remove streams from pathfindergoalselector -+ for (java.util.Iterator iterator = this.availableGoals.iterator(); iterator.hasNext();) { -+ WrappedGoal wrappedGoal = iterator.next(); - if (!wrappedGoal.isRunning()) { -- this.lockedFlags.remove(flag); -+ continue; -+ } -+ if (!this.goalTypes.hasCommonElements(wrappedGoal.getFlags()) && wrappedGoal.canContinueToUse()) { -+ continue; -+ } -+ wrappedGoal.stop(); -+ } -+ // Paper end - remove streams from pathfindergoalselector -+ this.lockedFlags.forEach((pathfindergoal_type, pathfindergoalwrapped) -> { -+ if (!pathfindergoalwrapped.isRunning()) { -+ this.lockedFlags.remove(pathfindergoal_type); - } - - }); - profilerFiller.pop(); - profilerFiller.push("goalUpdate"); -- this.availableGoals.stream().filter((wrappedGoal) -> { -- return !wrappedGoal.isRunning(); -- }).filter((wrappedGoal) -> { -- return wrappedGoal.getFlags().stream().noneMatch(this.disabledFlags::contains); -- }).filter((wrappedGoal) -> { -- return wrappedGoal.getFlags().stream().allMatch((flag) -> { -- return this.lockedFlags.getOrDefault(flag, NO_GOAL).canBeReplacedBy(wrappedGoal); -- }); -- }).filter(WrappedGoal::canUse).forEach((wrappedGoal) -> { -- wrappedGoal.getFlags().forEach((flag) -> { -- WrappedGoal wrappedGoal2 = this.lockedFlags.getOrDefault(flag, NO_GOAL); -- wrappedGoal2.stop(); -- this.lockedFlags.put(flag, wrappedGoal); -- }); -+ -+ // Paper start - remove streams from pathfindergoalselector -+ goal_update_loop: for (java.util.Iterator iterator = this.availableGoals.iterator(); iterator.hasNext();) { -+ WrappedGoal wrappedGoal = iterator.next(); -+ if (wrappedGoal.isRunning()) { -+ continue; -+ } -+ -+ com.destroystokyo.paper.util.set.OptimizedSmallEnumSet wrappedGoalSet = wrappedGoal.getFlags(); -+ -+ if (this.goalTypes.hasCommonElements(wrappedGoalSet)) { -+ continue; -+ } -+ -+ long iterator1 = wrappedGoalSet.getBackingSet(); -+ int wrappedGoalSize = wrappedGoalSet.size(); -+ for (int i = 0; i < wrappedGoalSize; ++i) { -+ Goal.Flag type = PATHFINDER_GOAL_TYPES[Long.numberOfTrailingZeros(iterator1)]; -+ iterator1 ^= io.papermc.paper.util.IntegerUtil.getTrailingBit(iterator1); -+ WrappedGoal wrapped = this.lockedFlags.getOrDefault(type, GoalSelector.NO_GOAL); -+ if (!wrapped.canBeReplacedBy(wrappedGoal)) { -+ continue goal_update_loop; -+ } -+ } -+ -+ if (!wrappedGoal.canUse()) { -+ continue; -+ } -+ -+ iterator1 = wrappedGoalSet.getBackingSet(); -+ wrappedGoalSize = wrappedGoalSet.size(); -+ for (int i = 0; i < wrappedGoalSize; ++i) { -+ Goal.Flag type = PATHFINDER_GOAL_TYPES[Long.numberOfTrailingZeros(iterator1)]; -+ iterator1 ^= io.papermc.paper.util.IntegerUtil.getTrailingBit(iterator1); -+ WrappedGoal wrapped = this.lockedFlags.getOrDefault(type, GoalSelector.NO_GOAL); -+ -+ wrapped.stop(); -+ this.lockedFlags.put(type, wrappedGoal); -+ } - wrappedGoal.start(); -- }); -+ } -+ // Paper end - remove streams from pathfindergoalselector - profilerFiller.pop(); - profilerFiller.push("goalTick"); -- this.getRunningGoals().forEach(WrappedGoal::tick); -+ // Paper start - remove streams from pathfindergoalselector -+ for (java.util.Iterator iterator = this.availableGoals.iterator(); iterator.hasNext();) { -+ WrappedGoal wrappedGoal = iterator.next(); -+ if (wrappedGoal.isRunning()) { -+ wrappedGoal.tick(); -+ } -+ } -+ // Paper end - remove streams from pathfindergoalselector - profilerFiller.pop(); - } - -@@ -118,11 +168,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 1e915b999f4261fb27846a0e559ea22e4b09b4db..eb3492962e58cad8f2927e53a0d3518d1b06bdf9 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 -@@ -58,9 +58,10 @@ public class WrappedGoal extends Goal { - this.goal.setFlags(controls); - } - -- @Override -- public EnumSet getFlags() { -+ // Paper start - remove streams from pathfindergoalselector -+ public com.destroystokyo.paper.util.set.OptimizedSmallEnumSet getFlags() { - return this.goal.getFlags(); -+ // Paper end - remove streams from pathfindergoalselector - } - - public boolean isRunning() {