p a t c h e s

This commit is contained in:
Jason Penilla 2021-11-24 03:06:34 -08:00 committed by MiniDigger | Martin
parent e208af9741
commit 0358549f7b
19 changed files with 263 additions and 286 deletions

View file

@ -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 <Spottedleaf@users.noreply.github.com>
@ -2020,6 +2022,29 @@ index 0000000000000000000000000000000000000000..9df0006c1a283f77c4d01d9fce9062fc
+ public boolean hasCommonElements(final OptimizedSmallEnumSet<E> other) {
+ return (other.backingSet & this.backingSet) != 0;
+ }
+
+ public void forEach(final E[] values, final Consumer<E> 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<E> 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

View file

@ -0,0 +1,175 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <spottedleaf@spottedleaf.dev>
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<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 com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<net.minecraft.world.entity.ai.goal.Goal.Flag> 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<Goal.Flag> 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<Goal.Flag> getFlags() {
- return this.flags;
+ // Paper start - remove streams from pathfindergoalselector
+ public com.destroystokyo.paper.util.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 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<Goal.Flag, WrappedGoal> lockedFlags = new EnumMap<>(Goal.Flag.class);
public final Set<WrappedGoal> availableGoals = Sets.newLinkedHashSet();
private final Supplier<ProfilerFiller> profiler;
- private final EnumSet<Goal.Flag> disabledFlags = EnumSet.noneOf(Goal.Flag.class);
+ private final EnumSet<Goal.Flag> 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<net.minecraft.world.entity.ai.goal.Goal.Flag> 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<ProfilerFiller> 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<Goal.Flag> controls) {
- for(Goal.Flag flag : goal.getFlags()) {
- if (controls.contains(flag)) {
- return true;
+ // Paper start - remove streams from pathfindergoalselector
+ for (java.util.Iterator<WrappedGoal> 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<Goal.Flag> controls) {
+ return goal.getFlags().hasCommonElements(controls); // Paper
}
private static boolean goalCanBeReplacedForAllFlags(WrappedGoal goal, Map<Goal.Flag, WrappedGoal> 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<Goal.Flag> getFlags() {
+ // Paper start - remove streams from pathfindergoalselector
+ public com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<Goal.Flag> getFlags() {
return this.goal.getFlags();
+ // Paper end - remove streams from pathfindergoalselector
}
public boolean isRunning() {

View file

@ -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<TickTa
@@ -297,7 +297,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
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<TickTa
@@ -308,6 +308,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Spigot end
public static long currentTickLong = 0L; // Paper
@ -93,7 +93,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new Thread(() -> {
@@ -933,6 +936,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -914,6 +917,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// CraftBukkit start
private boolean hasStopped = false;
@ -101,7 +101,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
private final Object stopLock = new Object();
public final boolean hasStopped() {
synchronized (this.stopLock) {
@@ -947,6 +951,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -928,6 +932,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
if (this.hasStopped) return;
this.hasStopped = true;
}
@ -121,7 +121,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
// CraftBukkit end
MinecraftServer.LOGGER.info("Stopping server");
MinecraftTimings.stopServer(); // Paper
@@ -1012,7 +1029,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -991,7 +1008,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.getProfileCache().save(false); // Paper
}
// Spigot end
@ -140,7 +140,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
}
public String getLocalIp() {
@@ -1105,6 +1133,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1084,6 +1112,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
protected void runServer() {
try {
@ -148,7 +148,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
if (this.initServer()) {
this.nextTickTime = Util.getMillis();
this.status.setDescription(new TextComponent(this.motd));
@@ -1112,6 +1141,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1091,6 +1120,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.updateStatusIcon(this.status);
// Spigot start
@ -167,7 +167,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
Arrays.fill( recentTps, 20 );
long start = System.nanoTime(), curTime, tickSection = start; // Paper - Further improve server tick loop
@@ -1168,6 +1209,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1148,6 +1189,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.onServerCrash((CrashReport) null);
}
} catch (Throwable throwable) {
@ -180,10 +180,10 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
MinecraftServer.LOGGER.error("Encountered an unexpected exception", throwable);
// Spigot Start
if ( throwable.getCause() != null )
@@ -1203,14 +1250,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} catch (Throwable throwable1) {
MinecraftServer.LOGGER.error("Exception stopping the server", throwable1);
} finally {
@@ -1187,14 +1234,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.profileCache.clearExecutor();
}
- org.spigotmc.WatchdogThread.doStop(); // Spigot
+ //org.spigotmc.WatchdogThread.doStop(); // Spigot // Paper - move into stop
// CraftBukkit start - Restore terminal to original settings
@ -194,11 +194,11 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
}
// CraftBukkit end
- this.onServerExit();
+ //this.exit(); // Paper - moved into stop
+ //this.onServerExit(); // Paper - moved into stop
}
}
@@ -1249,6 +1296,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1233,6 +1280,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@Override
public TickTask wrapRunnable(Runnable runnable) {
@ -211,7 +211,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
return new TickTask(this.tickCount, runnable);
}
@@ -1484,6 +1537,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1461,6 +1514,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
try {
crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
} catch (Throwable t) {
@ -219,7 +219,7 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
throw new RuntimeException("Error generating crash report", t);
}
// Spigot End
@@ -1961,7 +2015,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1893,7 +1947,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.packRepository.setSelected(datapacks);
this.worldData.setDataPackConfig(MinecraftServer.getSelectedPacks(this.packRepository));
datapackresources.updateGlobals();
@ -230,19 +230,19 @@ index ec0921c1a24c3408fefd03d452cafa6d51eacb54..79267dace0130350e172cd03c9041048
this.functionManager.replaceLibrary(this.resources.getFunctionLibrary());
this.structureManager.onResourceManagerReload(this.resources.getResourceManager());
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index b6ccc8cacb615a35a60c73f145b7bd1cf0b891ee..a335d48467d1730bfed25eb5fd9046e115f23ed0 100644
index 049eb5693dc98e1d0ec3bd88c73a41fdb2f59bff..0716aaf29f9d76240a0de4ca02daba442b36ec7d 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -285,7 +285,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -281,7 +281,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
long j = Util.getNanos() - i;
String s = String.format(Locale.ROOT, "%.3fs", (double) j / 1.0E9D);
- DedicatedServer.LOGGER.info("Done ({})! For help, type \"help\"", s);
+ //DedicatedServer.LOGGER.info("Done ({})! For help, type \"help\"", s); // Paper moved to after init
if (dedicatedserverproperties.announcePlayerAchievements != null) {
((GameRules.BooleanValue) this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)).set(dedicatedserverproperties.announcePlayerAchievements, (MinecraftServer) this);
((GameRules.BooleanValue) this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)).set(dedicatedserverproperties.announcePlayerAchievements, this);
}
@@ -448,7 +448,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -438,7 +438,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
//this.remoteStatusListener.b(); // Paper - don't wait for remote connections
}
@ -252,20 +252,20 @@ index b6ccc8cacb615a35a60c73f145b7bd1cf0b891ee..a335d48467d1730bfed25eb5fd9046e1
}
@Override
@@ -781,7 +782,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -764,7 +765,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@Override
public void stopServer() {
super.stopServer();
- Util.shutdownExecutors();
+ //SystemUtils.h(); // Paper - moved into super
+ //Util.shutdownExecutors(); // Paper - moved into super
SkullBlockEntity.clear();
}
@Override
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 764e33719471dcd8549e0feee2ceb5f5318316be..862729188385dec47b43dcfed53c49897569b662 100644
index 847d1b447e3796cc03e26df46b92815a76707b81..0758f0983c17e7e4b5b5aea64ea12e990f7a22e4 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -581,6 +581,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -540,6 +540,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
MutableBoolean mutableboolean = new MutableBoolean();
do {
@ -274,10 +274,10 @@ index 764e33719471dcd8549e0feee2ceb5f5318316be..862729188385dec47b43dcfed53c4989
list.stream().map((playerchunk) -> {
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();
}

View file

@ -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);
}

View file

@ -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() {

View file

@ -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 {

View file

@ -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<Entity> list = this.level.getEntities(this, this.getBoundingBox(), EntitySelector.pushableBy(this));
List<Entity> 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);

View file

@ -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
}
+

View file

@ -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<ServerPlayer> objectset = (ObjectSet) this.playersPerChunk.get(i);
if (objectset == null) return; // CraftBukkit - SPIGOT-6208

View file

@ -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

View file

@ -1,223 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <spottedleaf@spottedleaf.dev>
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<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 com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<net.minecraft.world.entity.ai.goal.Goal.Flag> 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<Goal.Flag> 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<Goal.Flag> getFlags() {
- return this.flags;
+ // Paper start - remove streams from pathfindergoalselector
+ public com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<Goal.Flag> 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<Goal.Flag, WrappedGoal> lockedFlags = new EnumMap<>(Goal.Flag.class);
public final Set<WrappedGoal> availableGoals = Sets.newLinkedHashSet();
private final Supplier<ProfilerFiller> profiler;
- private final EnumSet<Goal.Flag> disabledFlags = EnumSet.noneOf(Goal.Flag.class);
+ private final EnumSet<Goal.Flag> 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<net.minecraft.world.entity.ai.goal.Goal.Flag> 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<ProfilerFiller> 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<WrappedGoal> 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<WrappedGoal> 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<WrappedGoal> iterator = this.availableGoals.iterator(); iterator.hasNext();) {
+ WrappedGoal wrappedGoal = iterator.next();
+ if (wrappedGoal.isRunning()) {
+ continue;
+ }
+
+ com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<net.minecraft.world.entity.ai.goal.Goal.Flag> 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<WrappedGoal> 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<Goal.Flag> getFlags() {
+ // Paper start - remove streams from pathfindergoalselector
+ public com.destroystokyo.paper.util.set.OptimizedSmallEnumSet<Goal.Flag> getFlags() {
return this.goal.getFlags();
+ // Paper end - remove streams from pathfindergoalselector
}
public boolean isRunning() {