-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cac9b0f
commit 0429830
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |