From 46d3ab50b4b6fa55e9bc39449652ea9543897e32 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 9 May 2024 16:36:04 -0700 Subject: [PATCH] Update to latest Paper 1.20.4 --- gradle.properties | 2 +- patches/server/0001-Build-changes.patch | 2 +- patches/server/0002-MC-Dev-fixes.patch | 52 +- patches/server/0003-Threaded-Regions.patch | 821 +++++++++--------- ...-getHandle-and-overrides-perform-thr.patch | 10 +- ...0007-Disable-mid-tick-task-execution.patch | 2 +- ...dates-in-non-loaded-or-non-owned-chu.patch | 10 +- ...-world-tile-entities-on-worldgen-thr.patch | 4 +- ...ccess-POI-data-for-lodestone-compass.patch | 2 +- .../0016-Fix-off-region-raid-heroes.patch | 4 +- patches/server/0018-Region-profiler.patch | 14 +- 11 files changed, 461 insertions(+), 462 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7e1ef76..519e942 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ group=dev.folia version=1.20.4-R0.1-SNAPSHOT mcVersion=1.20.4 -paperRef=5436d44bf2509ff89129f8790ee4643f09c72871 +paperRef=7ac24a18940da12beb39a030113f6e459f348e2f org.gradle.caching=true org.gradle.parallel=true diff --git a/patches/server/0001-Build-changes.patch b/patches/server/0001-Build-changes.patch index c7a497f..4a934a4 100644 --- a/patches/server/0001-Build-changes.patch +++ b/patches/server/0001-Build-changes.patch @@ -93,7 +93,7 @@ index 9d687da5bdf398bb3f6c84cdf1249a7213d09f2e..e2f704c115fd6e00960bb56bb0779f11 ).openBufferedStream()) { JsonObject json = new Gson().fromJson(reader, JsonObject.class); diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index c8772c773f9933ed1d1debfe707af4373c458152..50055e362a0de853c169a38c6cbd8681b73fc96d 100644 +index 2dc07e5ef249636e85ad9c78e3729e9e066a8fe8..6c42592bfaf85f23f7ff9966d7869aa0237f59c5 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -1865,7 +1865,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { - } +@@ -79,7 +79,7 @@ public class Brain { + } - public DataResult> decode(DynamicOps dynamicOps, MapLike mapLike) { -- MutableObject>>> mutableObject = new MutableObject<>(DataResult.success(ImmutableList.builder())); -+ MutableObject>>> mutableObject2 = new MutableObject<>(DataResult.success(ImmutableList.builder())); // Folia - decompile fix - mapLike.entries().forEach((pair) -> { - DataResult> dataResult = BuiltInRegistries.MEMORY_MODULE_TYPE.byNameCodec().parse(dynamicOps, pair.getFirst()); - DataResult> dataResult2 = dataResult.flatMap((memoryType) -> { - return this.captureRead(memoryType, dynamicOps, (T)pair.getSecond()); - }); -- mutableObject.setValue(mutableObject.getValue().apply2(ImmutableList.Builder::add, dataResult2)); -+ mutableObject2.setValue(mutableObject2.getValue().apply2(ImmutableList.Builder::add, dataResult2)); // Folia - decompile fix - }); -- ImmutableList> immutableList = mutableObject.getValue().resultOrPartial(Brain.LOGGER::error).map(ImmutableList.Builder::build).orElseGet(ImmutableList::of); -+ ImmutableList> immutableList = mutableObject2.getValue().resultOrPartial(Brain.LOGGER::error).map(ImmutableList.Builder::build).orElseGet(ImmutableList::of); // Folia - decompile fix - return DataResult.success(new Brain<>(memoryModules, sensors, immutableList, mutableObject::getValue)); - } - -@@ -181,14 +181,14 @@ public class Brain { + public DataResult> decode(DynamicOps dynamicOps, MapLike mapLike) { +- MutableObject>>> mutableObject = new MutableObject<>( ++ MutableObject>>> mutableObject2 = new MutableObject<>( // Folia - decompile fix + DataResult.success(ImmutableList.builder()) + ); + mapLike.entries() +@@ -91,10 +91,10 @@ public class Brain { + DataResult> dataResult2 = dataResult.flatMap( + memoryType -> this.captureRead((MemoryModuleType)memoryType, dynamicOps, (T)pair.getSecond()) + ); +- mutableObject.setValue(mutableObject.getValue().apply2(Builder::add, dataResult2)); ++ mutableObject2.setValue(mutableObject2.getValue().apply2(Builder::add, dataResult2)); // Folia - decompile fix + } + ); +- ImmutableList> immutableList = mutableObject.getValue() ++ ImmutableList> immutableList = mutableObject2.getValue() // Folia - decompile fix + .resultOrPartial(Brain.LOGGER::error) + .map(Builder::build) + .orElseGet(ImmutableList::of); +@@ -194,14 +194,14 @@ public class Brain { if (optional == null) { throw new IllegalStateException("Unregistered memory fetched: " + type); } else { @@ -44,12 +47,3 @@ index dea20f16ac97402f754c8e47d03e9ef38de73190..21e5d1451f90194aa415cf0a183d1a73 } public long getTimeUntilExpiry(MemoryModuleType type) { -@@ -483,7 +483,7 @@ public class Brain { - private final Optional> value; - - static Brain.MemoryValue createUnchecked(MemoryModuleType type, Optional> data) { -- return new Brain.MemoryValue<>(type, data); -+ return new Brain.MemoryValue<>(type, (Optional>)data); // Folia - decompile fix - } - - MemoryValue(MemoryModuleType type, Optional> data) { diff --git a/patches/server/0003-Threaded-Regions.patch b/patches/server/0003-Threaded-Regions.patch index a168633..6767459 100644 --- a/patches/server/0003-Threaded-Regions.patch +++ b/patches/server/0003-Threaded-Regions.patch @@ -1373,10 +1373,10 @@ index fa062e6543e8a0377e3d4715996955dba005ee80..6284262d8cc2a07ad43eb46c888ca647 // The variable 'k' holds the maximum redstone power value of any adjacent blocks. // If 'k' has the highest level of all neighbors, then the power level of this diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java -index e4fd372a1d585887287253a02531cd192929377b..772e3a864e0e70288a1c010d8bbb809d34d16a41 100644 +index 1d78e8beacbc93ef2cd6beb418edca843f8a5429..ccf869d2dcd788c8264589fa4205448855a49dfd 100644 --- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java +++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java -@@ -100,7 +100,7 @@ public final class ChatProcessor { +@@ -83,7 +83,7 @@ public final class ChatProcessor { final CraftPlayer player = this.player.getBukkitEntity(); final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.craftbukkit$originalMessage, new LazyPlayerSet(this.server)); this.post(ae); @@ -1385,7 +1385,7 @@ index e4fd372a1d585887287253a02531cd192929377b..772e3a864e0e70288a1c010d8bbb809d final PlayerChatEvent se = new PlayerChatEvent(player, ae.getMessage(), ae.getFormat(), ae.getRecipients()); se.setCancelled(ae.isCancelled()); // propagate cancelled state this.queueIfAsyncOrRunImmediately(new Waitable() { -@@ -180,7 +180,7 @@ public final class ChatProcessor { +@@ -150,7 +150,7 @@ public final class ChatProcessor { ae.setCancelled(cancelled); // propagate cancelled state this.post(ae); final boolean listenersOnSyncEvent = canYouHearMe(ChatEvent.getHandlerList()); @@ -1512,7 +1512,7 @@ index cbeaadaecf816070b3a37938c8e683180939afc4..f1991bbce762df848726d2f0b6f1d017 } diff --git a/src/main/java/io/papermc/paper/chunk/system/RegionizedPlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/system/RegionizedPlayerChunkLoader.java -index 1b090f1e79b996e52097afc49c1cec85936653e6..07abf5a326cc7aa8a449b74bd7ac8a43b98528c0 100644 +index bf3c5efa0d58c58a5b0b6b73880aaf03c8a37c12..a45dda1f81d250340ad0d8d7998e79d083dc7ebd 100644 --- a/src/main/java/io/papermc/paper/chunk/system/RegionizedPlayerChunkLoader.java +++ b/src/main/java/io/papermc/paper/chunk/system/RegionizedPlayerChunkLoader.java @@ -141,6 +141,7 @@ public class RegionizedPlayerChunkLoader { @@ -2370,7 +2370,7 @@ index bd68139ae635f2ad7ec8e7a21e0056a139c4c62e..48a43341b17247355a531164019d5cc9 } diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java -index 0cc2307636279915c1f8529e62174cc696e185ee..59aad39f2381d9cc72aa0bb0a2b86e4d06994c09 100644 +index 30fe1c0645a07d663b08c0f988a1ab3a750bf7c4..e45e2303ac69ce3a158bebb52bc8cbd96ceb3f71 100644 --- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java +++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java @@ -346,4 +346,18 @@ public class GlobalConfiguration extends ConfigurationPart { @@ -2393,10 +2393,10 @@ index 0cc2307636279915c1f8529e62174cc696e185ee..59aad39f2381d9cc72aa0bb0a2b86e4d + // Folia end - threaded regions } diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java -index dc7950f9a52a718317e5f41de9d396cd7b846bf3..805080704cf5280c7d97e5e510c547c5e0d0f120 100644 +index d3fdf62912d190f8b468b77230a927023c361074..17b538ee7591a75a5fc7e797c73e7730652fed69 100644 --- a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java +++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java -@@ -474,6 +474,14 @@ public class WorldConfiguration extends ConfigurationPart { +@@ -475,6 +475,14 @@ public class WorldConfiguration extends ConfigurationPart { public Chunks chunks; public class Chunks extends ConfigurationPart { @@ -9711,7 +9711,7 @@ index cb308808906a8cdb127df8284e106e00553473ca..05bc1f010b50e673e9a185d96e338bae } diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java -index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25cfbf9b89f 100644 +index a536ebcf29d8ef0ed32863bd8d5e70f7a0636e8d..936f8663b23908ac5de2076401a5d508f88a0376 100644 --- a/src/main/java/net/minecraft/network/Connection.java +++ b/src/main/java/net/minecraft/network/Connection.java @@ -84,7 +84,7 @@ public class Connection extends SimpleChannelInboundHandler> { @@ -9774,7 +9774,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c } public static void setInitialProtocolAttributes(Channel channel) { -@@ -386,7 +412,7 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -387,7 +413,7 @@ public class Connection extends SimpleChannelInboundHandler> { } packet.onPacketDispatch(this.getPlayer()); @@ -9783,7 +9783,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c || (io.papermc.paper.util.MCUtil.isMainThread() && packet.isReady() && this.pendingActions.isEmpty() && (packet.getExtraPackets() == null || packet.getExtraPackets().isEmpty())))) { this.sendPacket(packet, callbacks, flush); -@@ -415,11 +441,12 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -416,11 +442,12 @@ public class Connection extends SimpleChannelInboundHandler> { } public void runOnceConnected(Consumer task) { @@ -9797,7 +9797,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c } } -@@ -478,10 +505,11 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -479,10 +506,11 @@ public class Connection extends SimpleChannelInboundHandler> { } public void flushChannel() { @@ -9810,7 +9810,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c } } -@@ -516,53 +544,61 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -517,53 +545,61 @@ public class Connection extends SimpleChannelInboundHandler> { // Paper start - Optimize network: Rewrite this to be safer if ran off main thread private boolean flushQueue() { @@ -9906,7 +9906,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c } // Paper end - Optimize network -@@ -571,21 +607,41 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -572,21 +608,41 @@ public class Connection extends SimpleChannelInboundHandler> { private static int currTick; // Paper - Buffer joins to world public void tick() { this.flushQueue(); @@ -9956,7 +9956,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c // Paper start - detailed watchdog information net.minecraft.network.protocol.PacketUtils.packetProcessing.push(this.packetListener); try { // Paper end - detailed watchdog information -@@ -597,7 +653,7 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -598,7 +654,7 @@ public class Connection extends SimpleChannelInboundHandler> { // Paper end - Buffer joins to world } @@ -9965,7 +9965,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c this.handleDisconnection(); } -@@ -643,6 +699,7 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -644,6 +700,7 @@ public class Connection extends SimpleChannelInboundHandler> { this.channel.close(); // We can't wait as this may be called from an event loop. this.disconnectedReason = disconnectReason; } @@ -9973,7 +9973,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c } -@@ -822,10 +879,10 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -823,10 +880,10 @@ public class Connection extends SimpleChannelInboundHandler> { public void handleDisconnection() { if (this.channel != null && !this.channel.isOpen()) { @@ -9986,7 +9986,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c PacketListener packetlistener = this.getPacketListener(); PacketListener packetlistener1 = packetlistener != null ? packetlistener : this.disconnectListener; -@@ -857,6 +914,22 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -858,6 +915,22 @@ public class Connection extends SimpleChannelInboundHandler> { } } // Paper end - Add PlayerConnectionCloseEvent @@ -10009,7 +10009,7 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c } } -@@ -877,15 +950,25 @@ public class Connection extends SimpleChannelInboundHandler> { +@@ -878,15 +951,25 @@ public class Connection extends SimpleChannelInboundHandler> { // Paper start - Optimize network public void clearPacketQueue() { final net.minecraft.server.level.ServerPlayer player = getPlayer(); @@ -10042,14 +10042,14 @@ index 4716f8bd8a64d4f20f0d5957c1e7fabf63020f43..18b8651147dedcf80d9baf04e87fb25c private static class InnerUtil { // Attempt to hide these methods from ProtocolLib, so it doesn't accidently pick them up. diff --git a/src/main/java/net/minecraft/network/protocol/PacketUtils.java b/src/main/java/net/minecraft/network/protocol/PacketUtils.java -index 32838f87978c0694bdb573236b7cdf72b2e363cd..1192503d2729b3f14aa2936c2060df9884870cb4 100644 +index 83302c252f54481f239522e5c6861ccfe233070a..1192503d2729b3f14aa2936c2060df9884870cb4 100644 --- a/src/main/java/net/minecraft/network/protocol/PacketUtils.java +++ b/src/main/java/net/minecraft/network/protocol/PacketUtils.java @@ -44,7 +44,7 @@ public class PacketUtils { public static void ensureRunningOnSameThread(Packet packet, T listener, BlockableEventLoop engine) throws RunningOnDifferentThreadException { if (!engine.isSameThread()) { -- engine.execute(() -> { // Paper - Fix preemptive player kick on a server shutdown +- engine.executeIfPossible(() -> { + Runnable run = () -> { // Folia - region threading packetProcessing.push(listener); // Paper - detailed watchdog information try { // Paper - detailed watchdog information @@ -10078,7 +10078,7 @@ index 32838f87978c0694bdb573236b7cdf72b2e363cd..1192503d2729b3f14aa2936c2060df98 } } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 50055e362a0de853c169a38c6cbd8681b73fc96d..cf06989ad1ab55bf6836abe4cdeed2fff31ac93f 100644 +index 6c42592bfaf85f23f7ff9966d7869aa0237f59c5..4e94de4a3184fd36119bf39beccff62ac561c1e4 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -203,7 +203,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { // Folia - region threading -+ operation.perform(serverPlayer, selection); -+ }, null, 1L); // Folia - region threading -+ ++ // Folia start - region threading ++ i += 1; ++ serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { ++ operation.perform(player, selection); ++ }, null, 1L); ++ // Folia end - region threading } if (i == 0) { -@@ -120,9 +124,13 @@ public class AdvancementCommands { +@@ -332,9 +337,12 @@ public class AdvancementCommands { throw ERROR_CRITERION_NOT_FOUND.create(Advancement.name(advancement), criterion); } else { - for(ServerPlayer serverPlayer : targets) { -+ ++i; // Folia - region threading -+ serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { // Folia - region threading - if (operation.performCriterion(serverPlayer, advancement, criterion)) { -- ++i; -+ // Folia - region threading - } -+ }, null, 1L); // Folia - region threading -+ + for (ServerPlayer serverPlayer : targets) { +- if (operation.performCriterion(serverPlayer, advancement, criterion)) { +- i++; +- } ++ // Folia start - region threading ++ ++i; ++ serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { ++ operation.performCriterion(player, advancement, criterion); ++ }, null, 1L); ++ // Folia end - region threading } if (i == 0) { diff --git a/src/main/java/net/minecraft/server/commands/AttributeCommand.java b/src/main/java/net/minecraft/server/commands/AttributeCommand.java -index 0b054674ce8cb2465dc8658a21ff2ab10c465666..0b6134313f34789a3a245e82f6d1d64903e2817c 100644 +index 152ac7b347a1b85d65eb8a28ec9e85fd77484d31..a6b0b41fafe2993ceeaaea77605beb589eb9bd75 100644 --- a/src/main/java/net/minecraft/server/commands/AttributeCommand.java +++ b/src/main/java/net/minecraft/server/commands/AttributeCommand.java -@@ -92,25 +92,57 @@ public class AttributeCommand { +@@ -239,27 +239,59 @@ public class AttributeCommand { } } @@ -10904,16 +10906,16 @@ index 0b054674ce8cb2465dc8658a21ff2ab10c465666..0b6134313f34789a3a245e82f6d1d649 + // Folia end - region threading + private static int getAttributeValue(CommandSourceStack source, Entity target, Holder attribute, double multiplier) throws CommandSyntaxException { +- LivingEntity livingEntity = getEntityWithAttribute(target, attribute); + // Folia start - region threading -+ target.getBukkitEntity().taskScheduler.schedule((LivingEntity nmsEntity) -> { ++ target.getBukkitEntity().taskScheduler.schedule((Entity nmsEntity) -> { + try { + // Folia end - region threading - LivingEntity livingEntity = getEntityWithAttribute(target, attribute); ++ LivingEntity livingEntity = getEntityWithAttribute(nmsEntity, attribute); // Folia - region threading double d = livingEntity.getAttributeValue(attribute); - source.sendSuccess(() -> { - return Component.translatable("commands.attribute.value.get.success", getAttributeDescription(attribute), target.getName(), d); - }, false); +- source.sendSuccess(() -> Component.translatable("commands.attribute.value.get.success", getAttributeDescription(attribute), target.getName(), d), false); - return (int)(d * multiplier); ++ source.sendSuccess(() -> Component.translatable("commands.attribute.value.get.success", getAttributeDescription(attribute), nmsEntity.getName(), d), false); // Folia - region threading + return; // Folia - region threading + // Folia start - region threading + } catch (CommandSyntaxException ex) { @@ -10925,15 +10927,17 @@ index 0b054674ce8cb2465dc8658a21ff2ab10c465666..0b6134313f34789a3a245e82f6d1d649 } private static int getAttributeBase(CommandSourceStack source, Entity target, Holder attribute, double multiplier) throws CommandSyntaxException { +- LivingEntity livingEntity = getEntityWithAttribute(target, attribute); + // Folia start - region threading -+ target.getBukkitEntity().taskScheduler.schedule((LivingEntity nmsEntity) -> { ++ target.getBukkitEntity().taskScheduler.schedule((Entity nmsEntity) -> { + try { + // Folia end - region threading - LivingEntity livingEntity = getEntityWithAttribute(target, attribute); ++ LivingEntity livingEntity = getEntityWithAttribute(nmsEntity, attribute); // Folia - region threading double d = livingEntity.getAttributeBaseValue(attribute); - source.sendSuccess(() -> { - return Component.translatable("commands.attribute.base_value.get.success", getAttributeDescription(attribute), target.getName(), d); - }, false); + source.sendSuccess( +- () -> Component.translatable("commands.attribute.base_value.get.success", getAttributeDescription(attribute), target.getName(), d), false ++ () -> Component.translatable("commands.attribute.base_value.get.success", getAttributeDescription(attribute), nmsEntity.getName(), d), false // Folia - region threading + ); - return (int)(d * multiplier); + return; // Folia - region threading + // Folia start - region threading @@ -10946,17 +10950,29 @@ index 0b054674ce8cb2465dc8658a21ff2ab10c465666..0b6134313f34789a3a245e82f6d1d649 } private static int getAttributeModifier(CommandSourceStack source, Entity target, Holder attribute, UUID uuid, double multiplier) throws CommandSyntaxException { +- LivingEntity livingEntity = getEntityWithAttribute(target, attribute); + // Folia start - region threading -+ target.getBukkitEntity().taskScheduler.schedule((LivingEntity nmsEntity) -> { ++ target.getBukkitEntity().taskScheduler.schedule((Entity nmsEntity) -> { + try { -+ // Folia end - region threading - LivingEntity livingEntity = getEntityWithAttribute(target, attribute); ++ // Folia end - region threading ++ LivingEntity livingEntity = getEntityWithAttribute(nmsEntity, attribute); // Folia - region threading AttributeMap attributeMap = livingEntity.getAttributes(); if (!attributeMap.hasModifier(attribute, uuid)) { -@@ -120,19 +152,40 @@ public class AttributeCommand { - source.sendSuccess(() -> { - return Component.translatable("commands.attribute.modifier.value.get.success", Component.translationArg(uuid), getAttributeDescription(attribute), target.getName(), d); - }, false); +- throw ERROR_NO_SUCH_MODIFIER.create(target.getName(), getAttributeDescription(attribute), uuid); ++ throw ERROR_NO_SUCH_MODIFIER.create(nmsEntity.getName(), getAttributeDescription(attribute), uuid); // Folia - region threading + } else { + double d = attributeMap.getModifierValue(attribute, uuid); + source.sendSuccess( +@@ -267,55 +299,95 @@ public class AttributeCommand { + "commands.attribute.modifier.value.get.success", + Component.translationArg(uuid), + getAttributeDescription(attribute), +- target.getName(), ++ nmsEntity.getName(), // Folia - region threading + d + ), + false + ); - return (int)(d * multiplier); + return; // Folia - region threading } @@ -10970,35 +10986,49 @@ index 0b054674ce8cb2465dc8658a21ff2ab10c465666..0b6134313f34789a3a245e82f6d1d649 } private static int setAttributeBase(CommandSourceStack source, Entity target, Holder attribute, double value) throws CommandSyntaxException { +- getAttributeInstance(target, attribute).setBaseValue(value); + // Folia start - region threading -+ target.getBukkitEntity().taskScheduler.schedule((LivingEntity nmsEntity) -> { ++ target.getBukkitEntity().taskScheduler.schedule((Entity nmsEntity) -> { + try { + // Folia end - region threading - getAttributeInstance(target, attribute).setBaseValue(value); - source.sendSuccess(() -> { - return Component.translatable("commands.attribute.base_value.set.success", getAttributeDescription(attribute), target.getName(), value); - }, false); -+ // Folia start - region threading ++ getAttributeInstance(nmsEntity, attribute).setBaseValue(value); // Folia - region threading + source.sendSuccess( +- () -> Component.translatable("commands.attribute.base_value.set.success", getAttributeDescription(attribute), target.getName(), value), false ++ () -> Component.translatable("commands.attribute.base_value.set.success", getAttributeDescription(attribute), nmsEntity.getName(), value), false // Folia - region threading + ); +- return 1; ++ return; // Folia - region threading ++ // Folia start - region threading + } catch (CommandSyntaxException ex) { + sendMessage(source, ex); + } + }, null, 1L); ++ return 0; + // Folia end - region threading - return 1; } - private static int addModifier(CommandSourceStack source, Entity target, Holder attribute, UUID uuid, String name, double value, AttributeModifier.Operation operation) throws CommandSyntaxException { + private static int addModifier( + CommandSourceStack source, Entity target, Holder attribute, UUID uuid, String name, double value, AttributeModifier.Operation operation + ) throws CommandSyntaxException { +- AttributeInstance attributeInstance = getAttributeInstance(target, attribute); + // Folia start - region threading -+ target.getBukkitEntity().taskScheduler.schedule((LivingEntity nmsEntity) -> { ++ target.getBukkitEntity().taskScheduler.schedule((Entity nmsEntity) -> { + try { + // Folia end - region threading - AttributeInstance attributeInstance = getAttributeInstance(target, attribute); ++ AttributeInstance attributeInstance = getAttributeInstance(nmsEntity, attribute); // Folia - region threading AttributeModifier attributeModifier = new AttributeModifier(uuid, name, value, operation); if (attributeInstance.hasModifier(attributeModifier)) { -@@ -142,20 +195,38 @@ public class AttributeCommand { - source.sendSuccess(() -> { - return Component.translatable("commands.attribute.modifier.add.success", Component.translationArg(uuid), getAttributeDescription(attribute), target.getName()); - }, false); +- throw ERROR_MODIFIER_ALREADY_PRESENT.create(target.getName(), getAttributeDescription(attribute), uuid); ++ throw ERROR_MODIFIER_ALREADY_PRESENT.create(nmsEntity.getName(), getAttributeDescription(attribute), uuid); // Folia - region threading + } else { + attributeInstance.addPermanentModifier(attributeModifier); + source.sendSuccess( + () -> Component.translatable( +- "commands.attribute.modifier.add.success", Component.translationArg(uuid), getAttributeDescription(attribute), target.getName() ++ "commands.attribute.modifier.add.success", Component.translationArg(uuid), getAttributeDescription(attribute), nmsEntity.getName() // Folia - region threading + ), + false + ); - return 1; + return; // Folia - region threading } @@ -11012,19 +11042,25 @@ index 0b054674ce8cb2465dc8658a21ff2ab10c465666..0b6134313f34789a3a245e82f6d1d649 } private static int removeModifier(CommandSourceStack source, Entity target, Holder attribute, UUID uuid) throws CommandSyntaxException { +- AttributeInstance attributeInstance = getAttributeInstance(target, attribute); + // Folia start - region threading -+ target.getBukkitEntity().taskScheduler.schedule((LivingEntity nmsEntity) -> { ++ target.getBukkitEntity().taskScheduler.schedule((Entity nmsEntity) -> { + try { + // Folia end - region threading - AttributeInstance attributeInstance = getAttributeInstance(target, attribute); ++ AttributeInstance attributeInstance = getAttributeInstance(nmsEntity, attribute); // Folia - region threading if (attributeInstance.removePermanentModifier(uuid)) { - source.sendSuccess(() -> { - return Component.translatable("commands.attribute.modifier.remove.success", Component.translationArg(uuid), getAttributeDescription(attribute), target.getName()); - }, false); + source.sendSuccess( + () -> Component.translatable( +- "commands.attribute.modifier.remove.success", Component.translationArg(uuid), getAttributeDescription(attribute), target.getName() ++ "commands.attribute.modifier.remove.success", Component.translationArg(uuid), getAttributeDescription(attribute), nmsEntity.getName() // Folia - region threading + ), + false + ); - return 1; + return; // Folia - region threading } else { - throw ERROR_NO_SUCH_MODIFIER.create(target.getName(), getAttributeDescription(attribute), uuid); +- throw ERROR_NO_SUCH_MODIFIER.create(target.getName(), getAttributeDescription(attribute), uuid); ++ throw ERROR_NO_SUCH_MODIFIER.create(nmsEntity.getName(), getAttributeDescription(attribute), uuid); // Folia - region threading } + // Folia start - region threading + } catch (CommandSyntaxException ex) { @@ -11037,29 +11073,33 @@ index 0b054674ce8cb2465dc8658a21ff2ab10c465666..0b6134313f34789a3a245e82f6d1d649 private static Component getAttributeDescription(Holder attribute) { diff --git a/src/main/java/net/minecraft/server/commands/ClearInventoryCommands.java b/src/main/java/net/minecraft/server/commands/ClearInventoryCommands.java -index 3d8076ce2a04c550109fb8f04f2b3d0c76b28795..581172fdd35d8a34c7e5427007981f9d67a21513 100644 +index 64ea52a5402f252165a5d8bf4fbd4ec257e7558e..af49f41e9a4e07e32c5de8edad4d2be7c9b19088 100644 --- a/src/main/java/net/minecraft/server/commands/ClearInventoryCommands.java +++ b/src/main/java/net/minecraft/server/commands/ClearInventoryCommands.java -@@ -46,9 +46,12 @@ public class ClearInventoryCommands { +@@ -62,9 +62,14 @@ public class ClearInventoryCommands { int i = 0; - for(ServerPlayer serverPlayer : targets) { + for (ServerPlayer serverPlayer : targets) { - i += serverPlayer.getInventory().clearOrCountMatchingItems(item, maxCount, serverPlayer.inventoryMenu.getCraftSlots()); +- serverPlayer.containerMenu.broadcastChanges(); +- serverPlayer.inventoryMenu.slotsChanged(serverPlayer.getInventory()); ++ // Folia start - region threading + ++i; -+ serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { // Folia - region threading -+ serverPlayer.getInventory().clearOrCountMatchingItems(item, maxCount, serverPlayer.inventoryMenu.getCraftSlots()); - serverPlayer.containerMenu.broadcastChanges(); - serverPlayer.inventoryMenu.slotsChanged(serverPlayer.getInventory()); -+ }, null, 1L); // Folia - region threading ++ serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { ++ player.getInventory().clearOrCountMatchingItems(item, maxCount, player.inventoryMenu.getCraftSlots()); ++ player.containerMenu.broadcastChanges(); ++ player.inventoryMenu.slotsChanged(player.getInventory()); ++ }, null, 1L); ++ // Folia end - region threading } if (i == 0) { diff --git a/src/main/java/net/minecraft/server/commands/DamageCommand.java b/src/main/java/net/minecraft/server/commands/DamageCommand.java -index b8250748606d0356da0e15d432784fb3ae59438a..473d3016f604a41ec3626bb1816888d7d2b5778d 100644 +index 43121f35a944fd9f8d4c5f1cc53749e79892478e..737c815cb0453b2bfafd59857c443e1cf333c23f 100644 --- a/src/main/java/net/minecraft/server/commands/DamageCommand.java +++ b/src/main/java/net/minecraft/server/commands/DamageCommand.java -@@ -34,14 +34,30 @@ public class DamageCommand { - }))))))))); +@@ -104,12 +104,29 @@ public class DamageCommand { + ); } + // Folia start - region threading @@ -11070,16 +11110,14 @@ index b8250748606d0356da0e15d432784fb3ae59438a..473d3016f604a41ec3626bb1816888d7 + private static int damage(CommandSourceStack source, Entity target, float amount, DamageSource damageSource) throws CommandSyntaxException { - if (target.hurt(damageSource, amount)) { -+ // Folia start - region threading -+ target.getBukkitEntity().taskScheduler.schedule((Entity t) -> { -+ try { // Folia end - region threading -+ if (t.hurt(damageSource, amount)) { // Folia - region threading - source.sendSuccess(() -> { -- return Component.translatable("commands.damage.success", amount, target.getDisplayName()); -- }, true); +- source.sendSuccess(() -> Component.translatable("commands.damage.success", amount, target.getDisplayName()), true); - return 1; -+ return Component.translatable("commands.damage.success", amount, t.getDisplayName()); -+ }, true); // Folia - region threading ++ // Folia start - region threading ++ target.getBukkitEntity().taskScheduler.schedule((Entity nmsEntity) -> { ++ try { ++ // Folia end - region threading ++ if (nmsEntity.hurt(damageSource, amount)) { // Folia - region threading ++ source.sendSuccess(() -> Component.translatable("commands.damage.success", amount, nmsEntity.getDisplayName()), true); // Folia - region threading + return; // Folia - region threading } else { throw ERROR_INVULNERABLE.create(); @@ -11094,22 +11132,23 @@ index b8250748606d0356da0e15d432784fb3ae59438a..473d3016f604a41ec3626bb1816888d7 } } diff --git a/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java b/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java -index 21d6a2a5d1722d44146384c28a3cba2df9b42771..365f176f8c98f6963d5c30db3eefc730e7b46803 100644 +index a046a0b1519806ff3d987e6402f152b60a3a6f4c..60649ced046fa126ef59b7a2dc3e6b5eeaf42bc4 100644 --- a/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java +++ b/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java -@@ -25,12 +25,14 @@ public class DefaultGameModeCommands { +@@ -28,12 +28,14 @@ public class DefaultGameModeCommands { GameType gameType = minecraftServer.getForcedGameType(); if (gameType != null) { - for(ServerPlayer serverPlayer : minecraftServer.getPlayerList().getPlayers()) { -+ serverPlayer.getBukkitEntity().taskScheduler.schedule((nmsEntity) -> { // Folia - region threading + for (ServerPlayer serverPlayer : minecraftServer.getPlayerList().getPlayers()) { ++ serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { // Folia - region threading // Paper start - Expand PlayerGameModeChangeEvent - org.bukkit.event.player.PlayerGameModeChangeEvent event = serverPlayer.setGameMode(gameType, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, net.kyori.adventure.text.Component.empty()); +- org.bukkit.event.player.PlayerGameModeChangeEvent event = serverPlayer.setGameMode(gameType, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, net.kyori.adventure.text.Component.empty()); ++ org.bukkit.event.player.PlayerGameModeChangeEvent event = player.setGameMode(gameType, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, net.kyori.adventure.text.Component.empty()); // Folia - region threading if (event != null && event.isCancelled()) { source.sendSuccess(() -> io.papermc.paper.adventure.PaperAdventure.asVanilla(event.cancelMessage()), false); } // Paper end - Expand PlayerGameModeChangeEvent + }, null, 1L); // Folia - region threading - ++i; + i++; } } diff --git a/src/main/java/net/minecraft/server/commands/EffectCommands.java b/src/main/java/net/minecraft/server/commands/EffectCommands.java @@ -11170,11 +11209,11 @@ index ebe50e2e69d346ce9266ed3f180d91ceb58008bd..227acbe74ff009c9275542af734852e3 } diff --git a/src/main/java/net/minecraft/server/commands/EnchantCommand.java b/src/main/java/net/minecraft/server/commands/EnchantCommand.java -index 37d9c354af887c474094b1a364782007a5f2035d..e4c11fb7872338f684f97a48f95c122514180f4f 100644 +index 15bfe2e58d16864af29b04c17181ebf45fa21eba..3844b593c918a1f41c48acd1a3231eb43b483e41 100644 --- a/src/main/java/net/minecraft/server/commands/EnchantCommand.java +++ b/src/main/java/net/minecraft/server/commands/EnchantCommand.java -@@ -46,47 +46,73 @@ public class EnchantCommand { - }))))); +@@ -68,49 +68,76 @@ public class EnchantCommand { + ); } + // Folia start - region threading @@ -11193,14 +11232,15 @@ index 37d9c354af887c474094b1a364782007a5f2035d..e4c11fb7872338f684f97a48f95c1225 + final java.util.concurrent.atomic.AtomicInteger count = new java.util.concurrent.atomic.AtomicInteger(targets.size()); // Folia - region threading + final java.util.concurrent.atomic.AtomicReference possibleSingleDisplayName = new java.util.concurrent.atomic.AtomicReference<>(); // Folia - region threading - for(Entity entity : targets) { + for (Entity entity : targets) { if (entity instanceof LivingEntity) { - LivingEntity livingEntity = (LivingEntity)entity; - ItemStack itemStack = livingEntity.getMainHandItem(); - if (!itemStack.isEmpty()) { -- if (enchantment2.canEnchant(itemStack) && EnchantmentHelper.isEnchantmentCompatible(EnchantmentHelper.getEnchantments(itemStack).keySet(), enchantment2)) { +- if (enchantment2.canEnchant(itemStack) +- && EnchantmentHelper.isEnchantmentCompatible(EnchantmentHelper.getEnchantments(itemStack).keySet(), enchantment2)) { - itemStack.enchant(enchantment2, level); -- ++i; +- i++; - } else if (targets.size() == 1) { - throw ERROR_INCOMPATIBLE.create(itemStack.getItem().getName(itemStack).getString()); + // Folia start - region threading @@ -11209,7 +11249,8 @@ index 37d9c354af887c474094b1a364782007a5f2035d..e4c11fb7872338f684f97a48f95c1225 + LivingEntity livingEntity = (LivingEntity)nmsEntity; + ItemStack itemStack = livingEntity.getMainHandItem(); + if (!itemStack.isEmpty()) { -+ if (enchantment2.canEnchant(itemStack) && EnchantmentHelper.isEnchantmentCompatible(EnchantmentHelper.getEnchantments(itemStack).keySet(), enchantment2)) { ++ if (enchantment2.canEnchant(itemStack) ++ && EnchantmentHelper.isEnchantmentCompatible(EnchantmentHelper.getEnchantments(itemStack).keySet(), enchantment2)) { + itemStack.enchant(enchantment2, level); + possibleSingleDisplayName.set(livingEntity.getDisplayName()); + changed.incrementAndGet(); @@ -11235,10 +11276,10 @@ index 37d9c354af887c474094b1a364782007a5f2035d..e4c11fb7872338f684f97a48f95c1225 + // Folia end - region threading } } -- + return targets.size(); // Folia - region threading + } + } + + // Folia start - region threading + private static void sendFeedback(final CommandSourceStack source, final Enchantment enchantment2, final int level, final java.util.concurrent.atomic.AtomicReference possibleSingleDisplayName, final java.util.concurrent.atomic.AtomicInteger count, final java.util.concurrent.atomic.AtomicInteger changed) { + if (count.decrementAndGet() == 0) { @@ -11249,15 +11290,16 @@ index 37d9c354af887c474094b1a364782007a5f2035d..e4c11fb7872338f684f97a48f95c1225 } else { - if (targets.size() == 1) { + if (i == 1) { - source.sendSuccess(() -> { -- return Component.translatable("commands.enchant.success.single", enchantment2.getFullname(level), targets.iterator().next().getDisplayName()); -+ return Component.translatable("commands.enchant.success.single", enchantment2.getFullname(level), possibleSingleDisplayName.get()); - }, true); + source.sendSuccess( + () -> Component.translatable( +- "commands.enchant.success.single", enchantment2.getFullname(level), targets.iterator().next().getDisplayName() ++ "commands.enchant.success.single", enchantment2.getFullname(level), possibleSingleDisplayName.get() + ), + true + ); } else { - source.sendSuccess(() -> { -- return Component.translatable("commands.enchant.success.multiple", enchantment2.getFullname(level), targets.size()); -+ return Component.translatable("commands.enchant.success.multiple", enchantment2.getFullname(level), i); - }, true); +- source.sendSuccess(() -> Component.translatable("commands.enchant.success.multiple", enchantment2.getFullname(level), targets.size()), true); ++ source.sendSuccess(() -> Component.translatable("commands.enchant.success.multiple", enchantment2.getFullname(level), i), true); } - - return i; @@ -11267,39 +11309,40 @@ index 37d9c354af887c474094b1a364782007a5f2035d..e4c11fb7872338f684f97a48f95c1225 + // Folia end - region threading } diff --git a/src/main/java/net/minecraft/server/commands/ExperienceCommand.java b/src/main/java/net/minecraft/server/commands/ExperienceCommand.java -index 24dfe8e9697331f0d7e67e90b9ca537d7ead575e..30b2dafda64a2e56d53d5d90c3087774a471f950 100644 +index 337c2fe92a2727d3b0b9a0387c2ccaa2cbd48e9f..a795b750118845720b6aa101ab1e2f8ee37a91ed 100644 --- a/src/main/java/net/minecraft/server/commands/ExperienceCommand.java +++ b/src/main/java/net/minecraft/server/commands/ExperienceCommand.java -@@ -46,16 +46,20 @@ public class ExperienceCommand { +@@ -131,14 +131,18 @@ public class ExperienceCommand { } private static int queryExperience(CommandSourceStack source, ServerPlayer player, ExperienceCommand.Type component) { -+ player.getBukkitEntity().taskScheduler.schedule((ServerPlayer p) -> { // Folia - region threading - int i = component.query.applyAsInt(player); - source.sendSuccess(() -> { - return Component.translatable("commands.experience.query." + component.name, player.getDisplayName(), i); - }, false); +- int i = component.query.applyAsInt(player); +- source.sendSuccess(() -> Component.translatable("commands.experience.query." + component.name, player.getDisplayName(), i), false); - return i; ++ player.getBukkitEntity().taskScheduler.schedule((ServerPlayer serverPlayer) -> { // Folia - region threading ++ int i = component.query.applyAsInt(serverPlayer); // Folia - region threading ++ source.sendSuccess(() -> Component.translatable("commands.experience.query." + component.name, serverPlayer.getDisplayName(), i), false); // Folia - region threading + }, null, 1L); // Folia - region threading -+ return 0; ++ return 0; // Folia - region threading } private static int addExperience(CommandSourceStack source, Collection targets, int amount, ExperienceCommand.Type component) { - for(ServerPlayer serverPlayer : targets) { + for (ServerPlayer serverPlayer : targets) { +- component.add.accept(serverPlayer, amount); + serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { // Folia - region threading - component.add.accept(serverPlayer, amount); ++ component.add.accept(player, amount); // Folia - region threading + }, null, 1L); // Folia - region threading } if (targets.size() == 1) { -@@ -75,9 +79,12 @@ public class ExperienceCommand { +@@ -159,9 +163,11 @@ public class ExperienceCommand { int i = 0; - for(ServerPlayer serverPlayer : targets) { -+ ++i; // Folia - region threading -+ serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { // Folia - region threading - if (component.set.test(serverPlayer, amount)) { -- ++i; + for (ServerPlayer serverPlayer : targets) { +- if (component.set.test(serverPlayer, amount)) { +- i++; ++ ++i; serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { // Folia - region threading ++ if (component.set.test(player, amount)) { // Folia - region threading + // Folia - region threading } + }, null, 1L); // Folia - region threading @@ -11307,10 +11350,10 @@ index 24dfe8e9697331f0d7e67e90b9ca537d7ead575e..30b2dafda64a2e56d53d5d90c3087774 if (i == 0) { diff --git a/src/main/java/net/minecraft/server/commands/FillBiomeCommand.java b/src/main/java/net/minecraft/server/commands/FillBiomeCommand.java -index b920f1c8f48aa8e542028acc125293d603aee7c0..785f9be8e9c66c340e5f8f46386fddfd112685d6 100644 +index 6fbb6d215cffe12b8476eca1497698fdd5ac4111..d9056196b99ada4186e6642e0860727abd237a36 100644 --- a/src/main/java/net/minecraft/server/commands/FillBiomeCommand.java +++ b/src/main/java/net/minecraft/server/commands/FillBiomeCommand.java -@@ -80,6 +80,16 @@ public class FillBiomeCommand { +@@ -106,6 +106,16 @@ public class FillBiomeCommand { }); } @@ -11324,10 +11367,10 @@ index b920f1c8f48aa8e542028acc125293d603aee7c0..785f9be8e9c66c340e5f8f46386fddfd + } + // Folia end - region threading + - public static Either fill(ServerLevel world, BlockPos from, BlockPos to, Holder biome, Predicate> filter, Consumer> feedbackConsumer) { - BlockPos blockPos = quantize(from); - BlockPos blockPos2 = quantize(to); -@@ -89,8 +99,18 @@ public class FillBiomeCommand { + public static Either fill( + ServerLevel world, BlockPos from, BlockPos to, Holder biome, Predicate> filter, Consumer> feedbackConsumer + ) { +@@ -117,6 +127,17 @@ public class FillBiomeCommand { if (i > j) { return Either.right(ERROR_VOLUME_TOO_LARGE.create(j, i)); } else { @@ -11343,13 +11386,11 @@ index b920f1c8f48aa8e542028acc125293d603aee7c0..785f9be8e9c66c340e5f8f46386fddfd + (chunks) -> { + sendMessage(feedbackConsumer, () -> { List list = new ArrayList<>(); -- - for(int k = SectionPos.blockToSectionCoord(boundingBox.minZ()); k <= SectionPos.blockToSectionCoord(boundingBox.maxZ()); ++k) { - for(int l = SectionPos.blockToSectionCoord(boundingBox.minX()); l <= SectionPos.blockToSectionCoord(boundingBox.maxX()); ++l) { - ChunkAccess chunkAccess = world.getChunk(l, k, ChunkStatus.FULL, false); -@@ -114,6 +134,11 @@ public class FillBiomeCommand { - return Component.translatable("commands.fillbiome.success.count", mutableInt.getValue(), boundingBox.minX(), boundingBox.minY(), boundingBox.minZ(), boundingBox.maxX(), boundingBox.maxY(), boundingBox.maxZ()); - }); + + for (int k = SectionPos.blockToSectionCoord(boundingBox.minZ()); k <= SectionPos.blockToSectionCoord(boundingBox.maxZ()); k++) { +@@ -153,6 +174,11 @@ public class FillBiomeCommand { + ) + ); return Either.left(mutableInt.getValue()); + // Folia start - region threading + }); // sendMessage @@ -11360,11 +11401,11 @@ index b920f1c8f48aa8e542028acc125293d603aee7c0..785f9be8e9c66c340e5f8f46386fddfd } diff --git a/src/main/java/net/minecraft/server/commands/FillCommand.java b/src/main/java/net/minecraft/server/commands/FillCommand.java -index 287e0b193060829174d9ac7d127c3034c5eee1e1..353dd419f57e923672e065c0b7b27546e12ca7a9 100644 +index 4f61284c0d4ad6cd1b485956f5185552fd7800f8..67c313dedf354b09bb782d60e70673e08f17e03d 100644 --- a/src/main/java/net/minecraft/server/commands/FillCommand.java +++ b/src/main/java/net/minecraft/server/commands/FillCommand.java -@@ -57,6 +57,12 @@ public class FillCommand { - })))))); +@@ -151,6 +151,12 @@ public class FillCommand { + ); } + // Folia start - region threading @@ -11373,10 +11414,10 @@ index 287e0b193060829174d9ac7d127c3034c5eee1e1..353dd419f57e923672e065c0b7b27546 + } + // Folia end - region threading + - private static int fillBlocks(CommandSourceStack source, BoundingBox range, BlockInput block, FillCommand.Mode mode, @Nullable Predicate filter) throws CommandSyntaxException { - int i = range.getXSpan() * range.getYSpan() * range.getZSpan(); - int j = source.getLevel().getGameRules().getInt(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT); -@@ -65,6 +71,18 @@ public class FillCommand { + private static int fillBlocks( + CommandSourceStack source, BoundingBox range, BlockInput block, FillCommand.Mode mode, @Nullable Predicate filter + ) throws CommandSyntaxException { +@@ -161,6 +167,18 @@ public class FillCommand { } else { List list = Lists.newArrayList(); ServerLevel serverLevel = source.getLevel(); @@ -11394,11 +11435,11 @@ index 287e0b193060829174d9ac7d127c3034c5eee1e1..353dd419f57e923672e065c0b7b27546 + try { // Folia end - region threading int k = 0; - for(BlockPos blockPos : BlockPos.betweenClosed(range.minX(), range.minY(), range.minZ(), range.maxX(), range.maxY(), range.maxZ())) { -@@ -93,8 +111,13 @@ public class FillCommand { - source.sendSuccess(() -> { - return Component.translatable("commands.fill.success", l); - }, true); + for (BlockPos blockPos : BlockPos.betweenClosed(range.minX(), range.minY(), range.minZ(), range.maxX(), range.maxY(), range.maxZ())) { +@@ -187,8 +205,13 @@ public class FillCommand { + } else { + int l = k; + source.sendSuccess(() -> Component.translatable("commands.fill.success", l), true); - return k; + return; // Folia - region threading } @@ -11411,11 +11452,11 @@ index 287e0b193060829174d9ac7d127c3034c5eee1e1..353dd419f57e923672e065c0b7b27546 } diff --git a/src/main/java/net/minecraft/server/commands/ForceLoadCommand.java b/src/main/java/net/minecraft/server/commands/ForceLoadCommand.java -index cbcacceb69dd032b70c39075c59cd8d50a77ea17..8ccbb9584bb9aeb8507ba35fd1ce22da936788b5 100644 +index 2e6d55f5582310038db10ace47bc10e171359634..fdd27cbc02ac58c2a2d85c0db00fa347073e915f 100644 --- a/src/main/java/net/minecraft/server/commands/ForceLoadCommand.java +++ b/src/main/java/net/minecraft/server/commands/ForceLoadCommand.java -@@ -49,7 +49,17 @@ public class ForceLoadCommand { - })))); +@@ -97,7 +97,17 @@ public class ForceLoadCommand { + ); } + // Folia start - region threading @@ -11432,10 +11473,10 @@ index cbcacceb69dd032b70c39075c59cd8d50a77ea17..8ccbb9584bb9aeb8507ba35fd1ce22da ChunkPos chunkPos = pos.toChunkPos(); ServerLevel serverLevel = source.getLevel(); ResourceKey resourceKey = serverLevel.dimension(); -@@ -58,14 +68,22 @@ public class ForceLoadCommand { - source.sendSuccess(() -> { - return Component.translatable("commands.forceload.query.success", Component.translationArg(chunkPos), Component.translationArg(resourceKey.location())); - }, false); +@@ -109,14 +119,22 @@ public class ForceLoadCommand { + ), + false + ); - return 1; + return; // Folia - region threading } else { @@ -11456,7 +11497,7 @@ index cbcacceb69dd032b70c39075c59cd8d50a77ea17..8ccbb9584bb9aeb8507ba35fd1ce22da ResourceKey resourceKey = serverLevel.dimension(); LongSet longSet = serverLevel.getForcedChunks(); int i = longSet.size(); -@@ -83,13 +101,15 @@ public class ForceLoadCommand { +@@ -134,20 +152,27 @@ public class ForceLoadCommand { } else { source.sendFailure(Component.translatable("commands.forceload.added.none", Component.translationArg(resourceKey.location()))); } @@ -11471,12 +11512,8 @@ index cbcacceb69dd032b70c39075c59cd8d50a77ea17..8ccbb9584bb9aeb8507ba35fd1ce22da ResourceKey resourceKey = serverLevel.dimension(); + io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> { // Folia - region threading LongSet longSet = serverLevel.getForcedChunks(); - longSet.forEach((chunkPos) -> { - serverLevel.setChunkForced(ChunkPos.getX(chunkPos), ChunkPos.getZ(chunkPos), false); -@@ -97,10 +117,15 @@ public class ForceLoadCommand { - source.sendSuccess(() -> { - return Component.translatable("commands.forceload.removed.all", Component.translationArg(resourceKey.location())); - }, true); + longSet.forEach(chunkPos -> serverLevel.setChunkForced(ChunkPos.getX(chunkPos), ChunkPos.getZ(chunkPos), false)); + source.sendSuccess(() -> Component.translatable("commands.forceload.removed.all", Component.translationArg(resourceKey.location())), true); + }); // Folia - region threading return 0; } @@ -11489,8 +11526,8 @@ index cbcacceb69dd032b70c39075c59cd8d50a77ea17..8ccbb9584bb9aeb8507ba35fd1ce22da int i = Math.min(from.x(), to.x()); int j = Math.min(from.z(), to.z()); int k = Math.max(from.x(), to.x()); -@@ -147,11 +172,18 @@ public class ForceLoadCommand { - }, true); +@@ -206,11 +231,18 @@ public class ForceLoadCommand { + ); } - return r; @@ -11510,19 +11547,19 @@ index cbcacceb69dd032b70c39075c59cd8d50a77ea17..8ccbb9584bb9aeb8507ba35fd1ce22da } } diff --git a/src/main/java/net/minecraft/server/commands/GameModeCommand.java b/src/main/java/net/minecraft/server/commands/GameModeCommand.java -index f7c9127346261d83413ca03a1cdaa84975ae17d6..a47b92b63c40666ce240514905d2a3b254a532bb 100644 +index d1da3600dc07107309b20ebe6e7c0c4da0e8de76..a2075133b0e8ea6299dec0fa5125e4296eb3276a 100644 --- a/src/main/java/net/minecraft/server/commands/GameModeCommand.java +++ b/src/main/java/net/minecraft/server/commands/GameModeCommand.java -@@ -48,15 +48,18 @@ public class GameModeCommand { +@@ -60,15 +60,18 @@ public class GameModeCommand { int i = 0; - for(ServerPlayer serverPlayer : targets) { + for (ServerPlayer serverPlayer : targets) { + serverPlayer.getBukkitEntity().taskScheduler.schedule((nmsEntity) -> { // Folia - region threading // Paper start - Expand PlayerGameModeChangeEvent org.bukkit.event.player.PlayerGameModeChangeEvent event = serverPlayer.setGameMode(gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.COMMAND, net.kyori.adventure.text.Component.empty()); if (event != null && !event.isCancelled()) { logGamemodeChange(context.getSource(), serverPlayer, gameMode); -- ++i; +- i++; + // Folia - region threading } else if (event != null && event.cancelMessage() != null) { context.getSource().sendSuccess(() -> io.papermc.paper.adventure.PaperAdventure.asVanilla(event.cancelMessage()), true); @@ -11554,16 +11591,16 @@ index 1b459a8ee8a6bc039e742d65796bc76660a1c765..4efd0b529ee0431fb4dc76a950ab8f98 } diff --git a/src/main/java/net/minecraft/server/commands/KillCommand.java b/src/main/java/net/minecraft/server/commands/KillCommand.java -index 0026da50714adca207b1d3970ee808c9c09d4443..ac694041183e49ab44c5a27f3aa57ad1638298fd 100644 +index c2974a6bd6851b54d1df2689195d896baf4906ee..57f5c571e63355b0e32480f31b9e5c8173d840c6 100644 --- a/src/main/java/net/minecraft/server/commands/KillCommand.java +++ b/src/main/java/net/minecraft/server/commands/KillCommand.java -@@ -22,7 +22,9 @@ public class KillCommand { +@@ -24,7 +24,9 @@ public class KillCommand { private static int kill(CommandSourceStack source, Collection targets) { - for(Entity entity : targets) { + for (Entity entity : targets) { - entity.kill(); + entity.getBukkitEntity().taskScheduler.schedule((nmsEntity) -> { // Folia - region threading -+ nmsEntity.kill(); // Folia - region threading ++ nmsEntity.kill(); // Folia - region threading + }, null, 1L); // Folia - region threading } @@ -11707,43 +11744,43 @@ index a78ac2c2a536abb0a77371c3d8a9ce0dc5084c38..4f0c962231562c13be8980f98a7d801a private static void checkLoaded(ServerLevel world, ChunkPos pos1, ChunkPos pos2) throws CommandSyntaxException { diff --git a/src/main/java/net/minecraft/server/commands/RecipeCommand.java b/src/main/java/net/minecraft/server/commands/RecipeCommand.java -index c5c690b044ff799d9909fce6856b3bf133f6ef04..bf245691e3b264cbec4428f51b2ec8e8ddbb5521 100644 +index 869eceace975ae0a14e6be27f4c0d0e77afd715a..f8635a3beb5433269e3e7b7dc6c7f456783fd939 100644 --- a/src/main/java/net/minecraft/server/commands/RecipeCommand.java +++ b/src/main/java/net/minecraft/server/commands/RecipeCommand.java -@@ -36,7 +36,12 @@ public class RecipeCommand { +@@ -83,7 +83,12 @@ public class RecipeCommand { int i = 0; - for(ServerPlayer serverPlayer : targets) { + for (ServerPlayer serverPlayer : targets) { - i += serverPlayer.awardRecipes(recipes); + // Folia start - region threading + ++i; + serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { -+ serverPlayer.awardRecipes(recipes); ++ player.awardRecipes(recipes); + }, null, 1L); + // Folia end - region threading } if (i == 0) { -@@ -60,7 +65,12 @@ public class RecipeCommand { +@@ -105,7 +110,12 @@ public class RecipeCommand { int i = 0; - for(ServerPlayer serverPlayer : targets) { + for (ServerPlayer serverPlayer : targets) { - i += serverPlayer.resetRecipes(recipes); + // Folia start - region threading + ++i; + serverPlayer.getBukkitEntity().taskScheduler.schedule((ServerPlayer player) -> { -+ serverPlayer.resetRecipes(recipes); ++ player.resetRecipes(recipes); + }, null, 1L); + // Folia end - region threading } if (i == 0) { diff --git a/src/main/java/net/minecraft/server/commands/SetBlockCommand.java b/src/main/java/net/minecraft/server/commands/SetBlockCommand.java -index 342d7c12a26c6a211aae3db03ec3029c68ef650c..eda5bd9e1e1f1e1d41295874b239f503e4474cb0 100644 +index 977f3b1f0b6822d37254452c681717d31d3e1011..ea13a3b409b8a4a6a77071c700b4dd0a33b02716 100644 --- a/src/main/java/net/minecraft/server/commands/SetBlockCommand.java +++ b/src/main/java/net/minecraft/server/commands/SetBlockCommand.java -@@ -38,31 +38,47 @@ public class SetBlockCommand { - }))))); +@@ -80,10 +80,21 @@ public class SetBlockCommand { + ); } + // Folia start - region threading @@ -11752,60 +11789,31 @@ index 342d7c12a26c6a211aae3db03ec3029c68ef650c..eda5bd9e1e1f1e1d41295874b239f503 + } + // Folia end - region threading + - private static int setBlock(CommandSourceStack source, BlockPos pos, BlockInput block, SetBlockCommand.Mode mode, @Nullable Predicate condition) throws CommandSyntaxException { + private static int setBlock( + CommandSourceStack source, BlockPos pos, BlockInput block, SetBlockCommand.Mode mode, @Nullable Predicate condition + ) throws CommandSyntaxException { ServerLevel serverLevel = source.getLevel(); -- if (condition != null && !condition.test(new BlockInWorld(serverLevel, pos, true))) { -- throw ERROR_FAILED.create(); -- } else { -- boolean bl; -- if (mode == SetBlockCommand.Mode.DESTROY) { -- serverLevel.destroyBlock(pos, true); -- bl = !block.getState().isAir() || !serverLevel.getBlockState(pos).isAir(); -- } else { -- BlockEntity blockEntity = serverLevel.getBlockEntity(pos); -- Clearable.tryClear(blockEntity); -- bl = true; -- } + // Folia start - region threading + io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueTickTaskQueue( + serverLevel, pos.getX() >> 4, pos.getZ() >> 4, () -> { + try { -+ if (condition != null && !condition.test(new BlockInWorld(serverLevel, pos, true))) { -+ throw ERROR_FAILED.create(); -+ } else { -+ boolean bl; -+ if (mode == SetBlockCommand.Mode.DESTROY) { -+ serverLevel.destroyBlock(pos, true); -+ bl = !block.getState().isAir() || !serverLevel.getBlockState(pos).isAir(); -+ } else { -+ BlockEntity blockEntity = serverLevel.getBlockEntity(pos); -+ Clearable.tryClear(blockEntity); -+ bl = true; -+ } - -- if (bl && !block.place(serverLevel, pos, 2)) { -- throw ERROR_FAILED.create(); -- } else { -- serverLevel.blockUpdated(pos, block.getState().getBlock()); -- source.sendSuccess(() -> { -- return Component.translatable("commands.setblock.success", pos.getX(), pos.getY(), pos.getZ()); -- }, true); ++ // Folia end - region threading + if (condition != null && !condition.test(new BlockInWorld(serverLevel, pos, true))) { + throw ERROR_FAILED.create(); + } else { +@@ -102,9 +113,16 @@ public class SetBlockCommand { + } else { + serverLevel.blockUpdated(pos, block.getState().getBlock()); + source.sendSuccess(() -> Component.translatable("commands.setblock.success", pos.getX(), pos.getY(), pos.getZ()), true); - return 1; -+ if (bl && !block.place(serverLevel, pos, 2)) { -+ throw ERROR_FAILED.create(); -+ } else { -+ serverLevel.blockUpdated(pos, block.getState().getBlock()); -+ source.sendSuccess(() -> { -+ return Component.translatable("commands.setblock.success", pos.getX(), pos.getY(), pos.getZ()); -+ }, true); -+ } -+ } ++ return; // Folia - region threading + } + } ++ // Folia start - region threading + } catch (CommandSyntaxException ex) { + sendMessage(source, ex); + } - } -- } -+ ); ++ }); + return 1; + // Folia end - region threading } @@ -11940,18 +11948,16 @@ index 44fcd43a466fb47d31ab05e44bafbef3c4cae63f..2989750a75b3dd244cf8f9ca78769308 } } diff --git a/src/main/java/net/minecraft/server/commands/WeatherCommand.java b/src/main/java/net/minecraft/server/commands/WeatherCommand.java -index 8f5714221bc32fb2c9201cbc8a0a35610977f574..c78a7e5e5c6b012756e6a1e50159dd970243cd5e 100644 +index 3100dcd0bbba9e109c26f5932c648cd2bab212d7..e17fcbe35cb7293ac72d49c1fa659e70dc0b38ff 100644 --- a/src/main/java/net/minecraft/server/commands/WeatherCommand.java +++ b/src/main/java/net/minecraft/server/commands/WeatherCommand.java -@@ -35,26 +35,32 @@ public class WeatherCommand { +@@ -48,20 +48,26 @@ public class WeatherCommand { } private static int setClear(CommandSourceStack source, int duration) { + io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> { // Folia - region threading source.getLevel().setWeatherParameters(getDuration(source, duration, ServerLevel.RAIN_DELAY), 0, false, false); - source.sendSuccess(() -> { - return Component.translatable("commands.weather.set.clear"); - }, true); + source.sendSuccess(() -> Component.translatable("commands.weather.set.clear"), true); + }); // Folia - region threading return duration; } @@ -11959,9 +11965,7 @@ index 8f5714221bc32fb2c9201cbc8a0a35610977f574..c78a7e5e5c6b012756e6a1e50159dd97 private static int setRain(CommandSourceStack source, int duration) { + io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> { // Folia - region threading source.getLevel().setWeatherParameters(0, getDuration(source, duration, ServerLevel.RAIN_DURATION), true, false); - source.sendSuccess(() -> { - return Component.translatable("commands.weather.set.rain"); - }, true); + source.sendSuccess(() -> Component.translatable("commands.weather.set.rain"), true); + }); // Folia - region threading return duration; } @@ -11969,9 +11973,7 @@ index 8f5714221bc32fb2c9201cbc8a0a35610977f574..c78a7e5e5c6b012756e6a1e50159dd97 private static int setThunder(CommandSourceStack source, int duration) { + io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> { // Folia - region threading source.getLevel().setWeatherParameters(0, getDuration(source, duration, ServerLevel.THUNDER_DURATION), true, true); - source.sendSuccess(() -> { - return Component.translatable("commands.weather.set.thunder"); - }, true); + source.sendSuccess(() -> Component.translatable("commands.weather.set.thunder"), true); + }); // Folia - region threading return duration; } @@ -14873,10 +14875,10 @@ index a7b217ddbcbf92513bd38101fdfca2075505e267..8d2d0852ca5d137a74ba7be9a58e45c6 org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, itemsToDrop); // Paper - capture all item additions to the world } diff --git a/src/main/java/net/minecraft/server/level/ThreadedLevelLightEngine.java b/src/main/java/net/minecraft/server/level/ThreadedLevelLightEngine.java -index f382d138959b34bfc3a114bc9d96e056cccbfc89..100293099156978ff701bc6c9d8df94ba8282021 100644 +index 17b624294fc0cab2976e3804e6c9a24b91a0e3aa..7c10a1f9f7bcb1711a05cddabe0cc86258d49a57 100644 --- a/src/main/java/net/minecraft/server/level/ThreadedLevelLightEngine.java +++ b/src/main/java/net/minecraft/server/level/ThreadedLevelLightEngine.java -@@ -97,10 +97,15 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl +@@ -103,10 +103,15 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl this.chunkMap.level.chunkTaskScheduler.radiusAwareScheduler.queueInfiniteRadiusTask(() -> { // Paper - rewrite chunk system this.theLightEngine.relightChunks(chunks, (ChunkPos chunkPos) -> { chunkLightCallback.accept(chunkPos); @@ -14894,7 +14896,7 @@ index f382d138959b34bfc3a114bc9d96e056cccbfc89..100293099156978ff701bc6c9d8df94b }, onComplete); }); this.tryScheduleUpdate(); -@@ -108,7 +113,7 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl +@@ -114,7 +119,7 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl return totalChunks; } @@ -14903,7 +14905,7 @@ index f382d138959b34bfc3a114bc9d96e056cccbfc89..100293099156978ff701bc6c9d8df94b private void queueTaskForSection(final int chunkX, final int chunkY, final int chunkZ, final Supplier runnable) { // Paper - rewrite chunk system -@@ -128,11 +133,16 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl +@@ -134,11 +139,16 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl return; } @@ -14923,7 +14925,7 @@ index f382d138959b34bfc3a114bc9d96e056cccbfc89..100293099156978ff701bc6c9d8df94b return; } -@@ -151,22 +161,28 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl +@@ -157,22 +167,28 @@ public class ThreadedLevelLightEngine extends LevelLightEngine implements AutoCl } updateFuture.isTicketAdded = true; @@ -15182,7 +15184,7 @@ index 586521a2cbb1d4dcfb912029f65e4363ec7674a7..6e95017f4c36208abdf344e3b7d55efe Collections.shuffle( this.connections ); } diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 860d33ac56680babd87358b1d7d2216dac3f7865..954809d8997750959541e6462668f17efd0b0f70 100644 +index fe2ef36ab5dc4b933abf24dbfd0e811c53239cf0..e7b510dee355a9865bd67f5aea52c62957226eb3 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -291,7 +291,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl @@ -15617,7 +15619,7 @@ index 860d33ac56680babd87358b1d7d2216dac3f7865..954809d8997750959541e6462668f17e this.player = this.server.getPlayerList().respawn(this.player, false, RespawnReason.DEATH); if (this.server.isHardcore()) { this.player.setGameMode(GameType.SPECTATOR, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.HARDCORE_DEATH, null); // Paper - Expand PlayerGameModeChangeEvent -@@ -3196,7 +3287,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -3209,7 +3300,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl // Paper start - auto recipe limit if (!org.bukkit.Bukkit.isPrimaryThread()) { if (this.recipeSpamPackets.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamLimit) { @@ -15626,7 +15628,7 @@ index 860d33ac56680babd87358b1d7d2216dac3f7865..954809d8997750959541e6462668f17e return; } } -@@ -3365,7 +3456,18 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -3378,7 +3469,18 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl this.filterTextPacket(list).thenAcceptAsync((list1) -> { this.updateSignText(packet, list1); @@ -16211,7 +16213,7 @@ index 7e133752ccb1ea7c0b4fa781feb1a88e2cfdcf6d..9756d1750f40bda0578f4c965953a27c } } diff --git a/src/main/java/net/minecraft/util/SortedArraySet.java b/src/main/java/net/minecraft/util/SortedArraySet.java -index a6ac76707da39cf86113003b1f326433fdc86c86..531ccc48154b25378e9039478ce7f89be4740bce 100644 +index 0793dfe47e68a2b48b010aad5b12dcfa1701293a..50e3ad4ce20915943fbd9115cec221a374e778fb 100644 --- a/src/main/java/net/minecraft/util/SortedArraySet.java +++ b/src/main/java/net/minecraft/util/SortedArraySet.java @@ -90,7 +90,7 @@ public class SortedArraySet extends AbstractSet { @@ -16278,7 +16280,7 @@ index c5d54abfcbd74c3041d9a46f77705460fa65ce30..025bf2306851347a12035d81e4dd92a4 } } diff --git a/src/main/java/net/minecraft/world/RandomSequences.java b/src/main/java/net/minecraft/world/RandomSequences.java -index b8adc775270a4cc179ce009d41f48c8c898a5b68..281f41edbb08ec2872e42f4fca0082a48e26d8a5 100644 +index a9bbe79831183e119562e27038e4a9c651529bf4..645c0823718a4013aba149c693b267ea59691d2d 100644 --- a/src/main/java/net/minecraft/world/RandomSequences.java +++ b/src/main/java/net/minecraft/world/RandomSequences.java @@ -20,7 +20,7 @@ public class RandomSequences extends SavedData { @@ -16289,8 +16291,8 @@ index b8adc775270a4cc179ce009d41f48c8c898a5b68..281f41edbb08ec2872e42f4fca0082a4 + private final Map sequences = new java.util.concurrent.ConcurrentHashMap<>(); // Folia - region threading public static SavedData.Factory factory(long seed) { - return new SavedData.Factory<>(() -> { -@@ -116,61 +116,61 @@ public class RandomSequences extends SavedData { + return new SavedData.Factory<>(() -> new RandomSequences(seed), nbt -> load(seed, nbt), DataFixTypes.SAVED_DATA_RANDOM_SEQUENCES); +@@ -113,61 +113,61 @@ public class RandomSequences extends SavedData { @Override public RandomSource fork() { RandomSequences.this.setDirty(); @@ -16363,19 +16365,19 @@ index b8adc775270a4cc179ce009d41f48c8c898a5b68..281f41edbb08ec2872e42f4fca0082a4 @Override diff --git a/src/main/java/net/minecraft/world/damagesource/CombatTracker.java b/src/main/java/net/minecraft/world/damagesource/CombatTracker.java -index 9c99b2e365aacb8309f29acb9025faccd2c676b3..d02bc26812321745795d2f0bc3705addd0be912d 100644 +index 7056c8ca7a87748f14142c6af274aae492f29f1c..c92063c527aef85c932453d4761fd1955542dd98 100644 --- a/src/main/java/net/minecraft/world/damagesource/CombatTracker.java +++ b/src/main/java/net/minecraft/world/damagesource/CombatTracker.java @@ -52,7 +52,7 @@ public class CombatTracker { + } private Component getMessageForAssistedFall(Entity attacker, Component attackerDisplayName, String itemDeathTranslationKey, String deathTranslationKey) { - ItemStack var10000; -- if (attacker instanceof LivingEntity livingEntity) { -+ if (attacker instanceof LivingEntity livingEntity && io.papermc.paper.util.TickThread.isTickThreadFor(livingEntity)) { // Folia - region threading - var10000 = livingEntity.getMainHandItem(); - } else { - var10000 = ItemStack.EMPTY; -@@ -81,7 +81,7 @@ public class CombatTracker { +- ItemStack itemStack = attacker instanceof LivingEntity livingEntity ? livingEntity.getMainHandItem() : ItemStack.EMPTY; ++ ItemStack itemStack = attacker instanceof LivingEntity livingEntity && io.papermc.paper.util.TickThread.isTickThreadFor(livingEntity) ? livingEntity.getMainHandItem() : ItemStack.EMPTY; // Folia - region threading + return !itemStack.isEmpty() && itemStack.hasCustomHoverName() + ? Component.translatable(itemDeathTranslationKey, this.mob.getDisplayName(), attackerDisplayName, itemStack.getDisplayName()) + : Component.translatable(deathTranslationKey, this.mob.getDisplayName(), attackerDisplayName); +@@ -79,7 +79,7 @@ public class CombatTracker { @Nullable private static Component getDisplayName(@Nullable Entity entity) { @@ -16405,10 +16407,10 @@ index b26e4d58ea1898a5e4b31c3d6ab33f38835ab2c6..90781fffbb7e6293d3a30d6041dc3018 itemstack = entityliving2.getMainHandItem(); diff --git a/src/main/java/net/minecraft/world/damagesource/FallLocation.java b/src/main/java/net/minecraft/world/damagesource/FallLocation.java -index ea27b46eec01bda427653335f922ccd068cffcb5..e551d3b875eab6851b75041f418c9a085a8903b6 100644 +index e9df8f8541b8a1b85c7d2925ff3cba813007a1ef..35e3e67c0c74f95007c55ee8fb44822a712a25b1 100644 --- a/src/main/java/net/minecraft/world/damagesource/FallLocation.java +++ b/src/main/java/net/minecraft/world/damagesource/FallLocation.java -@@ -39,7 +39,7 @@ public record FallLocation(String id) { +@@ -35,7 +35,7 @@ public record FallLocation(String id) { @Nullable public static FallLocation getCurrentFallLocation(LivingEntity entity) { Optional optional = entity.getLastClimbablePos(); @@ -16418,7 +16420,7 @@ index ea27b46eec01bda427653335f922ccd068cffcb5..e551d3b875eab6851b75041f418c9a08 return blockToFallLocation(blockState); } else { diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 0b4ed99658b083a83a90db1b32edb358da9e9514..518487d4cd489110bebcf75078935a95b5d3e9cf 100644 +index 637478fd8a284e6833cf8f5fa17ccf9d73d1dd3f..fe07f0881f5835974f00c65498a31a19c8ead97c 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -170,7 +170,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @@ -17560,7 +17562,7 @@ index e9bb7feb591032904516d1b9374f486d8a7d066c..73e0c2ec5ab8cf54767755f31d1a8d0a while (!flag2 && blockposition.getY() > world.getMinBuildHeight()) { diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java -index 2439f8d48daca7329049436414f06a36b4b79029..54297b9dde40fe853d873d60373cd8c0a3c9466b 100644 +index d2c92df28475f0a32a0134324eb0a5609a9afb99..3228d15fc21fec08e8683f96c829935a1de6cf45 100644 --- a/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java @@ -138,6 +138,14 @@ public abstract class Mob extends LivingEntity implements Targeting { @@ -17618,7 +17620,7 @@ index 2439f8d48daca7329049436414f06a36b4b79029..54297b9dde40fe853d873d60373cd8c0 if (i % 2 != 0 && this.tickCount > 1) { this.level().getProfiler().push("targetSelector"); -@@ -1758,6 +1778,17 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -1759,6 +1779,17 @@ public abstract class Mob extends LivingEntity implements Targeting { this.goalSelector.removeAllGoals(predicate); } @@ -17636,7 +17638,7 @@ index 2439f8d48daca7329049436414f06a36b4b79029..54297b9dde40fe853d873d60373cd8c0 @Override protected void removeAfterChangingDimensions() { super.removeAfterChangingDimensions(); -@@ -1766,12 +1797,7 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -1767,12 +1798,7 @@ public abstract class Mob extends LivingEntity implements Targeting { this.level().getCraftServer().getPluginManager().callEvent(event); // CraftBukkit this.dropLeash(true, event.isDropLeash()); // Paper end - Expand EntityUnleashEvent @@ -17651,10 +17653,10 @@ index 2439f8d48daca7329049436414f06a36b4b79029..54297b9dde40fe853d873d60373cd8c0 @Nullable diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java -index 21e5d1451f90194aa415cf0a183d1a731854f605..c83e9f99f8f3e1b147b1a5122651540dc86abdff 100644 +index af6f91c66e9cc7e0d491e6efed992a140947155e..d4e6198fdfbefe54e374479a1f1d835ab98ce93a 100644 --- a/src/main/java/net/minecraft/world/entity/ai/Brain.java +++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java -@@ -412,9 +412,17 @@ public class Brain { +@@ -424,9 +424,17 @@ public class Brain { } public void stopAll(ServerLevel world, E entity) { @@ -17668,27 +17670,27 @@ index 21e5d1451f90194aa415cf0a183d1a731854f605..c83e9f99f8f3e1b147b1a5122651540d + // Folia end - region threading long l = entity.level().getGameTime(); -- for(BehaviorControl behaviorControl : this.getRunningBehaviors()) { -+ for(BehaviorControl behaviorControl : behaviors) { // Folia - region threading +- for (BehaviorControl behaviorControl : this.getRunningBehaviors()) { ++ for (BehaviorControl behaviorControl : behaviors) { // Folia - region threading behaviorControl.doStop(world, entity, l); } - + } diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/PoiCompetitorScan.java b/src/main/java/net/minecraft/world/entity/ai/behavior/PoiCompetitorScan.java -index 8ec07578c1e41997a2e5ef158885ad3f4c2a31b6..003d85261bc0df871a8247c193e2b45c822b66b3 100644 +index 7302d397d39d8400527ab2da4adaf8d792256749..cb92900d5528b953ec4c9f071a75a064987b9a9f 100644 --- a/src/main/java/net/minecraft/world/entity/ai/behavior/PoiCompetitorScan.java +++ b/src/main/java/net/minecraft/world/entity/ai/behavior/PoiCompetitorScan.java -@@ -17,6 +17,11 @@ public class PoiCompetitorScan { - return context.group(context.present(MemoryModuleType.JOB_SITE), context.present(MemoryModuleType.NEAREST_LIVING_ENTITIES)).apply(context, (jobSite, mobs) -> { - return (world, entity, time) -> { - GlobalPos globalPos = context.get(jobSite); -+ // Folia start - region threading -+ if (globalPos.dimension() != world.dimension() || !io.papermc.paper.util.TickThread.isTickThreadFor(world, globalPos.pos())) { -+ return true; -+ } -+ // Folia end - region threading - world.getPoiManager().getType(globalPos.pos()).ifPresent((poiType) -> { - context.>get(mobs).stream().filter((mob) -> { - return mob instanceof Villager && mob != entity; +@@ -19,6 +19,11 @@ public class PoiCompetitorScan { + context, + (jobSite, mobs) -> (world, entity, time) -> { + GlobalPos globalPos = context.get(jobSite); ++ // Folia start - region threading ++ if (globalPos.dimension() != world.dimension() || !io.papermc.paper.util.TickThread.isTickThreadFor(world, globalPos.pos())) { ++ return true; ++ } ++ // Folia end - region threading + world.getPoiManager() + .getType(globalPos.pos()) + .ifPresent( diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/FollowOwnerGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/FollowOwnerGoal.java index c0da573e3818a1dd2c1ef5a61c7cb34934b0a252..d34a3018264ec196ef57151af3c1d584b0576c68 100644 --- a/src/main/java/net/minecraft/world/entity/ai/goal/FollowOwnerGoal.java @@ -17747,7 +17749,7 @@ index c0da573e3818a1dd2c1ef5a61c7cb34934b0a252..d34a3018264ec196ef57151af3c1d584 this.navigation.stop(); return true; diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java -index 47de460ff5435ea6712c800c77093126908d0fce..b31ba4e2286eaee5028cb4dc236829d1a302a25a 100644 +index 74ae984ac41bcdd2cc45f1bec461cdc5f69977c6..a978b9c3edb64a5a0b91166b20fa28a3d9e8b2f8 100644 --- a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java +++ b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java @@ -42,6 +42,11 @@ public class GroundPathNavigation extends PathNavigation { @@ -17759,11 +17761,11 @@ index 47de460ff5435ea6712c800c77093126908d0fce..b31ba4e2286eaee5028cb4dc236829d1 + return null; + } + // Folia end - region threading - LevelChunk levelChunk = this.level.getChunkSource().getChunkNow(SectionPos.blockToSectionCoord(target.getX()), SectionPos.blockToSectionCoord(target.getZ())); - if (levelChunk == null) { - return null; + LevelChunk levelChunk = this.level + .getChunkSource() + .getChunkNow(SectionPos.blockToSectionCoord(target.getX()), SectionPos.blockToSectionCoord(target.getZ())); 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 a04fb58c29b462e20ed0b702cef478e3985b7cd2..089baec30e0c16149b147a501d68958663519b96 100644 +index e3a7eaf31ab19cc9f23a0c87649b74bb42976cb4..1a364f9857608413813c8c2ca5b71ec8c90fe8b6 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 @@ -80,11 +80,11 @@ public abstract class PathNavigation { @@ -17780,7 +17782,7 @@ index a04fb58c29b462e20ed0b702cef478e3985b7cd2..089baec30e0c16149b147a501d689586 this.hasDelayedRecomputation = false; } } else { -@@ -200,7 +200,7 @@ public abstract class PathNavigation { +@@ -199,7 +199,7 @@ public abstract class PathNavigation { public boolean moveTo(Entity entity, double speed) { // Paper start - Perf: Optimise pathfinding @@ -17789,7 +17791,7 @@ index a04fb58c29b462e20ed0b702cef478e3985b7cd2..089baec30e0c16149b147a501d689586 return false; } // Paper end - Perf: Optimise pathfinding -@@ -212,7 +212,7 @@ public abstract class PathNavigation { +@@ -211,7 +211,7 @@ public abstract class PathNavigation { return true; } else { this.pathfindFailures++; @@ -17958,7 +17960,7 @@ index 2b5b2869589991be37a4f128faabbff50e661470..c8d4878a0574a603bbb4bce45d1fb4d8 SIEGE_CAN_ACTIVATE, SIEGE_TONIGHT, SIEGE_DONE; diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java -index 12a7aaeaa8b4b788b620b1985591c3b93253ccd5..5150d447c9dc2f539446749c8bee102050bab4ed 100644 +index 61a06706f1468a8d4cceb9fb2aae61cf56bd991d..79e9e5ece5859938ca0c86ead4c25cf5bde9da27 100644 --- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java +++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java @@ -48,11 +48,13 @@ public class PoiManager extends SectionStorage { @@ -18281,10 +18283,10 @@ index 4e6c2f6b2e54a4c126e9a026b9cad05ce835ad66..d2fbeb0e4e3e681b22455b9cf2d125dc } diff --git a/src/main/java/net/minecraft/world/entity/npc/CatSpawner.java b/src/main/java/net/minecraft/world/entity/npc/CatSpawner.java -index 5f407535298a31a34cfe114dd863fd6a9b977707..cb0f75fb32836efa50f0a86dfae7907b0c88780f 100644 +index 5d1610eddcaf0cf65c726a5438b42e53bab85332..dd8e1bb65d7832d173e460eb4d8e97a8ba1ba26e 100644 --- a/src/main/java/net/minecraft/world/entity/npc/CatSpawner.java +++ b/src/main/java/net/minecraft/world/entity/npc/CatSpawner.java -@@ -21,17 +21,18 @@ import net.minecraft.world.phys.AABB; +@@ -19,17 +19,18 @@ import net.minecraft.world.phys.AABB; public class CatSpawner implements CustomSpawner { private static final int TICK_DELAY = 1200; @@ -18294,7 +18296,7 @@ index 5f407535298a31a34cfe114dd863fd6a9b977707..cb0f75fb32836efa50f0a86dfae7907b @Override public int tick(ServerLevel world, boolean spawnMonsters, boolean spawnAnimals) { if (spawnAnimals && world.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING)) { -- --this.nextTick; +- this.nextTick--; - if (this.nextTick > 0) { + io.papermc.paper.threadedregions.RegionizedWorldData worldData = world.getCurrentWorldData(); // Folia - region threading + --worldData.catSpawnerNextTick; // Folia - region threading @@ -18483,7 +18485,7 @@ index 20ce474b72894a8bb3fc21018b9d79bbdc8bb14b..cd150b14afe46dcc5d96eb11106bf2bb this.setSecondsOnFire(1); } diff --git a/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java b/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java -index 5b3b59057b962438c6f4fc8a1507342865b3bc11..01579e1f4d2c62b636e08cc06dc891728c352efe 100644 +index 813c4a52c8ddd70e252125ebfd3654346c71f13c..2deddd55d6571bbab50ff8cdc6b705df9199f287 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java +++ b/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java @@ -131,6 +131,11 @@ public class FireworkRocketEntity extends Projectile implements ItemSupplier { @@ -18750,12 +18752,12 @@ index 1fb1e729d6879568d8b4943071fa940325b2e5b0..0c4b158d574ad0e9e257532ac3b9a3a3 @Override public Entity changeDimension(ServerLevel destination) { diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java -index eaa2943b667967f93f28d9d794d702fdaeb670ec..8fc22de1aa17cd8cb52d3804533d56cbb0e6bfeb 100644 +index bf2c23fad919820512ce031cf28a000b249b2876..2905dab1f9b3dd846261c5b0777d073927882825 100644 --- a/src/main/java/net/minecraft/world/entity/raid/Raid.java +++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java -@@ -107,6 +107,13 @@ public class Raid { - private int celebrationTicks; - private Optional waveSpawnPos; +@@ -112,6 +112,13 @@ public class Raid { + public final org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer(PDC_TYPE_REGISTRY); + // Paper end + // Folia start - make raids thread-safe + public boolean ownsRaid() { @@ -18767,7 +18769,7 @@ index eaa2943b667967f93f28d9d794d702fdaeb670ec..8fc22de1aa17cd8cb52d3804533d56cb public Raid(int id, ServerLevel world, BlockPos pos) { this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10); this.random = RandomSource.create(); -@@ -215,7 +222,7 @@ public class Raid { +@@ -225,7 +232,7 @@ public class Raid { return (entityplayer) -> { BlockPos blockposition = entityplayer.blockPosition(); @@ -18776,7 +18778,7 @@ index eaa2943b667967f93f28d9d794d702fdaeb670ec..8fc22de1aa17cd8cb52d3804533d56cb }; } -@@ -531,7 +538,7 @@ public class Raid { +@@ -541,7 +548,7 @@ public class Raid { boolean flag = true; Collection collection = this.raidEvent.getPlayers(); long i = this.random.nextLong(); @@ -18937,10 +18939,10 @@ index 88b00556322f078b8a9d28fb7c759bb8c84bfcf0..9badca2723f43e4caddb741252caeaf5 } } diff --git a/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java b/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java -index fc35cfc9d045f3e5b6a50af1d0ba83b6e322091f..c87765a28f31673d547653b293c48856511bc693 100644 +index 761142374f793a1cd4228936b21a68d7a0458894..b04f06aeb62cdc0f498dc97049bf27862da51b1d 100644 --- a/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java +++ b/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java -@@ -128,7 +128,7 @@ public class MinecartHopper extends AbstractMinecartContainer implements Hopper +@@ -127,7 +127,7 @@ public class MinecartHopper extends AbstractMinecartContainer implements Hopper // Paper start public void immunize() { @@ -19232,10 +19234,10 @@ index 524b0f1086c01888fe0b76e180c40915d16a1eb9..50b3025189938374886c7e2725dd3e4d this.lastOutput = Component.literal("[" + simpledateformat.format(date) + "] ").append(message); diff --git a/src/main/java/net/minecraft/world/level/EntityGetter.java b/src/main/java/net/minecraft/world/level/EntityGetter.java -index ed84c87a3f76bc0254c1abb189e6b8b808823465..894a25e9dfd61b8409f2883fc0af7c799cf5aabe 100644 +index ea0aee88c7d901034427db201c1b2430f8a1d522..2a147a839e78b1d7bfb5eea86975402598aacf6c 100644 --- a/src/main/java/net/minecraft/world/level/EntityGetter.java +++ b/src/main/java/net/minecraft/world/level/EntityGetter.java -@@ -38,6 +38,12 @@ public interface EntityGetter { +@@ -39,6 +39,12 @@ public interface EntityGetter { return this.getEntities(EntityTypeTest.forClass(entityClass), box, predicate); } @@ -19248,16 +19250,16 @@ index ed84c87a3f76bc0254c1abb189e6b8b808823465..894a25e9dfd61b8409f2883fc0af7c79 List players(); default List getEntities(@Nullable Entity except, AABB box) { -@@ -129,7 +135,7 @@ public interface EntityGetter { - double d = -1.0D; +@@ -130,7 +136,7 @@ public interface EntityGetter { + double d = -1.0; Player player = null; -- for(Player player2 : this.players()) { -+ for(Player player2 : this.getLocalPlayers()) { // Folia - region threading +- for (Player player2 : this.players()) { ++ for (Player player2 : this.getLocalPlayers()) { // Folia - region threading if (targetPredicate == null || targetPredicate.test(player2)) { double e = player2.distanceToSqr(x, y, z); - if ((maxDistance < 0.0D || e < maxDistance * maxDistance) && (d == -1.0D || e < d)) { -@@ -150,7 +156,7 @@ public interface EntityGetter { + if ((maxDistance < 0.0 || e < maxDistance * maxDistance) && (d == -1.0 || e < d)) { +@@ -151,7 +157,7 @@ public interface EntityGetter { default List findNearbyBukkitPlayers(double x, double y, double z, double radius, @Nullable Predicate predicate) { com.google.common.collect.ImmutableList.Builder builder = com.google.common.collect.ImmutableList.builder(); @@ -19266,7 +19268,7 @@ index ed84c87a3f76bc0254c1abb189e6b8b808823465..894a25e9dfd61b8409f2883fc0af7c79 if (predicate == null || predicate.test(human)) { double distanceSquared = human.distanceToSqr(x, y, z); -@@ -177,7 +183,7 @@ public interface EntityGetter { +@@ -178,7 +184,7 @@ public interface EntityGetter { // Paper start - Affects Spawning API default boolean hasNearbyAlivePlayerThatAffectsSpawning(double x, double y, double z, double range) { @@ -19275,16 +19277,16 @@ index ed84c87a3f76bc0254c1abb189e6b8b808823465..894a25e9dfd61b8409f2883fc0af7c79 if (EntitySelector.PLAYER_AFFECTS_SPAWNING.test(player)) { // combines NO_SPECTATORS and LIVING_ENTITY_STILL_ALIVE with an "affects spawning" check double distanceSqr = player.distanceToSqr(x, y, z); if (range < 0.0D || distanceSqr < range * range) { -@@ -190,7 +196,7 @@ public interface EntityGetter { +@@ -191,7 +197,7 @@ public interface EntityGetter { // Paper end - Affects Spawning API default boolean hasNearbyAlivePlayer(double x, double y, double z, double range) { -- for(Player player : this.players()) { -+ for(Player player : this.getLocalPlayers()) { // Folia - region threading +- for (Player player : this.players()) { ++ for (Player player : this.getLocalPlayers()) { // Folia - region threading if (EntitySelector.NO_SPECTATORS.test(player) && EntitySelector.LIVING_ENTITY_STILL_ALIVE.test(player)) { double d = player.distanceToSqr(x, y, z); - if (range < 0.0D || d < range * range) { -@@ -204,17 +210,17 @@ public interface EntityGetter { + if (range < 0.0 || d < range * range) { +@@ -205,17 +211,17 @@ public interface EntityGetter { @Nullable default Player getNearestPlayer(TargetingConditions targetPredicate, LivingEntity entity) { @@ -19300,27 +19302,27 @@ index ed84c87a3f76bc0254c1abb189e6b8b808823465..894a25e9dfd61b8409f2883fc0af7c79 @Nullable default Player getNearestPlayer(TargetingConditions targetPredicate, double x, double y, double z) { -- return this.getNearestEntity(this.players(), targetPredicate, (LivingEntity)null, x, y, z); -+ return this.getNearestEntity(this.getLocalPlayers(), targetPredicate, (LivingEntity)null, x, y, z); // Folia - region threading +- return this.getNearestEntity(this.players(), targetPredicate, null, x, y, z); ++ return this.getNearestEntity(this.getLocalPlayers(), targetPredicate, null, x, y, z); // Folia - region threading } @Nullable -@@ -249,7 +255,7 @@ public interface EntityGetter { +@@ -252,7 +258,7 @@ public interface EntityGetter { default List getNearbyPlayers(TargetingConditions targetPredicate, LivingEntity entity, AABB box) { List list = Lists.newArrayList(); -- for(Player player : this.players()) { -+ for(Player player : this.getLocalPlayers()) { // Folia - region threading +- for (Player player : this.players()) { ++ for (Player player : this.getLocalPlayers()) { // Folia - region threading if (box.contains(player.getX(), player.getY(), player.getZ()) && targetPredicate.test(entity, player)) { list.add(player); } -@@ -275,8 +281,7 @@ public interface EntityGetter { +@@ -278,8 +284,7 @@ public interface EntityGetter { @Nullable default Player getPlayerByUUID(UUID uuid) { -- for(int i = 0; i < this.players().size(); ++i) { +- for (int i = 0; i < this.players().size(); i++) { - Player player = this.players().get(i); -+ for(Player player : this.getLocalPlayers()) { // Folia - region threading ++ for (Player player : this.getLocalPlayers()) { // Folia - region threading if (uuid.equals(player.getUUID())) { return player; } @@ -19794,11 +19796,11 @@ index bd9ac874b2d4333bc5c3a79657d63f1bd41fd8c8..f706159a85fe463806b44c768dc9d438 default void scheduleTick(BlockPos pos, Block block, int delay, TickPriority priority) { diff --git a/src/main/java/net/minecraft/world/level/LevelReader.java b/src/main/java/net/minecraft/world/level/LevelReader.java -index 12eaafdbd324fa36b3f46c3b644bc8117a4123ad..c8c358a2ce567567159039ed6a1ba804b5d3ee85 100644 +index dab86988686cf7c926b7432b8a4afffd7a23327a..a956c88b82ca39c18f933369c8db2df8722a2e2c 100644 --- a/src/main/java/net/minecraft/world/level/LevelReader.java +++ b/src/main/java/net/minecraft/world/level/LevelReader.java -@@ -210,6 +210,25 @@ public interface LevelReader extends BlockAndTintGetter, CollisionGetter, Signal - return maxY >= this.getMinBuildHeight() && minY < this.getMaxBuildHeight() ? this.hasChunksAt(minX, minZ, maxX, maxZ) : false; +@@ -205,6 +205,25 @@ public interface LevelReader extends BlockAndTintGetter, CollisionGetter, Signal + return maxY >= this.getMinBuildHeight() && minY < this.getMaxBuildHeight() && this.hasChunksAt(minX, minZ, maxX, maxZ); } + // Folia start - region threading @@ -19820,9 +19822,9 @@ index 12eaafdbd324fa36b3f46c3b644bc8117a4123ad..c8c358a2ce567567159039ed6a1ba804 + } + // Folia end - region threading + - /** @deprecated */ @Deprecated default boolean hasChunksAt(int minX, int minZ, int maxX, int maxZ) { + int i = SectionPos.blockToSectionCoord(minX); diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java index da7489986848316fed029b71d1bc4e1248c9c9a8..9c1263fdc3731e04ac28c6d0ed904ecdc3ea3038 100644 --- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java @@ -19854,10 +19856,10 @@ index 3d377b9e461040405e0a7dcbd72d1506b48eb44e..782890e227ff9dab44dd92327979c201 // CraftBukkit start this.addFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); diff --git a/src/main/java/net/minecraft/world/level/StructureManager.java b/src/main/java/net/minecraft/world/level/StructureManager.java -index b59581b92aed0bc1b09008c695b0b112c3e65743..e91f36528862c0ee4c5b5d765113fdaf1be487e8 100644 +index 07eb481380e8fd4e492f36342ba633579c1b624e..9f3a8f26f4ecd33ea0e4c82a40c9432c094ac899 100644 --- a/src/main/java/net/minecraft/world/level/StructureManager.java +++ b/src/main/java/net/minecraft/world/level/StructureManager.java -@@ -44,12 +44,9 @@ public class StructureManager { +@@ -46,11 +46,7 @@ public class StructureManager { } public List startsForStructure(ChunkPos pos, Predicate predicate) { @@ -19866,14 +19868,11 @@ index b59581b92aed0bc1b09008c695b0b112c3e65743..e91f36528862c0ee4c5b5d765113fdaf - } - public List startsForStructure(ChunkPos pos, Predicate predicate, @Nullable ServerLevelAccessor levelAccessor) { - Map map = (levelAccessor == null ? this.level : levelAccessor).getChunk(pos.x, pos.z, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences(); -- // Paper end - Fix swamp hut cat generation deadlock -+ // Folia - region threading + Map map = this.level.getChunk(pos.x, pos.z, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences(); // Folia - region threading -+ // Paper end - ImmutableList.Builder builder = ImmutableList.builder(); + // Paper end - Fix swamp hut cat generation deadlock + Builder builder = ImmutableList.builder(); - for(Map.Entry entry : map.entrySet()) { -@@ -113,18 +110,14 @@ public class StructureManager { +@@ -116,15 +112,11 @@ public class StructureManager { } public StructureStart getStructureWithPieceAt(BlockPos pos, TagKey structureTag) { @@ -19885,16 +19884,13 @@ index b59581b92aed0bc1b09008c695b0b112c3e65743..e91f36528862c0ee4c5b5d765113fdaf + // Folia - region threading Registry registry = this.registryAccess().registryOrThrow(Registries.STRUCTURE); - for(StructureStart structureStart : this.startsForStructure(new ChunkPos(pos), (structure) -> { - return registry.getHolder(registry.getId(structure)).map((reference) -> { - return reference.is(structureTag); - }).orElse(false); -- }, levelAccessor)) { // Paper - Fix swamp hut cat generation deadlock -+ })) { // Paper // Folia - region threading + for (StructureStart structureStart : this.startsForStructure( +- new ChunkPos(pos), structure -> registry.getHolder(registry.getId(structure)).map(reference -> reference.is(structureTag)).orElse(false), levelAccessor // Paper - Fix swamp hut cat generation deadlock ++ new ChunkPos(pos), structure -> registry.getHolder(registry.getId(structure)).map(reference -> reference.is(structureTag)).orElse(false) // Paper - Fix swamp hut cat generation deadlock // Folia - region threading + )) { if (this.structureHasPieceAt(pos, structureStart)) { return structureStart; - } -@@ -168,7 +161,7 @@ public class StructureManager { +@@ -169,7 +161,7 @@ public class StructureManager { } public void addReference(StructureStart structureStart) { @@ -20037,10 +20033,10 @@ index 50d7235cf2ef036451db708c45a063d037051ae9..c0433491be43bb8cc6d00e32edf7699a // CraftBukkit end ((ConfiguredFeature) holder.value()).place(world, world.getChunkSource().getGenerator(), random, pos); diff --git a/src/main/java/net/minecraft/world/level/block/HoneyBlock.java b/src/main/java/net/minecraft/world/level/block/HoneyBlock.java -index 39e2fe8c5f5a2a4d4f3a7be3645923b5a1dca875..21b5a5abad737243f3d44ae3aa40aed9f67ab26f 100644 +index 409b4818840916a8ddbfc1ee87c8c22902939f38..c1f6922168f5d996e80aeb4035822d5506712b6b 100644 --- a/src/main/java/net/minecraft/world/level/block/HoneyBlock.java +++ b/src/main/java/net/minecraft/world/level/block/HoneyBlock.java -@@ -87,7 +87,7 @@ public class HoneyBlock extends HalfTransparentBlock { +@@ -86,7 +86,7 @@ public class HoneyBlock extends HalfTransparentBlock { } private void maybeDoSlideAchievement(Entity entity, BlockPos pos) { @@ -20048,7 +20044,7 @@ index 39e2fe8c5f5a2a4d4f3a7be3645923b5a1dca875..21b5a5abad737243f3d44ae3aa40aed9 + if (entity instanceof ServerPlayer && entity.level().getRedstoneGameTime() % 20L == 0L) { // Folia - region threading CriteriaTriggers.HONEY_BLOCK_SLIDE.trigger((ServerPlayer)entity, entity.level().getBlockState(pos)); } - + } diff --git a/src/main/java/net/minecraft/world/level/block/LightningRodBlock.java b/src/main/java/net/minecraft/world/level/block/LightningRodBlock.java index ec4aaaca2160312452d724dc6639ac8c4fa42ae4..e1f67599724f67f4f1321f219af8099e8c54e9e7 100644 --- a/src/main/java/net/minecraft/world/level/block/LightningRodBlock.java @@ -20975,11 +20971,11 @@ index be74adc86f0ca467f3b59e7b57fd47a8f381d86e..363a712d6b9e717b075aa52643c6cf91 } } diff --git a/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java b/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java -index c71690dbc3dc52803945f1608f0ee3ba94146354..1955b660907c5d6b5ca4bf7741f8d568b9255347 100644 +index 9f45dda6ff45ac1ffb7ac99575b7d09bdc61c56a..9a0d66b48470a6bef70b6643ff05812da519adfa 100644 --- a/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java -@@ -41,9 +41,19 @@ public class PistonMovingBlockEntity extends BlockEntity { - }); +@@ -39,9 +39,19 @@ public class PistonMovingBlockEntity extends BlockEntity { + private static final ThreadLocal NOCLIP = ThreadLocal.withInitial(() -> null); private float progress; private float progressO; - private long lastTicked; @@ -20999,7 +20995,7 @@ index c71690dbc3dc52803945f1608f0ee3ba94146354..1955b660907c5d6b5ca4bf7741f8d568 public PistonMovingBlockEntity(BlockPos pos, BlockState state) { super(BlockEntityType.PISTON, pos, state); } -@@ -144,8 +154,8 @@ public class PistonMovingBlockEntity extends BlockEntity { +@@ -148,8 +158,8 @@ public class PistonMovingBlockEntity extends BlockEntity { entity.setDeltaMovement(e, g, h); // Paper - EAR items stuck in in slime pushed by a piston @@ -21010,7 +21006,7 @@ index c71690dbc3dc52803945f1608f0ee3ba94146354..1955b660907c5d6b5ca4bf7741f8d568 // Paper end break; } -@@ -277,7 +287,7 @@ public class PistonMovingBlockEntity extends BlockEntity { +@@ -289,7 +299,7 @@ public class PistonMovingBlockEntity extends BlockEntity { } public static void tick(Level world, BlockPos pos, BlockState state, PistonMovingBlockEntity blockEntity) { @@ -21049,7 +21045,7 @@ index 350aabd20329f429248c84d73ab8b5eb145943a7..bdb864f5e7a1bacde88be632442c9de0 // Paper end - Bound treasure maps to world border diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java -index b8b78494449c0cd638f9706a803dc54e184d981f..b31f1e0522ff18fa5853af6104d46f980b916285 100644 +index 4c03297fb523ef59cd9d11edbed437398e562a00..484cd058ca3cd317d2c82e502c064edca4293e74 100644 --- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java +++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java @@ -320,7 +320,7 @@ public abstract class ChunkGenerator { @@ -21159,10 +21155,10 @@ index 465458e8a7dbaf9afb32709a71c7b2620d1e1fd2..ff1a7b78fa010857daab7a306cb9483c public void tick() { if (!this.blockEntity.isRemoved() && this.blockEntity.hasLevel()) { diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java -index d53c4f3d47a8728d56fbd9b5e12be51885560d52..ecffd7fb1c7686479bd04ae9e391b69f3499a45d 100644 +index d312ce27364f84d32dec8d58a2b37a8a6ad756af..c1629db60017acccc0cf246941afa02c03048bbb 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java -@@ -644,7 +644,7 @@ public class ChunkSerializer { +@@ -645,7 +645,7 @@ public class ChunkSerializer { } private static void saveTicks(ServerLevel world, CompoundTag nbt, ChunkAccess.TicksToSave tickSchedulers) { @@ -21413,17 +21409,17 @@ index 5d4c18b068f41f349bdccec14e08ca6ca7cb0c6c..4945bf03176e1842ae3e1bdd4708e39b }); } diff --git a/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java b/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java -index 87db9febbbf53702be0e1e89a95db99e823713e5..de048d920452b04922871eaaafacd1abd0ee21b7 100644 +index 106af2b2c7ff72c7549975aef75cdcff8d9a7d97..67be58de9f684e440b62541365c079cfffe30e51 100644 --- a/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java +++ b/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java -@@ -46,6 +46,7 @@ public class CollectingNeighborUpdater implements NeighborUpdater { +@@ -48,6 +48,7 @@ public class CollectingNeighborUpdater implements NeighborUpdater { } private void addAndRun(BlockPos pos, CollectingNeighborUpdater.NeighborUpdates entry) { + io.papermc.paper.util.TickThread.ensureTickThread((net.minecraft.server.level.ServerLevel)this.level, pos, "Adding block without owning region"); // Folia - region threading boolean bl = this.count > 0; boolean bl2 = this.maxChainedNeighborUpdates >= 0 && this.count >= this.maxChainedNeighborUpdates; - ++this.count; + this.count++; diff --git a/src/main/java/net/minecraft/world/level/saveddata/SavedData.java b/src/main/java/net/minecraft/world/level/saveddata/SavedData.java index 0655a26a58b3df19d81b18abf6b8ab81fd000ef7..d222b102abdd71b9487e11b4b7637be0d129bb2b 100644 --- a/src/main/java/net/minecraft/world/level/saveddata/SavedData.java @@ -21455,15 +21451,15 @@ index 0655a26a58b3df19d81b18abf6b8ab81fd000ef7..d222b102abdd71b9487e11b4b7637be0 if (ioExecutor == null) { return java.util.concurrent.CompletableFuture.runAsync(writeRunnable); // No executor, just use common pool diff --git a/src/main/java/net/minecraft/world/level/saveddata/maps/MapIndex.java b/src/main/java/net/minecraft/world/level/saveddata/maps/MapIndex.java -index 3eca0b1d1407770d3986e0f09c49bc86804b604e..d76df0d600d7f17ac01ce131b85ce9289989995a 100644 +index 7640752188b9cb62f19e20b832f39d009cbcb62f..b158e9f2f3a97d2f88f1fb43825f1192650c0924 100644 --- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapIndex.java +++ b/src/main/java/net/minecraft/world/level/saveddata/maps/MapIndex.java -@@ -32,17 +32,21 @@ public class MapIndex extends SavedData { +@@ -33,17 +33,21 @@ public class MapIndex extends SavedData { @Override public CompoundTag save(CompoundTag nbt) { + synchronized (this.usedAuxIds) { // Folia - make map data thread-safe - for(Object2IntMap.Entry entry : this.usedAuxIds.object2IntEntrySet()) { + for (Entry entry : this.usedAuxIds.object2IntEntrySet()) { nbt.putInt(entry.getKey(), entry.getIntValue()); } + } // Folia - make map data thread-safe @@ -21646,7 +21642,7 @@ index 45269115e63cfc3bd7dc740a5694e2cc7c35bcb1..df799198d4d77a1827002d6d192ebaea } } diff --git a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java -index 1c16f43872d9cf9b087f247e9aaa04e7abe3d4ae..2e40f64ffe439f91de74bd7ece4d679021a9c049 100644 +index b89bd2d046e99d0c4848579a5ab4385453358b89..2c000f830ca3b99b13546ae2edd7e90059290543 100644 --- a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java +++ b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java @@ -39,6 +39,7 @@ public class DimensionDataStorage implements java.io.Closeable { // Paper - Writ @@ -21689,10 +21685,10 @@ index 1c16f43872d9cf9b087f247e9aaa04e7abe3d4ae..2e40f64ffe439f91de74bd7ece4d6790 public CompoundTag readTagFromDisk(String id, DataFixTypes dataFixTypes, int currentSaveVersion) throws IOException { diff --git a/src/main/java/net/minecraft/world/ticks/LevelChunkTicks.java b/src/main/java/net/minecraft/world/ticks/LevelChunkTicks.java -index ac807277a6b26d140ea9873d17c7aa4fb5fe37b2..e13d8700593f1f486cfc5c96ac25894202c07b71 100644 +index 2cdd18f724296f10cd4a522d1e8196723d39cf45..b329d8327d73fc90586945834305fc3a50610c6e 100644 --- a/src/main/java/net/minecraft/world/ticks/LevelChunkTicks.java +++ b/src/main/java/net/minecraft/world/ticks/LevelChunkTicks.java -@@ -37,6 +37,21 @@ public class LevelChunkTicks implements SerializableTickContainer, TickCon +@@ -38,6 +38,21 @@ public class LevelChunkTicks implements SerializableTickContainer, TickCon this.dirty = false; } // Paper end - add dirty flag @@ -21715,10 +21711,10 @@ index ac807277a6b26d140ea9873d17c7aa4fb5fe37b2..e13d8700593f1f486cfc5c96ac258942 public LevelChunkTicks() { } diff --git a/src/main/java/net/minecraft/world/ticks/LevelTicks.java b/src/main/java/net/minecraft/world/ticks/LevelTicks.java -index 1d7c663fa0e550bd0cfb9a4b83ccd7e2968666f0..f3df9c9b6cff85565514f990597f3fe53652812c 100644 +index 7a69564572357a7acc043e35b9c113beeb738951..f71661ef4250d3b668fffeea7cd74a28eec95acd 100644 --- a/src/main/java/net/minecraft/world/ticks/LevelTicks.java +++ b/src/main/java/net/minecraft/world/ticks/LevelTicks.java -@@ -42,13 +42,70 @@ public class LevelTicks implements LevelTickAccess { +@@ -39,12 +39,69 @@ public class LevelTicks implements LevelTickAccess { private final List> alreadyRunThisTick = new ArrayList<>(); private final Set> toRunThisTickSet = new ObjectOpenCustomHashSet<>(ScheduledTick.UNIQUE_TICK_HASH); private final BiConsumer, ScheduledTick> chunkScheduleUpdater = (chunkTickScheduler, tick) -> { @@ -21727,7 +21723,6 @@ index 1d7c663fa0e550bd0cfb9a4b83ccd7e2968666f0..f3df9c9b6cff85565514f990597f3fe5 + if (tick.equals(chunkTickScheduler.peek())) { // Folia - diff on change + this.updateContainerScheduling(tick); // Folia - diff on change } - }; - public LevelTicks(LongPredicate tickingFutureReadyPredicate, Supplier profilerGetter) { @@ -21792,7 +21787,7 @@ index 1d7c663fa0e550bd0cfb9a4b83ccd7e2968666f0..f3df9c9b6cff85565514f990597f3fe5 this.tickCheck = tickingFutureReadyPredicate; this.profiler = profilerGetter; } -@@ -61,7 +118,17 @@ public class LevelTicks implements LevelTickAccess { +@@ -57,7 +114,17 @@ public class LevelTicks implements LevelTickAccess { this.nextTickForContainer.put(l, scheduledTick.triggerTick()); } @@ -21811,7 +21806,7 @@ index 1d7c663fa0e550bd0cfb9a4b83ccd7e2968666f0..f3df9c9b6cff85565514f990597f3fe5 } public void removeContainer(ChunkPos pos) { -@@ -76,6 +143,7 @@ public class LevelTicks implements LevelTickAccess { +@@ -71,6 +138,7 @@ public class LevelTicks implements LevelTickAccess { @Override public void schedule(ScheduledTick orderedTick) { @@ -21912,7 +21907,7 @@ index b63effd92be5a8a75db6c37e5a1b91541020ec75..350fc61fd709453a86c9f7f6e4bccc43 @Override diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index 01797d9791f19dfda4b168218eadeaae97f11eab..becb3b07876715d7c39ba4e7289cc5ac85f84412 100644 +index 00357d78182b3ff87e3d9a45705b072af56739c8..f325532b326fd7fe8c36003833890db57371eacc 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -193,7 +193,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @@ -22335,7 +22330,7 @@ index 01797d9791f19dfda4b168218eadeaae97f11eab..becb3b07876715d7c39ba4e7289cc5ac getHandle().gameEvent(sourceEntity != null ? ((CraftEntity) sourceEntity).getHandle(): null, net.minecraft.core.registries.BuiltInRegistries.GAME_EVENT.get(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(gameEvent.getKey())), org.bukkit.craftbukkit.util.CraftVector.toBlockPos(position)); } // Paper end -@@ -2479,7 +2522,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -2487,7 +2530,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { // Paper start public java.util.concurrent.CompletableFuture getChunkAtAsync(int x, int z, boolean gen, boolean urgent) { warnUnsafeChunk("getting a faraway chunk async", x, z); // Paper @@ -22344,7 +22339,7 @@ index 01797d9791f19dfda4b168218eadeaae97f11eab..becb3b07876715d7c39ba4e7289cc5ac net.minecraft.world.level.chunk.LevelChunk immediate = this.world.getChunkSource().getChunkAtIfLoadedImmediately(x, z); if (immediate != null) { return java.util.concurrent.CompletableFuture.completedFuture(new CraftChunk(immediate)); -@@ -2496,7 +2539,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -2504,7 +2547,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { java.util.concurrent.CompletableFuture ret = new java.util.concurrent.CompletableFuture<>(); io.papermc.paper.chunk.system.ChunkSystem.scheduleChunkLoad(this.getHandle(), x, z, gen, ChunkStatus.FULL, true, priority, (c) -> { @@ -22366,7 +22361,7 @@ index dfe5fa29a29af06640382456ef59aed794f5362b..ba5e47037f4dc3eb3efe86cd31183b39 tileentitybeehive.addOccupantWithPresetTicks(entitybee, false, random.nextInt(599)); } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63d7d2ff14 100644 +index ac11f18690434922179b61ffcc3036dea025b0cb..9efe9fce59a0b4fe7315dc41d1e21615b97e5cf6 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -75,6 +75,11 @@ public class CraftBlock implements Block { @@ -22381,7 +22376,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 return this.world.getBlockState(this.position); } -@@ -151,6 +156,11 @@ public class CraftBlock implements Block { +@@ -157,6 +162,11 @@ public class CraftBlock implements Block { } private void setData(final byte data, int flag) { @@ -22393,7 +22388,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 this.world.setBlock(this.position, CraftMagicNumbers.getBlock(this.getType(), data), flag); } -@@ -192,6 +202,11 @@ public class CraftBlock implements Block { +@@ -198,6 +208,11 @@ public class CraftBlock implements Block { } public static boolean setTypeAndData(LevelAccessor world, BlockPos position, net.minecraft.world.level.block.state.BlockState old, net.minecraft.world.level.block.state.BlockState blockData, boolean applyPhysics) { @@ -22405,7 +22400,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 // SPIGOT-611: need to do this to prevent glitchiness. Easier to handle this here (like /setblock) than to fix weirdness in tile entity cleanup if (old.hasBlockEntity() && blockData.getBlock() != old.getBlock()) { // SPIGOT-3725 remove old tile entity if block changes // SPIGOT-4612: faster - just clear tile -@@ -337,18 +352,33 @@ public class CraftBlock implements Block { +@@ -343,18 +358,33 @@ public class CraftBlock implements Block { @Override public Biome getBiome() { @@ -22439,7 +22434,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 this.getWorld().setBiome(this.getX(), this.getY(), this.getZ(), bio); } -@@ -396,6 +426,11 @@ public class CraftBlock implements Block { +@@ -402,6 +432,11 @@ public class CraftBlock implements Block { @Override public boolean isBlockFaceIndirectlyPowered(BlockFace face) { @@ -22451,7 +22446,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 int power = this.world.getMinecraftWorld().getSignal(this.position, CraftBlock.blockFaceToNotch(face)); Block relative = this.getRelative(face); -@@ -408,6 +443,11 @@ public class CraftBlock implements Block { +@@ -414,6 +449,11 @@ public class CraftBlock implements Block { @Override public int getBlockPower(BlockFace face) { @@ -22463,7 +22458,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 int power = 0; net.minecraft.world.level.Level world = this.world.getMinecraftWorld(); int x = this.getX(); -@@ -494,6 +534,11 @@ public class CraftBlock implements Block { +@@ -500,6 +540,11 @@ public class CraftBlock implements Block { @Override public boolean breakNaturally(ItemStack item, boolean triggerEffect, boolean dropExperience) { @@ -22475,7 +22470,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 // Paper end // Order matters here, need to drop before setting to air so skulls can get their data net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS(); -@@ -537,21 +582,27 @@ public class CraftBlock implements Block { +@@ -543,21 +588,27 @@ public class CraftBlock implements Block { @Override public boolean applyBoneMeal(BlockFace face) { @@ -22510,7 +22505,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 StructureGrowEvent structureEvent = null; if (treeType != null) { -@@ -638,6 +689,11 @@ public class CraftBlock implements Block { +@@ -644,6 +695,11 @@ public class CraftBlock implements Block { @Override public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode) { @@ -22522,7 +22517,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 Preconditions.checkArgument(start != null, "Location start cannot be null"); Preconditions.checkArgument(this.getWorld().equals(start.getWorld()), "Location start cannot be a different world"); start.checkFinite(); -@@ -679,6 +735,11 @@ public class CraftBlock implements Block { +@@ -685,6 +741,11 @@ public class CraftBlock implements Block { @Override public boolean canPlace(BlockData data) { @@ -22534,7 +22529,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 Preconditions.checkArgument(data != null, "BlockData cannot be null"); net.minecraft.world.level.block.state.BlockState iblockdata = ((CraftBlockData) data).getState(); net.minecraft.world.level.Level world = this.world.getMinecraftWorld(); -@@ -713,6 +774,11 @@ public class CraftBlock implements Block { +@@ -719,18 +780,32 @@ public class CraftBlock implements Block { @Override public void tick() { @@ -22543,10 +22538,20 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 + io.papermc.paper.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously"); + } + // Folia end - region threading - net.minecraft.world.level.block.state.BlockState blockData = this.getNMS(); - net.minecraft.server.level.ServerLevel level = this.world.getMinecraftWorld(); + final ServerLevel level = this.world.getMinecraftWorld(); + this.getNMS().tick(level, this.position, level.random); + } -@@ -721,6 +787,11 @@ public class CraftBlock implements Block { +- + @Override + public void fluidTick() { ++ // Folia start - region threading ++ if (this.world instanceof ServerLevel serverWorld) { ++ io.papermc.paper.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously"); ++ } ++ // Folia end - region threading + this.getNMSFluid().tick(this.world.getMinecraftWorld(), this.position); + } @Override public void randomTick() { @@ -22555,9 +22560,9 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 + io.papermc.paper.util.TickThread.ensureTickThread(serverWorld, this.position, "Cannot read world asynchronously"); + } + // Folia end - region threading - net.minecraft.world.level.block.state.BlockState blockData = this.getNMS(); - net.minecraft.server.level.ServerLevel level = this.world.getMinecraftWorld(); - + final ServerLevel level = this.world.getMinecraftWorld(); + this.getNMS().randomTick(level, this.position, level.random); + } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java index 2cfaa59a0bb6b5253b5a8dcc38ae65e0f085fd3f..5cf33427847068fc589ada9f731b985f791ac013 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -22705,10 +22710,10 @@ index e8e4489bcd64fde1b3226bdc7a7cc612508bda3f..1cfe604573000fa9b32237313aa46787 // Paper end - more teleport API / async chunk API diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -index e77bf7f432387bdfa7f69d31b014e8cd254fd4ca..8db8ceb161557b9803c3bda80f3e57b8626191c3 100644 +index 44f4665db613c558078df5bb49106e4ca5679dfe..232490c970d67e6bc77a35d5ccfef8fa95646ffe 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -@@ -560,7 +560,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -562,7 +562,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public void kickPlayer(String message) { @@ -22717,7 +22722,7 @@ index e77bf7f432387bdfa7f69d31b014e8cd254fd4ca..8db8ceb161557b9803c3bda80f3e57b8 if (this.getHandle().connection == null) return; this.getHandle().connection.disconnect(message == null ? "" : message, org.bukkit.event.player.PlayerKickEvent.Cause.PLUGIN); // Paper - kick event cause -@@ -1307,6 +1307,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -1309,6 +1309,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public boolean teleport(Location location, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) { @@ -22729,7 +22734,7 @@ index e77bf7f432387bdfa7f69d31b014e8cd254fd4ca..8db8ceb161557b9803c3bda80f3e57b8 Set relativeArguments; Set allFlags; if (flags.length == 0) { -@@ -1953,7 +1958,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -1955,7 +1960,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { private void unregisterEntity(Entity other) { // Paper end ChunkMap tracker = ((ServerLevel) this.getHandle().level()).getChunkSource().chunkMap; @@ -22738,7 +22743,7 @@ index e77bf7f432387bdfa7f69d31b014e8cd254fd4ca..8db8ceb161557b9803c3bda80f3e57b8 if (entry != null) { entry.removePlayer(this.getHandle()); } -@@ -2050,7 +2055,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -2052,7 +2057,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { if (original != null) otherPlayer.setUUID(original); // Paper - uuid override } diff --git a/patches/server/0006-Make-CraftEntity-getHandle-and-overrides-perform-thr.patch b/patches/server/0006-Make-CraftEntity-getHandle-and-overrides-perform-thr.patch index 96453f2..ca2a490 100644 --- a/patches/server/0006-Make-CraftEntity-getHandle-and-overrides-perform-thr.patch +++ b/patches/server/0006-Make-CraftEntity-getHandle-and-overrides-perform-thr.patch @@ -29,7 +29,7 @@ index 41bf71d116ffc5431586ce54abba7f8def6c1dcf..519da6886613b8460e989767b1a21e31 } diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 518487d4cd489110bebcf75078935a95b5d3e9cf..1119b6a7f307763c13ef48bcd7643539082aebdc 100644 +index fe07f0881f5835974f00c65498a31a19c8ead97c..0e71fa29ebfa649bc23899046396a6b01c4bd131 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -2930,6 +2930,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @@ -2140,10 +2140,10 @@ index 2638c341bc02f201f7ab17fdebcdbdf3a7ec05bf..0f5c2d31a2dea13a46ba81e353393633 } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -index 8db8ceb161557b9803c3bda80f3e57b8626191c3..b0a70287ff1fc9b3d5eba322d949aaf510b165d2 100644 +index 232490c970d67e6bc77a35d5ccfef8fa95646ffe..0ece776a1e281a328e28dc07fb4dc882b19d029c 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -@@ -580,7 +580,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -582,7 +582,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public void kick(net.kyori.adventure.text.Component message, org.bukkit.event.player.PlayerKickEvent.Cause cause) { @@ -2152,7 +2152,7 @@ index 8db8ceb161557b9803c3bda80f3e57b8626191c3..b0a70287ff1fc9b3d5eba322d949aaf5 final ServerGamePacketListenerImpl connection = this.getHandle().connection; if (connection != null) { connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message, cause); -@@ -2207,9 +2207,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -2209,9 +2209,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return this; } @@ -2170,7 +2170,7 @@ index 8db8ceb161557b9803c3bda80f3e57b8626191c3..b0a70287ff1fc9b3d5eba322d949aaf5 } public void setHandle(final ServerPlayer entity) { -@@ -3264,7 +3271,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -3266,7 +3273,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { { if ( CraftPlayer.this.getHealth() <= 0 && CraftPlayer.this.isOnline() ) { diff --git a/patches/server/0007-Disable-mid-tick-task-execution.patch b/patches/server/0007-Disable-mid-tick-task-execution.patch index b1562a1..0cb632d 100644 --- a/patches/server/0007-Disable-mid-tick-task-execution.patch +++ b/patches/server/0007-Disable-mid-tick-task-execution.patch @@ -10,7 +10,7 @@ the impact from scaling the region threads, but is not a fix to the underlying issue. diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index cf06989ad1ab55bf6836abe4cdeed2fff31ac93f..82b18aebb7c1472efdadc4b2e959fbdb3116fbe3 100644 +index 4e94de4a3184fd36119bf39beccff62ac561c1e4..2bd923c61642edf67338471d0578609039a51822 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -1476,6 +1476,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { +@@ -281,10 +281,17 @@ public class BlockEntityType { } Type type = Util.fetchChoiceType(References.BLOCK_ENTITY, id); @@ -1908,7 +1908,7 @@ index 2e110da3502a7ac5ec4cc20510a3fac933569895..5aac65f37a0190c5d6a7175073fb0cc0 this.factory = factory; this.validBlocks = blocks; this.dataType = type; -@@ -128,7 +135,12 @@ public class BlockEntityType { +@@ -329,7 +336,12 @@ public class BlockEntityType { } public BlockEntityType build(Type type) { @@ -1950,10 +1950,10 @@ index ff1a7b78fa010857daab7a306cb9483c98560b79..8c6ade7cf14e367d6390849ef1b2a1bf gameprofilerfiller.pop(); } catch (Throwable throwable) { diff --git a/src/main/java/net/minecraft/world/ticks/LevelTicks.java b/src/main/java/net/minecraft/world/ticks/LevelTicks.java -index f3df9c9b6cff85565514f990597f3fe53652812c..860124fdafa8abc280039cbd7cf7968106920b24 100644 +index f71661ef4250d3b668fffeea7cd74a28eec95acd..71b13d6b4c1c3db272ccd7c021af00c34c5a0956 100644 --- a/src/main/java/net/minecraft/world/ticks/LevelTicks.java +++ b/src/main/java/net/minecraft/world/ticks/LevelTicks.java -@@ -255,6 +255,12 @@ public class LevelTicks implements LevelTickAccess { +@@ -250,6 +250,12 @@ public class LevelTicks implements LevelTickAccess { } private void runCollectedTicks(BiConsumer ticker) { @@ -1963,6 +1963,6 @@ index f3df9c9b6cff85565514f990597f3fe53652812c..860124fdafa8abc280039cbd7cf79681 + (long)this.toRunThisTick.size() + ); + // Folia end - profiler - while(!this.toRunThisTick.isEmpty()) { + while (!this.toRunThisTick.isEmpty()) { ScheduledTick scheduledTick = this.toRunThisTick.poll(); if (!this.toRunThisTickSet.isEmpty()) {