9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-19 14:59:30 +00:00

Fix an oversight with optimise new liquid level

This commit is contained in:
Samsuik
2025-03-08 11:20:10 +00:00
parent b1703fbf85
commit 17faf0f0bd

View File

@@ -11,7 +11,7 @@
FluidState fluidState1 = blockState1.getFluidState(); FluidState fluidState1 = blockState1.getFluidState();
if (this.canMaybePassThrough(level, pos, blockState, Direction.DOWN, blockPos, blockState1, fluidState1)) { if (this.canMaybePassThrough(level, pos, blockState, Direction.DOWN, blockPos, blockState1, fluidState1)) {
- FluidState newLiquid = this.getNewLiquid(level, blockPos, blockState1); - FluidState newLiquid = this.getNewLiquid(level, blockPos, blockState1);
+ FluidState newLiquid = this.getLiquidFlowingDown(level, blockPos, blockState1); // Sakura - optimise new liquid level + FluidState newLiquid = this.getLiquidFromSurroundings(level, blockPos, blockState1, Direction.DOWN); // Sakura - optimise new liquid level
Fluid type = newLiquid.getType(); Fluid type = newLiquid.getType();
if (fluidState1.canBeReplacedWith(level, blockPos, type, Direction.DOWN) && canHoldSpecificFluid(level, blockPos, blockState1, type)) { if (fluidState1.canBeReplacedWith(level, blockPos, type, Direction.DOWN) && canHoldSpecificFluid(level, blockPos, blockState1, type)) {
// CraftBukkit start // CraftBukkit start
@@ -27,7 +27,7 @@
// CraftBukkit start // CraftBukkit start
org.bukkit.block.Block source = org.bukkit.craftbukkit.block.CraftBlock.at(level, pos); org.bukkit.block.Block source = org.bukkit.craftbukkit.block.CraftBlock.at(level, pos);
org.bukkit.event.block.BlockFromToEvent event = new org.bukkit.event.block.BlockFromToEvent(source, org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(direction)); org.bukkit.event.block.BlockFromToEvent event = new org.bukkit.event.block.BlockFromToEvent(source, org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(direction));
@@ -213,17 +_,72 @@ @@ -213,17 +_,71 @@
} }
} }
@@ -44,29 +44,28 @@
+ && canPassThroughWall(Direction.UP, level, pos, state, abovePos, stateAbove); + && canPassThroughWall(Direction.UP, level, pos, state, abovePos, stateAbove);
+ } + }
+ +
+ @Deprecated + private boolean canFormLiquidSource(final ServerLevel level, final BlockPos pos, final BlockPos.MutableBlockPos mutableBlockPos) {
protected FluidState getNewLiquid(ServerLevel level, BlockPos pos, BlockState state) { + if (!this.canConvertToSource(level)) {
+ return this.getLiquidFromSurroundings(level, pos, state, null, false); + return false;
+ } + }
+ + final BlockPos belowPos = mutableBlockPos.setWithOffset(pos, Direction.DOWN);
+ private FluidState getLiquidFlowingDown(final ServerLevel level, final BlockPos pos, final BlockState state) { + final BlockState stateBelow = level.getBlockState(belowPos);
+ final BlockState stateBelow = level.getBlockState(pos.below());
+ final FluidState fluidStateBelow = stateBelow.getFluidState(); + final FluidState fluidStateBelow = stateBelow.getFluidState();
+ + return stateBelow.isSolid() || this.isSourceBlockOfThisType(fluidStateBelow);
+ // 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); protected FluidState getNewLiquid(ServerLevel level, BlockPos pos, BlockState state) {
+ return this.getLiquidFromSurroundings(level, pos, state, null);
+ } + }
+ +
+ @org.jspecify.annotations.NullUnmarked + @org.jspecify.annotations.NullUnmarked
+ private FluidState getLiquidFromSurroundings(final ServerLevel level, final BlockPos pos, final BlockState state, + private FluidState getLiquidFromSurroundings(final ServerLevel level, final BlockPos pos, final BlockState state,
+ final Direction flowing, final boolean draining) { + final Direction flowing) {
+ final BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); + final BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
+ final boolean flowingDown = flowing == Direction.DOWN || this.canLiquidFlowDown(level, pos, state, mutableBlockPos); + final boolean flowingDown = flowing == Direction.DOWN || this.canLiquidFlowDown(level, pos, state, mutableBlockPos);
+ if (draining && flowingDown) { +
+ // There's no point checking the surroundings if the liquid is unable to turn into a source.
+ if (flowingDown && !this.canFormLiquidSource(level, pos, mutableBlockPos)) {
+ return this.getFlowing(8, true); + return this.getFlowing(8, true);
+ } + }
+ +
@@ -129,7 +128,7 @@
FluidState fluidState = blockState.getFluidState(); FluidState fluidState = blockState.getFluidState();
if (this.canMaybePassThrough(level, pos, state, direction, blockPos, blockState, fluidState)) { if (this.canMaybePassThrough(level, pos, state, direction, blockPos, blockState, fluidState)) {
- FluidState newLiquid = this.getNewLiquid(level, blockPos, blockState); - FluidState newLiquid = this.getNewLiquid(level, blockPos, blockState);
+ FluidState newLiquid = this.getLiquidFromSurroundings(level, blockPos, blockState, direction, false); // Sakura - optimise new liquid level + FluidState newLiquid = this.getLiquidFromSurroundings(level, blockPos, blockState, direction); // Sakura - optimise new liquid level
if (canHoldSpecificFluid(level, blockPos, blockState, newLiquid.getType())) { if (canHoldSpecificFluid(level, blockPos, blockState, newLiquid.getType())) {
if (spreadContext == null) { if (spreadContext == null) {
spreadContext = new FlowingFluid.SpreadContext(level, pos); spreadContext = new FlowingFluid.SpreadContext(level, pos);
@@ -150,7 +149,7 @@
public void tick(ServerLevel level, BlockPos pos, BlockState blockState, FluidState fluidState) { public void tick(ServerLevel level, BlockPos pos, BlockState blockState, FluidState fluidState) {
if (!fluidState.isSource()) { if (!fluidState.isSource()) {
- FluidState newLiquid = this.getNewLiquid(level, pos, level.getBlockState(pos)); - FluidState newLiquid = this.getNewLiquid(level, pos, level.getBlockState(pos));
+ FluidState newLiquid = this.getLiquidFromSurroundings(level, pos, blockState, null, true); // Sakura - optimise new liquid level; liquid draining + FluidState newLiquid = this.getNewLiquid(level, pos, blockState); // Sakura - optimise new liquid level; liquid draining
int spreadDelay = this.getSpreadDelay(level, pos, fluidState, newLiquid); int spreadDelay = this.getSpreadDelay(level, pos, fluidState, newLiquid);
if (newLiquid.isEmpty()) { if (newLiquid.isEmpty()) {
fluidState = newLiquid; fluidState = newLiquid;