Skip to content

Commit f3532d7

Browse files
committed
Cleanup
1 parent 8bb1272 commit f3532d7

File tree

4 files changed

+35
-50
lines changed

4 files changed

+35
-50
lines changed

src/main/kotlin/com/lambda/config/groups/PlaceSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PlaceSettings(
3131
) : PlaceConfig {
3232
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing", visibility = vis).group(groupPath)
3333
override val airPlace by c.setting("Air Place", AirPlaceMode.None, "Allows for placing blocks without adjacent faces", visibility = vis).group(groupPath)
34-
override val axisRotateSetting by c.setting("Axis Rotate", true, "Overrides the Rotate For Place setting and rotates the player on each axis to air place rotational blocks") { vis() && airPlace.isEnabled() }.group(groupPath)
34+
override val axisRotateSetting by c.setting("Axis Rotate", true, "Overrides the Rotate For Place setting and rotates the player on each axis to air place rotational blocks") { vis() && airPlace.isEnabled }.group(groupPath)
3535
override val placeStageMask by c.setting("Place Sequence Mode", setOf(TickEvent.Pre, TickEvent.Input.Pre, TickEvent.Player.Post), description = "The sub-tick timing at which break actions are performed", visibility = vis).group(groupPath)
3636
override val placeConfirmationMode by c.setting("Place Confirmation", PlaceConfirmationMode.PlaceThenAwait, "Wait for block placement confirmation", visibility = vis).group(groupPath)
3737
override val maxPendingPlacements by c.setting("Max Pending Placements", 5, 0..30, 1, "The maximum amount of pending placements", visibility = vis).group(groupPath)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ object BuildSimulator {
203203
val validHits = mutableListOf<CheckedHit>()
204204
val blockedHits = mutableSetOf<Vec3d>()
205205
val misses = mutableSetOf<Vec3d>()
206-
val airPlace = placing && place.airPlace.isEnabled()
206+
val airPlace = placing && place.airPlace.isEnabled
207207

208208
boxes.forEach { box ->
209209
val refinedSides = if (interactionConfig.checkSideVisibility) {
@@ -396,13 +396,13 @@ object BuildSimulator {
396396
if (!currentState.isReplaceable && !statePromoting) return acc
397397

398398
preProcessing.sides.forEach { neighbor ->
399-
val hitPos = if (!place.airPlace.isEnabled() && (currentState.isEmpty || statePromoting))
399+
val hitPos = if (!place.airPlace.isEnabled && (currentState.isEmpty || statePromoting))
400400
pos.offset(neighbor)
401401
else pos
402402
val hitSide = neighbor.opposite
403403

404404
val voxelShape = blockState(hitPos).getOutlineShape(world, hitPos).let { outlineShape ->
405-
if (!outlineShape.isEmpty || !place.airPlace.isEnabled()) outlineShape
405+
if (!outlineShape.isEmpty || !place.airPlace.isEnabled) outlineShape
406406
else VoxelShapes.fullCube()
407407
}
408408
if (voxelShape.isEmpty) return@forEach
@@ -433,10 +433,10 @@ object BuildSimulator {
433433
val hit = if (interactionConfig.strictRayCast) {
434434
val rayCast = newRotation.rayCast(interactionConfig.interactReach, eye)
435435
when {
436-
rayCast != null && (!place.airPlace.isEnabled() || eye distSq rayCast.pos <= distSquared) ->
436+
rayCast != null && (!place.airPlace.isEnabled || eye distSq rayCast.pos <= distSquared) ->
437437
rayCast.blockResult
438438

439-
place.airPlace.isEnabled() -> {
439+
place.airPlace.isEnabled -> {
440440
val hitVec = newRotation.castBox(box, interactionConfig.interactReach, eye)
441441
BlockHitResult(hitVec, hitSide, hitPos, false)
442442
}

src/main/kotlin/com/lambda/interaction/request/placing/PlaceConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface PlaceConfig : RequestConfig {
2828
val airPlace: AirPlaceMode
2929
val axisRotateSetting: Boolean
3030
val axisRotate
31-
get() = rotateForPlace && airPlace.isEnabled() && axisRotateSetting
31+
get() = rotateForPlace && airPlace.isEnabled && axisRotateSetting
3232
val placeStageMask: Set<Event>
3333
val placeConfirmationMode: PlaceConfirmationMode
3434
val maxPendingPlacements: Int
@@ -46,7 +46,7 @@ interface PlaceConfig : RequestConfig {
4646
Grim("Grim", "Use grim specific air placing.")
4747
;
4848

49-
fun isEnabled() = this != None
49+
val isEnabled get() = this != None
5050
}
5151

5252
enum class PlaceConfirmationMode(

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

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import com.lambda.config.groups.InteractionSettings
2323
import com.lambda.config.groups.InventorySettings
2424
import com.lambda.config.groups.RotationSettings
2525
import com.lambda.context.SafeContext
26+
import com.lambda.event.events.MovementEvent
2627
import com.lambda.event.events.TickEvent
2728
import com.lambda.event.listener.SafeListener.Companion.listen
2829
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
2930
import com.lambda.interaction.construction.context.BuildContext
30-
import com.lambda.interaction.construction.context.PlaceContext
3131
import com.lambda.interaction.construction.result.PlaceResult
3232
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
3333
import com.lambda.interaction.construction.verify.TargetState
@@ -37,7 +37,6 @@ import com.lambda.module.Module
3737
import com.lambda.module.tag.ModuleTag
3838
import com.lambda.util.BlockUtils.blockPos
3939
import com.lambda.util.BlockUtils.blockState
40-
import com.lambda.util.BlockUtils.isNotEmpty
4140
import com.lambda.util.KeyCode
4241
import com.lambda.util.KeyboardUtils.isKeyPressed
4342
import com.lambda.util.NamedEnum
@@ -61,9 +60,9 @@ object Scaffold : Module(
6160
Inventory("Inventory")
6261
}
6362

64-
private val bridgeRange by setting("Bridge Range", 5, 0..5, 1, "The range at which blocks can be placed to help build support for the player").group(Group.General)
65-
private val onlyBelow by setting("Only Below", true, "Restricts bridging to only below the player to avoid place spam if it's impossible to reach the supporting position") { bridgeRange > 0 }.group(Group.General)
63+
private val bridgeRange by setting("Bridge Range", 5, 0..5, 1, "The range at which blocks can be placed to help build support for the player", unit = " blocks").group(Group.General)
6664
private val descend by setting("Descend", KeyCode.UNBOUND, "Lower the place position by one to allow the player to lower y level").group(Group.General)
65+
private val descendAmount by setting("Descend Amount", 1, 1..5, 1, "The amount to lower the place position by when descending", unit = " blocks") { descend != KeyCode.UNBOUND }.group(Group.General)
6766
private val buildConfig = BuildSettings(this, Group.Build)
6867
private val rotationConfig = RotationSettings(this, Group.Rotation)
6968
private val interactionConfig = InteractionSettings(this, Group.Interaction, InteractionMask.Block)
@@ -74,54 +73,40 @@ object Scaffold : Module(
7473

7574
init {
7675
listen<TickEvent.Pre> {
77-
val beneath = player.blockPos.offset(Direction.DOWN, if (isKeyPressed(descend.code)) 2 else 1)
78-
val placements = getPlacements(beneath) ?: return@listen
79-
placements
80-
.associate { it to TargetState.Solid }
76+
val offset = if (isKeyPressed(descend.code)) descendAmount + 1 else 1
77+
val beneath = player.blockPos.offset(Direction.DOWN, offset)
78+
scaffoldPositions(beneath)
79+
.associateWith { TargetState.Solid }
8180
.toBlueprint()
8281
.simulate(player.eyePos, interactionConfig, rotationConfig, inventoryConfig, buildConfig)
8382
.filterIsInstance<PlaceResult.Place>()
84-
.let { results ->
85-
val context = results
86-
.map { it.context }
87-
.distinctBy { it.blockPos }
88-
.sortedWith { o1, o2 -> getBridgeCompareBy(beneath).compare(o1, o2) }
89-
.firstOrNull() ?: return@listen
90-
submit(PlaceRequest(setOf(context), pendingActions, buildConfig, hotbarConfig, rotationConfig))
83+
.minByOrNull { it.blockPos distSq beneath }
84+
?.let { result ->
85+
submit(PlaceRequest(
86+
setOf(result.context),
87+
pendingActions,
88+
buildConfig,
89+
hotbarConfig,
90+
rotationConfig
91+
))
9192
}
9293
}
94+
95+
listen<MovementEvent.Sneak> {
96+
if (descend != KeyCode.LEFT_SHIFT && descend != KeyCode.RIGHT_SHIFT) return@listen
97+
it.sneak = false
98+
}
9399
}
94100

95-
private fun SafeContext.getPlacements(beneath: BlockPos): List<BlockPos>? {
96-
if (!blockState(beneath).isReplaceable) return null
101+
private fun SafeContext.scaffoldPositions(beneath: BlockPos): List<BlockPos> {
102+
if (!blockState(beneath).isReplaceable) return emptyList()
103+
if (buildConfig.placing.airPlace.isEnabled) return listOf(beneath)
97104

98-
return BlockPos
99-
.iterateOutwards(beneath, bridgeRange, bridgeRange, bridgeRange)
105+
return BlockPos.iterateOutwards(beneath, bridgeRange, bridgeRange, bridgeRange)
100106
.asSequence()
107+
.filter { it.y <= beneath.y }
108+
.filter { blockState(it).isReplaceable }
101109
.map { it.blockPos }
102-
.run {
103-
if (onlyBelow) filter { it.y <= beneath.y }
104-
else this
105-
}
106-
.filter { placingCloserToCenter(it, beneath) }
107110
.toList()
108111
}
109-
110-
private fun getBridgeCompareBy(blockPos: BlockPos) =
111-
compareBy<PlaceContext> {
112-
it.blockPos.toCenterPos() distSq blockPos.toCenterPos()
113-
}
114-
115-
private fun SafeContext.placingCloserToCenter(blockPos: BlockPos, center: BlockPos): Boolean {
116-
val potentials = mutableListOf<BlockPos>()
117-
Direction.entries.forEach { direction ->
118-
val offset = blockPos.offset(direction)
119-
val offsetState = blockState(offset)
120-
if (offsetState.isNotEmpty) potentials.add(offset)
121-
}
122-
val trueCenter = center.toCenterPos()
123-
return potentials.isEmpty() || potentials.any {
124-
it.toCenterPos() distSq trueCenter > blockPos.toCenterPos() distSq trueCenter
125-
}
126-
}
127112
}

0 commit comments

Comments
 (0)