Skip to content

Commit e19e5af

Browse files
committed
fillFluids setting in nuker and better fluid removal logic in build sim. Also improved sorting for place contexts with a fluid level != 0
1 parent de62f07 commit e19e5af

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ data class PlaceContext(
5050
when (other) {
5151
is PlaceContext -> compareBy<PlaceContext> {
5252
BlockUtils.fluids.indexOf(it.cachedState.fluidState.fluid)
53+
}.thenByDescending {
54+
if (it.cachedState.fluidState.level != 0) it.blockPos.y
55+
else 0
5356
}.thenByDescending {
5457
it.cachedState.fluidState.level
5558
}.thenBy {

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,15 @@ object BuildSimulator {
342342
val currentState = blockState(pos)
343343

344344
val statePromoting = currentState.block is SlabBlock && targetState.matches(currentState, pos, world, preProcessing.ignore)
345-
if (targetState.isEmpty() || (!currentState.isReplaceable && !statePromoting)) return acc
345+
// If the target state is air then the only possible blocks it could place are to remove liquids so we use the Solid TargetState
346+
val nextTargetState = if (targetState is TargetState.Air) {
347+
TargetState.Solid
348+
} else if (targetState.isEmpty()) {
349+
// Otherwise if the target state is empty, there's no situation where placement would be required so we can return
350+
return acc
351+
} else targetState
352+
// For example, slabs count as state promoting because you are placing another block to promote the current state to the target state
353+
if (!currentState.isReplaceable && !statePromoting) return acc
346354

347355
preProcessing.sides.forEach { neighbor ->
348356
val hitPos = if (!place.airPlace.isEnabled() && (currentState.isEmpty || statePromoting))
@@ -415,7 +423,7 @@ object BuildSimulator {
415423
}
416424

417425
interactionConfig.pointSelection.select(validHits)?.let { checkedHit ->
418-
val optimalStack = targetState.getStack(world, pos, inventory)
426+
val optimalStack = nextTargetState.getStack(world, pos, inventory)
419427

420428
// ToDo: For each hand and sneak or not?
421429
val fakePlayer = copyPlayer(player).apply {
@@ -424,6 +432,7 @@ object BuildSimulator {
424432

425433
val checkedResult = checkedHit.hit
426434

435+
// ToDo: Override the stack used for this to account for blocks where replaceability is dependent on the held item
427436
val usageContext = ItemUsageContext(
428437
fakePlayer,
429438
Hand.MAIN_HAND,
@@ -476,8 +485,8 @@ object BuildSimulator {
476485
resultState = blockItem.getPlacementState(context)
477486
?: return@placeState PlaceResult.BlockedByEntity(pos)
478487

479-
return@placeState if (!targetState.matches(resultState, pos, world, preProcessing.ignore))
480-
PlaceResult.NoIntegrity(pos, resultState, context, (targetState as? TargetState.State)?.blockState)
488+
return@placeState if (!nextTargetState.matches(resultState, pos, world, preProcessing.ignore))
489+
PlaceResult.NoIntegrity(pos, resultState, context, (nextTargetState as? TargetState.State)?.blockState)
481490
else null
482491
}
483492

@@ -638,12 +647,12 @@ object BuildSimulator {
638647
if (fluidState.isEmpty || fluid !is FlowableFluid) return@forEach
639648

640649
if (offset == Direction.UP) {
641-
accumulator.put(offsetPos, offsetState)
650+
accumulator[offsetPos] = offsetState
642651
return@fold accumulator
643652
}
644653

645654
if (offsetState.block is Waterloggable && !fluidState.isEmpty) {
646-
accumulator.put(offsetPos, offsetState)
655+
accumulator[offsetPos] = offsetState
647656
return@fold accumulator
648657
}
649658

@@ -663,17 +672,8 @@ object BuildSimulator {
663672
return@fold accumulator
664673
}
665674

666-
/* block has liquids next to it that will leak when broken */
667675
if (affectedFluids.isNotEmpty()) {
668676
acc.add(BreakResult.BlockedByFluid(pos, state))
669-
affectedFluids.entries.forEach { fluid ->
670-
val submerge = if (fluid.value.isReplaceable) {
671-
checkPlaceResults(fluid.key, eye, preProcessing, TargetState.Solid, build.placing, interactionConfig, rotation, inventory)
672-
} else {
673-
checkBreakResults(fluid.key, eye, preProcessing, breaking, interactionConfig, rotation, inventory, build)
674-
}
675-
acc.addAll(submerge)
676-
}
677677
return acc
678678
}
679679
}

common/src/main/kotlin/com/lambda/module/modules/player/Nuker.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import com.lambda.task.tasks.BuildTask.Companion.build
2828
import com.lambda.util.BaritoneUtils
2929
import com.lambda.util.BlockUtils.blockPos
3030
import com.lambda.util.BlockUtils.blockState
31-
import com.lambda.util.BlockUtils.isNotEmpty
3231
import net.minecraft.util.math.BlockPos
3332

3433
object Nuker : Module(
@@ -39,6 +38,7 @@ object Nuker : Module(
3938
private val height by setting("Height", 4, 1..8, 1)
4039
private val width by setting("Width", 4, 1..8, 1)
4140
private val flatten by setting("Flatten", true)
41+
private val fillFluids by setting("Fill Fluids", false, "Removes liquids by filling them in before breaking")
4242
private val instantOnly by setting("Instant Only", false)
4343
private val fillFloor by setting("Fill Floor", false)
4444
private val baritoneSelection by setting("Baritone Selection", false, "Restricts nuker to your baritone selection")
@@ -51,7 +51,7 @@ object Nuker : Module(
5151
val selection = BlockPos.iterateOutwards(player.blockPos, width, height, width)
5252
.asSequence()
5353
.map { it.blockPos }
54-
.filter { blockState(it).isNotEmpty }
54+
.filter { !blockState(it).isAir }
5555
.filter { !flatten || it.y >= player.blockPos.y }
5656
.filter { !instantOnly || blockState(it).getHardness(world, it) <= TaskFlowModule.build.breaking.breakThreshold }
5757
.filter { pos ->
@@ -64,7 +64,7 @@ object Nuker : Module(
6464
&& pos.z >= min.z && pos.z <= max.z
6565
}
6666
}
67-
.associateWith { TargetState.Air }
67+
.associateWith { if (fillFluids) TargetState.Air else TargetState.Empty }
6868

6969
if (fillFloor) {
7070
val floor = BlockPos.iterateOutwards(player.blockPos.down(), width, 0, width)

common/src/main/kotlin/com/lambda/util/BlockUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ object BlockUtils {
230230
)
231231

232232
val fluids = listOf(
233-
Fluids.LAVA,
234233
Fluids.FLOWING_LAVA,
235-
Fluids.WATER,
234+
Fluids.LAVA,
236235
Fluids.FLOWING_WATER,
236+
Fluids.WATER,
237237
Fluids.EMPTY,
238238
)
239239

0 commit comments

Comments
 (0)