Skip to content

Commit a6a3bcf

Browse files
committed
Break waterlogged blocks first with proper targetstate
1 parent 258ed6c commit a6a3bcf

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ data class BreakContext(
3838
override val result: BlockHitResult,
3939
override val rotation: RotationRequest,
4040
override val checkedState: BlockState,
41+
override val targetState: TargetState,
4142
override var hand: Hand,
4243
val instantBreak: Boolean,
4344
) : BuildContext {
44-
override val targetState = TargetState.Air
4545
private val baseColor = Color(222, 0, 0, 25)
4646
private val sideColor = Color(222, 0, 0, 100)
4747

common/src/main/kotlin/com/lambda/interaction/construction/result/PlaceResult.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ sealed class PlaceResult : BuildResult() {
9393
) : Navigable, PlaceResult() {
9494
override val rank = Rank.PLACE_BLOCKED_BY_PLAYER
9595

96+
// ToDo: check what type of entity. player -> leave box, other entity -> kill?
9697
override val goal = GoalInverted(GoalBlock(blockPos))
9798
}
9899

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,17 @@ object BuildSimulator {
355355

356356
val adjacentLiquids = Direction.entries.filter {
357357
it != Direction.DOWN && !pos.offset(it).blockState(world).fluidState.isEmpty
358-
}
358+
}.map { pos.offset(it) }
359359

360360
/* block has liquids next to it that will leak when broken */
361361
if (adjacentLiquids.isNotEmpty()) {
362362
acc.add(BreakResult.BlockedByLiquid(pos, state))
363-
adjacentLiquids.forEach {
364-
val submerge = checkPlaceResults(pos.offset(it), TargetState.Solid, eye, interact, rotation, inventory)
363+
adjacentLiquids.forEach { liquidPos ->
364+
val submerge = if (liquidPos.blockState(world).isReplaceable) {
365+
checkPlaceResults(liquidPos, TargetState.Solid, eye, interact, rotation, inventory)
366+
} else {
367+
checkBreakResults(liquidPos, eye, interact, rotation, inventory, build)
368+
}
365369
acc.addAll(submerge)
366370
}
367371
return acc
@@ -388,6 +392,11 @@ object BuildSimulator {
388392
val verify: CheckedHit.() -> Boolean = {
389393
hit.blockResult?.blockPos == pos
390394
}
395+
val targetState = if (!state.fluidState.isEmpty) {
396+
TargetState.State(state.fluidState.blockState)
397+
} else {
398+
TargetState.Air
399+
}
391400

392401
/* the player is buried inside the block */
393402
if (boxes.any { it.contains(eye) }) {
@@ -396,7 +405,7 @@ object BuildSimulator {
396405
lookAtBlock(pos, config = interact), rotation
397406
)
398407
val breakContext = BreakContext(
399-
eye, blockHit, rotationRequest, state, player.activeHand, instantBreakable(state, pos)
408+
eye, blockHit, rotationRequest, state, targetState, player.activeHand, instantBreakable(state, pos)
400409
)
401410
acc.add(BreakResult.Break(pos, breakContext))
402411
return acc
@@ -440,7 +449,13 @@ object BuildSimulator {
440449
val blockHit = checkedHit.hit.blockResult ?: return@let
441450

442451
val breakContext = BreakContext(
443-
eye, blockHit, RotationRequest(lookAt(checkedHit.targetRotation, 0.001), rotation), state, player.activeHand, instantBreakable(state, pos)
452+
eye,
453+
blockHit,
454+
RotationRequest(lookAt(checkedHit.targetRotation, 0.001), rotation),
455+
state,
456+
targetState,
457+
player.activeHand,
458+
instantBreakable(state, pos)
444459
)
445460

446461
/* player has a better tool for the job available */

0 commit comments

Comments
 (0)