From 04298301c1c4d4cc5bad1fccbef837cf51e6a553 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Wed, 5 Jul 2023 17:43:45 +0800 Subject: [PATCH] Cache ignite odds --- ...004-Leaves-Server-Config-And-Command.patch | 9 ++- patches/server/0080-Cache-ignite-odds.patch | 64 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 patches/server/0080-Cache-ignite-odds.patch diff --git a/patches/server/0004-Leaves-Server-Config-And-Command.patch b/patches/server/0004-Leaves-Server-Config-And-Command.patch index 0402071a..f3bfff3a 100644 --- a/patches/server/0004-Leaves-Server-Config-And-Command.patch +++ b/patches/server/0004-Leaves-Server-Config-And-Command.patch @@ -128,10 +128,10 @@ index a53514f2c510b29f596c361de7bc0b405c27e964..269c7ba0707db4fdc45a70000e0be892 .withRequiredArg() diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java new file mode 100644 -index 0000000000000000000000000000000000000000..5873e0c0c41aea52abc7795f49f7a97f613fa1a4 +index 0000000000000000000000000000000000000000..cf9f2097abbfe6050b91301b2807feed7f697b71 --- /dev/null +++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java -@@ -0,0 +1,797 @@ +@@ -0,0 +1,802 @@ +package top.leavesmc.leaves; + +import com.destroystokyo.paper.util.SneakyThrow; @@ -754,6 +754,11 @@ index 0000000000000000000000000000000000000000..5873e0c0c41aea52abc7795f49f7a97f + fixPaper9372 = getBoolean("settings.performance.fix.fix-paper-9372", fixPaper9372); + } + ++ public static boolean cacheIgniteOdds = true; ++ private static void cacheIgniteOdds() { ++ cacheIgniteOdds = getBoolean("settings.performance.cache-ignite-odds", cacheIgniteOdds); ++ } ++ + public static final class WorldConfig { + + public final String worldName; diff --git a/patches/server/0080-Cache-ignite-odds.patch b/patches/server/0080-Cache-ignite-odds.patch new file mode 100644 index 00000000..0461e2aa --- /dev/null +++ b/patches/server/0080-Cache-ignite-odds.patch @@ -0,0 +1,64 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: violetc <58360096+s-yh-china@users.noreply.github.com> +Date: Wed, 5 Jul 2023 17:42:24 +0800 +Subject: [PATCH] Cache ignite odds + + +diff --git a/src/main/java/net/minecraft/world/level/block/FireBlock.java b/src/main/java/net/minecraft/world/level/block/FireBlock.java +index 4002e0fffb60556e7af1aeff71b4be244f02b0f5..8fc696d806aa3f4af313f145397ec497e186def2 100644 +--- a/src/main/java/net/minecraft/world/level/block/FireBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/FireBlock.java +@@ -214,6 +214,7 @@ public class FireBlock extends BaseFireBlock { + this.trySpread(world, pos.south(), 300 + k, random, i, pos); + // CraftBukkit end + BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos(); ++ Object2IntOpenHashMap blockPositionIgniteCache = new Object2IntOpenHashMap<>(); // Leaves - cache ignite odds + + for (int l = -1; l <= 1; ++l) { + for (int i1 = -1; i1 <= 1; ++i1) { +@@ -226,7 +227,7 @@ public class FireBlock extends BaseFireBlock { + } + + blockposition_mutableblockposition.setWithOffset(pos, l, j1, i1); +- int l1 = this.getIgniteOdds(world, blockposition_mutableblockposition); ++ int l1 = this.getIgniteOdds(world, blockposition_mutableblockposition, top.leavesmc.leaves.LeavesConfig.cacheIgniteOdds ? blockPositionIgniteCache : null); // Leaves - cache ignite odds + + if (l1 > 0) { + int i2 = (l1 + 40 + world.getDifficulty().getId() * 7) / (i + 30); +@@ -338,6 +339,11 @@ public class FireBlock extends BaseFireBlock { + } + + private int getIgniteOdds(LevelReader world, BlockPos pos) { ++ // Leaves start - cache ignite odds ++ return getIgniteOdds(world, pos, null); ++ } ++ ++ private int getIgniteOdds(LevelReader world, BlockPos pos, Object2IntOpenHashMap cache) { + if (!world.isEmptyBlock(pos)) { + return 0; + } else { +@@ -346,10 +352,20 @@ public class FireBlock extends BaseFireBlock { + int j = aenumdirection.length; + + for (int k = 0; k < j; ++k) { +- Direction enumdirection = aenumdirection[k]; +- BlockState iblockdata = world.getBlockState(pos.relative(enumdirection)); +- +- i = Math.max(this.getIgniteOdds(iblockdata), i); ++ if (cache != null) { ++ int finalK = k; ++ i = Math.max(cache.computeIfAbsent(pos, key -> { ++ Direction enumdirection = aenumdirection[finalK]; ++ BlockState iblockdata = world.getBlockState(pos.relative(enumdirection)); ++ return this.getIgniteOdds(iblockdata); ++ }), i); ++ } else { ++ Direction enumdirection = aenumdirection[k]; ++ BlockState iblockdata = world.getBlockState(pos.relative(enumdirection)); ++ ++ i = Math.max(this.getIgniteOdds(iblockdata), i); ++ } ++ // Leaves end - cache ignite odds + } + + return i;