Skip to content

Commit a6557a4

Browse files
Improvement: Build Sim Scaffold (#137)
uses the build sim / place manager for scaffold --------- Co-authored-by: Constructor <fractalminds@protonmail.com>
1 parent 455c94d commit a6557a4

File tree

7 files changed

+75
-341
lines changed

7 files changed

+75
-341
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/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)) }

0 commit comments

Comments
 (0)