Skip to content

Commit 9bd5068

Browse files
committed
improved bridging logic and onlyBelow setting to avoid placement spam if its impossible to reach the supporting position
1 parent e563d4b commit 9bd5068

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
7878

7979
private var shouldSneak = false
8080
private val validSneak: (player: ClientPlayerEntity) -> Boolean =
81-
{ player -> shouldSneak && !player.isSneaking }
81+
{ player -> !shouldSneak || player.isSneaking }
8282

8383
override val blockedPositions
8484
get() = pendingActions.map { it.context.blockPos }

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ import net.minecraft.util.math.BlockPos
3030

3131
data class PlaceRequest(
3232
val contexts: Collection<PlaceContext>,
33+
val pendingInteractions: MutableCollection<BuildContext>,
3334
val build: BuildConfig,
34-
val rotation: RotationConfig,
3535
val hotbar: HotbarConfig,
36-
val pendingInteractions: MutableCollection<BuildContext>,
36+
val rotation: RotationConfig,
3737
val onPlace: ((BlockPos) -> Unit)? = null
3838
) : Request(), PlaceConfig by build.placing {
3939
override val config = build.placing
40+
4041
override val done: Boolean
4142
get() = runSafe {
4243
contexts.all { it.expectedState.matches(blockState(it.blockPos)) }

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ object Scaffold : Module(
6161
}
6262

6363
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)
64+
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)
6465
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)
6566
private val buildConfig = BuildSettings(this, Group.Build)
6667
private val rotationConfig = RotationSettings(this, Group.Rotation)
@@ -85,7 +86,7 @@ object Scaffold : Module(
8586
.map { it.context }
8687
.distinctBy { it.blockPos }
8788
.sortedWith { o1, o2 -> getBridgeCompareBy(beneath).compare(o1, o2) }
88-
submit(PlaceRequest(contexts, buildConfig, rotationConfig, hotbarConfig, pendingActions))
89+
submit(PlaceRequest(contexts, pendingActions, buildConfig, hotbarConfig, rotationConfig))
8990
}
9091
}
9192
}
@@ -95,11 +96,29 @@ object Scaffold : Module(
9596

9697
return BlockPos
9798
.iterateOutwards(beneath, bridgeRange, bridgeRange, bridgeRange)
99+
.asSequence()
98100
.map { it.blockPos }
101+
.run {
102+
if (onlyBelow) filter { it.y <= beneath.y }
103+
else this
104+
}
105+
.filter { placingCloserToCenter(it, beneath) }
106+
.toList()
99107
}
100108

101109
private fun getBridgeCompareBy(blockPos: BlockPos) =
102110
compareBy<PlaceContext> {
103111
it.blockPos.toCenterPos() distSq blockPos.toCenterPos()
104112
}
113+
114+
private fun SafeContext.placingCloserToCenter(blockPos: BlockPos, center: BlockPos): Boolean {
115+
val potentials = mutableListOf<BlockPos>()
116+
Direction.entries.forEach { direction ->
117+
val offset = blockPos.offset(direction)
118+
val offsetState = blockState(offset)
119+
if (!offsetState.isReplaceable) potentials.add(offset)
120+
}
121+
val trueCenter = center.toCenterPos()
122+
return potentials.any { it.toCenterPos() distSq trueCenter > blockPos.toCenterPos() distSq trueCenter }
123+
}
105124
}

src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class BuildTask @Ta5kBuilder constructor(
162162
.take(emptyPendingInteractionSlots)
163163
.map { it.context }
164164

165-
PlaceRequest(placeResults, build, rotation, hotbar, pendingInteractions) { placements++ }.submit()
165+
PlaceRequest(placeResults, pendingInteractions, build, hotbar, rotation) { placements++ }.submit()
166166
}
167167
is InteractResult.Interact -> {
168168
val interactResults = resultsNotBlocked

0 commit comments

Comments
 (0)