Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit cdf06ce

Browse files
committed
Optimize fluid spreading by caching fluid state lookups
Caches fluid state lookups in the spreadToSides method to avoid repeated getFluidState() calls, reducing method calls and object allocations during fluid spreading.
1 parent e11accb commit cdf06ce

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Leaf Optimizations <optimizations@leafmc.org>
3+
Date: Mon, 1 Jan 2025 00:00:00 +0000
4+
Subject: [PATCH] optimize fluid spreading
5+
6+
Optimizes fluid spreading by caching fluid state lookups to avoid
7+
repeated getFluidState() calls in the spreadToSides method. This reduces
8+
the number of method calls and object allocations during fluid spreading.
9+
10+
diff --git a/net/minecraft/world/level/material/FlowingFluid.java b/net/minecraft/world/level/material/FlowingFluid.java
11+
index ca6df49381fd41e6aad20604acc58f4b4c504f1a..a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 100644
12+
--- a/net/minecraft/world/level/material/FlowingFluid.java
13+
+++ b/net/minecraft/world/level/material/FlowingFluid.java
14+
@@ -420,7 +422,10 @@ public abstract class FlowingFluid extends Fluid {
15+
if (i >= 8) {
16+
for (Direction direction2 : Direction.Plane.HORIZONTAL) {
17+
BlockPos blockPos2 = pos.relative(direction2);
18+
+ // Leaf start - optimize fluid spreading - cache fluid state lookup
19+
BlockState blockState3 = spreadContext.getBlockStateIfLoaded(blockPos2);
20+
if (blockState3 == null) continue;
21+
- if (this.canSpreadTo(level, pos, blockState, direction2, blockPos2, blockState3, blockState3.getFluidState())) {
22+
+ FluidState spreadPosFluidState = blockState3.getFluidState(); // Cache to avoid repeated getFluidState() call
23+
+ if (this.canSpreadTo(level, pos, blockState, direction2, blockPos2, blockState3, spreadPosFluidState)) {
24+
this.spreadTo(level, blockPos2, blockState3, direction2, fluidState);
25+
}
26+
+ // Leaf end - optimize fluid spreading
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)