Skip to content

Commit

Permalink
Cache ignite odds
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 5, 2023
1 parent cac9b0f commit 0429830
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
9 changes: 7 additions & 2 deletions patches/server/0004-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
64 changes: 64 additions & 0 deletions patches/server/0080-Cache-ignite-odds.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <[email protected]>
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<BlockPos> 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<BlockPos> 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;

0 comments on commit 0429830

Please sign in to comment.