@@ -10,31 +10,39 @@ which the contains iteration call is very expensive if called everytime
1010In the test, it can improve ~30% performance in ~1577000 times of canHoldAnyFluid calls (~159ms -> ~111ms)
1111
1212diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
13- index cabb4b79248725ea8f831d5f1b27902c3c9ea262..d97e98e4c4076694be465eb65e95cd1629b025ec 100644
13+ index cabb4b79248725ea8f831d5f1b27902c3c9ea262..d371c3846917a7cea17cd38510d366535c2b6954 100644
1414--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
1515+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
16- @@ -844,6 +844,7 @@ public abstract class BlockBehaviour implements FeatureElement {
16+ @@ -844,6 +844,8 @@ public abstract class BlockBehaviour implements FeatureElement {
1717 private VoxelShape[] occlusionShapesByFace;
1818 private boolean propagatesSkylightDown;
1919 private int lightBlock;
2020+ private boolean canHoldAnyFluidInternal; // Leaf - Cache canHoldAnyFluid result
21+ + private boolean canHoldAnyFluidInternalInit; // Leaf - Cache canHoldAnyFluid result
2122
2223 // Paper start - rewrite chunk system
2324 private boolean isConditionallyFullOpaque;
24- @@ -999,6 +1000,7 @@ public abstract class BlockBehaviour implements FeatureElement {
25+ @@ -999,6 +1001,8 @@ public abstract class BlockBehaviour implements FeatureElement {
2526
2627 this.propagatesSkylightDown = ((Block) this.owner).propagatesSkylightDown(this.asState());
2728 this.lightBlock = ((Block) this.owner).getLightBlock(this.asState());
28- + this.canHoldAnyFluidInternal = net.minecraft.world.level.material.FlowingFluid.canHoldAnyFluid(this.asState()); // Leaf - Cache canHoldAnyFluid result
29+ + this.canHoldAnyFluidInternal = false; // Leaf - Cache canHoldAnyFluid result
30+ + this.canHoldAnyFluidInternalInit = false; // Leaf - Cache canHoldAnyFluid result
2931 // Paper start - rewrite chunk system
3032 this.isConditionallyFullOpaque = this.canOcclude & this.useShapeForLightOcclusion;
3133 // Paper end - rewrite chunk system
32- @@ -1058,6 +1060,12 @@ public abstract class BlockBehaviour implements FeatureElement {
34+ @@ -1058,6 +1062,18 @@ public abstract class BlockBehaviour implements FeatureElement {
3335 return this.legacySolid;
3436 }
3537
3638+ // Leaf start - Cache canHoldAnyFluid result
3739+ public boolean canHoldAnyFluidInternal() {
40+ + // Lazy load cache
41+ + if (!canHoldAnyFluidInternalInit) {
42+ + canHoldAnyFluidInternal = net.minecraft.world.level.material.FlowingFluid.canHoldAnyFluid(this.asState());
43+ + canHoldAnyFluidInternalInit = true;
44+ + }
45+ +
3846+ return canHoldAnyFluidInternal;
3947+ }
4048+ // Leaf end - Cache canHoldAnyFluid result
0 commit comments