mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-04 15:41:31 +00:00
64 lines
3.2 KiB
Diff
64 lines
3.2 KiB
Diff
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/net/minecraft/world/level/block/FireBlock.java b/net/minecraft/world/level/block/FireBlock.java
|
|
index c03ad7be16fbb9f98c28bc09de59bf33d4edf5d7..8c0b2eb643ccaaa921a90dc2963ce4abcede854d 100644
|
|
--- a/net/minecraft/world/level/block/FireBlock.java
|
|
+++ b/net/minecraft/world/level/block/FireBlock.java
|
|
@@ -205,6 +205,7 @@ public class FireBlock extends BaseFireBlock {
|
|
this.checkBurnOut(level, pos.south(), 300 + i, random, ageValue, pos);
|
|
// CraftBukkit end
|
|
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
|
+ Object2IntOpenHashMap<BlockPos> blockPositionIgniteCache = new Object2IntOpenHashMap<>(); // Leaves - cache ignite odds
|
|
|
|
for (int i1 = -1; i1 <= 1; i1++) {
|
|
for (int i2 = -1; i2 <= 1; i2++) {
|
|
@@ -216,7 +217,7 @@ public class FireBlock extends BaseFireBlock {
|
|
}
|
|
|
|
mutableBlockPos.setWithOffset(pos, i1, i3, i2);
|
|
- int igniteOdds = this.getIgniteOdds(level, mutableBlockPos);
|
|
+ int igniteOdds = this.getIgniteOdds(level, mutableBlockPos, org.leavesmc.leaves.LeavesConfig.performance.cacheIgniteOdds ? blockPositionIgniteCache : null); // Leaves - cache ignite odds
|
|
if (igniteOdds > 0) {
|
|
int i5 = (igniteOdds + 40 + level.getDifficulty().getId() * 7) / (ageValue + 30);
|
|
if (isIncreasedFireBurnout) {
|
|
@@ -319,20 +320,33 @@ public class FireBlock extends BaseFireBlock {
|
|
return false;
|
|
}
|
|
|
|
+ // Leaves start - cache ignite odds
|
|
private int getIgniteOdds(LevelReader level, BlockPos pos) {
|
|
+ return getIgniteOdds(level, pos, null);
|
|
+ }
|
|
+
|
|
+ private int getIgniteOdds(LevelReader level, BlockPos pos, @org.jetbrains.annotations.Nullable Object2IntOpenHashMap<BlockPos> cache) {
|
|
if (!level.isEmptyBlock(pos)) {
|
|
return 0;
|
|
} else {
|
|
int i = 0;
|
|
|
|
for (Direction direction : Direction.values()) {
|
|
- BlockState blockState = level.getBlockState(pos.relative(direction));
|
|
- i = Math.max(this.getIgniteOdds(blockState), i);
|
|
+ if (cache != null) {
|
|
+ i = Math.max(cache.computeIfAbsent(pos, key -> {
|
|
+ BlockState blockState = level.getBlockState(pos.relative(direction));
|
|
+ return this.getIgniteOdds(blockState);
|
|
+ }), i);
|
|
+ } else {
|
|
+ BlockState blockState = level.getBlockState(pos.relative(direction));
|
|
+ i = Math.max(this.getIgniteOdds(blockState), i);
|
|
+ }
|
|
}
|
|
|
|
return i;
|
|
}
|
|
}
|
|
+ // Leaves end - cache ignite odds
|
|
|
|
@Override
|
|
protected boolean canBurn(BlockState state) {
|