|
| 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