diff --git a/patches/server/0019-Recode-DirtyFolia.patch b/patches/server/0019-Recode-DirtyFolia.patch index 1be19fdac1..01f01722ac 100644 --- a/patches/server/0019-Recode-DirtyFolia.patch +++ b/patches/server/0019-Recode-DirtyFolia.patch @@ -1148,7 +1148,7 @@ index fa35d2c1c8de225acd68e08f15976c92f7ab82aa..bc4e1db0e00e564122418f155f35298a } diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java -index f636bdf1075fa784ce7ee25478d4d94bacb05677..125526a6ba4230c7b252c5a7df83ce4c7d9d5371 100644 +index 17d6349ccdbb6ac91b2705be0b855e768423c50a..98670b79944a6c7e4fc62783511945e26f44391c 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -864,7 +864,7 @@ public abstract class LivingEntity extends Entity implements Attackable { @@ -1161,7 +1161,7 @@ index f636bdf1075fa784ce7ee25478d4d94bacb05677..125526a6ba4230c7b252c5a7df83ce4c PlayerTeam scoreboardteam = this.level().getScoreboard().getPlayerTeam(s); if (!this.level().paperConfig().scoreboards.allowNonPlayerEntitiesOnScoreboards && !(this instanceof net.minecraft.world.entity.player.Player)) { scoreboardteam = null; } // Paper diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java -index 4338b948a53d32cac5c780cbd43c6ca1cc5d11e5..449ee90a97f01e7794c96d989b84ff91268a7d84 100644 +index 916df0c8d263f90e04564c5f512fd5ed5eaaa6d5..d3641216339a94f28aa5e2ec576971134949b311 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -15,6 +15,8 @@ import java.util.function.Consumer; @@ -2282,7 +2282,7 @@ index 61f7630d2160411f35cc3ca33def30b9cea65408..be0d22f81e3267747926ddeca0f0dfd1 } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java -index ab53eab269b204a59b2c9a9bef4f6cf4098e0dfd..0a477d8e90a3804800083ae9ba927a4304b67cbc 100644 +index d2ab898c0f3902f5f0f9847232dac244b4095854..aa3d17b4cc2fa2f13d0dad5b3b544370b67d7394 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -437,7 +437,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { diff --git a/patches/server/0023-Removed-some-checks-and-fix-getTickCount.patch b/patches/server/0023-Removed-some-checks-and-fix-getTickCount.patch index 375641e7b8..902556fc81 100644 --- a/patches/server/0023-Removed-some-checks-and-fix-getTickCount.patch +++ b/patches/server/0023-Removed-some-checks-and-fix-getTickCount.patch @@ -5573,7 +5573,7 @@ index bc4e1db0e00e564122418f155f35298a7c18c746..af07c9d24374b7d969f1e524ce0bbb26 // CraftBukkit end // Paper start - fix bad state entities causing dupes diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java -index 125526a6ba4230c7b252c5a7df83ce4c7d9d5371..ec9589650527d4ffd3cef4613ab3bb0898bda1fd 100644 +index 98670b79944a6c7e4fc62783511945e26f44391c..0215dd0e802708d9818d3946e3e7abe5c3b0bf1c 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -1144,7 +1144,7 @@ public abstract class LivingEntity extends Entity implements Attackable { @@ -5619,7 +5619,7 @@ index 19cb22df8eb29d1708e3da2124de3b43378b575a..c75640198642b594be7779d8edff62b1 if ("Searge".equalsIgnoreCase(this.command)) { this.lastOutput = Component.literal("#itzlipofutzli"); diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java -index 449ee90a97f01e7794c96d989b84ff91268a7d84..9e0d086c5fd8094b0c5cb377c5521711881f09b2 100644 +index d3641216339a94f28aa5e2ec576971134949b311..c12d57b2956efa15c22e7d1cdbd74a1c518c169c 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -1,44 +1,27 @@ @@ -5725,7 +5725,7 @@ index 449ee90a97f01e7794c96d989b84ff91268a7d84..9e0d086c5fd8094b0c5cb377c5521711 // CraftBukkit end public abstract class Level implements LevelAccessor, AutoCloseable { -@@ -1152,7 +1127,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1236,7 +1211,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @Override public List getEntities(@Nullable Entity except, AABB box, Predicate predicate) { @@ -5734,7 +5734,7 @@ index 449ee90a97f01e7794c96d989b84ff91268a7d84..9e0d086c5fd8094b0c5cb377c5521711 this.getProfiler().incrementCounter("getEntities"); List list = Lists.newArrayList(); ((ServerLevel)this).getEntityLookup().getEntities(except, box, list, predicate); // Paper - optimise this call -@@ -1172,7 +1147,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { +@@ -1256,7 +1231,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } public void getEntities(EntityTypeTest filter, AABB box, Predicate predicate, List result, int limit) { diff --git a/patches/server/0031-Cache-world-data-when-it-not-null.patch b/patches/server/0031-Cache-world-data-when-it-not-null.patch index 9ded4cd1de..f46a0f60ed 100644 --- a/patches/server/0031-Cache-world-data-when-it-not-null.patch +++ b/patches/server/0031-Cache-world-data-when-it-not-null.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Cache world data when it not null diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java -index 9e0d086c5fd8094b0c5cb377c5521711881f09b2..bb0e11bd907a062dbfd977fe3c792c2e8299586a 100644 +index c12d57b2956efa15c22e7d1cdbd74a1c518c169c..acf4994aec33fe25e67a5d620154d1f2f097a0d1 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -254,6 +254,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { diff --git a/patches/server/0036-Force-check-thread-for-including-classes.patch b/patches/server/0036-Force-check-thread-for-including-classes.patch index 329b86ea83..258655c960 100644 --- a/patches/server/0036-Force-check-thread-for-including-classes.patch +++ b/patches/server/0036-Force-check-thread-for-including-classes.patch @@ -108,7 +108,7 @@ index f0b7d802951d901c23d221a7787bfddfd28f3a56..53ea21e04529a6f2cabfaa5c46b1d39d // Paper end worldserver.timings.doTick.stopTiming(); // Spigot diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java -index bb0e11bd907a062dbfd977fe3c792c2e8299586a..486b580746ca086430548f4f2c44af00e373bd94 100644 +index acf4994aec33fe25e67a5d620154d1f2f097a0d1..739a849b1ec94a9b1541a887c99cde6961d2e4d5 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -250,12 +250,21 @@ public abstract class Level implements LevelAccessor, AutoCloseable { diff --git a/patches/server/0038-Try-resolve-high-cpu-problem.patch b/patches/server/0038-Try-resolve-high-cpu-problem.patch index 521c0fec54..8792c76b50 100644 --- a/patches/server/0038-Try-resolve-high-cpu-problem.patch +++ b/patches/server/0038-Try-resolve-high-cpu-problem.patch @@ -52,7 +52,7 @@ index 0358f7d026c3fd519b9871515f55b1965f43fd93..77ea6cf7b702675e89aab67d4d9994c9 // Folia end - region threading diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java -index 486b580746ca086430548f4f2c44af00e373bd94..9bef693f40c2b6b73e9f35307742f809268c3803 100644 +index 739a849b1ec94a9b1541a887c99cde6961d2e4d5..db03ecdd5ba2a9ec256247bc4a3915e2f0678557 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -262,8 +262,6 @@ public abstract class Level implements LevelAccessor, AutoCloseable { diff --git a/patches/server/0049-Remove-wrong-code-optimize-performance.patch b/patches/server/0049-Remove-wrong-code-optimize-performance.patch new file mode 100644 index 0000000000..49615870f9 --- /dev/null +++ b/patches/server/0049-Remove-wrong-code-optimize-performance.patch @@ -0,0 +1,172 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: killerprojecte +Date: Sat, 30 Sep 2023 21:14:22 +0800 +Subject: [PATCH] Remove wrong code & optimize performance + + +diff --git a/src/main/java/dev/rgbmc/folia/CachedRegionData.java b/src/main/java/dev/rgbmc/folia/CachedRegionData.java +index 3d8431243d64e490d5c7c54a4a98a3e94fea58b3..a452393f824261973e2fa9be322d1587c1e2455a 100644 +--- a/src/main/java/dev/rgbmc/folia/CachedRegionData.java ++++ b/src/main/java/dev/rgbmc/folia/CachedRegionData.java +@@ -1,39 +1,15 @@ + package dev.rgbmc.folia; + +-import io.papermc.paper.threadedregions.RegionizedWorldData; + import io.papermc.paper.threadedregions.ThreadedRegionizer; + import io.papermc.paper.threadedregions.TickRegions; ++import net.minecraft.server.level.ChunkLevel; ++import net.minecraft.world.level.chunk.LevelChunk; + + import java.util.HashMap; + import java.util.Map; + + public class CachedRegionData { +- private static final Map> cachedData = new HashMap<>(); +- private static final Map> worldCachedData = new HashMap<>(); +- +- public static void update(long id, ThreadedRegionizer.ThreadedRegion data) { +- cachedData.put(id, data); +- } +- +- public static void updateWorld(String world, ThreadedRegionizer.ThreadedRegion data) { +- worldCachedData.put(world, data); +- } +- +- public static boolean isCached(long id) { +- return cachedData.containsKey(id); +- } +- +- public static boolean isCachedWorld(String world) { +- return worldCachedData.containsKey(world); ++ public static ThreadedRegionizer.ThreadedRegion get(LevelChunk chunk) { ++ return chunk.level.regioniser.getRegionAtUnsynchronised(chunk.locX << 4, chunk.locZ << 4); + } +- +- public static ThreadedRegionizer.ThreadedRegion get(long id) { +- return cachedData.get(id); +- } +- +- public static ThreadedRegionizer.ThreadedRegion getWorld(String world) { +- return worldCachedData.get(world); +- } +- +- + } +diff --git a/src/main/java/dev/rgbmc/folia/CachedWorldData.java b/src/main/java/dev/rgbmc/folia/CachedWorldData.java +index 85515235d59669db0dc189438af85759c3f3b81e..0b1d17a57e097563325242ec6a7b96cdc126182c 100644 +--- a/src/main/java/dev/rgbmc/folia/CachedWorldData.java ++++ b/src/main/java/dev/rgbmc/folia/CachedWorldData.java +@@ -1,19 +1,20 @@ + package dev.rgbmc.folia; + + import io.papermc.paper.threadedregions.RegionizedWorldData; ++import net.minecraft.server.level.ServerLevel; ++import net.minecraft.world.level.Level; + + import java.util.HashMap; + import java.util.Map; + import java.util.concurrent.CompletableFuture; + + public class CachedWorldData { +- private static final Map cachedData = new HashMap<>(); +- +- public static void update(String world, RegionizedWorldData data) { +- cachedData.put(world, data); ++ private static final Map dataMap = new HashMap<>(); ++ public static RegionizedWorldData get(String world) { ++ return dataMap.get(world); + } + +- public static RegionizedWorldData get(String world) { +- return cachedData.get(world); ++ public static void set(ServerLevel level, RegionizedWorldData data) { ++ dataMap.put(level.serverLevelData.getLevelName(), data); + } + } +diff --git a/src/main/java/io/papermc/paper/threadedregions/RegionizedData.java b/src/main/java/io/papermc/paper/threadedregions/RegionizedData.java +index 1f48ada99d6d24880f9bda1cd05d41a4562e42f5..2e2a938b13e418d5c71d2fd8d2a68e26f53f1b1b 100644 +--- a/src/main/java/io/papermc/paper/threadedregions/RegionizedData.java ++++ b/src/main/java/io/papermc/paper/threadedregions/RegionizedData.java +@@ -126,7 +126,13 @@ public final class RegionizedData { + } + + T createNewValue() { +- return Validate.notNull(this.initialValueSupplier.get(), "Initial value supplier may not return null"); ++ // DirtyFolia - Start ++ T value = this.initialValueSupplier.get(); ++ if (value != null) { ++ if (value instanceof io.papermc.paper.threadedregions.RegionizedWorldData data) dev.rgbmc.folia.CachedWorldData.set(world, data); ++ } ++ // DirtyFolia - End ++ return Validate.notNull(value, "Initial value supplier may not return null"); + } + + RegioniserCallback getCallback() { +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 0829ed685ba3bccc844edc57f306b3e8835d7e21..c10ffd23653bc93e91db3d42e836492c16e04421 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -1454,10 +1454,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { // Folia (Third Party) +- CachedWorldData.update(region.world.serverLevelData.getLevelName(), worldserver.getCurrentWorldData()); +- }); + // Paper end + worldserver.timings.doTick.stopTiming(); // Spigot + } catch (Throwable throwable) { +diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +index 1dee8d897981b56d243f74caba3c82873f204672..c36c65a7def8b067badbe71a4308d8c44c079ef0 100644 +--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java ++++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +@@ -4,7 +4,6 @@ import com.google.common.annotations.VisibleForTesting; + import com.google.common.collect.Lists; + import com.mojang.datafixers.DataFixer; + import com.mojang.datafixers.util.Either; +-import dev.rgbmc.folia.CachedRegionData; + import io.papermc.paper.threadedregions.*; + import net.minecraft.Util; + import net.minecraft.core.BlockPos; +@@ -840,14 +839,9 @@ public class ServerChunkCache extends ChunkSource { + } + // DirtyFolia + ThreadedRegionizer.ThreadedRegion data = TickRegionScheduler.getCurrentRegion(); +- if (data != null && CachedRegionData.isCached(data.id)) { +- CachedRegionData.update(data.id, data); +- if (!CachedRegionData.isCachedWorld(ServerChunkCache.this.level.serverLevelData.getLevelName())) { +- CachedRegionData.updateWorld(ServerChunkCache.this.level.serverLevelData.getLevelName(), data); +- } +- } else if (data == null) { +- return CachedRegionData.getWorld(ServerChunkCache.this.level.serverLevelData.getLevelName()).getData().getTaskQueueData().executeChunkTask(); +- } ++ //if (data == null) { ++ // return data.getData().getTaskQueueData().executeChunkTask(); ++ //} + return data.getData().getTaskQueueData().executeChunkTask(); // Paper - rewrite chunk system // Folia - region threading + } + } +diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java +index db03ecdd5ba2a9ec256247bc4a3915e2f0678557..b3797c444aa649b2774e439af7f1bde1f860abf1 100644 +--- a/src/main/java/net/minecraft/world/level/Level.java ++++ b/src/main/java/net/minecraft/world/level/Level.java +@@ -255,7 +255,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { + if (this instanceof ServerLevel serverLevel) { + return CachedWorldData.get(serverLevel.serverLevelData.getLevelName()); + } +- return ret; // DirtyFolia - cache world data ++ return null; // DirtyFolia - cache world data + } + Level world = ret.world; + if (world != this) {