diff --git a/build.gradle.kts b/build.gradle.kts index f9badde4fd..a072754703 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { java `maven-publish` id("com.github.johnrengelman.shadow") version "8.1.1" apply false - id("io.papermc.paperweight.patcher") version "1.5.11" + id("io.papermc.paperweight.patcher") version "1.5.12" } val paperMavenPublicUrl = "https://repo.papermc.io/repository/maven-public/" @@ -17,7 +17,7 @@ repositories { } dependencies { - remapper("net.fabricmc:tiny-remapper:0.8.10:fat") + remapper("net.fabricmc:tiny-remapper:0.10.1:fat") decompiler("net.minecraftforge:forgeflower:2.0.627.2") paperclip("io.papermc:paperclip:3.0.3") } diff --git a/gradle.properties b/gradle.properties index f0edd3a266..7e1ef76b33 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=4939f8711884901ddf1c56337f606de71cdae78d +paperRef=5436d44bf2509ff89129f8790ee4643f09c72871 org.gradle.caching=true org.gradle.parallel=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd49177..e6441136f3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b..b82aa23a4f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew.bat b/gradlew.bat index 93e3f59f13..25da30dbde 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/patches/api/0005-Add-API-for-checking-ownership-of-region-by-position.patch b/patches/api/0005-Add-API-for-checking-ownership-of-region-by-position.patch index 1360595bc5..4977302821 100644 --- a/patches/api/0005-Add-API-for-checking-ownership-of-region-by-position.patch +++ b/patches/api/0005-Add-API-for-checking-ownership-of-region-by-position.patch @@ -11,10 +11,10 @@ the schedulers depending on the result of the ownership check. diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java -index ca27559cf4aa1c2e44fdca2022e213b1b1c80f4e..3fae7b21353d18ff1e8005fbbe83be783de8a953 100644 +index 9a428153f34291bdc026a71f7e60e285b7794b0c..c37904d1aae749030620e1bbdb955e25c91ab1f8 100644 --- a/src/main/java/org/bukkit/Bukkit.java +++ b/src/main/java/org/bukkit/Bukkit.java -@@ -2857,6 +2857,14 @@ public final class Bukkit { +@@ -2879,6 +2879,14 @@ public final class Bukkit { return server.isOwnedByCurrentRegion(entity); } // Paper end - Folia region threading API @@ -30,10 +30,10 @@ index ca27559cf4aa1c2e44fdca2022e213b1b1c80f4e..3fae7b21353d18ff1e8005fbbe83be78 @NotNull public static Server.Spigot spigot() { diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java -index b4f8281d3797ec825a7671f38077cd65d5a1d76e..fe3d89c2c319c4f4b2b3e4a121d6626a898f501b 100644 +index 4ff1b38eb65f97344257204cf018f176f247ed36..15395ef52505087e7eef3b1a5981e787dcc16508 100644 --- a/src/main/java/org/bukkit/Server.java +++ b/src/main/java/org/bukkit/Server.java -@@ -2497,4 +2497,10 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi +@@ -2518,4 +2518,10 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi */ boolean isOwnedByCurrentRegion(@NotNull Entity entity); // Paper end - Folia region threading API diff --git a/patches/server/0001-Build-changes.patch b/patches/server/0001-Build-changes.patch index 2c86290b69..c7a497f238 100644 --- a/patches/server/0001-Build-changes.patch +++ b/patches/server/0001-Build-changes.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Build changes diff --git a/build.gradle.kts b/build.gradle.kts -index ce3747d8d2a8f4327766cf23d5aaa72cfcb380bc..08d434023226af0d2c469055a3b2188fe8a4ed38 100644 +index bcfe59b6efb628ee1e7f9d60667360d4d885fb6a..12f9f9d46c098c5c88058cb1f73ae39a7d1debd5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,8 +13,12 @@ configurations.named(log4jPlugins.compileClasspathConfigurationName) { @@ -23,7 +23,7 @@ index ce3747d8d2a8f4327766cf23d5aaa72cfcb380bc..08d434023226af0d2c469055a3b2188f // Paper start implementation("org.jline:jline-terminal-jansi:3.21.0") implementation("net.minecrell:terminalconsoleappender:1.3.0") -@@ -70,7 +74,7 @@ tasks.jar { +@@ -71,7 +75,7 @@ tasks.jar { attributes( "Main-Class" to "org.bukkit.craftbukkit.Main", "Implementation-Title" to "CraftBukkit", @@ -32,7 +32,7 @@ index ce3747d8d2a8f4327766cf23d5aaa72cfcb380bc..08d434023226af0d2c469055a3b2188f "Implementation-Vendor" to date, // Paper "Specification-Title" to "Bukkit", "Specification-Version" to project.version, -@@ -154,7 +158,7 @@ fun TaskContainer.registerRunTask( +@@ -150,7 +154,7 @@ fun TaskContainer.registerRunTask( name: String, block: JavaExec.() -> Unit ): TaskProvider = register(name) { @@ -93,10 +93,10 @@ 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 d06185566b447c432d4dc2e3ba04d121bcdbc71b..680919045310be7e50e2d503a23d265f2e9b2bc6 100644 +index c8772c773f9933ed1d1debfe707af4373c458152..50055e362a0de853c169a38c6cbd8681b73fc96d 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1855,7 +1855,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { // Folia - region threading packetProcessing.push(listener); // Paper - detailed watchdog information try { // Paper - detailed watchdog information - if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerCommonPacketListenerImpl && ((ServerCommonPacketListenerImpl) listener).processedDisconnect)) return; // CraftBukkit, MC-142590 + if (listener instanceof ServerCommonPacketListenerImpl serverCommonPacketListener && serverCommonPacketListener.processedDisconnect) return; // CraftBukkit - Don't handle sync packets for kicked players @@ -91,7 +91,21 @@ public class PacketUtils { } // Paper end - detailed watchdog information @@ -10063,10 +10075,10 @@ index 3e2d5dcd62775b6ed7c0ce0ba51a71b635b1d644..98fb69a9adeb6eaab199aec127692acb + } + // Folia end - region threading throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD; - // CraftBukkit start - SPIGOT-5477, MC-142590 - } else if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerCommonPacketListenerImpl && ((ServerCommonPacketListenerImpl) listener).processedDisconnect)) { + } + } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 680919045310be7e50e2d503a23d265f2e9b2bc6..11eb550cba3a8eee1deb2f00e5514863e255ea07 100644 +index 50055e362a0de853c169a38c6cbd8681b73fc96d..cf06989ad1ab55bf6836abe4cdeed2fff31ac93f 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 { return worldserver + " " + worldserver.dimension().location(); -@@ -1711,7 +1790,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop list = new ObjectArrayList(); @@ -13822,7 +13837,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 while (iterator.hasNext()) { // CraftBukkit start - fix SPIGOT-6362 -@@ -1871,7 +2027,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -1882,7 +2038,7 @@ public class ServerLevel extends Level implements WorldGenLevel { } try { @@ -13831,7 +13846,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 iterator = list.iterator(); while (iterator.hasNext()) { -@@ -1880,7 +2036,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -1891,7 +2047,7 @@ public class ServerLevel extends Level implements WorldGenLevel { navigationabstract1.recomputePath(); } } finally { @@ -13840,7 +13855,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } } -@@ -1889,23 +2045,23 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -1900,23 +2056,23 @@ public class ServerLevel extends Level implements WorldGenLevel { @Override public void updateNeighborsAt(BlockPos pos, Block sourceBlock) { @@ -13869,7 +13884,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } @Override -@@ -1936,7 +2092,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -1947,7 +2103,7 @@ public class ServerLevel extends Level implements WorldGenLevel { explosion.clearToBlow(); } @@ -13878,7 +13893,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 while (iterator.hasNext()) { ServerPlayer entityplayer = (ServerPlayer) iterator.next(); -@@ -1951,25 +2107,28 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -1962,25 +2118,28 @@ public class ServerLevel extends Level implements WorldGenLevel { @Override public void blockEvent(BlockPos pos, Block block, int type, int data) { @@ -13913,7 +13928,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } private boolean doBlockEvent(BlockEventData event) { -@@ -1980,12 +2139,12 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -1991,12 +2150,12 @@ public class ServerLevel extends Level implements WorldGenLevel { @Override public LevelTicks getBlockTicks() { @@ -13928,7 +13943,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } @Nonnull -@@ -2009,7 +2168,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2020,7 +2179,7 @@ public class ServerLevel extends Level implements WorldGenLevel { public int sendParticles(ServerPlayer sender, T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, boolean force) { // Paper start - Particle API @@ -13937,7 +13952,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } public int sendParticles(List receivers, @Nullable ServerPlayer sender, T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, boolean force) { // Paper end - Particle API -@@ -2062,7 +2221,14 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2073,7 +2232,14 @@ public class ServerLevel extends Level implements WorldGenLevel { public Entity getEntityOrPart(int id) { Entity entity = (Entity) this.getEntities().get(id); @@ -13953,7 +13968,23 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } @Nullable -@@ -2240,6 +2406,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2128,6 +2294,7 @@ public class ServerLevel extends Level implements WorldGenLevel { + // Paper start - Call missing map initialize event and set id + final DimensionDataStorage storage = this.getServer().overworld().getDataStorage(); + ++ synchronized (storage.cache) { // Folia - region threading + final net.minecraft.world.level.saveddata.SavedData existing = storage.cache.get(id); + if (existing == null && !storage.cache.containsKey(id)) { + final net.minecraft.world.level.saveddata.SavedData.Factory factory = MapItemSavedData.factory(); +@@ -2143,6 +2310,7 @@ public class ServerLevel extends Level implements WorldGenLevel { + } + + return existing instanceof MapItemSavedData data ? data : null; ++ } // Folia - region threading + // Paper end - Call missing map initialize event and set id + } + +@@ -2251,6 +2419,7 @@ public class ServerLevel extends Level implements WorldGenLevel { } public boolean setChunkForced(int x, int z, boolean forced) { @@ -13961,7 +13992,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) this.getDataStorage().computeIfAbsent(ForcedChunksSavedData.factory(), "chunks"); ChunkPos chunkcoordintpair = new ChunkPos(x, z); long k = chunkcoordintpair.toLong(); -@@ -2248,7 +2415,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2259,7 +2428,7 @@ public class ServerLevel extends Level implements WorldGenLevel { if (forced) { flag1 = forcedchunk.getChunks().add(k); if (flag1) { @@ -13970,7 +14001,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } } else { flag1 = forcedchunk.getChunks().remove(k); -@@ -2276,13 +2443,18 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2287,13 +2456,18 @@ public class ServerLevel extends Level implements WorldGenLevel { BlockPos blockposition1 = pos.immutable(); optional.ifPresent((holder) -> { @@ -13992,7 +14023,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 // Paper start - Remove stale POIs if (optional.isEmpty() && this.getPoiManager().exists(blockposition1, poiType -> true)) { this.getPoiManager().remove(blockposition1); -@@ -2290,7 +2462,12 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2301,7 +2475,12 @@ public class ServerLevel extends Level implements WorldGenLevel { // Paper end - Remove stale POIs this.getPoiManager().add(blockposition1, holder); DebugPackets.sendPoiAddedPacket(this, blockposition1); @@ -14006,7 +14037,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 }); } } -@@ -2337,7 +2514,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2348,7 +2527,7 @@ public class ServerLevel extends Level implements WorldGenLevel { BufferedWriter bufferedwriter = Files.newBufferedWriter(path.resolve("stats.txt")); try { @@ -14015,7 +14046,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 NaturalSpawner.SpawnState spawnercreature_d = this.getChunkSource().getLastSpawnState(); if (spawnercreature_d != null) { -@@ -2351,7 +2528,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2362,7 +2541,7 @@ public class ServerLevel extends Level implements WorldGenLevel { } bufferedwriter.write(String.format(Locale.ROOT, "entities: %s\n", this.entityLookup.getDebugInfo())); // Paper - rewrite chunk system @@ -14024,7 +14055,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 bufferedwriter.write(String.format(Locale.ROOT, "block_ticks: %d\n", this.getBlockTicks().count())); bufferedwriter.write(String.format(Locale.ROOT, "fluid_ticks: %d\n", this.getFluidTicks().count())); bufferedwriter.write("distance_manager: " + playerchunkmap.getDistanceManager().getDebugStatus() + "\n"); -@@ -2497,7 +2674,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2508,7 +2687,7 @@ public class ServerLevel extends Level implements WorldGenLevel { private void dumpBlockEntityTickers(Writer writer) throws IOException { CsvOutput csvwriter = CsvOutput.builder().addColumn("x").addColumn("y").addColumn("z").addColumn("type").build(writer); @@ -14033,7 +14064,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 while (iterator.hasNext()) { TickingBlockEntity tickingblockentity = (TickingBlockEntity) iterator.next(); -@@ -2510,7 +2687,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2521,7 +2700,7 @@ public class ServerLevel extends Level implements WorldGenLevel { @VisibleForTesting public void clearBlockEvents(BoundingBox box) { @@ -14042,7 +14073,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 return box.isInside(blockactiondata.pos()); }); } -@@ -2519,7 +2696,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2530,7 +2709,7 @@ public class ServerLevel extends Level implements WorldGenLevel { public void blockUpdated(BlockPos pos, Block block) { if (!this.isDebug()) { // CraftBukkit start @@ -14051,7 +14082,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 return; } // CraftBukkit end -@@ -2562,9 +2739,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2573,9 +2752,7 @@ public class ServerLevel extends Level implements WorldGenLevel { @VisibleForTesting public String getWatchdogStats() { @@ -14062,7 +14093,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } private static String getTypeCount(Iterable items, Function classifier) { -@@ -2597,6 +2772,12 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2608,6 +2785,12 @@ public class ServerLevel extends Level implements WorldGenLevel { public static void makeObsidianPlatform(ServerLevel worldserver, Entity entity) { // CraftBukkit end BlockPos blockposition = ServerLevel.END_SPAWN_POINT; @@ -14075,7 +14106,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 int i = blockposition.getX(); int j = blockposition.getY() - 2; int k = blockposition.getZ(); -@@ -2609,11 +2790,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2620,11 +2803,7 @@ public class ServerLevel extends Level implements WorldGenLevel { BlockPos.betweenClosed(i - 2, j, k - 2, i + 2, j, k + 2).forEach((blockposition1) -> { blockList.setBlock(blockposition1, Blocks.OBSIDIAN.defaultBlockState(), 3); }); @@ -14088,7 +14119,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 blockList.updateList(); } // CraftBukkit end -@@ -2634,13 +2811,14 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2645,13 +2824,14 @@ public class ServerLevel extends Level implements WorldGenLevel { } public void startTickingChunk(LevelChunk chunk) { @@ -14107,7 +14138,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } @Override -@@ -2662,7 +2840,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2673,7 +2853,7 @@ public class ServerLevel extends Level implements WorldGenLevel { // Paper end - rewrite chunk system } @@ -14116,7 +14147,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 // Paper start - optimize is ticking ready type functions io.papermc.paper.chunk.system.scheduling.NewChunkHolder chunkHolder = this.chunkTaskScheduler.chunkHolderManager.getChunkHolder(chunkPos); // isTicking implies the chunk is loaded, and the chunk is loaded now implies the entities are loaded -@@ -2717,7 +2895,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2728,7 +2908,7 @@ public class ServerLevel extends Level implements WorldGenLevel { // Paper start - optimize redstone (Alternate Current) @Override public alternate.current.wire.WireHandler getWireHandler() { @@ -14125,7 +14156,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } // Paper end - optimize redstone (Alternate Current) -@@ -2728,16 +2906,16 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2739,16 +2919,16 @@ public class ServerLevel extends Level implements WorldGenLevel { public void onCreated(Entity entity) {} public void onDestroyed(Entity entity) { @@ -14145,7 +14176,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 // Paper start - Reset pearls when they stop being ticked if (paperConfig().fixes.disableUnloadedChunkEnderpearlExploit && entity instanceof net.minecraft.world.entity.projectile.ThrownEnderpearl pearl) { pearl.cachedOwner = null; -@@ -2748,6 +2926,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2759,6 +2939,7 @@ public class ServerLevel extends Level implements WorldGenLevel { public void onTrackingStart(Entity entity) { org.spigotmc.AsyncCatcher.catchOp("entity register"); // Spigot @@ -14153,7 +14184,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 // ServerLevel.this.getChunkSource().addEntity(entity); // Paper - ignore and warn about illegal addEntity calls instead of crashing server; moved down below valid=true if (entity instanceof ServerPlayer) { ServerPlayer entityplayer = (ServerPlayer) entity; -@@ -2765,7 +2944,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2776,7 +2957,7 @@ public class ServerLevel extends Level implements WorldGenLevel { Util.logAndPauseIfInIde("onTrackingStart called during navigation iteration", new IllegalStateException("onTrackingStart called during navigation iteration")); } @@ -14162,7 +14193,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } if (entity instanceof EnderDragon) { -@@ -2776,7 +2955,9 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2787,7 +2968,9 @@ public class ServerLevel extends Level implements WorldGenLevel { for (int j = 0; j < i; ++j) { EnderDragonPart entitycomplexpart = aentitycomplexpart[j]; @@ -14172,7 +14203,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } } -@@ -2798,16 +2979,24 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2809,16 +2992,24 @@ public class ServerLevel extends Level implements WorldGenLevel { public void onTrackingEnd(Entity entity) { org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot @@ -14198,7 +14229,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 map.carriedByPlayers.remove( (Player) entity ); for ( Iterator iter = (Iterator) map.carriedBy.iterator(); iter.hasNext(); ) { -@@ -2817,6 +3006,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2828,6 +3019,7 @@ public class ServerLevel extends Level implements WorldGenLevel { iter.remove(); } } @@ -14206,7 +14237,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } } } ); -@@ -2851,7 +3041,7 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2862,7 +3054,7 @@ public class ServerLevel extends Level implements WorldGenLevel { Util.logAndPauseIfInIde("onTrackingStart called during navigation iteration", new IllegalStateException("onTrackingStart called during navigation iteration")); } @@ -14215,7 +14246,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 } if (entity instanceof EnderDragon) { -@@ -2862,13 +3052,16 @@ public class ServerLevel extends Level implements WorldGenLevel { +@@ -2873,13 +3065,16 @@ public class ServerLevel extends Level implements WorldGenLevel { for (int j = 0; j < i; ++j) { EnderDragonPart entitycomplexpart = aentitycomplexpart[j]; @@ -14233,7 +14264,7 @@ index 6934e9dac0d69c043b73b7c46d59f2d39b37c67f..a74538bdc720efc435e7890aa835c9f2 for (ServerPlayer player : ServerLevel.this.players) { player.getBukkitEntity().onEntityRemove(entity); diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java -index 58591bf2f63b9c5e97d9ce4188dff3366968a178..add6fc106d3c38d97b48ec0df3ac2515c8c0486e 100644 +index b3781efbd3edcf102fe1bda5d6149915dc1127c6..36d074d1abed62b09ca808dc2774bc83a6fd5df7 100644 --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java @@ -191,7 +191,7 @@ import org.bukkit.inventory.MainHand; @@ -14952,7 +14983,7 @@ index 658e63ebde81dc14c8ab5850fb246dc0aab25dea..7e1f15ac8d2f7c86d4aba1be5df71705 public static TicketType create(String name, Comparator argumentComparator) { return new TicketType<>(name, argumentComparator, 0L); diff --git a/src/main/java/net/minecraft/server/level/WorldGenRegion.java b/src/main/java/net/minecraft/server/level/WorldGenRegion.java -index 5ece375eaf6bcc61864997a389bb5e24625e4505..33c1ef45ed620f8424c2c83dd30b674892ddffe3 100644 +index 9c3f8f79c2b3389a118dce9a1558edda52446833..8c455cda45ca2d724fbc140d53ffc7ecba3ca44c 100644 --- a/src/main/java/net/minecraft/server/level/WorldGenRegion.java +++ b/src/main/java/net/minecraft/server/level/WorldGenRegion.java @@ -84,6 +84,13 @@ public class WorldGenRegion implements WorldGenLevel { @@ -15052,7 +15083,7 @@ index 0306771b8f90dcdd77f151c19c6c2d75c41f8feb..22f0d91df0a81040d72c499fbff32b3a protected boolean isSingleplayerOwner() { diff --git a/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java -index 76f31845fe50200d09e5ab6a6c08da00444414ad..58ec60ad6e597f2f3e6cbbe8a4e5bc696e709d1d 100644 +index 87c5690774363edc1b7ebff10b041e48c0a6d56d..18113fdd0d3f269e2ffb3b661d6adfa5b20d7386 100644 --- a/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java @@ -43,6 +43,7 @@ public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketLis @@ -15063,7 +15094,7 @@ index 76f31845fe50200d09e5ab6a6c08da00444414ad..58ec60ad6e597f2f3e6cbbe8a4e5bc69 public ServerConfigurationPacketListenerImpl(MinecraftServer minecraftserver, Connection networkmanager, CommonListenerCookie commonlistenercookie, ServerPlayer player) { // CraftBukkit super(minecraftserver, networkmanager, commonlistenercookie, player); // CraftBukkit -@@ -127,7 +128,57 @@ public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketLis +@@ -131,7 +132,57 @@ public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketLis ServerPlayer entityplayer = playerlist.getPlayerForLogin(this.gameProfile, this.clientInformation, this.player); // CraftBukkit @@ -15151,7 +15182,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 ab5b259d8f72022c875cae73be25fe2da346c6b3..9555ae82d68cf217bc17e3bd9af2462702a2506b 100644 +index 860d33ac56680babd87358b1d7d2216dac3f7865..954809d8997750959541e6462668f17efd0b0f70 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 @@ -15518,7 +15549,7 @@ index ab5b259d8f72022c875cae73be25fe2da346c6b3..9555ae82d68cf217bc17e3bd9af24627 final String conversationInput = s; this.server.processQueue.add(new Runnable() { @Override -@@ -2670,8 +2726,25 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -2674,8 +2730,25 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl // Spigot End public void switchToConfig() { @@ -15545,7 +15576,7 @@ index ab5b259d8f72022c875cae73be25fe2da346c6b3..9555ae82d68cf217bc17e3bd9af24627 this.send(new ClientboundStartConfigurationPacket()); } -@@ -2696,7 +2769,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -2700,7 +2773,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl this.player.resetLastActionTime(); this.player.setShiftKeyDown(packet.isUsingSecondaryAction()); @@ -15554,7 +15585,7 @@ index ab5b259d8f72022c875cae73be25fe2da346c6b3..9555ae82d68cf217bc17e3bd9af24627 if (!worldserver.getWorldBorder().isWithinBounds(entity.blockPosition())) { return; } -@@ -2826,6 +2899,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -2830,6 +2903,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl switch (packetplayinclientcommand_enumclientcommand) { case PERFORM_RESPAWN: if (this.player.wonGame) { @@ -15567,7 +15598,7 @@ index ab5b259d8f72022c875cae73be25fe2da346c6b3..9555ae82d68cf217bc17e3bd9af24627 this.player.wonGame = false; this.player = this.server.getPlayerList().respawn(this.player, this.server.getLevel(this.player.getRespawnDimension()), true, null, true, RespawnReason.END_PORTAL, org.bukkit.event.player.PlayerRespawnEvent.RespawnFlag.END_PORTAL); // Paper - Expand PlayerRespawnEvent CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD); -@@ -2834,6 +2913,18 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -2838,6 +2917,18 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl return; } @@ -15586,7 +15617,7 @@ index ab5b259d8f72022c875cae73be25fe2da346c6b3..9555ae82d68cf217bc17e3bd9af24627 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 -@@ -3192,7 +3283,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -3196,7 +3287,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) { @@ -15595,7 +15626,7 @@ index ab5b259d8f72022c875cae73be25fe2da346c6b3..9555ae82d68cf217bc17e3bd9af24627 return; } } -@@ -3361,7 +3452,18 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -3365,7 +3456,18 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl this.filterTextPacket(list).thenAcceptAsync((list1) -> { this.updateSignText(packet, list1); @@ -15716,10 +15747,10 @@ index 45d4638d568ea2aee805aa1b0542533019e5870d..599feff33b43623d7c6bd22158afa730 date1 = fallback; } diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda118fe137d 100644 +index 1e5f709115007ff19901c0a6c3cf884d9e4d3a6c..08daa5ed0b4b599836b97eef1e53e630e7659443 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java -@@ -131,10 +131,10 @@ public abstract class PlayerList { +@@ -132,10 +132,10 @@ public abstract class PlayerList { public static final Component DUPLICATE_LOGIN_DISCONNECT_MESSAGE = Component.translatable("multiplayer.disconnect.duplicate_login"); private static final Logger LOGGER = LogUtils.getLogger(); private static final int SEND_PLAYER_INFO_INTERVAL = 600; @@ -15732,7 +15763,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 private final UserBanList bans; private final IpBanList ipBans; private final ServerOpList ops; -@@ -155,9 +155,56 @@ public abstract class PlayerList { +@@ -156,9 +156,63 @@ public abstract class PlayerList { // CraftBukkit start private CraftServer cserver; @@ -15744,6 +15775,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 + private final Object connectionsStateLock = new Object(); + private final Map connectionByName = new java.util.HashMap<>(); + private final Map connectionById = new java.util.HashMap<>(); ++ private final it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet usersCountedAgainstLimit = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); + + public boolean pushPendingJoin(String userName, UUID byId, Connection conn) { + userName = userName.toLowerCase(java.util.Locale.ROOT); @@ -15777,12 +15809,18 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 + synchronized (this.connectionsStateLock) { + this.connectionByName.remove(userName, conn); + this.connectionById.remove(byId, conn); ++ this.usersCountedAgainstLimit.remove(conn); + } + } + -+ private int getTotalConnections() { ++ private boolean countConnection(Connection conn, int limit) { + synchronized (this.connectionsStateLock) { -+ return this.connectionById.size(); ++ int count = this.usersCountedAgainstLimit.size(); ++ if (count >= limit) { ++ return false; ++ } ++ this.usersCountedAgainstLimit.add(conn); ++ return true; + } + } + // Folia end - region threading @@ -15790,7 +15828,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 public PlayerList(MinecraftServer server, LayeredRegistryAccess registryManager, PlayerDataStorage saveHandler, int maxPlayers) { this.cserver = server.server = new CraftServer((DedicatedServer) server, this); server.console = new com.destroystokyo.paper.console.TerminalConsoleCommandSender(); // Paper -@@ -178,7 +225,7 @@ public abstract class PlayerList { +@@ -179,7 +233,7 @@ public abstract class PlayerList { } abstract public void loadAndSaveFiles(); // Paper - fix converting txt to json file; moved from DedicatedPlayerList constructor @@ -15799,7 +15837,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 player.isRealPlayer = true; // Paper player.loginTime = System.currentTimeMillis(); // Paper - Replace OfflinePlayer#getLastPlayed GameProfile gameprofile = player.getGameProfile(); -@@ -257,18 +304,42 @@ public abstract class PlayerList { +@@ -258,18 +312,42 @@ public abstract class PlayerList { player.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT; // set Player SpawnReason to DEFAULT on first login // Paper start - reset to main world spawn if first spawn or invalid world } @@ -15844,7 +15882,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 Location loc = ev.getSpawnLocation(); worldserver1 = ((CraftWorld) loc.getWorld()).getHandle(); -@@ -287,6 +358,10 @@ public abstract class PlayerList { +@@ -288,6 +366,10 @@ public abstract class PlayerList { player.loadGameTypes(nbttagcompound); ServerGamePacketListenerImpl playerconnection = new ServerGamePacketListenerImpl(this.server, connection, player, clientData); @@ -15855,7 +15893,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 GameRules gamerules = worldserver1.getGameRules(); boolean flag = gamerules.getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN); boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO); -@@ -302,7 +377,7 @@ public abstract class PlayerList { +@@ -303,7 +385,7 @@ public abstract class PlayerList { this.sendPlayerPermissionLevel(player); player.getStats().markAllDirty(); player.getRecipeBook().sendInitialRecipeBook(player); @@ -15864,7 +15902,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 this.server.invalidateStatus(); MutableComponent ichatmutablecomponent; -@@ -344,7 +419,7 @@ public abstract class PlayerList { +@@ -345,7 +427,7 @@ public abstract class PlayerList { this.cserver.getPluginManager().callEvent(playerJoinEvent); if (!player.connection.isAcceptingMessages()) { @@ -15873,7 +15911,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage(); -@@ -359,8 +434,7 @@ public abstract class PlayerList { +@@ -360,8 +442,7 @@ public abstract class PlayerList { ClientboundPlayerInfoUpdatePacket packet = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(player)); // Paper - Add Listing API for Player final List onlinePlayers = Lists.newArrayListWithExpectedSize(this.players.size() - 1); // Paper - Use single player info update packet on join @@ -15883,7 +15921,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 if (entityplayer1.getBukkitEntity().canSee(bukkitPlayer)) { // Paper start - Add Listing API for Player -@@ -482,7 +556,7 @@ public abstract class PlayerList { +@@ -483,7 +564,7 @@ public abstract class PlayerList { // Paper start - Configurable player collision; Add to collideRule team if needed final net.minecraft.world.scores.Scoreboard scoreboard = this.getServer().getLevel(Level.OVERWORLD).getScoreboard(); final PlayerTeam collideRuleTeam = scoreboard.getPlayerTeam(this.collideRuleTeamName); @@ -15892,7 +15930,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 scoreboard.addPlayerToTeam(player.getScoreboardName(), collideRuleTeam); } // Paper end - Configurable player collision -@@ -576,7 +650,7 @@ public abstract class PlayerList { +@@ -577,7 +658,7 @@ public abstract class PlayerList { protected void save(ServerPlayer player) { if (!player.getBukkitEntity().isPersistent()) return; // CraftBukkit @@ -15901,7 +15939,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 this.playerIo.save(player); ServerStatsCounter serverstatisticmanager = (ServerStatsCounter) player.getStats(); // CraftBukkit -@@ -616,7 +690,7 @@ public abstract class PlayerList { +@@ -617,7 +698,7 @@ public abstract class PlayerList { // CraftBukkit end // Paper start - Configurable player collision; Remove from collideRule team if needed @@ -15910,7 +15948,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 final net.minecraft.world.scores.Scoreboard scoreBoard = this.server.getLevel(Level.OVERWORLD).getScoreboard(); final PlayerTeam team = scoreBoard.getPlayersTeam(this.collideRuleTeamName); if (entityplayer.getTeam() == team && team != null) { -@@ -656,7 +730,7 @@ public abstract class PlayerList { +@@ -657,7 +738,7 @@ public abstract class PlayerList { entityplayer.unRide(); worldserver.removePlayerImmediately(entityplayer, Entity.RemovalReason.UNLOADED_WITH_PLAYER); @@ -15919,7 +15957,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 entityplayer.getAdvancements().stopListening(); this.players.remove(entityplayer); this.playersByName.remove(entityplayer.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot -@@ -675,8 +749,7 @@ public abstract class PlayerList { +@@ -676,8 +757,7 @@ public abstract class PlayerList { // CraftBukkit start // this.broadcastAll(new ClientboundPlayerInfoRemovePacket(List.of(entityplayer.getUUID()))); ClientboundPlayerInfoRemovePacket packet = new ClientboundPlayerInfoRemovePacket(List.of(entityplayer.getUUID())); @@ -15929,7 +15967,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 if (entityplayer2.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) { entityplayer2.connection.send(packet); -@@ -701,19 +774,12 @@ public abstract class PlayerList { +@@ -702,19 +782,12 @@ public abstract class PlayerList { ServerPlayer entityplayer; @@ -15951,7 +15989,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } // Instead of kicking then returning, we need to store the kick reason -@@ -732,7 +798,7 @@ public abstract class PlayerList { +@@ -733,7 +806,7 @@ public abstract class PlayerList { ichatmutablecomponent = Component.translatable("multiplayer.disconnect.banned.reason", gameprofilebanentry.getReason()); if (gameprofilebanentry.getExpires() != null) { @@ -15960,7 +15998,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } // return chatmessage; -@@ -745,14 +811,14 @@ public abstract class PlayerList { +@@ -746,14 +819,14 @@ public abstract class PlayerList { ichatmutablecomponent = Component.translatable("multiplayer.disconnect.banned_ip.reason", ipbanentry.getReason()); if (ipbanentry.getExpires() != null) { @@ -15973,11 +16011,11 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } else { // return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? IChatBaseComponent.translatable("multiplayer.disconnect.server_full") : null; - if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) { -+ if (this.getTotalConnections() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) { // Folia - region threading - we control connection state here now async, not player list size ++ if (!this.countConnection(loginlistener.connection, this.maxPlayers) && !this.canBypassPlayerLimit(gameprofile)) { // Folia - region threading - we control connection state here now async, not player list size event.disallow(PlayerLoginEvent.Result.KICK_FULL, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.serverFullMessage)); // Spigot // Paper - Adventure } } -@@ -818,6 +884,11 @@ public abstract class PlayerList { +@@ -819,6 +892,11 @@ public abstract class PlayerList { public ServerPlayer respawn(ServerPlayer entityplayer, ServerLevel worldserver, boolean flag, Location location, boolean avoidSuffocation, RespawnReason reason, org.bukkit.event.player.PlayerRespawnEvent.RespawnFlag...respawnFlags) { // Paper end - Expand PlayerRespawnEvent @@ -15989,7 +16027,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 entityplayer.stopRiding(); // CraftBukkit this.players.remove(entityplayer); this.playersByName.remove(entityplayer.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot -@@ -1017,10 +1088,10 @@ public abstract class PlayerList { +@@ -1018,10 +1096,10 @@ public abstract class PlayerList { public void tick() { if (++this.sendAllPlayerInfoIn > 600) { // CraftBukkit start @@ -16003,7 +16041,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 @Override public boolean test(ServerPlayer input) { return target.getBukkitEntity().canSee(input.getBukkitEntity()); -@@ -1046,18 +1117,17 @@ public abstract class PlayerList { +@@ -1047,18 +1125,17 @@ public abstract class PlayerList { // CraftBukkit start - add a world/entity limited version public void broadcastAll(Packet packet, net.minecraft.world.entity.player.Player entityhuman) { @@ -16026,7 +16064,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } } -@@ -1101,8 +1171,7 @@ public abstract class PlayerList { +@@ -1102,8 +1179,7 @@ public abstract class PlayerList { if (scoreboardteam == null) { this.broadcastSystemMessage(message, false); } else { @@ -16036,7 +16074,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 if (entityplayer.getTeam() != scoreboardteam) { entityplayer.sendSystemMessage(message); -@@ -1113,10 +1182,12 @@ public abstract class PlayerList { +@@ -1114,10 +1190,12 @@ public abstract class PlayerList { } public String[] getPlayerNamesArray() { @@ -16052,7 +16090,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } return astring; -@@ -1135,7 +1206,9 @@ public abstract class PlayerList { +@@ -1136,7 +1214,9 @@ public abstract class PlayerList { ServerPlayer entityplayer = this.getPlayer(profile.getId()); if (entityplayer != null) { @@ -16062,7 +16100,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } } -@@ -1145,7 +1218,10 @@ public abstract class PlayerList { +@@ -1146,7 +1226,10 @@ public abstract class PlayerList { ServerPlayer entityplayer = this.getPlayer(profile.getId()); if (entityplayer != null) { @@ -16073,7 +16111,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } } -@@ -1206,8 +1282,7 @@ public abstract class PlayerList { +@@ -1207,8 +1290,7 @@ public abstract class PlayerList { } public void broadcast(@Nullable net.minecraft.world.entity.player.Player player, double x, double y, double z, double distance, ResourceKey worldKey, Packet packet) { @@ -16083,7 +16121,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 // CraftBukkit start - Test if player receiving packet can see the source of the packet if (player != null && !entityplayer.getBukkitEntity().canSee(player.getBukkitEntity())) { -@@ -1237,12 +1312,21 @@ public abstract class PlayerList { +@@ -1238,12 +1320,21 @@ public abstract class PlayerList { io.papermc.paper.util.MCUtil.ensureMain("Save Players" , () -> { // Paper - Ensure main MinecraftTimings.savePlayers.startTiming(); // Paper int numSaved = 0; @@ -16110,7 +16148,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 } // Paper end - Incremental chunk and player saving } -@@ -1361,6 +1445,20 @@ public abstract class PlayerList { +@@ -1362,6 +1453,20 @@ public abstract class PlayerList { } public void removeAll(boolean isRestarting) { @@ -16131,7 +16169,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 // Paper end // CraftBukkit start - disconnect safely for (ServerPlayer player : this.players) { -@@ -1370,7 +1468,7 @@ public abstract class PlayerList { +@@ -1371,7 +1476,7 @@ public abstract class PlayerList { // CraftBukkit end // Paper start - Configurable player collision; Remove collideRule team if it exists @@ -16141,7 +16179,7 @@ index 91feb12732564c90656da487664dbc12e55397fc..fa36e892b019877a770a618fe8d4cda1 final PlayerTeam team = scoreboard.getPlayersTeam(this.collideRuleTeamName); if (team != null) scoreboard.removePlayerTeam(team); diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java -index 35f973cc2c0989256fa21abaf0327c2f36dbe4c9..3208b37cd74462e4efdc4985109a443a7e38883a 100644 +index 7e133752ccb1ea7c0b4fa781feb1a88e2cfdcf6d..9756d1750f40bda0578f4c965953a27c384e7db2 100644 --- a/src/main/java/net/minecraft/server/players/StoredUserList.java +++ b/src/main/java/net/minecraft/server/players/StoredUserList.java @@ -103,6 +103,7 @@ public abstract class StoredUserList> { @@ -16227,15 +16265,15 @@ index a6ac76707da39cf86113003b1f326433fdc86c86..531ccc48154b25378e9039478ce7f89b @Override public boolean remove(Object object) { diff --git a/src/main/java/net/minecraft/util/SpawnUtil.java b/src/main/java/net/minecraft/util/SpawnUtil.java -index 1954fdc7b72700d5948e93ebcb0e6a26fe244a1b..0167951b4dfbe07866bbf12f7ee81732788206f4 100644 +index c5d54abfcbd74c3041d9a46f77705460fa65ce30..025bf2306851347a12035d81e4dd92a47dc00dba 100644 --- a/src/main/java/net/minecraft/util/SpawnUtil.java +++ b/src/main/java/net/minecraft/util/SpawnUtil.java @@ -59,7 +59,7 @@ public class SpawnUtil { return Optional.of(t0); } -- t0.discard(); -+ //t0.discard(); // Folia - region threading +- t0.discard(null); // CraftBukkit - add Bukkit remove cause ++ //t0.discard(null); // CraftBukkit - add Bukkit remove cause // Folia - region threading } } } @@ -16347,10 +16385,10 @@ index 9c99b2e365aacb8309f29acb9025faccd2c676b3..d02bc26812321745795d2f0bc3705add public Component getDeathMessage() { diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSource.java b/src/main/java/net/minecraft/world/damagesource/DamageSource.java -index 1561b85a45f52a8162f43553f8485bfe084b8f1f..7f9bcaf76aca00e4bc5d2428beb0dcad6b538378 100644 +index b26e4d58ea1898a5e4b31c3d6ab33f38835ab2c6..90781fffbb7e6293d3a30d6041dc30186c84caaf 100644 --- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java +++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java -@@ -150,13 +150,13 @@ public class DamageSource { +@@ -156,13 +156,13 @@ public class DamageSource { LivingEntity entityliving1 = killed.getKillCredit(); String s1 = s + ".player"; @@ -16380,10 +16418,10 @@ 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 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449ee0dbc6ad 100644 +index 0b4ed99658b083a83a90db1b32edb358da9e9514..518487d4cd489110bebcf75078935a95b5d3e9cf 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -169,7 +169,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -170,7 +170,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S // Paper start - Share random for entities to make them more random public static RandomSource SHARED_RANDOM = new RandomRandomSource(); @@ -16392,7 +16430,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e private boolean locked = false; @Override -@@ -243,7 +243,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -244,7 +244,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper public boolean collisionLoadChunks = false; // Paper @@ -16401,7 +16439,16 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e public @org.jetbrains.annotations.Nullable net.minecraft.server.level.ChunkMap.TrackedEntity tracker; // Paper public CraftEntity getBukkitEntity() { -@@ -478,28 +478,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -378,7 +378,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S + private boolean hasGlowingTag; + private final Set tags; + private final double[] pistonDeltas; +- private long pistonDeltasGameTime; ++ private long pistonDeltasGameTime = Long.MIN_VALUE; // Folia - region threading + private EntityDimensions dimensions; + private float eyeHeight; + public boolean isInPowderSnow; +@@ -479,28 +479,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S this.isLegacyTrackingEntity = isLegacyTrackingEntity; } @@ -16431,7 +16478,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e // Paper end - optimise entity tracking public float getBukkitYaw() { return this.yRot; -@@ -566,6 +545,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -567,6 +546,19 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S public boolean updatingSectionStatus = false; // Paper end @@ -16443,12 +16490,15 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e + if (this.activatedImmunityTick != Integer.MIN_VALUE) { + this.activatedImmunityTick += fromTickOffset; + } ++ if (this.pistonDeltasGameTime != Long.MIN_VALUE) { ++ this.pistonDeltasGameTime += fromRedstoneTimeOffset; ++ } + } + // Folia end - region ticking public Entity(EntityType type, Level world) { this.id = Entity.ENTITY_COUNTER.incrementAndGet(); -@@ -812,6 +801,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -825,6 +817,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S // CraftBukkit start public void postTick() { @@ -16461,7 +16511,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e // No clean way to break out of ticking once the entity has been copied to a new world, so instead we move the portalling later in the tick cycle if (!(this instanceof ServerPlayer) && this.isAlive()) { // Paper - don't attempt to teleport dead entities this.handleNetherPortal(); -@@ -834,7 +829,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -847,7 +845,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S this.walkDistO = this.walkDist; this.xRotO = this.getXRot(); this.yRotO = this.getYRot(); @@ -16470,7 +16520,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e if (this.canSpawnSprintParticle()) { this.spawnSprintParticle(); } -@@ -1092,8 +1087,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -1105,8 +1103,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S } else { this.wasOnFire = this.isOnFire(); if (movementType == MoverType.PISTON) { @@ -16481,7 +16531,16 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e movement = this.limitPistonMovement(movement); if (movement.equals(Vec3.ZERO)) { return; -@@ -3002,7 +2997,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -1433,7 +1431,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S + if (movement.lengthSqr() <= 1.0E-7D) { + return movement; + } else { +- long i = this.level().getGameTime(); ++ long i = this.level().getRedstoneGameTime(); // Folia - region threading + + if (i != this.pistonDeltasGameTime) { + Arrays.fill(this.pistonDeltas, 0.0D); +@@ -3018,7 +3016,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S this.passengers = ImmutableList.copyOf(list); } @@ -16490,7 +16549,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e } } -@@ -3050,7 +3045,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3066,7 +3064,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S } entity.boardingCooldown = 60; @@ -16499,7 +16558,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e } return true; // CraftBukkit } -@@ -3330,6 +3325,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3346,6 +3344,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @Nullable public PlayerTeam getTeam() { @@ -16511,7 +16570,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e if (!this.level().paperConfig().scoreboards.allowNonPlayerEntitiesOnScoreboards && !(this instanceof Player)) { return null; } // Paper - Perf: Disable Scoreboards for non players by default return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName()); } -@@ -3619,6 +3619,775 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3635,6 +3638,775 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S this.portalEntrancePos = original.portalEntrancePos; } @@ -17287,7 +17346,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e @Nullable public Entity changeDimension(ServerLevel destination) { // CraftBukkit start -@@ -3627,6 +4396,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3643,6 +4415,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @Nullable public Entity teleportTo(ServerLevel worldserver, Vec3 location) { @@ -17299,7 +17358,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e // CraftBukkit end // Paper start - Fix item duplication and teleport issues if (!this.isAlive() || !this.valid) { -@@ -3719,6 +4493,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3735,6 +4512,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S } } @@ -17310,9 +17369,9 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e + // Folia end - region threading - move inventory clearing until after the dimension change + protected void removeAfterChangingDimensions() { - this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION); + this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION, null); // CraftBukkit - add Bukkit remove cause } -@@ -4653,7 +5433,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -4669,7 +5452,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S } } // Paper end - Fix MC-4 @@ -17322,7 +17381,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e synchronized (this.posLock) { // Paper this.position = new Vec3(x, y, z); } // Paper -@@ -4674,7 +5455,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -4690,7 +5474,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S // Paper start - Block invalid positions and bounding box; don't allow desync of pos and AABB // hanging has its own special logic @@ -17331,7 +17390,7 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e this.setBoundingBox(this.makeBoundingBox()); } // Paper end - Block invalid positions and bounding box -@@ -4761,6 +5542,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -4777,6 +5561,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S return this.removalReason != null; } @@ -17344,17 +17403,17 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e @Nullable public Entity.RemovalReason getRemovalReason() { return this.removalReason; -@@ -4776,6 +5563,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S - } - // Paper end - rewrite chunk system +@@ -4800,6 +5590,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S + CraftEventFactory.callEntityRemoveEvent(this, cause); + // CraftBukkit end final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers + // Folia start - region threading -+ this.preRemove(reason); ++ this.preRemove(entity_removalreason); + // Folia end - region threading if (this.removalReason == null) { - this.removalReason = reason; + this.removalReason = entity_removalreason; } -@@ -4798,6 +5588,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -4822,6 +5615,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S this.removalReason = null; } @@ -17366,15 +17425,32 @@ index 906eded9a2ab61737a30cfe89292a71237ce4eb7..b8e77755a1706e60e9dfa1310aa2449e /** * Invoked only when the entity is truly removed from the server, never to be added to any world. diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java -index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e737dcedb1d 100644 +index e9bb7feb591032904516d1b9374f486d8a7d066c..73e0c2ec5ab8cf54767755f31d1a8d0a168ee46f 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java -@@ -275,6 +275,13 @@ public abstract class LivingEntity extends Entity implements Attackable { +@@ -246,7 +246,7 @@ public abstract class LivingEntity extends Entity implements Attackable { + private Optional lastClimbablePos; + @Nullable + private DamageSource lastDamageSource; +- private long lastDamageStamp; ++ private long lastDamageStamp = Long.MIN_VALUE; // Folia - region threading + protected int autoSpinAttackTicks; + private float swimAmount; + private float swimAmountO; +@@ -276,6 +276,21 @@ public abstract class LivingEntity extends Entity implements Attackable { ++this.noActionTime; // Above all the floats } // Spigot end + // Folia start - region threading + @Override ++ public void updateTicks(long fromTickOffset, long fromRedstoneTimeOffset) { ++ super.updateTicks(fromTickOffset, fromRedstoneTimeOffset); ++ if (this.lastDamageStamp != Long.MIN_VALUE) { ++ this.lastDamageStamp += fromRedstoneTimeOffset; ++ } ++ } ++ ++ @Override + protected void resetStoredPositions() { + super.resetStoredPositions(); + this.lastClimbablePos = Optional.empty(); @@ -17383,7 +17459,7 @@ index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e73 protected LivingEntity(EntityType type, Level world) { super(type, world); -@@ -480,7 +487,7 @@ public abstract class LivingEntity extends Entity implements Attackable { +@@ -481,7 +496,7 @@ public abstract class LivingEntity extends Entity implements Attackable { if (this.isDeadOrDying() && this.level().shouldTickDeath(this)) { this.tickDeath(); @@ -17392,7 +17468,7 @@ index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e73 if (this.lastHurtByPlayerTime > 0) { --this.lastHurtByPlayerTime; -@@ -626,11 +633,14 @@ public abstract class LivingEntity extends Entity implements Attackable { +@@ -627,11 +642,14 @@ public abstract class LivingEntity extends Entity implements Attackable { return true; } @@ -17402,14 +17478,14 @@ index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e73 - if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved()) { + if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved() && !this.broadcastedDeath) { // Folia - region threading this.level().broadcastEntityEvent(this, (byte) 60); -- this.remove(Entity.RemovalReason.KILLED); +- this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause + this.broadcastedDeath = true; // Folia - region threading - death has been broadcasted -+ if (!(this instanceof ServerPlayer)) this.remove(Entity.RemovalReason.KILLED); // Folia - region threading - don't remove, we want the tick scheduler to be running ++ if (!(this instanceof ServerPlayer)) this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause // Folia - region threading - don't remove, we want the tick scheduler to be running + if ((this instanceof ServerPlayer)) this.unRide(); // Folia - region threading - unmount player when dead } } -@@ -852,9 +862,9 @@ public abstract class LivingEntity extends Entity implements Attackable { +@@ -860,9 +878,9 @@ public abstract class LivingEntity extends Entity implements Attackable { } this.hurtTime = nbt.getShort("HurtTime"); @@ -17421,7 +17497,7 @@ index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e73 String s = nbt.getString("Team"); PlayerTeam scoreboardteam = this.level().getScoreboard().getPlayerTeam(s); if (!this.level().paperConfig().scoreboards.allowNonPlayerEntitiesOnScoreboards && !(this instanceof net.minecraft.world.entity.player.Player)) { scoreboardteam = null; } // Paper - Perf: Disable Scoreboards for non players by default -@@ -1141,6 +1151,7 @@ public abstract class LivingEntity extends Entity implements Attackable { +@@ -1149,6 +1167,7 @@ public abstract class LivingEntity extends Entity implements Attackable { public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause, boolean fireEvent) { // Paper end - Don't fire sync event during generation // org.spigotmc.AsyncCatcher.catchOp("effect add"); // Spigot // Paper - move to API @@ -17429,7 +17505,25 @@ index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e73 if (this.isTickingEffects) { this.effectsToProcess.add(new ProcessableEffect(mobeffect, cause)); return true; -@@ -2351,7 +2362,7 @@ public abstract class LivingEntity extends Entity implements Attackable { +@@ -1573,7 +1592,7 @@ public abstract class LivingEntity extends Entity implements Attackable { + + if (flag2) { + this.lastDamageSource = source; +- this.lastDamageStamp = this.level().getGameTime(); ++ this.lastDamageStamp = this.level().getRedstoneGameTime(); // Folia - region threading + } + + if (this instanceof ServerPlayer) { +@@ -1656,7 +1675,7 @@ public abstract class LivingEntity extends Entity implements Attackable { + + @Nullable + public DamageSource getLastDamageSource() { +- if (this.level().getGameTime() - this.lastDamageStamp > 40L) { ++ if (this.level().getRedstoneGameTime() - this.lastDamageStamp > 40L || this.lastDamageStamp == Long.MIN_VALUE) { // Folia - region threading + this.lastDamageSource = null; + } + +@@ -2359,7 +2378,7 @@ public abstract class LivingEntity extends Entity implements Attackable { @Nullable public LivingEntity getKillCredit() { @@ -17438,7 +17532,16 @@ index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e73 } public final float getMaxHealth() { -@@ -3494,7 +3505,7 @@ public abstract class LivingEntity extends Entity implements Attackable { +@@ -2437,7 +2456,7 @@ public abstract class LivingEntity extends Entity implements Attackable { + + this.hurt(this.damageSources().generic(), 0.0F); + this.lastDamageSource = damageSource; +- this.lastDamageStamp = this.level().getGameTime(); ++ this.lastDamageStamp = this.level().getRedstoneGameTime(); // Folia - region threading + } + + @Override +@@ -3502,7 +3521,7 @@ public abstract class LivingEntity extends Entity implements Attackable { this.pushEntities(); this.level().getProfiler().pop(); // Paper start - Add EntityMoveEvent @@ -17447,7 +17550,7 @@ index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e73 if (this.xo != this.getX() || this.yo != this.getY() || this.zo != this.getZ() || this.yRotO != this.getYRot() || this.xRotO != this.getXRot()) { Location from = new Location(this.level().getWorld(), this.xo, this.yo, this.zo, this.yRotO, this.xRotO); Location to = new Location(this.level().getWorld(), this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot()); -@@ -4187,7 +4198,7 @@ public abstract class LivingEntity extends Entity implements Attackable { +@@ -4195,7 +4214,7 @@ public abstract class LivingEntity extends Entity implements Attackable { BlockPos blockposition = BlockPos.containing(d0, d1, d2); Level world = this.level(); @@ -17457,10 +17560,10 @@ index aceee33eebd4d5f89e62a42910ec51843f33843b..ffec458e5b6dc4250758fb8a97ab1e73 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 fa0b78139fecc0245e168ebeb4172ea2531a3fec..a3992e21e7d4112b9903e8d16a5e898d448eaea8 100644 +index 2439f8d48daca7329049436414f06a36b4b79029..54297b9dde40fe853d873d60373cd8c0a3c9466b 100644 --- a/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java -@@ -137,6 +137,14 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -138,6 +138,14 @@ public abstract class Mob extends LivingEntity implements Targeting { public boolean aware = true; // CraftBukkit @@ -17475,7 +17578,7 @@ index fa0b78139fecc0245e168ebeb4172ea2531a3fec..a3992e21e7d4112b9903e8d16a5e898d protected Mob(EntityType type, Level world) { super(type, world); this.handItems = NonNullList.withSize(2, ItemStack.EMPTY); -@@ -288,9 +296,21 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -289,9 +297,21 @@ public abstract class Mob extends LivingEntity implements Targeting { @Nullable @Override public LivingEntity getTarget() { @@ -17497,7 +17600,7 @@ index fa0b78139fecc0245e168ebeb4172ea2531a3fec..a3992e21e7d4112b9903e8d16a5e898d public org.bukkit.craftbukkit.entity.CraftMob getBukkitMob() { return (org.bukkit.craftbukkit.entity.CraftMob) super.getBukkitEntity(); } // Paper public void setTarget(@Nullable LivingEntity target) { // CraftBukkit start - fire event -@@ -298,7 +318,7 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -299,7 +319,7 @@ public abstract class Mob extends LivingEntity implements Targeting { } public boolean setTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) { @@ -17506,7 +17609,7 @@ index fa0b78139fecc0245e168ebeb4172ea2531a3fec..a3992e21e7d4112b9903e8d16a5e898d if (fireEvent) { if (reason == EntityTargetEvent.TargetReason.UNKNOWN && this.getTarget() != null && entityliving == null) { reason = this.getTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED; -@@ -908,7 +928,7 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -909,7 +929,7 @@ public abstract class Mob extends LivingEntity implements Targeting { this.level().getProfiler().push("sensing"); this.sensing.tick(); this.level().getProfiler().pop(); @@ -17515,7 +17618,7 @@ index fa0b78139fecc0245e168ebeb4172ea2531a3fec..a3992e21e7d4112b9903e8d16a5e898d if (i % 2 != 0 && this.tickCount > 1) { this.level().getProfiler().push("targetSelector"); -@@ -1757,6 +1777,17 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -1758,6 +1778,17 @@ public abstract class Mob extends LivingEntity implements Targeting { this.goalSelector.removeAllGoals(predicate); } @@ -17533,7 +17636,7 @@ index fa0b78139fecc0245e168ebeb4172ea2531a3fec..a3992e21e7d4112b9903e8d16a5e898d @Override protected void removeAfterChangingDimensions() { super.removeAfterChangingDimensions(); -@@ -1765,12 +1796,7 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -1766,12 +1797,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 @@ -17935,7 +18038,7 @@ index f760ce7d9df79ef58f8963de3e901cba3e12fcaa..03bd7038bda7bd3bf592eab39ec6d985 this.setPersistenceRequired(); } diff --git a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java -index 80303f9466b8c7097151be313afc9a383693d18a..d53905cafc7bf257907e6c9b9ea2ba97fb266361 100644 +index c34701f95580e4cf45fe086115563127432a28c5..fe95aa9389f7d11e1380445a1eeca50cae549edb 100644 --- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java +++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java @@ -298,8 +298,10 @@ public class ItemFrame extends HangingEntity { @@ -17950,10 +18053,10 @@ index 80303f9466b8c7097151be313afc9a383693d18a..d53905cafc7bf257907e6c9b9ea2ba97 }); diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -index eb0d6238588efa35fa868f26290547574a08eca2..7c416a0e4734e6987279cfbb34103a0bf00ed087 100644 +index 29ce703a79f7893ac990ad80e0f1c1cf63546e6c..51bc4c0c8505e900cd3268048ac8cf71b2d22e6b 100644 --- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -@@ -54,7 +54,7 @@ public class ItemEntity extends Entity implements TraceableEntity { +@@ -55,7 +55,7 @@ public class ItemEntity extends Entity implements TraceableEntity { @Nullable public UUID target; public final float bobOffs; @@ -17962,8 +18065,8 @@ index eb0d6238588efa35fa868f26290547574a08eca2..7c416a0e4734e6987279cfbb34103a0b public boolean canMobPickup = true; // Paper - Item#canEntityPickup private int despawnRate = -1; // Paper - Alternative item-despawn-rate public net.kyori.adventure.util.TriState frictionState = net.kyori.adventure.util.TriState.NOT_SET; // Paper - Friction API -@@ -144,13 +144,11 @@ public class ItemEntity extends Entity implements TraceableEntity { - this.discard(); +@@ -145,13 +145,11 @@ public class ItemEntity extends Entity implements TraceableEntity { + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else { super.tick(); - // CraftBukkit start - Use wall time for pickup and despawn timers @@ -17981,7 +18084,7 @@ index eb0d6238588efa35fa868f26290547574a08eca2..7c416a0e4734e6987279cfbb34103a0b this.xo = this.getX(); this.yo = this.getY(); -@@ -204,11 +202,11 @@ public class ItemEntity extends Entity implements TraceableEntity { +@@ -205,11 +203,11 @@ public class ItemEntity extends Entity implements TraceableEntity { this.mergeWithNeighbours(); } @@ -17995,7 +18098,7 @@ index eb0d6238588efa35fa868f26290547574a08eca2..7c416a0e4734e6987279cfbb34103a0b this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing(); if (!this.level().isClientSide) { -@@ -235,13 +233,14 @@ public class ItemEntity extends Entity implements TraceableEntity { +@@ -236,13 +234,14 @@ public class ItemEntity extends Entity implements TraceableEntity { // Spigot start - copied from above @Override public void inactiveTick() { @@ -18017,7 +18120,7 @@ index eb0d6238588efa35fa868f26290547574a08eca2..7c416a0e4734e6987279cfbb34103a0b if (!this.level().isClientSide && this.age >= this.despawnRate) { // Spigot // Paper - Alternative item-despawn-rate // CraftBukkit start - fire ItemDespawnEvent -@@ -548,14 +547,20 @@ public class ItemEntity extends Entity implements TraceableEntity { +@@ -549,14 +548,20 @@ public class ItemEntity extends Entity implements TraceableEntity { return false; } @@ -18042,10 +18145,10 @@ index eb0d6238588efa35fa868f26290547574a08eca2..7c416a0e4734e6987279cfbb34103a0b return entity; } diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java -index cd7b955754b809826048b80723e2e9055b373a4a..9a48c2d943241a6d53daecf7e8125b7aeca77b38 100644 +index e712bd07ea2946167782473a536e0c72fab4bccd..94d1cc62f1b0b60882541764e7272c248689b831 100644 --- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java +++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java -@@ -71,7 +71,7 @@ public class PrimedTnt extends Entity implements TraceableEntity { +@@ -72,7 +72,7 @@ public class PrimedTnt extends Entity implements TraceableEntity { @Override public void tick() { @@ -18054,7 +18157,7 @@ index cd7b955754b809826048b80723e2e9055b373a4a..9a48c2d943241a6d53daecf7e8125b7a if (!this.isNoGravity()) { this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D)); } -@@ -113,7 +113,7 @@ public class PrimedTnt extends Entity implements TraceableEntity { +@@ -114,7 +114,7 @@ public class PrimedTnt extends Entity implements TraceableEntity { */ // Send position and velocity updates to nearby players on every tick while the TNT is in water. // This does pretty well at keeping their clients in sync with the server. @@ -18206,10 +18309,10 @@ index 5f407535298a31a34cfe114dd863fd6a9b977707..cb0f75fb32836efa50f0a86dfae7907b return 0; } else { diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java -index 1aae466e3e334d7f4bbb3ea9365a255afcc3dd3a..853c777bad19656cd48e9de9015c12e2c078d940 100644 +index 24044795d8e0f1fb15a4f2f5401f44897092f2a3..3eeff0cd8563939c656b5ded8470cab016903f25 100644 --- a/src/main/java/net/minecraft/world/entity/npc/Villager.java +++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java -@@ -203,7 +203,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler +@@ -204,7 +204,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler brain.setCoreActivities(ImmutableSet.of(Activity.CORE)); brain.setDefaultActivity(Activity.IDLE); brain.setActiveActivityIfPossible(Activity.IDLE); @@ -18218,7 +18321,7 @@ index 1aae466e3e334d7f4bbb3ea9365a255afcc3dd3a..853c777bad19656cd48e9de9015c12e2 } @Override -@@ -729,6 +729,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler +@@ -730,6 +730,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler ServerLevel worldserver = minecraftserver.getLevel(globalpos.dimension()); if (worldserver != null) { @@ -18227,7 +18330,7 @@ index 1aae466e3e334d7f4bbb3ea9365a255afcc3dd3a..853c777bad19656cd48e9de9015c12e2 PoiManager villageplace = worldserver.getPoiManager(); Optional> optional = villageplace.getType(globalpos.pos()); BiPredicate> bipredicate = (BiPredicate) Villager.POI_MEMORIES.get(pos); -@@ -737,6 +739,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler +@@ -738,6 +740,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler villageplace.release(globalpos.pos()); DebugPackets.sendPoiTicketCountPacket(worldserver, globalpos.pos()); } @@ -18329,10 +18432,10 @@ index d7bddedb19c10f62fd1f7d3128453ad706ed16be..948749a0a3ef9d06f0482bc5331a5283 entityvillagertrader.setWanderTarget(blockposition1); entityvillagertrader.restrictTo(blockposition1, 16); diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java -index 5ca1f834f311a87323ced2578535e66efa14e47f..d52823d8a6e3aefabe47a938b105c19545d10e98 100644 +index 567704f61034363e48ef2a5b5566ebdc91682297..579eb5a81281ca36c145153d8c24a517242ffe18 100644 --- a/src/main/java/net/minecraft/world/entity/player/Player.java +++ b/src/main/java/net/minecraft/world/entity/player/Player.java -@@ -1520,6 +1520,14 @@ public abstract class Player extends LivingEntity { +@@ -1528,6 +1528,14 @@ public abstract class Player extends LivingEntity { } @@ -18348,10 +18451,10 @@ index 5ca1f834f311a87323ced2578535e66efa14e47f..d52823d8a6e3aefabe47a938b105c195 return false; } diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java -index d14eab0d83d629a4522bf3f7d789d2853eb84f06..32ac9ffb1655e370255f2f3fe62b756217988196 100644 +index e8faca6e443239968f0111519f9e5cd018ed3297..88aa1a41be9f596e07af3632def749aff9ea3363 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java +++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java -@@ -156,6 +156,11 @@ public abstract class AbstractArrow extends Projectile { +@@ -157,6 +157,11 @@ public abstract class AbstractArrow extends Projectile { @Override public void tick() { super.tick(); @@ -18364,11 +18467,11 @@ index d14eab0d83d629a4522bf3f7d789d2853eb84f06..32ac9ffb1655e370255f2f3fe62b7562 Vec3 vec3d = this.getDeltaMovement(); diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java -index c4ecc5faa4f61e7974e8c475762924a89615b377..40489886060782681f960d1c4eab36981279b76b 100644 +index 20ce474b72894a8bb3fc21018b9d79bbdc8bb14b..cd150b14afe46dcc5d96eb11106bf2bb4744c944 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java +++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java -@@ -88,6 +88,11 @@ public abstract class AbstractHurtingProjectile extends Projectile { - this.discard(); +@@ -91,6 +91,11 @@ public abstract class AbstractHurtingProjectile extends Projectile { + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else { super.tick(); + // Folia start - region threading - make sure entities do not move into regions they do not own @@ -18380,10 +18483,10 @@ index c4ecc5faa4f61e7974e8c475762924a89615b377..40489886060782681f960d1c4eab3698 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 7005b3a26e9b5d79064981a4a41bee21b65a9fc3..3cdfe382b0d4f35ce34628e7c1630dff7c2623c4 100644 +index 5b3b59057b962438c6f4fc8a1507342865b3bc11..01579e1f4d2c62b636e08cc06dc891728c352efe 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java +++ b/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java -@@ -128,6 +128,11 @@ public class FireworkRocketEntity extends Projectile implements ItemSupplier { +@@ -131,6 +131,11 @@ public class FireworkRocketEntity extends Projectile implements ItemSupplier { }); } @@ -18396,10 +18499,10 @@ index 7005b3a26e9b5d79064981a4a41bee21b65a9fc3..3cdfe382b0d4f35ce34628e7c1630dff if (this.attachedToEntity != null) { if (this.attachedToEntity.isFallFlying()) { diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java -index 90a5f6bd729148f2adc745273536e48d704fcd1e..702949d3d4c46222d2ef8227a559acd54d399bc0 100644 +index 91497f5e6c07fcf1b05eca6846c51e1a15ed3bc0..16f847a21b0c636e8af332b999df4469b19cc943 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java +++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java -@@ -104,7 +104,7 @@ public class FishingHook extends Projectile { +@@ -105,7 +105,7 @@ public class FishingHook extends Projectile { public FishingHook(net.minecraft.world.entity.player.Player thrower, Level world, int luckOfTheSeaLevel, int lureLevel) { this(EntityType.FISHING_BOBBER, world, luckOfTheSeaLevel, lureLevel); @@ -18408,7 +18511,7 @@ index 90a5f6bd729148f2adc745273536e48d704fcd1e..702949d3d4c46222d2ef8227a559acd5 float f = thrower.getXRot(); float f1 = thrower.getYRot(); float f2 = Mth.cos(-f1 * 0.017453292F - 3.1415927F); -@@ -116,6 +116,7 @@ public class FishingHook extends Projectile { +@@ -117,6 +117,7 @@ public class FishingHook extends Projectile { double d2 = thrower.getZ() - (double) f2 * 0.3D; this.moveTo(d0, d1, d2, f1, f); @@ -18416,7 +18519,7 @@ index 90a5f6bd729148f2adc745273536e48d704fcd1e..702949d3d4c46222d2ef8227a559acd5 Vec3 vec3d = new Vec3((double) (-f3), (double) Mth.clamp(-(f5 / f4), -5.0F, 5.0F), (double) (-f2)); double d3 = vec3d.length(); -@@ -266,6 +267,11 @@ public class FishingHook extends Projectile { +@@ -267,6 +268,11 @@ public class FishingHook extends Projectile { } private boolean shouldStopFishing(net.minecraft.world.entity.player.Player player) { @@ -18428,13 +18531,13 @@ index 90a5f6bd729148f2adc745273536e48d704fcd1e..702949d3d4c46222d2ef8227a559acd5 ItemStack itemstack = player.getMainHandItem(); ItemStack itemstack1 = player.getOffhandItem(); boolean flag = itemstack.is(Items.FISHING_ROD); -@@ -605,10 +611,18 @@ public class FishingHook extends Projectile { - +@@ -613,10 +619,18 @@ public class FishingHook extends Projectile { @Override - public void remove(Entity.RemovalReason reason) { + public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) { + // CraftBukkit end - this.updateOwnerInfo((FishingHook) null); + // Folia - region threading - move into preRemove - super.remove(reason); + super.remove(entity_removalreason, cause); // CraftBukkit - add Bukkit remove cause } + // Folia start - region threading @@ -18449,10 +18552,10 @@ index 90a5f6bd729148f2adc745273536e48d704fcd1e..702949d3d4c46222d2ef8227a559acd5 public void onClientRemoval() { this.updateOwnerInfo((FishingHook) null); diff --git a/src/main/java/net/minecraft/world/entity/projectile/LlamaSpit.java b/src/main/java/net/minecraft/world/entity/projectile/LlamaSpit.java -index 0bbe853f7df93f9dcd2b21d762939f8b6be069aa..4f4d6dedb99feac995e9b5bdf1d5c9f1332d61be 100644 +index 8f5376543cca9cbfb2a014f67ec373d984b0df64..85a0f7b30db57a68133b38f42c17ac6e585fd629 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/LlamaSpit.java +++ b/src/main/java/net/minecraft/world/entity/projectile/LlamaSpit.java -@@ -29,6 +29,11 @@ public class LlamaSpit extends Projectile { +@@ -32,6 +32,11 @@ public class LlamaSpit extends Projectile { @Override public void tick() { super.tick(); @@ -18499,10 +18602,10 @@ index 156809090f1f83ad68e7e2477a3cfddac5757a8e..10d7c64fb3a9bafdcdae99f8dc870177 public boolean mayBreak(Level world) { diff --git a/src/main/java/net/minecraft/world/entity/projectile/SmallFireball.java b/src/main/java/net/minecraft/world/entity/projectile/SmallFireball.java -index 9d43c8520953d6fe0d0948f9dbe14e0650ee01c2..c7713583930240512cd94f2a6bd1ff819ca6cd48 100644 +index 6724fe4470aeea338eb4cfd10a7e61fbcac1e5b7..b6797d84356425945037d32b55c0d08c4699c8bf 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/SmallFireball.java +++ b/src/main/java/net/minecraft/world/entity/projectile/SmallFireball.java -@@ -23,7 +23,7 @@ public class SmallFireball extends Fireball { +@@ -26,7 +26,7 @@ public class SmallFireball extends Fireball { public SmallFireball(Level world, LivingEntity owner, double velocityX, double velocityY, double velocityZ) { super(EntityType.SMALL_FIREBALL, owner, velocityX, velocityY, velocityZ, world); // CraftBukkit start @@ -18528,10 +18631,10 @@ index ab777952bda1651796ed41e8a7fc6621f27db9aa..6b9365eba3339578ee2984605240b74d boolean flag = false; diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java -index 3be611e7ae35b696ba44cd361042f79b69391815..f34d9fcf55a40b59a8753de656c128fc8917e5f7 100644 +index 1fb1e729d6879568d8b4943071fa940325b2e5b0..0c4b158d574ad0e9e257532ac3b9a3a34497216f 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java +++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java -@@ -45,6 +45,78 @@ public class ThrownEnderpearl extends ThrowableItemProjectile { +@@ -46,6 +46,78 @@ public class ThrownEnderpearl extends ThrowableItemProjectile { entityHitResult.getEntity().hurt(this.damageSources().thrown(this, this.getOwner()), 0.0F); } @@ -18610,7 +18713,7 @@ index 3be611e7ae35b696ba44cd361042f79b69391815..f34d9fcf55a40b59a8753de656c128fc @Override protected void onHit(HitResult hitResult) { super.onHit(hitResult); -@@ -54,6 +126,20 @@ public class ThrownEnderpearl extends ThrowableItemProjectile { +@@ -55,6 +127,20 @@ public class ThrownEnderpearl extends ThrowableItemProjectile { } if (!this.level().isClientSide && !this.isRemoved()) { @@ -18624,14 +18727,14 @@ index 3be611e7ae35b696ba44cd361042f79b69391815..f34d9fcf55a40b59a8753de656c128fc + if (entity != null) { + attemptTeleport(entity, (ServerLevel)this.level(), this.position()); + } -+ this.discard(); ++ this.discard(EntityRemoveEvent.Cause.HIT); + return; + } + // Folia end - region threading Entity entity = this.getOwner(); if (entity instanceof ServerPlayer) { -@@ -112,6 +198,14 @@ public class ThrownEnderpearl extends ThrowableItemProjectile { +@@ -113,6 +199,14 @@ public class ThrownEnderpearl extends ThrowableItemProjectile { } @@ -18683,10 +18786,10 @@ index eaa2943b667967f93f28d9d794d702fdaeb670ec..8fc22de1aa17cd8cb52d3804533d56cb while (iterator.hasNext()) { ServerPlayer entityplayer = (ServerPlayer) iterator.next(); diff --git a/src/main/java/net/minecraft/world/entity/raid/Raider.java b/src/main/java/net/minecraft/world/entity/raid/Raider.java -index 226fb5c88dd43c8008c5237299ef80db9e847af7..1c47705148815537b1ae67ef6d8b1379e4c0b1b4 100644 +index 93bbf7556f9599e9dd90761085a57d78bd521867..15e1ce9d50f176e475295f7d5e8d039f49e84ad8 100644 --- a/src/main/java/net/minecraft/world/entity/raid/Raider.java +++ b/src/main/java/net/minecraft/world/entity/raid/Raider.java -@@ -91,7 +91,7 @@ public abstract class Raider extends PatrollingMonster { +@@ -94,7 +94,7 @@ public abstract class Raider extends PatrollingMonster { if (this.canJoinRaid()) { if (raid == null) { @@ -18860,7 +18963,7 @@ index 6b81be03f87967124b046708557e05d519aa79e4..2220ac02eec17c0791e5b4ce8f5e0853 } diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java -index 1ad126d992d95062a3db08374db7a927f23a0cac..7de615a1b474269bb1c1dcb613d564fbc59c13b5 100644 +index 1ad126d992d95062a3db08374db7a927f23a0cac..43d8f91cdbc4e197f2811fb406a7dae8a8ebfdc1 100644 --- a/src/main/java/net/minecraft/world/item/ItemStack.java +++ b/src/main/java/net/minecraft/world/item/ItemStack.java @@ -379,31 +379,32 @@ public final class ItemStack { @@ -18905,8 +19008,12 @@ index 1ad126d992d95062a3db08374db7a927f23a0cac..7de615a1b474269bb1c1dcb613d564fb StructureGrowEvent structureEvent = null; if (treeType != null) { boolean isBonemeal = this.getItem() == Items.BONE_MEAL; -@@ -432,13 +433,13 @@ public final class ItemStack { - SignItem.openSign = null; // SPIGOT-6758 - Reset on early return +@@ -429,16 +430,16 @@ public final class ItemStack { + entityhuman.awardStat(Stats.ITEM_USED.get(item)); // SPIGOT-7236 - award stat + } + +- SignItem.openSign = null; // SPIGOT-6758 - Reset on early return ++ SignItem.openSign.set(null); // SPIGOT-6758 - Reset on early return // Folia - region threading return enuminteractionresult; } - world.captureTreeGeneration = false; @@ -18939,6 +19046,15 @@ index 1ad126d992d95062a3db08374db7a927f23a0cac..7de615a1b474269bb1c1dcb613d564fb // Brute force all possible updates // Paper start - Don't resync blocks +@@ -464,7 +465,7 @@ public final class ItemStack { + // ((ServerPlayer) entityhuman).connection.send(new ClientboundBlockUpdatePacket(world, placedPos.relative(dir))); + // } + // Paper end - Don't resync blocks +- SignItem.openSign = null; // SPIGOT-6758 - Reset on early return ++ SignItem.openSign.set(null); // SPIGOT-6758 - Reset on early return // Folia - region threading + } else { + // Change the stack to its new contents if it hasn't been tampered with. + if (this.getCount() == oldCount && Objects.equals(this.tag, oldData)) { @@ -472,7 +473,7 @@ public final class ItemStack { this.setCount(newCount); } @@ -18948,6 +19064,26 @@ index 1ad126d992d95062a3db08374db7a927f23a0cac..7de615a1b474269bb1c1dcb613d564fb world.setBlockEntity(e.getValue()); } +@@ -523,15 +524,15 @@ public final class ItemStack { + } + + // SPIGOT-4678 +- if (this.item instanceof SignItem && SignItem.openSign != null) { ++ if (this.item instanceof SignItem && SignItem.openSign.get() != null) { // Folia - region threading + try { +- if (world.getBlockEntity(SignItem.openSign) instanceof SignBlockEntity tileentitysign) { +- if (world.getBlockState(SignItem.openSign).getBlock() instanceof SignBlock blocksign) { ++ if (world.getBlockEntity(SignItem.openSign.get()) instanceof SignBlockEntity tileentitysign) { // Folia - region threading ++ if (world.getBlockState(SignItem.openSign.get()).getBlock() instanceof SignBlock blocksign) { // Folia - region threading + blocksign.openTextEdit(entityhuman, tileentitysign, true, io.papermc.paper.event.player.PlayerOpenSignEvent.Cause.PLACE); // Paper - Add PlayerOpenSignEvent + } + } + } finally { +- SignItem.openSign = null; ++ SignItem.openSign.set(null); // Folia - region threading + } + } + @@ -559,8 +560,8 @@ public final class ItemStack { entityhuman.awardStat(Stats.ITEM_USED.get(item)); } @@ -19036,6 +19172,28 @@ index 3aa73cd44aa8c86b78c35bc1788e4f83018c49ed..cfead7686da25d2cd9203256962170d7 worldserver.getCraftServer().getPluginManager().callEvent(event); } +diff --git a/src/main/java/net/minecraft/world/item/SignItem.java b/src/main/java/net/minecraft/world/item/SignItem.java +index 21c25026da4117b2cb2c85576d2def945a97dbe2..e0b51cb4ef9e847dc9a2e66f2c87c94d6d93c6a3 100644 +--- a/src/main/java/net/minecraft/world/item/SignItem.java ++++ b/src/main/java/net/minecraft/world/item/SignItem.java +@@ -13,7 +13,7 @@ import net.minecraft.world.level.block.state.BlockState; + + public class SignItem extends StandingAndWallBlockItem { + +- public static BlockPos openSign; // CraftBukkit ++ public static final ThreadLocal openSign = new ThreadLocal<>(); // CraftBukkit // Folia - region threading + + public SignItem(Item.Properties settings, Block standingBlock, Block wallBlock) { + super(standingBlock, wallBlock, settings, Direction.DOWN); +@@ -39,7 +39,7 @@ public class SignItem extends StandingAndWallBlockItem { + + // CraftBukkit start - SPIGOT-4678 + // blocksign.openTextEdit(entityhuman, tileentitysign, true); +- SignItem.openSign = pos; ++ SignItem.openSign.set(pos); // Folia - region threading + // CraftBukkit end + } + } diff --git a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java index 524b0f1086c01888fe0b76e180c40915d16a1eb9..50b3025189938374886c7e2725dd3e4d54ac2160 100644 --- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java @@ -19167,7 +19325,7 @@ index ed84c87a3f76bc0254c1abb189e6b8b808823465..894a25e9dfd61b8409f2883fc0af7c79 return player; } diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java -index b678da2cbb93cea7971bc3c4d324cfca18b0bc97..409d71c9c659e0417d85d544f35f2279b6d8d399 100644 +index 90a82bd7977ebe520bdcc2ab99e11452d5cf4a21..b937437d4446fbf80376399067fd04dc7f95e64a 100644 --- a/src/main/java/net/minecraft/world/level/Explosion.java +++ b/src/main/java/net/minecraft/world/level/Explosion.java @@ -870,17 +870,18 @@ public class Explosion { @@ -19193,7 +19351,7 @@ index b678da2cbb93cea7971bc3c4d324cfca18b0bc97..409d71c9c659e0417d85d544f35f2279 private final double posX, posY, posZ; private final double minX, minY, minZ; diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java -index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b453834ee 100644 +index ca89d1593bf1b46c79a882db528cbca1359dc9d4..2c0ce270c947c7fc1d7e0163a43467129a65f999 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -115,10 +115,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @@ -19266,7 +19424,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b // Paper start - fix and optimise world upgrading // copied from below -@@ -207,6 +197,33 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -216,6 +206,33 @@ public abstract class Level implements LevelAccessor, AutoCloseable { public abstract ResourceKey getTypeKey(); @@ -19300,7 +19458,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b protected Level(WritableLevelData worlddatamutable, ResourceKey resourcekey, RegistryAccess iregistrycustom, Holder holder, Supplier supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function paperWorldConfigCreator, java.util.concurrent.Executor executor) { // Paper - create paper world config; Async-Anti-Xray: Pass executor this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config -@@ -250,7 +267,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -259,7 +276,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { this.thread = Thread.currentThread(); this.biomeManager = new BiomeManager(this, i); this.isDebug = flag1; @@ -19309,7 +19467,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b this.registryAccess = iregistrycustom; this.damageSources = new DamageSources(iregistrycustom); // CraftBukkit start -@@ -839,8 +856,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -848,8 +865,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @Nullable public final BlockState getBlockStateIfLoaded(BlockPos pos) { // CraftBukkit start - tree generation @@ -19320,7 +19478,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b if (previous != null) { return previous.getHandle(); } -@@ -902,16 +919,18 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -911,16 +928,18 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @Override public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) { @@ -19340,9 +19498,9 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b - this.capturedBlockStates.put(pos.immutable(), blockstate); + worldData.capturedBlockStates.put(pos.immutable(), blockstate); // Folia - region threading } - blockstate.setFlag(flags); // Paper - update the flag also blockstate.setData(state); -@@ -928,10 +947,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable { + blockstate.setFlag(flags); +@@ -937,10 +956,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable { // CraftBukkit start - capture blockstates boolean captured = false; @@ -19355,7 +19513,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b captured = true; } // CraftBukkit end -@@ -941,8 +960,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -950,8 +969,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { if (iblockdata1 == null) { // CraftBukkit start - remove blockstate if failed (or the same) @@ -19366,7 +19524,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b } // CraftBukkit end return false; -@@ -979,7 +998,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -988,7 +1007,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { */ // CraftBukkit start @@ -19375,7 +19533,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b // Modularize client and physic updates // Spigot start try { -@@ -1029,7 +1048,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1038,7 +1057,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { iblockdata1.updateIndirectNeighbourShapes(this, blockposition, k, j - 1); // Don't call an event for the old block to limit event spam CraftWorld world = ((ServerLevel) this).getWorld(); boolean cancelledUpdates = false; // Paper - Fix block place logic @@ -19384,7 +19542,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata)); this.getCraftServer().getPluginManager().callEvent(event); -@@ -1043,7 +1062,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1052,7 +1071,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } // CraftBukkit start - SPIGOT-5710 @@ -19393,7 +19551,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b this.onBlockStateChange(blockposition, iblockdata1, iblockdata2); } // CraftBukkit end -@@ -1127,7 +1146,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1136,7 +1155,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @Override public void neighborShapeChanged(Direction direction, BlockState neighborState, BlockPos pos, BlockPos neighborPos, int flags, int maxUpdateDepth) { @@ -19402,7 +19560,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b } @Override -@@ -1152,11 +1171,34 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1161,11 +1180,34 @@ public abstract class Level implements LevelAccessor, AutoCloseable { return this.getChunkSource().getLightEngine(); } @@ -19439,7 +19597,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b if (previous != null) { return previous.getHandle(); } -@@ -1253,7 +1295,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1262,7 +1304,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } public void addBlockEntityTicker(TickingBlockEntity ticker) { @@ -19448,7 +19606,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b } protected void tickBlockEntities() { -@@ -1261,11 +1303,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1270,11 +1312,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable { gameprofilerfiller.push("blockEntities"); this.timings.tileEntityPending.startTiming(); // Spigot @@ -19464,7 +19622,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b this.timings.tileEntityPending.stopTiming(); // Spigot this.timings.tileEntityTick.startTiming(); // Spigot -@@ -1276,9 +1317,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1285,9 +1326,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { int tilesThisCycle = 0; var toRemove = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet(); // Paper - Fix MC-117075; use removeAll toRemove.add(null); // Paper - Fix MC-117075 @@ -19476,7 +19634,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b // Spigot end if (tickingblockentity.isRemoved()) { -@@ -1289,19 +1329,19 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1298,19 +1338,19 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } else if (flag && this.shouldTickBlocksAt(tickingblockentity.getPos())) { tickingblockentity.tick(); // Paper start - execute chunk tasks during tick @@ -19501,17 +19659,17 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b } public void guardEntityTick(Consumer tickConsumer, T entity) { -@@ -1314,7 +1354,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1323,7 +1363,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { final String msg = String.format("Entity threw exception at %s:%s,%s,%s", entity.level().getWorld().getName(), entity.getX(), entity.getY(), entity.getZ()); MinecraftServer.LOGGER.error(msg, throwable); getCraftServer().getPluginManager().callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerInternalException(msg, throwable))); // Paper - ServerExceptionEvent -- entity.discard(); -+ if (!(entity instanceof net.minecraft.server.level.ServerPlayer)) entity.discard(); // Folia - properly disconnect players +- entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD); ++ if (!(entity instanceof net.minecraft.server.level.ServerPlayer)) entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD); // Folia - properly disconnect players + if (entity instanceof net.minecraft.server.level.ServerPlayer player) player.connection.disconnect(net.minecraft.network.chat.Component.translatable("multiplayer.disconnect.generic"), org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN); // Folia - properly disconnect players // Paper end - Prevent block entity and entity crashes } } -@@ -1414,9 +1455,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1423,9 +1464,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @Nullable public BlockEntity getBlockEntity(BlockPos blockposition, boolean validate) { @@ -19527,7 +19685,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b return blockEntity; } // Paper end - Perf: Optimize capturedTileEntities lookup -@@ -1429,8 +1475,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1438,8 +1484,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { if (!this.isOutsideBuildHeight(blockposition)) { // CraftBukkit start @@ -19538,7 +19696,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b return; } // CraftBukkit end -@@ -1510,6 +1556,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1519,6 +1565,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @Override public List getEntities(@Nullable Entity except, AABB box, Predicate predicate) { @@ -19546,7 +19704,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b this.getProfiler().incrementCounter("getEntities"); List list = Lists.newArrayList(); ((ServerLevel)this).getEntityLookup().getEntities(except, box, list, predicate); // Paper - optimise this call -@@ -1529,6 +1576,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1538,6 +1585,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } public void getEntities(EntityTypeTest filter, AABB box, Predicate predicate, List result, int limit) { @@ -19554,7 +19712,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b this.getProfiler().incrementCounter("getEntities"); // Paper start - optimise this call //TODO use limit -@@ -1566,13 +1614,30 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1575,13 +1623,30 @@ public abstract class Level implements LevelAccessor, AutoCloseable { public void disconnect() {} @@ -19587,7 +19745,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b public boolean mayInteract(Player player, BlockPos pos) { return true; -@@ -1776,8 +1841,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1785,8 +1850,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } public final BlockPos.MutableBlockPos getRandomBlockPosition(int x, int y, int z, int l, BlockPos.MutableBlockPos out) { // Paper end @@ -19597,7 +19755,7 @@ index 19f23a6c8fb5c02843c27fb8a242ec9d0d1b538b..2b8674034979e3f8d45362f7cbae3c1b out.set(x + (i1 & 15), y + (i1 >> 16 & l), z + (i1 >> 8 & 15)); // Paper - change to setValues call return out; // Paper -@@ -1808,7 +1872,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1817,7 +1881,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @Override public long nextSubTickCount() { @@ -19834,6 +19992,19 @@ index 03b5ab8251497c0c94467f90e6663a0dc766babb..4fb595a8300ce2b163540603c7a2b002 return; } // CraftBukkit end +diff --git a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java +index 4ba24bced9a2de4616a0418857d3738e0e322ea0..afc9445941b984cc1122839e4a8a17cf27aa966e 100644 +--- a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java +@@ -64,7 +64,7 @@ public class EndPortalBlock extends BaseEntityBlock { + // Paper start - move all of this logic into portal tick + entity.portalWorld = ((ServerLevel)world); + entity.portalBlock = pos.immutable(); +- if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowUnsafeEndPortalTeleportation) { ++ if (false) { // Folia - region threading - synchronous teleports are not allowed + entity.tickEndPortal(); + } + // Paper end - move all of this logic into portal tick diff --git a/src/main/java/net/minecraft/world/level/block/FarmBlock.java b/src/main/java/net/minecraft/world/level/block/FarmBlock.java index 6e4c852c93f2418ea69e485ed3a10cbe3a6e3bd2..ab2b9b85b844cf3e6ef5a0379fa3279b85a7328c 100644 --- a/src/main/java/net/minecraft/world/level/block/FarmBlock.java @@ -19905,7 +20076,7 @@ index 1f27ae8abd5891a0b8057b454f2210b088b4e95a..a978a6130f5f6fdd1dab194e753cbe24 return true; } else { diff --git a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java -index b5a71fd4e2f55bf036c2c697da5d50cc90fc657c..1fd29331e928bc76de06d5eb5ba781390af76ebe 100644 +index b5a71fd4e2f55bf036c2c697da5d50cc90fc657c..7f33db05284a957690eac6eb6f5b3b05586727bb 100644 --- a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java +++ b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java @@ -69,7 +69,7 @@ public class RedStoneWireBlock extends Block { @@ -19988,12 +20159,15 @@ index b5a71fd4e2f55bf036c2c697da5d50cc90fc657c..1fd29331e928bc76de06d5eb5ba78139 int i = (Integer) state.getValue(RedStoneWireBlock.POWER); return i == 0 ? 0 : (direction != Direction.UP && !((RedstoneSide) this.getConnectionState(world, state, pos).getValue((Property) RedStoneWireBlock.PROPERTY_BY_DIRECTION.get(direction.getOpposite()))).isConnected() ? 0 : i); -@@ -584,7 +588,7 @@ public class RedStoneWireBlock extends Block { +@@ -584,7 +588,10 @@ public class RedStoneWireBlock extends Block { @Override public boolean isSignalSource(BlockState state) { - return this.shouldSignal; -+ return io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegionizedWorldData().shouldSignal; // Folia - region threading ++ // Folia start - region threading ++ io.papermc.paper.threadedregions.RegionizedWorldData worldData = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegionizedWorldData(); ++ return worldData == null || worldData.shouldSignal; ++ // Folia end - region threading } public static int getColorForPower(int powerLevel) { @@ -20236,10 +20410,45 @@ index 37e0b762b86e74f607a4541ecb7b24ad7a591d0e..4ddc3b3dc704610bf1fb7082e1c89a28 if (i % 40L == 0L) { diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java -index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7feede600 100644 +index cdb739df2a285032d25d84f4464f202a7a3fa578..82e7e76fecceb55522b5828a56f036e42ef55201 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java -@@ -233,12 +233,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -50,7 +50,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen + public static final int HOPPER_CONTAINER_SIZE = 5; + private NonNullList items; + public int cooldownTime; +- private long tickedGameTime; ++ private long tickedGameTime = Long.MIN_VALUE; // Folia - region threading + + // CraftBukkit start - add fields and methods + public List transaction = new java.util.ArrayList(); +@@ -82,6 +82,16 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen + } + // CraftBukkit end + ++ // Folia start - region threading ++ @Override ++ public void updateTicks(final long fromTickOffset, final long fromRedstoneTimeOffset) { ++ super.updateTicks(fromTickOffset, fromRedstoneTimeOffset); ++ if (this.tickedGameTime != Long.MIN_VALUE) { ++ this.tickedGameTime += fromRedstoneTimeOffset; ++ } ++ } ++ // Folia end - region threading ++ + public HopperBlockEntity(BlockPos pos, BlockState state) { + super(BlockEntityType.HOPPER, pos, state); + this.items = NonNullList.withSize(5, ItemStack.EMPTY); +@@ -137,7 +147,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen + + public static void pushItemsTick(Level world, BlockPos pos, BlockState state, HopperBlockEntity blockEntity) { + --blockEntity.cooldownTime; +- blockEntity.tickedGameTime = world.getGameTime(); ++ blockEntity.tickedGameTime = world.getRedstoneGameTime(); // Folia - region threading + if (!blockEntity.isOnCooldown()) { + blockEntity.setCooldown(0); + // Spigot start +@@ -234,12 +244,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen } // Paper start - Perf: Optimize Hoppers @@ -20255,7 +20464,7 @@ index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7 boolean foundItem = false; for (int i = 0; i < hopper.getContainerSize(); ++i) { final ItemStack item = hopper.getItem(i); -@@ -253,7 +252,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -254,7 +263,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen // We only need to fire the event once to give protection plugins a chance to cancel this event // Because nothing uses getItem, every event call should end up the same result. @@ -20264,7 +20473,7 @@ index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7 movedItem = callPushMoveEvent(destination, movedItem, hopper); if (movedItem == null) { // cancelled origItemStack.setCount(originalItemCount); -@@ -283,13 +282,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -284,13 +293,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen } private static boolean hopperPull(final Level level, final Hopper hopper, final Container container, ItemStack origItemStack, final int i) { @@ -20280,7 +20489,7 @@ index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7 movedItem = callPullMoveEvent(hopper, container, movedItem); if (movedItem == null) { // cancelled origItemStack.setCount(originalItemCount); -@@ -309,9 +309,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -310,9 +320,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen origItemStack.setCount(originalItemCount - movedItemCount + remainingItemCount); } @@ -20292,7 +20501,7 @@ index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7 container.setChanged(); return true; } -@@ -326,12 +326,13 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -327,12 +337,13 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @Nullable private static ItemStack callPushMoveEvent(Container iinventory, ItemStack itemstack, HopperBlockEntity hopper) { @@ -20307,7 +20516,7 @@ index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7 } if (!result) { cooldownHopper(hopper); -@@ -347,6 +348,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -348,6 +359,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @Nullable private static ItemStack callPullMoveEvent(final Hopper hopper, final Container container, final ItemStack itemstack) { @@ -20315,7 +20524,7 @@ index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7 final Inventory sourceInventory = getInventory(container); final Inventory destination = getInventory(hopper); -@@ -354,7 +356,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -355,7 +367,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen final io.papermc.paper.event.inventory.PaperInventoryMoveItemEvent event = new io.papermc.paper.event.inventory.PaperInventoryMoveItemEvent(sourceInventory, CraftItemStack.asCraftMirror(itemstack), destination, false); final boolean result = event.callEvent(); if (!event.calledGetItem && !event.calledSetItem) { @@ -20324,7 +20533,7 @@ index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7 } if (!result) { cooldownHopper(hopper); -@@ -517,13 +519,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -518,13 +530,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen } public static boolean suckInItems(Level world, Hopper hopper) { @@ -20340,7 +20549,7 @@ index a61d7cd2b078fe511ff00344197b6ea11feebfb2..26ff1a3d07c92f7035020d08d35116f7 // merge container isEmpty check and move logic into one loop if (iinventory instanceof WorldlyContainer worldlyContainer) { for (final int slot : worldlyContainer.getSlotsForFace(enumdirection)) { -@@ -723,9 +726,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -724,9 +737,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen stack = stack.split(to.getMaxStackSize()); } // Spigot end @@ -20369,10 +20578,10 @@ index 83481539e058e5f428d9951e409fed62ef159e5c..48260dce982181e2ee4e92614f8ed3af @Override diff --git a/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java -index d0e8842a2c4f7dbd0d6ac3694b2a6a5395d8a542..1a3be48e5636e80f5a5a5562e89b9f0e8070f889 100644 +index 098fde8200a11f91f934ddab6b1486dac4014dfe..412fa8a03be7215fa2695f07ac4f2334d1e70903 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java -@@ -50,9 +50,12 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity { +@@ -51,9 +51,12 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity { public long age; private int teleportCooldown; @Nullable @@ -20386,7 +20595,7 @@ index d0e8842a2c4f7dbd0d6ac3694b2a6a5395d8a542..1a3be48e5636e80f5a5a5562e89b9f0e public TheEndGatewayBlockEntity(BlockPos pos, BlockState state) { super(BlockEntityType.END_GATEWAY, pos, state); } -@@ -127,7 +130,7 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity { +@@ -121,7 +124,7 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity { } public static boolean canEntityTeleport(Entity entity) { @@ -20395,7 +20604,7 @@ index d0e8842a2c4f7dbd0d6ac3694b2a6a5395d8a542..1a3be48e5636e80f5a5a5562e89b9f0e } public boolean isSpawning() { -@@ -175,8 +178,136 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity { +@@ -169,8 +172,136 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity { } } @@ -20474,7 +20683,7 @@ index d0e8842a2c4f7dbd0d6ac3694b2a6a5395d8a542..1a3be48e5636e80f5a5a5562e89b9f0e + // to teleport the vehicle, rather just the owner given the lack of getRootVehicle + owner.unRide(); + chosenEntity = owner; -+ pearl.discard(); ++ pearl.discard(EntityRemoveEvent.Cause.HIT); + } else { + // see above for unRide() + pearl.unRide(); @@ -20532,7 +20741,7 @@ index d0e8842a2c4f7dbd0d6ac3694b2a6a5395d8a542..1a3be48e5636e80f5a5a5562e89b9f0e ServerLevel worldserver = (ServerLevel) world; blockEntity.teleportCooldown = 100; -@@ -280,6 +411,129 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity { +@@ -275,6 +406,129 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity { return TheEndGatewayBlockEntity.findTallestBlock(world, blockposition1, 16, true); } @@ -20752,11 +20961,45 @@ index 8cb822fed0cda4268f288feae1079a3dc4dc103e..3f53d51960ded5df3b8be12362110f22 } // CraftBukkit end +diff --git a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java +index be74adc86f0ca467f3b59e7b57fd47a8f381d86e..363a712d6b9e717b075aa52643c6cf91497e7c3b 100644 +--- a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java +@@ -152,7 +152,7 @@ public class PistonBaseBlock extends DirectionalBlock { + if (tileentity instanceof PistonMovingBlockEntity) { + PistonMovingBlockEntity tileentitypiston = (PistonMovingBlockEntity) tileentity; + +- if (tileentitypiston.isExtending() && (tileentitypiston.getProgress(0.0F) < 0.5F || world.getGameTime() == tileentitypiston.getLastTicked() || ((ServerLevel) world).isHandlingTick())) { ++ if (tileentitypiston.isExtending() && (tileentitypiston.getProgress(0.0F) < 0.5F || world.getRedstoneGameTime() == tileentitypiston.getLastTicked() || ((ServerLevel) world).isHandlingTick())) { // Folia - region threading + b0 = 2; + } + } 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..1c23597f172f46eec714b510acfedb415bb01bff 100644 +index c71690dbc3dc52803945f1608f0ee3ba94146354..1955b660907c5d6b5ca4bf7741f8d568b9255347 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 -@@ -144,8 +144,8 @@ public class PistonMovingBlockEntity extends BlockEntity { +@@ -41,9 +41,19 @@ public class PistonMovingBlockEntity extends BlockEntity { + }); + private float progress; + private float progressO; +- private long lastTicked; ++ private long lastTicked = Long.MIN_VALUE; // Folia - region threading + private int deathTicks; + ++ // Folia start - region threading ++ @Override ++ public void updateTicks(long fromTickOffset, long fromRedstoneTimeOffset) { ++ super.updateTicks(fromTickOffset, fromRedstoneTimeOffset); ++ if (this.lastTicked != Long.MIN_VALUE) { ++ this.lastTicked += fromRedstoneTimeOffset; ++ } ++ } ++ // Folia end - region threading ++ + public PistonMovingBlockEntity(BlockPos pos, BlockState state) { + super(BlockEntityType.PISTON, pos, state); + } +@@ -144,8 +154,8 @@ public class PistonMovingBlockEntity extends BlockEntity { entity.setDeltaMovement(e, g, h); // Paper - EAR items stuck in in slime pushed by a piston @@ -20767,6 +21010,15 @@ index c71690dbc3dc52803945f1608f0ee3ba94146354..1c23597f172f46eec714b510acfedb41 // Paper end break; } +@@ -277,7 +287,7 @@ public class PistonMovingBlockEntity extends BlockEntity { + } + + public static void tick(Level world, BlockPos pos, BlockState state, PistonMovingBlockEntity blockEntity) { +- blockEntity.lastTicked = world.getGameTime(); ++ blockEntity.lastTicked = world.getRedstoneGameTime(); // Folia - region threading + blockEntity.progressO = blockEntity.progress; + if (blockEntity.progressO >= 1.0F) { + if (world.isClientSide && blockEntity.deathTicks < 5) { diff --git a/src/main/java/net/minecraft/world/level/border/WorldBorder.java b/src/main/java/net/minecraft/world/level/border/WorldBorder.java index 350aabd20329f429248c84d73ab8b5eb145943a7..bdb864f5e7a1bacde88be632442c9de000ce7729 100644 --- a/src/main/java/net/minecraft/world/level/border/WorldBorder.java @@ -20810,7 +21062,7 @@ index b8b78494449c0cd638f9706a803dc54e184d981f..b31f1e0522ff18fa5853af6104d46f98 return true; } else { diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java -index 6ec3fc801453fd54c25b642e6fa71c19b463311d..852fef18497435827a03e0056a09e5deb2525ed9 100644 +index 465458e8a7dbaf9afb32709a71c7b2620d1e1fd2..ff1a7b78fa010857daab7a306cb9483c98560b79 100644 --- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java @@ -59,6 +59,13 @@ public class LevelChunk extends ChunkAccess { @@ -20920,7 +21172,7 @@ index d53c4f3d47a8728d56fbd9b5e12be51885560d52..ecffd7fb1c7686479bd04ae9e391b69f nbt.put("block_ticks", tickSchedulers.blocks().save(i, (block) -> { return BuiltInRegistries.BLOCK.getKey(block).toString(); diff --git a/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java b/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java -index 7e9c502a7bcda445333adc250a3106f33d38c128..2a56d59daf8c57770cbd15d3103a666ec4d5aaa0 100644 +index d4f903c402765c6e8e1db99e148613748f530726..9568ec33e2b0efdb536930edb44d46e082b86152 100644 --- a/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java +++ b/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java @@ -76,7 +76,7 @@ public class EndDragonFight { @@ -21568,7 +21820,7 @@ index 1d7c663fa0e550bd0cfb9a4b83ccd7e2968666f0..f3df9c9b6cff85565514f990597f3fe5 LevelChunkTicks levelChunkTicks = this.allContainers.get(l); if (levelChunkTicks == null) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index c4144c239a5d91bc0faec84fe49829337aa339dc..a4e47391105366e52b949f39ba4a1ebed94b2188 100644 +index b63effd92be5a8a75db6c37e5a1b91541020ec75..350fc61fd709453a86c9f7f6e4bccc434065cc35 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -309,7 +309,7 @@ public final class CraftServer implements Server { @@ -21650,7 +21902,7 @@ index c4144c239a5d91bc0faec84fe49829337aa339dc..a4e47391105366e52b949f39ba4a1ebe if (this.commandMap.dispatch(sender, commandLine)) { return true; } -@@ -3219,7 +3262,7 @@ public final class CraftServer implements Server { +@@ -3234,7 +3277,7 @@ public final class CraftServer implements Server { @Override public int getCurrentTick() { @@ -21660,10 +21912,10 @@ index c4144c239a5d91bc0faec84fe49829337aa339dc..a4e47391105366e52b949f39ba4a1ebe @Override diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1ac7d84381 100644 +index 01797d9791f19dfda4b168218eadeaae97f11eab..becb3b07876715d7c39ba4e7289cc5ac85f84412 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -@@ -192,7 +192,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -193,7 +193,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public int getTickableTileEntityCount() { @@ -21672,7 +21924,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a } @Override -@@ -254,7 +254,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -255,7 +255,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { // Paper start - per world spawn limits for (SpawnCategory spawnCategory : SpawnCategory.values()) { if (CraftSpawnCategory.isValidForLimits(spawnCategory)) { @@ -21681,7 +21933,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a } } // Paper end - per world spawn limits -@@ -341,6 +341,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -342,6 +342,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public Chunk getChunkAt(int x, int z) { @@ -21689,7 +21941,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a warnUnsafeChunk("getting a faraway chunk", x, z); // Paper // Paper start - add ticket to hold chunk for a little while longer if plugin accesses it net.minecraft.world.level.chunk.LevelChunk chunk = this.world.getChunkSource().getChunkAtIfLoadedImmediately(x, z); -@@ -364,7 +365,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -365,7 +366,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { // Paper start private void addTicket(int x, int z) { @@ -21698,7 +21950,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a } // Paper end -@@ -383,10 +384,10 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -384,10 +385,10 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean isChunkGenerated(int x, int z) { // Paper start - Fix this method @@ -21711,7 +21963,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a } ChunkAccess chunk = world.getChunkSource().getChunkAtImmediately(x, z); if (chunk == null) { -@@ -440,7 +441,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -441,7 +442,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { } private boolean unloadChunk0(int x, int z, boolean save) { @@ -21720,7 +21972,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a if (!this.isChunkLoaded(x, z)) { return true; } -@@ -455,7 +456,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -456,7 +457,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean regenerateChunk(int x, int z) { @@ -21729,7 +21981,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a warnUnsafeChunk("regenerating a faraway chunk", x, z); // Paper // Paper start - implement regenerateChunk method final ServerLevel serverLevel = this.world; -@@ -518,6 +519,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -519,6 +520,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean refreshChunk(int x, int z) { @@ -21737,7 +21989,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a ChunkHolder playerChunk = this.world.getChunkSource().chunkMap.getVisibleChunkIfPresent(ChunkPos.asLong(x, z)); if (playerChunk == null) return false; -@@ -553,7 +555,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -554,7 +556,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean loadChunk(int x, int z, boolean generate) { @@ -21746,7 +21998,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a warnUnsafeChunk("loading a faraway chunk", x, z); // Paper // Paper start - Optimize this method ChunkPos chunkPos = new ChunkPos(x, z); -@@ -622,7 +624,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -623,7 +625,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { DistanceManager chunkDistanceManager = this.world.getChunkSource().chunkMap.distanceManager; if (chunkDistanceManager.addRegionTicketAtDistance(TicketType.PLUGIN_TICKET, new ChunkPos(x, z), 2, plugin)) { // keep in-line with force loading, add at level 31 @@ -21755,7 +22007,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a return true; } -@@ -813,13 +815,15 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -833,13 +835,15 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { @@ -21776,7 +22028,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a BlockPos position = ((CraftBlockState) blockstate).getPosition(); net.minecraft.world.level.block.state.BlockState oldBlock = this.world.getBlockState(position); int flag = ((CraftBlockState) blockstate).getFlag(); -@@ -827,10 +831,10 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -847,10 +851,10 @@ public class CraftWorld extends CraftRegionAccessor implements World { net.minecraft.world.level.block.state.BlockState newBlock = this.world.getBlockState(position); this.world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, newBlock, flag, 512); } @@ -21789,7 +22041,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a return false; } } -@@ -864,6 +868,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -884,6 +888,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setTime(long time) { @@ -21797,7 +22049,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a long margin = (time - this.getFullTime()) % 24000; if (margin < 0) margin += 24000; this.setFullTime(this.getFullTime() + margin); -@@ -876,6 +881,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -896,6 +901,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setFullTime(long time) { @@ -21805,7 +22057,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a // Notify anyone who's listening TimeSkipEvent event = new TimeSkipEvent(this, TimeSkipEvent.SkipReason.CUSTOM, time - this.world.getDayTime()); this.server.getPluginManager().callEvent(event); -@@ -903,7 +909,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -923,7 +929,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public long getGameTime() { @@ -21814,7 +22066,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a } @Override -@@ -923,11 +929,13 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -943,11 +949,13 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks, Entity source) { @@ -21828,7 +22080,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a return !world.explode(source != null ? ((org.bukkit.craftbukkit.entity.CraftEntity) source).getHandle() : null, loc.getX(), loc.getY(), loc.getZ(), power, setFire, breakBlocks ? net.minecraft.world.level.Level.ExplosionInteraction.MOB : net.minecraft.world.level.Level.ExplosionInteraction.NONE).wasCanceled; } // Paper end -@@ -1004,6 +1012,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1024,6 +1032,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public int getHighestBlockYAt(int x, int z, org.bukkit.HeightMap heightMap) { @@ -21836,7 +22088,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a warnUnsafeChunk("getting a faraway chunk", x >> 4, z >> 4); // Paper // Transient load for this tick return this.world.getChunk(x >> 4, z >> 4).getHeight(CraftHeightMap.toNMS(heightMap), x, z); -@@ -1034,6 +1043,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1054,6 +1063,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setBiome(int x, int y, int z, Holder bb) { BlockPos pos = new BlockPos(x, 0, z); @@ -21844,7 +22096,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a if (this.world.hasChunkAt(pos)) { net.minecraft.world.level.chunk.LevelChunk chunk = this.world.getChunkAt(pos); -@@ -1344,6 +1354,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1364,6 +1374,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setStorm(boolean hasStorm) { @@ -21852,7 +22104,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.world.serverLevelData.setRaining(hasStorm, org.bukkit.event.weather.WeatherChangeEvent.Cause.PLUGIN); // Paper - Add cause to Weather/ThunderChangeEvents this.setWeatherDuration(0); // Reset weather duration (legacy behaviour) this.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands) -@@ -1356,6 +1367,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1376,6 +1387,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setWeatherDuration(int duration) { @@ -21860,7 +22112,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.world.serverLevelData.setRainTime(duration); } -@@ -1366,6 +1378,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1386,6 +1398,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setThundering(boolean thundering) { @@ -21868,7 +22120,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.world.serverLevelData.setThundering(thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause.PLUGIN); // Paper - Add cause to Weather/ThunderChangeEvents this.setThunderDuration(0); // Reset weather duration (legacy behaviour) this.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands) -@@ -1378,6 +1391,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1398,6 +1411,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setThunderDuration(int duration) { @@ -21876,7 +22128,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.world.serverLevelData.setThunderTime(duration); } -@@ -1388,6 +1402,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1408,6 +1422,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setClearWeatherDuration(int duration) { @@ -21884,7 +22136,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.world.serverLevelData.setClearWeatherTime(duration); } -@@ -1582,6 +1597,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1602,6 +1617,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setKeepSpawnInMemory(boolean keepLoaded) { @@ -21892,7 +22144,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a // Paper start - Configurable spawn radius if (keepLoaded == this.world.keepSpawnInMemory) { // do nothing, nothing has changed -@@ -1660,6 +1676,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1680,6 +1696,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setHardcore(boolean hardcore) { @@ -21900,7 +22152,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.world.serverLevelData.settings.hardcore = hardcore; } -@@ -1672,6 +1689,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1692,6 +1709,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setTicksPerAnimalSpawns(int ticksPerAnimalSpawns) { @@ -21908,7 +22160,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setTicksPerSpawns(SpawnCategory.ANIMAL, ticksPerAnimalSpawns); } -@@ -1684,6 +1702,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1704,6 +1722,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setTicksPerMonsterSpawns(int ticksPerMonsterSpawns) { @@ -21916,7 +22168,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setTicksPerSpawns(SpawnCategory.MONSTER, ticksPerMonsterSpawns); } -@@ -1696,6 +1715,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1716,6 +1735,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setTicksPerWaterSpawns(int ticksPerWaterSpawns) { @@ -21924,7 +22176,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setTicksPerSpawns(SpawnCategory.WATER_ANIMAL, ticksPerWaterSpawns); } -@@ -1708,6 +1728,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1728,6 +1748,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setTicksPerWaterAmbientSpawns(int ticksPerWaterAmbientSpawns) { @@ -21932,7 +22184,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setTicksPerSpawns(SpawnCategory.WATER_AMBIENT, ticksPerWaterAmbientSpawns); } -@@ -1720,6 +1741,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1740,6 +1761,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setTicksPerWaterUndergroundCreatureSpawns(int ticksPerWaterUndergroundCreatureSpawns) { @@ -21940,7 +22192,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setTicksPerSpawns(SpawnCategory.WATER_UNDERGROUND_CREATURE, ticksPerWaterUndergroundCreatureSpawns); } -@@ -1732,11 +1754,13 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1752,11 +1774,13 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setTicksPerAmbientSpawns(int ticksPerAmbientSpawns) { @@ -21954,7 +22206,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a Preconditions.checkArgument(spawnCategory != null, "SpawnCategory cannot be null"); Preconditions.checkArgument(CraftSpawnCategory.isValidForLimits(spawnCategory), "SpawnCategory.%s are not supported", spawnCategory); -@@ -1753,21 +1777,25 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1773,21 +1797,25 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setMetadata(String metadataKey, MetadataValue newMetadataValue) { @@ -21980,7 +22232,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.server.getWorldMetadata().removeMetadata(this, metadataKey, owningPlugin); } -@@ -1780,6 +1808,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1800,6 +1828,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setMonsterSpawnLimit(int limit) { @@ -21988,7 +22240,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setSpawnLimit(SpawnCategory.MONSTER, limit); } -@@ -1792,6 +1821,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1812,6 +1841,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setAnimalSpawnLimit(int limit) { @@ -21996,7 +22248,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setSpawnLimit(SpawnCategory.ANIMAL, limit); } -@@ -1804,6 +1834,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1824,6 +1854,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setWaterAnimalSpawnLimit(int limit) { @@ -22004,7 +22256,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setSpawnLimit(SpawnCategory.WATER_ANIMAL, limit); } -@@ -1816,6 +1847,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1836,6 +1867,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setWaterAmbientSpawnLimit(int limit) { @@ -22012,7 +22264,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setSpawnLimit(SpawnCategory.WATER_AMBIENT, limit); } -@@ -1828,6 +1860,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1848,6 +1880,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setWaterUndergroundCreatureSpawnLimit(int limit) { @@ -22020,7 +22272,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setSpawnLimit(SpawnCategory.WATER_UNDERGROUND_CREATURE, limit); } -@@ -1840,6 +1873,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1860,6 +1893,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override @Deprecated public void setAmbientSpawnLimit(int limit) { @@ -22028,7 +22280,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a this.setSpawnLimit(SpawnCategory.AMBIENT, limit); } -@@ -1862,6 +1896,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1882,6 +1916,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setSpawnLimit(SpawnCategory spawnCategory, int limit) { @@ -22036,7 +22288,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a Preconditions.checkArgument(spawnCategory != null, "SpawnCategory cannot be null"); Preconditions.checkArgument(CraftSpawnCategory.isValidForLimits(spawnCategory), "SpawnCategory.%s are not supported", spawnCategory); -@@ -1944,7 +1979,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1964,7 +1999,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return; ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed); @@ -22045,7 +22297,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a if (entityTracker != null) { entityTracker.broadcastAndSend(packet); } -@@ -1956,7 +1991,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1976,7 +2011,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return; ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(Holder.direct(SoundEvent.createVariableRangeEvent(new ResourceLocation(sound))), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed); @@ -22054,7 +22306,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a if (entityTracker != null) { entityTracker.broadcastAndSend(packet); } -@@ -2045,6 +2080,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -2065,6 +2100,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean setGameRuleValue(String rule, String value) { @@ -22062,7 +22314,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a // No null values allowed if (rule == null || value == null) return false; -@@ -2087,6 +2123,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -2107,6 +2143,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean setGameRule(GameRule rule, T newValue) { @@ -22070,7 +22322,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a Preconditions.checkArgument(rule != null, "GameRule cannot be null"); Preconditions.checkArgument(newValue != null, "GameRule value cannot be null"); -@@ -2339,6 +2376,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -2359,6 +2396,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void sendGameEvent(Entity sourceEntity, org.bukkit.GameEvent gameEvent, Vector position) { @@ -22083,7 +22335,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a 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 -@@ -2459,7 +2502,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -2479,7 +2522,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 @@ -22092,7 +22344,7 @@ index bfb178c69026e9759e9afaebb9da141b62d1f144..379c10e791a961d25d7de571f81ace1a 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)); -@@ -2476,7 +2519,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -2496,7 +2539,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) -> { @@ -22307,7 +22559,7 @@ index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..b451b9df3233355fb16092edc3a4dd63 net.minecraft.server.level.ServerLevel level = this.world.getMinecraftWorld(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java -index d11d854ae90b99aa2ce227994d07fe1fe9b4a60a..6a6d95dcad917dd60b47236a130bcd2c9425a529 100644 +index 2cfaa59a0bb6b5253b5a8dcc38ae65e0f085fd3f..5cf33427847068fc589ada9f731b985f791ac013 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -210,6 +210,12 @@ public class CraftBlockState implements BlockState { @@ -22323,16 +22575,16 @@ index d11d854ae90b99aa2ce227994d07fe1fe9b4a60a..6a6d95dcad917dd60b47236a130bcd2c if (block.getType() != this.getType()) { if (!force) { return false; -@@ -350,6 +356,9 @@ public class CraftBlockState implements BlockState { +@@ -340,6 +346,9 @@ public class CraftBlockState implements BlockState { @Override public java.util.Collection getDrops(org.bukkit.inventory.ItemStack item, org.bukkit.entity.Entity entity) { + // Folia start - region threading + io.papermc.paper.util.TickThread.ensureTickThread(world.getHandle(), position, "Cannot modify world asynchronously"); + // Folia end - region threading + this.requirePlaced(); net.minecraft.world.item.ItemStack nms = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(item); - // Modelled off EntityHuman#hasBlock diff --git a/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java b/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java index 3e93a6c489972ff2b4ecff3d83cc72b2d5c970f8..66dc7e20544c7000f4824b02cc3a31bc5c87f74c 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/ConsoleCommandCompleter.java @@ -22356,10 +22608,10 @@ index 3e93a6c489972ff2b4ecff3d83cc72b2d5c970f8..66dc7e20544c7000f4824b02cc3a31bc List offers = waitable.get(); if (offers == null) { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java -index 8698104e3eb98e2cc5da5de87a8f538860c1d91d..ac91fe913b4f6a6148955e7181e5abda13f15820 100644 +index e8e4489bcd64fde1b3226bdc7a7cc612508bda3f..1cfe604573000fa9b32237313aa467875a891f3c 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java -@@ -233,6 +233,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { +@@ -234,6 +234,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { @Override public boolean teleport(Location location, TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) { @@ -22371,7 +22623,7 @@ index 8698104e3eb98e2cc5da5de87a8f538860c1d91d..ac91fe913b4f6a6148955e7181e5abda // Paper end Preconditions.checkArgument(location != null, "location cannot be null"); location.checkFinite(); -@@ -699,7 +704,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { +@@ -700,7 +705,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { ImmutableSet.Builder players = ImmutableSet.builder(); ServerLevel world = ((CraftWorld) this.getWorld()).getHandle(); @@ -22380,7 +22632,7 @@ index 8698104e3eb98e2cc5da5de87a8f538860c1d91d..ac91fe913b4f6a6148955e7181e5abda if (entityTracker != null) { for (ServerPlayerConnection connection : entityTracker.seenBy) { -@@ -993,7 +998,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { +@@ -994,7 +999,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { } ServerLevel world = ((CraftWorld) this.getWorld()).getHandle(); @@ -22389,42 +22641,41 @@ index 8698104e3eb98e2cc5da5de87a8f538860c1d91d..ac91fe913b4f6a6148955e7181e5abda if (entityTracker == null) { return; -@@ -1061,30 +1066,43 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { - Preconditions.checkArgument(location != null, "location"); +@@ -1032,29 +1037,43 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { location.checkFinite(); Location locationClone = location.clone(); // clone so we don't need to worry about mutations after this call. -- + - net.minecraft.server.level.ServerLevel world = ((CraftWorld)locationClone.getWorld()).getHandle(); + // Folia start - region threading java.util.concurrent.CompletableFuture ret = new java.util.concurrent.CompletableFuture<>(); - - world.loadChunksForMoveAsync(getHandle().getBoundingBoxAt(locationClone.getX(), locationClone.getY(), locationClone.getZ()), - this instanceof CraftPlayer ? ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.HIGHER : ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.NORMAL, (list) -> { -- net.minecraft.server.level.ServerChunkCache chunkProviderServer = world.getChunkSource(); -- for (net.minecraft.world.level.chunk.ChunkAccess chunk : list) { -- chunkProviderServer.addTicketAtLevel(net.minecraft.server.level.TicketType.POST_TELEPORT, chunk.getPos(), 33, CraftEntity.this.getEntityId()); -- } -- net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> { -- try { -- ret.complete(CraftEntity.this.teleport(locationClone, cause) ? Boolean.TRUE : Boolean.FALSE); -- } catch (Throwable throwable) { -- if (throwable instanceof ThreadDeath) { -- throw (ThreadDeath)throwable; -- } -- net.minecraft.server.MinecraftServer.LOGGER.error("Failed to teleport entity " + CraftEntity.this, throwable); -- ret.completeExceptionally(throwable); +- net.minecraft.server.level.ServerChunkCache chunkProviderServer = world.getChunkSource(); +- for (net.minecraft.world.level.chunk.ChunkAccess chunk : list) { +- chunkProviderServer.addTicketAtLevel(net.minecraft.server.level.TicketType.POST_TELEPORT, chunk.getPos(), 33, CraftEntity.this.getEntityId()); + java.util.function.Consumer run = (Entity nmsEntity) -> { + boolean success = nmsEntity.teleportAsync( + ((CraftWorld)locationClone.getWorld()).getHandle(), + new net.minecraft.world.phys.Vec3(locationClone.getX(), locationClone.getY(), locationClone.getZ()), + locationClone.getYaw(), locationClone.getPitch(), net.minecraft.world.phys.Vec3.ZERO, + cause == null ? TeleportCause.UNKNOWN : cause, -+ Entity.TELEPORT_FLAG_LOAD_CHUNK | Entity.TELEPORT_FLAG_UNMOUNT, // preserve behavior with old API: dismount the entity so it can teleport ++ Entity.TELEPORT_FLAG_LOAD_CHUNK | Entity.TELEPORT_FLAG_TELEPORT_PASSENGERS, // preserve behavior with old API: dismount the entity so it can teleport + (Entity entityTp) -> { + ret.complete(Boolean.TRUE); } +- net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> { +- try { +- ret.complete(CraftEntity.this.teleport(locationClone, cause, teleportFlags) ? Boolean.TRUE : Boolean.FALSE); +- } catch (Throwable throwable) { +- if (throwable instanceof ThreadDeath) { +- throw (ThreadDeath)throwable; +- } +- net.minecraft.server.MinecraftServer.LOGGER.error("Failed to teleport entity " + CraftEntity.this, throwable); +- ret.completeExceptionally(throwable); +- } +- }); - }); -- }); + ); + if (!success) { + ret.complete(Boolean.FALSE); @@ -22436,7 +22687,7 @@ index 8698104e3eb98e2cc5da5de87a8f538860c1d91d..ac91fe913b4f6a6148955e7181e5abda + } + boolean scheduled = this.taskScheduler.schedule( + // success -+ run, ++ run, + // retired + (Entity nmsEntity) -> { + ret.complete(Boolean.FALSE); @@ -22451,10 +22702,10 @@ index 8698104e3eb98e2cc5da5de87a8f538860c1d91d..ac91fe913b4f6a6148955e7181e5abda return ret; + // Folia end - region threading } + // Paper end - more teleport API / async chunk API - @Override diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -index 206520f6f20b2e48b1eefdd4edb26510b88e4c92..3d47913cb590463b636cbdc052fb54778951ba61 100644 +index e77bf7f432387bdfa7f69d31b014e8cd254fd4ca..8db8ceb161557b9803c3bda80f3e57b8626191c3 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 { @@ -22497,10 +22748,10 @@ index 206520f6f20b2e48b1eefdd4edb26510b88e4c92..3d47913cb590463b636cbdc052fb5477 entry.updatePlayer(this.getHandle()); } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java -index d677759ac6b6d3cfe5a2af76dc1f0034b216ac2d..1c5c9d6f36a8bc4e9e4de8ddd2e17ff73ada8cca 100644 +index c0823c612de9dc2a64cc797f061eef25c5f31359..ccab0ec21a6827475d97654f1b54c166ccb99085 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java -@@ -941,7 +941,7 @@ public class CraftEventFactory { +@@ -943,7 +943,7 @@ public class CraftEventFactory { return CraftEventFactory.handleBlockSpreadEvent(world, source, target, block, 2); } @@ -22509,7 +22760,7 @@ index d677759ac6b6d3cfe5a2af76dc1f0034b216ac2d..1c5c9d6f36a8bc4e9e4de8ddd2e17ff7 public static boolean handleBlockSpreadEvent(LevelAccessor world, BlockPos source, BlockPos target, net.minecraft.world.level.block.state.BlockState block, int flag) { // Suppress during worldgen -@@ -953,7 +953,7 @@ public class CraftEventFactory { +@@ -955,7 +955,7 @@ public class CraftEventFactory { CraftBlockState state = CraftBlockStates.getBlockState(world, target, flag); state.setData(block); @@ -22518,7 +22769,7 @@ index d677759ac6b6d3cfe5a2af76dc1f0034b216ac2d..1c5c9d6f36a8bc4e9e4de8ddd2e17ff7 Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { -@@ -2126,7 +2126,7 @@ public class CraftEventFactory { +@@ -2146,7 +2146,7 @@ public class CraftEventFactory { CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemStack.copyWithCount(1)); org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(bukkitBlock, craftItem.clone(), CraftVector.toBukkit(to)); @@ -22540,7 +22791,7 @@ index e85b9bb3f9c225d289a4959921970b9963881199..b00e3b9b628f3d2a2fdbf1d2c7790496 if (!this.isAsyncScheduler && !task.isSync()) { this.asyncScheduler.handle(task, delay); diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 1324f05de8106032ce290e928cf106fb4f450517..20178003ee9a0314266d4fc6a589e9d509a25072 100644 +index 3c7a771c48cc2732cc038ca11bb93ec5f8c2d667..d365e26799822f39af2d5a27761bb8b41308297e 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -382,6 +382,12 @@ public final class CraftMagicNumbers implements UnsafeValues { @@ -22575,7 +22826,7 @@ index 86a20c91beff6b27e6ec886e49ba902b216106f2..96007426144b78f91c12614f04350855 return this.handle; } diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java -index c39894e824334f1dc52e0466cf9d84f7e219be70..f8718d91f4c15c74d6e6dd5f60f7f05f45f63655 100644 +index 3283ed99c35ffed6805567705e0518d9f84feedc..4fc4690d03fd5f39e019f16845954052210c7361 100644 --- a/src/main/java/org/spigotmc/ActivationRange.java +++ b/src/main/java/org/spigotmc/ActivationRange.java @@ -52,7 +52,7 @@ public class ActivationRange @@ -22633,7 +22884,7 @@ index c39894e824334f1dc52e0466cf9d84f7e219be70..f8718d91f4c15c74d6e6dd5f60f7f05f /** * Initializes an entities type on construction to specify what group this -@@ -174,10 +175,11 @@ public class ActivationRange +@@ -176,10 +177,11 @@ public class ActivationRange final int waterActivationRange = world.spigotConfig.waterActivationRange; final int flyingActivationRange = world.spigotConfig.flyingMonsterActivationRange; final int villagerActivationRange = world.spigotConfig.villagerActivationRange; @@ -22649,7 +22900,7 @@ index c39894e824334f1dc52e0466cf9d84f7e219be70..f8718d91f4c15c74d6e6dd5f60f7f05f final ServerChunkCache chunkProvider = (ServerChunkCache) world.getChunkSource(); // Paper end -@@ -191,9 +193,9 @@ public class ActivationRange +@@ -193,9 +195,9 @@ public class ActivationRange // Paper end maxRange = Math.min( ( world.spigotConfig.simulationDistance << 4 ) - 8, maxRange ); @@ -22661,7 +22912,7 @@ index c39894e824334f1dc52e0466cf9d84f7e219be70..f8718d91f4c15c74d6e6dd5f60f7f05f if ( world.spigotConfig.ignoreSpectatorActivation && player.isSpectator() ) { continue; -@@ -201,26 +203,33 @@ public class ActivationRange +@@ -203,26 +205,33 @@ public class ActivationRange // Paper start int worldHeight = world.getHeight(); @@ -22705,7 +22956,7 @@ index c39894e824334f1dc52e0466cf9d84f7e219be70..f8718d91f4c15c74d6e6dd5f60f7f05f } // Paper end } -@@ -232,18 +241,18 @@ public class ActivationRange +@@ -234,18 +243,18 @@ public class ActivationRange * * @param chunk */ @@ -22729,7 +22980,7 @@ index c39894e824334f1dc52e0466cf9d84f7e219be70..f8718d91f4c15c74d6e6dd5f60f7f05f } } } -@@ -266,10 +275,10 @@ public class ActivationRange +@@ -268,10 +277,10 @@ public class ActivationRange if (entity.getRemainingFireTicks() > 0) { return 2; } @@ -22742,7 +22993,7 @@ index c39894e824334f1dc52e0466cf9d84f7e219be70..f8718d91f4c15c74d6e6dd5f60f7f05f // Paper end // quick checks. if ( (entity.activationType != ActivationType.WATER && entity.wasTouchingWater && entity.isPushedByFluid()) ) // Paper -@@ -392,19 +401,19 @@ public class ActivationRange +@@ -394,19 +403,19 @@ public class ActivationRange } // Paper end diff --git a/patches/server/0004-Max-pending-logins.patch b/patches/server/0004-Max-pending-logins.patch index 2aa79fe32e..4008a6e3c8 100644 --- a/patches/server/0004-Max-pending-logins.patch +++ b/patches/server/0004-Max-pending-logins.patch @@ -19,10 +19,10 @@ index 58cdb65083134680230d7070f9f6209f2d32873b..aa4b461bbb2c8c4753f7c9057bab1740 if (this.state == ServerLoginPacketListenerImpl.State.WAITING_FOR_DUPE_DISCONNECT && !this.isPlayerAlreadyInWorld((GameProfile) Objects.requireNonNull(this.authenticatedProfile))) { diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index fa36e892b019877a770a618fe8d4cda118fe137d..93e192ea1a0cda2d7aae983980a6fead013c8b90 100644 +index 08daa5ed0b4b599836b97eef1e53e630e7659443..a390227e5af1232f2090d2be72f7789805025f76 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java -@@ -171,6 +171,17 @@ public abstract class PlayerList { +@@ -173,6 +173,17 @@ public abstract class PlayerList { conflictingId = this.connectionById.get(byId); if (conflictingName == null && conflictingId == null) { 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 157b36bc28..96453f2080 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,10 +29,10 @@ 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 b8e77755a1706e60e9dfa1310aa2449ee0dbc6ad..0725386d7ef47171012671725ceddfe92b43b203 100644 +index 518487d4cd489110bebcf75078935a95b5d3e9cf..1119b6a7f307763c13ef48bcd7643539082aebdc 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -2911,6 +2911,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -2930,6 +2930,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) { return false; } else { @@ -40,7 +40,7 @@ index b8e77755a1706e60e9dfa1310aa2449ee0dbc6ad..0725386d7ef47171012671725ceddfe9 // CraftBukkit start if (entity.getBukkitEntity() instanceof Vehicle && this.getBukkitEntity() instanceof LivingEntity) { VehicleEnterEvent event = new VehicleEnterEvent((Vehicle) entity.getBukkitEntity(), this.getBukkitEntity()); -@@ -2932,6 +2933,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -2951,6 +2952,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S return false; } // CraftBukkit end @@ -48,7 +48,7 @@ index b8e77755a1706e60e9dfa1310aa2449ee0dbc6ad..0725386d7ef47171012671725ceddfe9 if (this.isPassenger()) { this.stopRiding(); } -@@ -3009,6 +3011,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3028,6 +3030,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)"); } else { // CraftBukkit start @@ -56,7 +56,7 @@ index b8e77755a1706e60e9dfa1310aa2449ee0dbc6ad..0725386d7ef47171012671725ceddfe9 CraftEntity craft = (CraftEntity) entity.getBukkitEntity().getVehicle(); Entity orig = craft == null ? null : craft.getHandle(); if (this.getBukkitEntity() instanceof Vehicle && entity.getBukkitEntity() instanceof LivingEntity) { -@@ -3036,6 +3039,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3055,6 +3058,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S return false; } // CraftBukkit end @@ -288,10 +288,10 @@ index ccda0d7a96c201905f0f62dcb0e5b278a51dee9f..3ba6c46e0f5bc5f6b5994d41aaa9c4dd } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java -index 6d2fe30742f8b41d53dd2cbff120fcc042ea0e0c..ed236cf2b405d954e69390c6f6fa4e79369058ee 100644 +index 0fd2677181d741e553b9825c8c319a209194ec46..a3a5c77b264a40911ddcee9b8c593fd07b3041d7 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java -@@ -142,8 +142,16 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow { +@@ -135,6 +135,13 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow { this.getHandle().setShotFromCrossbow(shotFromCrossbow); } @@ -302,6 +302,11 @@ index 6d2fe30742f8b41d53dd2cbff120fcc042ea0e0c..ed236cf2b405d954e69390c6f6fa4e79 + } + // Folia end - region threading + + @Override + public ItemStack getItem() { + return CraftItemStack.asBukkitCopy(this.getHandle().pickupItemStack); +@@ -149,6 +156,7 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow { + @Override public net.minecraft.world.entity.projectile.AbstractArrow getHandle() { + io.papermc.paper.util.TickThread.ensureTickThread(this.entity, "Accessing entity state off owning region's thread"); // Folia - region threading @@ -897,10 +902,10 @@ index d657fd2c507a5b215aeab0a5f3e9c2ee892a27c8..9fc90b162aab15a9cd60b02aba563181 } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java -index ac91fe913b4f6a6148955e7181e5abda13f15820..5adbfb278aed3c32b6d4992b8932cc3dafd8f9cc 100644 +index 1cfe604573000fa9b32237313aa467875a891f3c..8c7e01972888df4ccbaccc4eebceeeb5ab357f4c 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java -@@ -490,7 +490,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { +@@ -491,7 +491,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { @Override public UUID getUniqueId() { @@ -909,7 +914,7 @@ index ac91fe913b4f6a6148955e7181e5abda13f15820..5adbfb278aed3c32b6d4992b8932cc3d } @Override -@@ -505,6 +505,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { +@@ -506,6 +506,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { } public Entity getHandle() { @@ -1002,12 +1007,12 @@ index 1359d25a32b4a5d5e8e68ce737bd19f7b5afaf69..0be7f84a50b7568d0c639f5906b5ca76 } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java -index 1d8aab2fda18c6e2bb30f6ba4a6325263267b628..61ad4e93c01ccdae9cdf4efb08f43959af9aafc4 100644 +index a8699b274b51c5f6691557c3c3db88436f05e304..45e900cd12c5615149c99a5dc85e8f78edb5483b 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java -@@ -58,8 +58,16 @@ public class CraftFireball extends AbstractProjectile implements Fireball { +@@ -60,8 +60,16 @@ public class CraftFireball extends AbstractProjectile implements Fireball { } - // Paper end - set direction without normalizing + // Paper end - Expose power on fireball projectiles + // Folia start - region threading + @Override @@ -1359,10 +1364,10 @@ index 8746f80d08df5501b32958eb123aa7d814573ddf..c6c6eb55f4649e18beef9832c2ea7b9d } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java -index acbb64010cd59668aa1bcb52ff1220789cadb1d3..35958bb85389ca0ed02f567e0fd9f4a9dbc66ff2 100644 +index 7984365c8290ac9e526a413b56e1c8c0841e330c..0c468a1324996137eba5d1927d38a39859b705f0 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java -@@ -291,8 +291,16 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { +@@ -292,8 +292,16 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { this.mode = mode; } @@ -1464,7 +1469,7 @@ index 63cae1a2e95d8da17c45c4404a8dd0ca6a413c39..f57139f03da9519802ee156f37691d08 } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java -index 832def3c518be8d6d81e71f6022566e6179e2d17..725e016dcd8177dcee0f0e1bd345c985fc1e95af 100644 +index 30d62ee4d5cd2ddacb8783b5bbbf475d592b3e02..c78498010a01b7d4c0b5c7350a11d0e1cf8ab013 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java @@ -18,8 +18,16 @@ public class CraftItem extends CraftEntity implements Item { @@ -1590,10 +1595,10 @@ index e9f471e60af0725ec34e2985d63ae9ea9f88590a..6a443f42ecec16abea3ddf7bc2e85bb8 } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java -index f1e4dfd203d455ec089cd2b5679c4083400dbc7f..6abb7ee0f5d32613b2ff7da09810ae407e293838 100644 +index c4a166a0c226c6083c25c58145d9631d4296e615..ee1d3f33cf5f3cfc7909dbc33178df69bd656ab8 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java -@@ -454,6 +454,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { +@@ -470,6 +470,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { this.getHandle().invulnerableTime = ticks; } @@ -1607,7 +1612,7 @@ index f1e4dfd203d455ec089cd2b5679c4083400dbc7f..6abb7ee0f5d32613b2ff7da09810ae40 @Override public int getNoActionTicks() { return this.getHandle().getNoActionTime(); -@@ -467,6 +474,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { +@@ -483,6 +490,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @Override public net.minecraft.world.entity.LivingEntity getHandle() { @@ -1878,7 +1883,7 @@ index 706c74c832f6893df3797023f68add31139c7d57..80a612f16669e571e336dd6369a968b4 } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java -index 1d78ae1db211a452a42fb4a7bef4cca4b7c71a1f..e4e8d7561036ab04d069cfe54f1fba61b478c5d8 100644 +index 983e0cdbd1bd950807967a36cba49859fb956f31..7dc7e382d63cd5c42bb0ef72d4766d24be99c3a6 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java @@ -19,6 +19,13 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm @@ -1895,7 +1900,7 @@ index 1d78ae1db211a452a42fb4a7bef4cca4b7c71a1f..e4e8d7561036ab04d069cfe54f1fba61 @Override public boolean hasEffectsForNextStew() { return this.getHandle().stewEffects != null && !this.getHandle().stewEffects.isEmpty(); -@@ -74,6 +81,7 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm +@@ -100,6 +107,7 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm @Override public net.minecraft.world.entity.animal.MushroomCow getHandle() { @@ -2135,7 +2140,7 @@ 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 3d47913cb590463b636cbdc052fb54778951ba61..8fc071a6249193af5e1795cc19f50996ea22d96f 100644 +index 8db8ceb161557b9803c3bda80f3e57b8626191c3..b0a70287ff1fc9b3d5eba322d949aaf510b165d2 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 { @@ -2147,7 +2152,7 @@ index 3d47913cb590463b636cbdc052fb54778951ba61..8fc071a6249193af5e1795cc19f50996 final ServerGamePacketListenerImpl connection = this.getHandle().connection; if (connection != null) { connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message, cause); -@@ -2209,9 +2209,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -2207,9 +2207,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return this; } @@ -2165,7 +2170,7 @@ index 3d47913cb590463b636cbdc052fb54778951ba61..8fc071a6249193af5e1795cc19f50996 } public void setHandle(final ServerPlayer entity) { -@@ -3266,7 +3273,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -3264,7 +3271,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 a13e934424..b1562a1086 100644 --- a/patches/server/0007-Disable-mid-tick-task-execution.patch +++ b/patches/server/0007-Disable-mid-tick-task-execution.patch @@ -10,10 +10,10 @@ 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 11eb550cba3a8eee1deb2f00e5514863e255ea07..39cbb724820a07778191b0421c9ded6a9af1ad04 100644 +index cf06989ad1ab55bf6836abe4cdeed2fff31ac93f..82b18aebb7c1472efdadc4b2e959fbdb3116fbe3 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1466,6 +1466,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0 && io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() % autosavePeriod == 0; // Folia - region threading @@ -1424,7 +1424,7 @@ index 39cbb724820a07778191b0421c9ded6a9af1ad04..3ec07e77748ee9bb21f9d09230f935bc try { this.isSaving = true; if (playerSaveInterval > 0) { -@@ -1661,6 +1672,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { // Folia - region threading entityplayer.connection.suspendFlushing(); -@@ -1791,12 +1804,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { // Paper - Ensure main @@ -1790,7 +1790,7 @@ index b19f1db38e71d9185cca9fc0e44937f91443a042..d13edeff0de64cb77d7668e5b964cabc MinecraftTimings.savePlayers.startTiming(); // Paper int numSaved = 0; long now = System.nanoTime(); // Folia - region threading -@@ -1338,7 +1339,9 @@ public abstract class PlayerList { +@@ -1346,7 +1347,9 @@ public abstract class PlayerList { } // Folia end - region threading if (interval == -1 || now - entityplayer.lastSave >= timeInterval) { // Folia - region threading @@ -1832,10 +1832,10 @@ index 09e8445a3f8c6b3ebc852a75a9a25b41a51ba659..f921c159c4f7556daf3c8405241de360 this.factory = factory; this.category = spawnGroup; diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java -index de7c06785e3914fe7181bcb836b70a96a4900011..bc38893427cbe560ffea30996a391b7ba97f9d5c 100644 +index 38ff839aa25fa2b7397f6fc6e3eadda7ae600d48..3cd8573db9dadb2e32f3c107f4812b525db014b1 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java -@@ -223,6 +223,9 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -232,6 +232,9 @@ public abstract class Level implements LevelAccessor, AutoCloseable { return this.getCurrentWorldData().getLocalPlayers(); } // Folia end - region ticking @@ -1845,7 +1845,7 @@ index de7c06785e3914fe7181bcb836b70a96a4900011..bc38893427cbe560ffea30996a391b7b protected Level(WritableLevelData worlddatamutable, ResourceKey resourcekey, RegistryAccess iregistrycustom, Holder holder, Supplier supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function paperWorldConfigCreator, java.util.concurrent.Executor executor) { // Paper - create paper world config; Async-Anti-Xray: Pass executor this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot -@@ -315,6 +318,9 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -324,6 +327,9 @@ public abstract class Level implements LevelAccessor, AutoCloseable { this.minSection = io.papermc.paper.util.WorldUtil.getMinSection(this); this.maxSection = io.papermc.paper.util.WorldUtil.getMaxSection(this); // Paper end - optimise collisions @@ -1855,7 +1855,7 @@ index de7c06785e3914fe7181bcb836b70a96a4900011..bc38893427cbe560ffea30996a391b7b } // Paper start - Cancel hit for vanished players -@@ -1299,17 +1305,21 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1308,17 +1314,21 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } protected void tickBlockEntities() { @@ -1877,7 +1877,7 @@ index de7c06785e3914fe7181bcb836b70a96a4900011..bc38893427cbe560ffea30996a391b7b // Spigot start // Iterator iterator = this.blockEntityTickers.iterator(); boolean flag = this.tickRateManager().runsNormally(); -@@ -1336,6 +1346,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1345,6 +1355,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } } blockEntityTickers.removeAll(toRemove); // Paper - Fix MC-117075 // Folia - regionised ticking @@ -1923,7 +1923,7 @@ index 2e110da3502a7ac5ec4cc20510a3fac933569895..5aac65f37a0190c5d6a7175073fb0cc0 } } diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java -index 852fef18497435827a03e0056a09e5deb2525ed9..4847f7caa9147a63f85a86c1c45500f45ff48fbb 100644 +index ff1a7b78fa010857daab7a306cb9483c98560b79..8c6ade7cf14e367d6390849ef1b2a1bfef0d52ac 100644 --- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java @@ -1181,11 +1181,14 @@ public class LevelChunk extends ChunkAccess { @@ -1941,9 +1941,9 @@ index 852fef18497435827a03e0056a09e5deb2525ed9..4847f7caa9147a63f85a86c1c45500f4 BlockState iblockdata = LevelChunk.this.getBlockState(blockposition); if (this.blockEntity.getType().isValid(iblockdata)) { -@@ -1195,6 +1198,7 @@ public class LevelChunk extends ChunkAccess { - this.loggedInvalidBlockState = true; - LevelChunk.LOGGER.warn("Block entity {} @ {} state {} invalid for ticking:", new Object[]{LogUtils.defer(this::getType), LogUtils.defer(this::getPos), iblockdata}); +@@ -1200,6 +1203,7 @@ public class LevelChunk extends ChunkAccess { + } + // Paper end - Remove the Block Entity if it's invalid } + } finally { profiler.stopTimer(timerId); } // Folia - profiler diff --git a/patches/server/0019-Fix-entity-tracker-desync-when-new-players-are-added.patch b/patches/server/0019-Fix-entity-tracker-desync-when-new-players-are-added.patch index 8d75f69318..9f59fd1e7d 100644 --- a/patches/server/0019-Fix-entity-tracker-desync-when-new-players-are-added.patch +++ b/patches/server/0019-Fix-entity-tracker-desync-when-new-players-are-added.patch @@ -21,7 +21,7 @@ added to the tracker is just easier to do, so that is what this patch does. diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java -index 21ec49acb3c1241d9286959c42a7f8363f637e4f..79e507c1463dbb9039b1fed8bdf41c0ee5f4fec3 100644 +index 30aa7891292da87092724e0e046a08e500dd22ca..6ab9f83786dcfbd3156d2f2bd6da57baed1399f4 100644 --- a/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java @@ -1419,6 +1419,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider diff --git a/settings.gradle.kts b/settings.gradle.kts index 74161b75aa..11560c7048 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,7 +8,7 @@ pluginManagement { } plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" } if (!file(".git").exists()) {