Skip to content

Commit 2b4ffa5

Browse files
committed
more nuker qol options from epic nuker
1 parent 91a11c2 commit 2b4ffa5

File tree

1 file changed

+90
-14
lines changed
  • src/main/kotlin/com/lambda/module/modules/player

1 file changed

+90
-14
lines changed

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

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package com.lambda.module.modules.player
1919

2020
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
21-
import com.lambda.config.applyEdits
21+
import com.lambda.context.SafeContext
2222
import com.lambda.interaction.BaritoneManager
2323
import com.lambda.interaction.construction.blueprint.TickingBlueprint.Companion.tickingBlueprint
2424
import com.lambda.interaction.construction.verify.TargetState
@@ -28,8 +28,12 @@ import com.lambda.task.RootTask.run
2828
import com.lambda.task.Task
2929
import com.lambda.task.tasks.BuildTask.Companion.build
3030
import com.lambda.util.BlockUtils.blockPos
31+
import com.lambda.util.BlockUtils.blockState
32+
import com.lambda.util.BlockUtils.isNotEmpty
33+
import com.lambda.util.math.MathUtils.ceilToInt
3134
import net.minecraft.block.Blocks
3235
import net.minecraft.util.math.BlockPos
36+
import net.minecraft.util.math.Direction
3337

3438
object Nuker : Module(
3539
name = "Nuker",
@@ -38,11 +42,14 @@ object Nuker : Module(
3842
) {
3943
private val height by setting("Height", 6, 1..8, 1)
4044
private val width by setting("Width", 6, 1..8, 1)
41-
private val flatten by setting("Flatten", true)
45+
private val flattenMode by setting("Flatten Mode", FlattenMode.Standard)
46+
private val directionalDig by setting("Directional Dig", DigDirection.None)
4247
private val onGround by setting("On Ground", false, "Only break blocks when the player is standing on ground")
4348
private val fillFluids by setting("Fill Fluids", false, "Removes liquids by filling them in before breaking")
4449
private val fillFloor by setting("Fill Floor", false)
4550
private val baritoneSelection by setting("Baritone Selection", false, "Restricts nuker to your baritone selection")
51+
private val inverseSelection by setting("Inverse Selection", false, "Breaks blocks outside of the baritone selection and ignores blocks inside") { baritoneSelection }
52+
private val sneakLowersFlatten by setting("Sneak Lowers Flatten", false)
4653

4754
private var task: Task<*>? = null
4855

@@ -57,17 +64,9 @@ object Nuker : Module(
5764
.asSequence()
5865
.map { it.blockPos }
5966
.filter { !world.isAir(it) }
60-
.filter { !flatten || it.y >= player.blockPos.y }
61-
.filter { pos ->
62-
if (!baritoneSelection) true
63-
else BaritoneManager.primary?.selectionManager?.selections?.any {
64-
val min = it.min()
65-
val max = it.max()
66-
pos.x >= min.x && pos.x <= max.x
67-
&& pos.y >= min.y && pos.y <= max.y
68-
&& pos.z >= min.z && pos.z <= max.z
69-
} ?: false
70-
}
67+
.filter { flattenMode == FlattenMode.None || isInFlatten(it) }
68+
.filter { isWithinDigDirection(it) }
69+
.filter { isInBaritoneSelection(it) == !inverseSelection }
7170
.associateWith { if (fillFluids) TargetState.Air else TargetState.Empty }
7271

7372
if (fillFloor) {
@@ -86,4 +85,81 @@ object Nuker : Module(
8685
task?.cancel()
8786
}
8887
}
89-
}
88+
89+
private fun SafeContext.isInFlatten(pos: BlockPos): Boolean {
90+
if (flattenMode == FlattenMode.Staircase) {
91+
val up = pos.up()
92+
if ((blockState(up).isNotEmpty && (!baritoneSelection || isInBaritoneSelection(up)))
93+
|| (blockState(up.east()).isNotEmpty && (!baritoneSelection || isInBaritoneSelection(up.east())))
94+
|| (blockState(up.south()).isNotEmpty && (!baritoneSelection || isInBaritoneSelection(up.south())))
95+
|| (blockState(up.west()).isNotEmpty && (!baritoneSelection || isInBaritoneSelection(up.west())))
96+
|| (blockState(up.north()).isNotEmpty && (!baritoneSelection || isInBaritoneSelection(up.north())))
97+
) { return false }
98+
}
99+
100+
val flattenY = player.y.ceilToInt()
101+
val playerPos = player.blockPos
102+
val flattenLevel =
103+
if (sneakLowersFlatten && player.isSneaking) flattenY - 1
104+
else flattenY
105+
106+
if (!flattenMode.isSmart && pos.y < flattenLevel)
107+
return false
108+
109+
if (pos == player.supportingBlockPos) return false
110+
111+
val playerLookDir = player.horizontalFacing
112+
val smartFlattenDir =
113+
if (flattenMode == FlattenMode.Smart) playerLookDir
114+
else playerLookDir?.opposite
115+
116+
if (pos.y >= flattenLevel) return true
117+
118+
val zeroedPos = pos.add(-playerPos.x, -flattenY, -playerPos.z)
119+
120+
return (zeroedPos.x < 0 && smartFlattenDir == Direction.EAST)
121+
|| (zeroedPos.z < 0 && smartFlattenDir == Direction.SOUTH)
122+
|| (zeroedPos.x > 0 && smartFlattenDir == Direction.WEST)
123+
|| (zeroedPos.z > 0 && smartFlattenDir == Direction.NORTH)
124+
}
125+
126+
private fun SafeContext.isWithinDigDirection(pos: BlockPos): Boolean {
127+
val playerPos = player.blockPos
128+
return when (directionalDig) {
129+
DigDirection.None -> true
130+
DigDirection.East -> playerPos.x <= pos.x
131+
DigDirection.West -> playerPos.x >= pos.x
132+
DigDirection.North -> playerPos.z >= pos.z
133+
DigDirection.South -> playerPos.z <= pos.z
134+
}
135+
}
136+
137+
private fun isInBaritoneSelection(pos: BlockPos) =
138+
if (!baritoneSelection) true
139+
else BaritoneManager.primary?.selectionManager?.selections?.any {
140+
val min = it.min()
141+
val max = it.max()
142+
pos.x >= min.x && pos.x <= max.x
143+
&& pos.y >= min.y && pos.y <= max.y
144+
&& pos.z >= min.z && pos.z <= max.z
145+
} ?: false
146+
147+
private enum class FlattenMode {
148+
None,
149+
Standard,
150+
Smart,
151+
ReverseSmart,
152+
Staircase;
153+
154+
val isSmart
155+
get() = this == Smart || this == ReverseSmart
156+
}
157+
158+
private enum class DigDirection {
159+
None,
160+
East,
161+
South,
162+
West,
163+
North
164+
}
165+
}

0 commit comments

Comments
 (0)