From 536951ac4efc7cadc290a33049f160c100e84ae1 Mon Sep 17 00:00:00 2001 From: 2No2Name <2no2name@web.de> Date: Fri, 25 Oct 2024 14:44:53 +0200 Subject: [PATCH] Fix fluid flow optimization --- .../block/fluid/flow/FlowingFluidMixin.java | 35 ++++++++++++------- .../mixin/block/fluid/flow/package-info.java | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/net/caffeinemc/mods/lithium/mixin/block/fluid/flow/FlowingFluidMixin.java b/common/src/main/java/net/caffeinemc/mods/lithium/mixin/block/fluid/flow/FlowingFluidMixin.java index ebbb517df..515ed2bc5 100644 --- a/common/src/main/java/net/caffeinemc/mods/lithium/mixin/block/fluid/flow/FlowingFluidMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/lithium/mixin/block/fluid/flow/FlowingFluidMixin.java @@ -139,11 +139,14 @@ public void getSpread(ServerLevel world, BlockPos pos, BlockState state, Callbac } } if (onlyPossibleFlowDirection != null) { - FluidState fluidState; - FluidState targetNewFluidState = this.getNewLiquid(world, onlyBlockPos, onlyBlockState); - if (this.canPassThrough(world, targetNewFluidState.getType(), pos, state, onlyPossibleFlowDirection, onlyBlockPos, onlyBlockState, onlyBlockState.getFluidState())) { - fluidState = targetNewFluidState; - flowResultByDirection.put(onlyPossibleFlowDirection, fluidState); + FluidState onlyFluidState = onlyBlockState.getFluidState(); + if (this.canMaybePassThrough(world, pos, state, onlyPossibleFlowDirection, onlyBlockPos, onlyBlockState, onlyFluidState)) { + FluidState targetNewFluidState = this.getNewLiquid(world, onlyBlockPos, onlyBlockState); + if (canHoldSpecificFluid(world, onlyBlockPos, onlyBlockState, targetNewFluidState.getType())) { + if (onlyFluidState.canBeReplacedWith(world, onlyBlockPos, targetNewFluidState.getType(), onlyPossibleFlowDirection)) { + flowResultByDirection.put(onlyPossibleFlowDirection, targetNewFluidState); + } + } } } cir.setReturnValue(flowResultByDirection); @@ -227,16 +230,22 @@ private void calculateComplexFluidFlowDirections(ServerLevel world, BlockPos sta BlockState targetBlockState = getBlock(world, flowTargetPos, blockStateCache, blockIndex); //TODO use block cache in getUpdatedState - FluidState targetNewFluidState = this.getNewLiquid(world, flowTargetPos, targetBlockState); - - //Store the resulting fluid state for each direction, remove later if no closest hole access in this direction. - flowResultByDirection.put(flowDirection, targetNewFluidState); + if (this.canMaybePassThrough(world, flowTargetPos, startState, flowDirection, flowTargetPos, targetBlockState, targetBlockState.getFluidState())) { + FluidState targetNewFluidState = this.getNewLiquid(world, flowTargetPos, targetBlockState); + if (canHoldSpecificFluid(world, flowTargetPos, targetBlockState, targetNewFluidState.getType())) {//Store the resulting fluid state for each direction, remove later if no closest hole access in this direction. + // 1.21.2+ Specialty: Only add the direction if the fluid can replace the other fluid. If it cannot, it still counts for the hole search though. + if (targetBlockState.getFluidState().canBeReplacedWith(world, flowTargetPos, targetNewFluidState.getType(), flowDirection)) { + flowResultByDirection.put(flowDirection, targetNewFluidState); + } - if (this.canPassThrough(world, targetNewFluidState.getType(), startPos, startState, flowDirection, flowTargetPos, targetBlockState, targetBlockState.getFluidState())) { - prevPositions.put(blockIndex, (byte) (0b10001 << i)); - if (isHoleBelow(world, holeCache, blockIndex, flowTargetPos, targetBlockState)) { - holeAccess |= (byte) (1 << i); + if (this.canPassThrough(world, targetNewFluidState.getType(), startPos, startState, flowDirection, flowTargetPos, targetBlockState, targetBlockState.getFluidState())) { + prevPositions.put(blockIndex, (byte) (0b10001 << i)); + if (isHoleBelow(world, holeCache, blockIndex, flowTargetPos, targetBlockState)) { + holeAccess |= (byte) (1 << i); + } + } } + } } diff --git a/common/src/main/java/net/caffeinemc/mods/lithium/mixin/block/fluid/flow/package-info.java b/common/src/main/java/net/caffeinemc/mods/lithium/mixin/block/fluid/flow/package-info.java index b8ed6a64d..646a203b1 100644 --- a/common/src/main/java/net/caffeinemc/mods/lithium/mixin/block/fluid/flow/package-info.java +++ b/common/src/main/java/net/caffeinemc/mods/lithium/mixin/block/fluid/flow/package-info.java @@ -1,4 +1,4 @@ -@MixinConfigOption(description = "Fluid flow optimization", enabled = false) //TODO this breaks ALL BLOCKS bruh +@MixinConfigOption(description = "Fluid flow optimization") package net.caffeinemc.mods.lithium.mixin.block.fluid.flow; import net.caffeinemc.gradle.MixinConfigOption; \ No newline at end of file