From f88c97fcc00baeffae04de1ca13fda0d4cd5d0ab Mon Sep 17 00:00:00 2001 From: Samsuik Date: Fri, 7 Mar 2025 14:02:16 +0000 Subject: [PATCH] Rewrite new liquid level optimisation This fixes water sources not forming when theres a liquid above. --- .../0009-Optimise-New-Liquid-Level.patch | 103 ++++++++++++++---- ...-Configure-cannon-physics-by-version.patch | 4 +- ...0-Configure-fluids-breaking-redstone.patch | 4 +- 3 files changed, 88 insertions(+), 23 deletions(-) diff --git a/patches/server/0009-Optimise-New-Liquid-Level.patch b/patches/server/0009-Optimise-New-Liquid-Level.patch index 75ebf28..4be9837 100644 --- a/patches/server/0009-Optimise-New-Liquid-Level.patch +++ b/patches/server/0009-Optimise-New-Liquid-Level.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Optimise New Liquid Level diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java -index 1c0712295695727ee9c4d430d4157b8e17cbd71f..1c82ff348769655f20ba4fde7914a326e072afce 100644 +index 1c0712295695727ee9c4d430d4157b8e17cbd71f..67a7141328382ba75f7f66b46f0a423757babe56 100644 --- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java +++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java @@ -137,7 +137,7 @@ public abstract class FlowingFluid extends Fluid { @@ -13,45 +13,93 @@ index 1c0712295695727ee9c4d430d4157b8e17cbd71f..1c82ff348769655f20ba4fde7914a326 BlockPos blockposition1 = fluidPos.below(); BlockState iblockdata1 = world.getBlockState(blockposition1); - FluidState fluid1 = this.getNewLiquid(world, blockposition1, iblockdata1); -+ FluidState fluid1 = this.getLiquid(world, blockposition1, iblockdata1, fluidPos, iblockdata); // Sakura - optimise new liquid level ++ FluidState fluid1 = this.getLiquidFlowingDown(world, blockposition1, iblockdata1); // Sakura - optimise new liquid level if (this.canSpreadTo(world, fluidPos, iblockdata, Direction.DOWN, blockposition1, iblockdata1, world.getFluidState(blockposition1), fluid1.getType())) { // CraftBukkit start -@@ -197,6 +197,25 @@ public abstract class FlowingFluid extends Fluid { +@@ -196,7 +196,60 @@ public abstract class FlowingFluid extends Fluid { + } } - protected FluidState getNewLiquid(Level world, BlockPos pos, BlockState state) { -+ // Sakura start - optimise new liquid level -+ BlockPos blockposition2 = pos.above(); -+ BlockState iblockdata3 = world.getBlockState(blockposition2); ++ // Sakura start - optimise new liquid level ++ private static final int FORM_LIQUID_SOURCE = 0xff; + -+ return getLiquid(world, pos, state, blockposition2, iblockdata3); ++ private boolean canLiquidFlowDown(final Level level, final BlockPos pos, final BlockState state) { ++ final BlockPos abovePos = pos.above(); ++ final BlockState stateAbove = level.getBlockState(abovePos); ++ final FluidState fluidStateAbove = stateAbove.getFluidState(); ++ ++ return !fluidStateAbove.isEmpty() && fluidStateAbove.getType().isSame(this) ++ && canPassThroughWall(Direction.UP, level, pos, state, abovePos, stateAbove); + } + -+ // SANITY: world, pos, state, above pos, above state -+ protected FluidState getLiquid(Level world, BlockPos pos, BlockState state, BlockPos blockposition2, BlockState iblockdata3) { -+ FluidState fluid2 = iblockdata3.getFluidState(); ++ @Deprecated + protected FluidState getNewLiquid(Level world, BlockPos pos, BlockState state) { ++ return this.getLiquidFromSurroundings(world, pos, state, null, false); ++ } + -+ if (!fluid2.isEmpty() && fluid2.getType().isSame(this) && this.canPassThroughWall(Direction.UP, world, pos, state, blockposition2, iblockdata3)) { ++ private FluidState getLiquidFlowingDown(final Level level, final BlockPos pos, final BlockState state) { ++ final BlockState stateBelow = level.getBlockState(pos.below()); ++ final FluidState fluidStateBelow = stateBelow.getFluidState(); ++ ++ // There's no point checking the surroundings if the liquid is unable to turn into a source. ++ if (!stateBelow.isSolid() || !this.isSourceBlockOfThisType(fluidStateBelow)) { ++ return this.getFlowing(8, true); ++ } ++ ++ return this.getLiquidFromSurroundings(level, pos, state, Direction.DOWN, true); ++ } ++ ++ @org.jspecify.annotations.NullUnmarked ++ private FluidState getLiquidFromSurroundings(final Level level, final BlockPos pos, final BlockState state, ++ final Direction flowing, final boolean draining) { ++ final boolean flowingDown = flowing == Direction.DOWN || this.canLiquidFlowDown(level, pos, state); ++ if (draining && flowingDown) { ++ return this.getFlowing(8, true); ++ } ++ ++ final Direction incoming = flowing != null ? flowing.getOpposite() : null; ++ final int liquidLevel = this.getLiquidLevelFromSurroundings(level, pos, state, incoming); ++ if (liquidLevel == FORM_LIQUID_SOURCE) { ++ return this.getSource(false); ++ } ++ ++ if (flowingDown) { + return this.getFlowing(8, true); + } else { -+ return this.getLiquidFromSurroundings(world, pos, state); ++ final int newLiquidLevel = liquidLevel - this.getDropOff(level); ++ return newLiquidLevel <= 0 ? Fluids.EMPTY.defaultFluidState() : this.getFlowing(newLiquidLevel, false); + } + } + -+ protected FluidState getLiquidFromSurroundings(Level world, BlockPos pos, BlockState state) { ++ @org.jspecify.annotations.NullUnmarked ++ private int getLiquidLevelFromSurroundings(final Level world, final BlockPos pos, final BlockState state, final Direction incoming) { ++ // Sakura end - optimise new liquid level int i = 0; int j = 0; Iterator iterator = Direction.Plane.HORIZONTAL.iterator(); -@@ -226,17 +245,10 @@ public abstract class FlowingFluid extends Fluid { +@@ -208,7 +261,7 @@ public abstract class FlowingFluid extends Fluid { + if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing + FluidState fluid = iblockdata1.getFluidState(); + +- if (fluid.getType().isSame(this) && this.canPassThroughWall(enumdirection, world, pos, state, blockposition1, iblockdata1)) { ++ if (fluid.getType().isSame(this) && (incoming == enumdirection || this.canPassThroughWall(enumdirection, world, pos, state, blockposition1, iblockdata1))) { // Sakura - optimise new liquid level + if (fluid.isSource()) { + ++j; + } +@@ -222,21 +275,11 @@ public abstract class FlowingFluid extends Fluid { + FluidState fluid1 = iblockdata2.getFluidState(); + + if (iblockdata2.isSolid() || this.isSourceBlockOfThisType(fluid1)) { +- return this.getSource(false); ++ return FORM_LIQUID_SOURCE; // Sakura - optimise new liquid level } } - BlockPos blockposition2 = pos.above(); - BlockState iblockdata3 = world.getBlockState(blockposition2); - FluidState fluid2 = iblockdata3.getFluidState(); -+ int k = i - this.getDropOff(world); - +- - if (!fluid2.isEmpty() && fluid2.getType().isSame(this) && this.canPassThroughWall(Direction.UP, world, pos, state, blockposition2, iblockdata3)) { - return this.getFlowing(8, true); - } else { @@ -59,8 +107,25 @@ index 1c0712295695727ee9c4d430d4157b8e17cbd71f..1c82ff348769655f20ba4fde7914a326 - - return k <= 0 ? Fluids.EMPTY.defaultFluidState() : this.getFlowing(k, false); - } -+ return k <= 0 ? Fluids.EMPTY.defaultFluidState() : this.getFlowing(k, false); -+ // Sakura end - optimise new liquid level ++ return i; // Sakura - optimise new liquid level } private boolean canPassThroughWall(Direction face, BlockGetter world, BlockPos pos, BlockState state, BlockPos fromPos, BlockState fromState) { +@@ -418,7 +461,7 @@ public abstract class FlowingFluid extends Fluid { + // Paper end - Prevent chunk loading from fluid flowing + BlockState iblockdata1 = (BlockState) pair.getFirst(); + FluidState fluid = (FluidState) pair.getSecond(); +- FluidState fluid1 = this.getNewLiquid(world, blockposition1, iblockdata1); ++ FluidState fluid1 = this.getLiquidFromSurroundings(world, blockposition1, iblockdata1, enumdirection, false); // Sakura - optimise new liquid level + + if (this.canPassThrough(world, fluid1.getType(), pos, state, enumdirection, blockposition1, iblockdata1, fluid)) { + BlockPos blockposition2 = blockposition1.below(); +@@ -472,7 +515,7 @@ public abstract class FlowingFluid extends Fluid { + @Override + public void tick(Level world, BlockPos pos, FluidState state) { + if (!state.isSource()) { +- FluidState fluid1 = this.getNewLiquid(world, pos, world.getBlockState(pos)); ++ FluidState fluid1 = this.getLiquidFromSurroundings(world, pos, world.getBlockState(pos), null, true); // Sakura - optimise new liquid level; liquid draining + int i = this.getSpreadDelay(world, pos, state, fluid1); + + if (fluid1.isEmpty()) { diff --git a/patches/server/0037-Configure-cannon-physics-by-version.patch b/patches/server/0037-Configure-cannon-physics-by-version.patch index e1a92d8..ad5fa94 100644 --- a/patches/server/0037-Configure-cannon-physics-by-version.patch +++ b/patches/server/0037-Configure-cannon-physics-by-version.patch @@ -1182,10 +1182,10 @@ index d555ad1dd2f648b84920eceec6cc99e8801334b3..b2ecc615379856f661ba87bdeb28f75a } diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java -index 1c82ff348769655f20ba4fde7914a326e072afce..700226cc972693336987184c761c0c8808fd77ad 100644 +index 67a7141328382ba75f7f66b46f0a423757babe56..09530353d1362f5c8d54c0163ca883866bf44087 100644 --- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java +++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java -@@ -514,7 +514,7 @@ public abstract class FlowingFluid extends Fluid { +@@ -545,7 +545,7 @@ public abstract class FlowingFluid extends Fluid { this.spread(world, pos, state); } diff --git a/patches/server/0050-Configure-fluids-breaking-redstone.patch b/patches/server/0050-Configure-fluids-breaking-redstone.patch index 712b7a7..80592b1 100644 --- a/patches/server/0050-Configure-fluids-breaking-redstone.patch +++ b/patches/server/0050-Configure-fluids-breaking-redstone.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Configure fluids breaking redstone diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java -index 700226cc972693336987184c761c0c8808fd77ad..b0d1c86dbbe6b6f1b8ac8f531b5f3bc3669e232a 100644 +index 09530353d1362f5c8d54c0163ca883866bf44087..0bb0a357b5adc72920b1ccc201871b1bcdc52bcd 100644 --- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java +++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java -@@ -466,6 +466,10 @@ public abstract class FlowingFluid extends Fluid { +@@ -497,6 +497,10 @@ public abstract class FlowingFluid extends Fluid { if (block instanceof LiquidBlockContainer ifluidcontainer) { return ifluidcontainer.canPlaceLiquid((Player) null, world, pos, state, fluid);