Skip to content

Commit 51db458

Browse files
committed
Revert to old surface scan function as new one was flawed and it hurts
1 parent 50654c6 commit 51db458

File tree

6 files changed

+49
-83
lines changed

6 files changed

+49
-83
lines changed

common/src/main/kotlin/com/lambda/config/groups/InteractionSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class InteractionSettings(
5858
override val strictRayCast by c.setting("Strict Raycast", true, "Whether to include the environment to the ray cast context", vis)
5959
override val checkSideVisibility by c.setting("Visibility Check", true, "Whether to check if an AABB side is visible", vis)
6060
override val resolution by c.setting("Resolution", 5, 1..20, 1, "The amount of grid divisions per surface of the hit box", "", vis)
61-
override val pointSelection by c.setting("Point Selection", PointSelection.Optimum, "The way to select the best point", vis)
61+
override val pointSelection by c.setting("Point Selection", PointSelection.Optimum, "The strategy to select the best hit point", vis)
6262

6363
// Swing
6464
override val swingHand by c.setting("Swing Hand", true, "Whether to swing hand on interactions", vis)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ interface BuildContext : Comparable<BuildContext>, Drawable {
4040

4141
fun interact(swingHand: Boolean)
4242

43-
override fun compareTo(other: BuildContext): Int {
44-
return compareBy<BuildContext> {
43+
override fun compareTo(other: BuildContext) =
44+
compareBy<BuildContext> {
4545
it.distance
4646
}.compare(this, other)
47-
}
4847

4948
fun shouldRotate(config: BuildConfig): Boolean
5049
}

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/VisibilityChecker.kt

Lines changed: 35 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -136,83 +136,49 @@ object VisibilityChecker {
136136
scan: SurfaceScan = SurfaceScan.DEFAULT,
137137
check: (Direction, Vec3d) -> Unit,
138138
) {
139-
val margin = 0.01
140-
141139
excludedSides.forEach { side ->
142140
if (excludedSides.isNotEmpty() && side !in excludedSides) return@forEach
143-
144-
val contractedBox = box.contract(1.0E-6)
145-
val (minX, minY, minZ, maxX, maxY, maxZ) = contractedBox.bounds(side)
146-
147-
// Determine start and end for each axis based on scan configuration
148-
val (startX, endX) = when (scan.axis) {
149-
Direction.Axis.X -> {
150-
val centerX = (minX + maxX) / 2
151-
when (scan.mode) {
152-
ScanMode.GREATER_HALF -> centerX + 0.01 to maxX
153-
ScanMode.LESSER_HALF -> minX to centerX - 0.01
154-
ScanMode.FULL -> minX to maxX
155-
}
141+
val (minX, minY, minZ, maxX, maxY, maxZ) = box.contract(1.0E-3).bounds(side)
142+
val stepX = (maxX - minX) / resolution
143+
val stepY = (maxY - minY) / resolution
144+
val stepZ = (maxZ - minZ) / resolution
145+
146+
// Determine the bounds to scan based on the axis and mode
147+
val (startX, endX) = if (scan.axis == Direction.Axis.X && stepX != 0.0) {
148+
val centerX = (minX + maxX) / 2
149+
when (scan.mode) {
150+
ScanMode.GREATER_HALF -> centerX + 0.01 to maxX
151+
ScanMode.LESSER_HALF -> minX to centerX - 0.01
152+
ScanMode.FULL -> minX to maxX
156153
}
157-
else -> minX to maxX
158-
}
159-
160-
val (startY, endY) = when (scan.axis) {
161-
Direction.Axis.Y -> {
162-
val centerY = (minY + maxY) / 2
163-
when (scan.mode) {
164-
ScanMode.GREATER_HALF -> centerY + 0.01 to maxY
165-
ScanMode.LESSER_HALF -> minY to centerY - 0.01
166-
ScanMode.FULL -> minY to maxY
167-
}
154+
} else minX to maxX
155+
156+
val (startY, endY) = if (scan.axis == Direction.Axis.Y && stepY != 0.0) {
157+
val centerY = (minY + maxY) / 2
158+
when (scan.mode) {
159+
ScanMode.GREATER_HALF -> centerY + 0.01 to maxY
160+
ScanMode.LESSER_HALF -> minY to centerY - 0.01
161+
ScanMode.FULL -> minY to maxY
168162
}
169-
else -> minY to maxY
170-
}
171-
172-
val (startZ, endZ) = when (scan.axis) {
173-
Direction.Axis.Z -> {
174-
val centerZ = (minZ + maxZ) / 2
175-
when (scan.mode) {
176-
ScanMode.GREATER_HALF -> centerZ + 0.01 to maxZ
177-
ScanMode.LESSER_HALF -> minZ to centerZ - 0.01
178-
ScanMode.FULL -> minZ to maxZ
179-
}
163+
} else minY to maxY
164+
165+
val (startZ, endZ) = if (scan.axis == Direction.Axis.Z && stepZ != 0.0) {
166+
val centerZ = (minZ + maxZ) / 2
167+
when (scan.mode) {
168+
ScanMode.GREATER_HALF -> centerZ + 0.01 to maxZ
169+
ScanMode.LESSER_HALF -> minZ to centerZ - 0.01
170+
ScanMode.FULL -> minZ to maxZ
180171
}
181-
else -> minZ to maxZ
182-
}
172+
} else minZ to maxZ
183173

184-
// Apply margin and calculate adjusted step values
185-
val adjustedStartX = startX + margin
186-
val adjustedEndX = (endX - margin).coerceAtLeast(adjustedStartX)
187-
val stepX = if (resolution > 0) (adjustedEndX - adjustedStartX) / resolution else 0.0
188-
189-
val adjustedStartY = startY + margin
190-
val adjustedEndY = (endY - margin).coerceAtLeast(adjustedStartY)
191-
val stepY = if (resolution > 0) (adjustedEndY - adjustedStartY) / resolution else 0.0
192-
193-
val adjustedStartZ = startZ + margin
194-
val adjustedEndZ = (endZ - margin).coerceAtLeast(adjustedStartZ)
195-
val stepZ = if (resolution > 0) (adjustedEndZ - adjustedStartZ) / resolution else 0.0
196-
197-
// Iterate over the adjusted ranges
198174
(0..resolution).forEach outer@{ i ->
199-
val x = adjustedStartX + stepX * i
200-
if (x > adjustedEndX) return@outer
201-
175+
val x = if (stepX != 0.0) startX + stepX * i else startX
176+
if (x > endX) return@outer
202177
(0..resolution).forEach inner@{ j ->
203-
val y = adjustedStartY + stepY * j
204-
if (y > adjustedEndY) return@inner
205-
206-
// Determine z based on which axis is being scanned
207-
val z = when (scan.axis) {
208-
Direction.Axis.X, Direction.Axis.Y -> {
209-
adjustedStartZ + stepZ * (if (scan.axis == Direction.Axis.X) j else i)
210-
}
211-
else -> adjustedStartZ + stepZ * j
212-
}
213-
214-
if (z > adjustedEndZ) return@inner
215-
178+
val y = if (stepY != 0.0) startY + stepY * j else startY
179+
if (y > endY) return@inner
180+
val z = if (stepZ != 0.0) startZ + stepZ * ((if (stepX != 0.0) j else i)) else startZ
181+
if (z > endZ) return@inner
216182
check(side, Vec3d(x, y, z))
217183
}
218184
}

common/src/main/kotlin/com/lambda/module/modules/player/HighwayTools.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object HighwayTools : Module(
6767

6868
private val build = BuildSettings(this) { page == Page.Build }
6969
private val rotation = RotationSettings(this) { page == Page.Rotation }
70-
private val interact = InteractionSettings(this, InteractionMask.BOTH) { page == Page.Interaction }
70+
private val interact = InteractionSettings(this, InteractionMask.BLOCK) { page == Page.Interaction }
7171
private val inventory = InventorySettings(this) { page == Page.Inventory }
7272

7373
private var octant = EightWayDirection.NORTH

common/src/main/kotlin/com/lambda/task/Task.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ abstract class Task<Result> : Nameable, Muteable {
4545
val isCompleted get() = state == State.COMPLETED
4646
val size: Int get() = subTasks.sumOf { it.size } + 1
4747

48-
open var unpausable = false
49-
5048
private var nextTask: TaskGenerator<Result>? = null
5149
private var nextTaskOrNull: TaskGeneratorOrNull<Result>? = null
5250
private var onFinish: TaskGeneratorUnit<Result>? = null
@@ -115,9 +113,9 @@ abstract class Task<Result> : Nameable, Muteable {
115113
owner.subTasks.add(this)
116114
parent = owner
117115
LOG.info("${owner.name} started $name")
118-
if (!unpausable || pauseParent) {
119-
LOG.info("$name deactivating parent ${owner.name}")
120-
if (owner !is RootTask) owner.deactivate()
116+
if (pauseParent) {
117+
LOG.info("$name pausing parent ${owner.name}")
118+
if (owner !is RootTask) owner.pause()
121119
}
122120
state = State.RUNNING
123121
runSafe { runCatching { onStart() }.onFailure { failure(it) } }
@@ -145,9 +143,8 @@ abstract class Task<Result> : Nameable, Muteable {
145143
}
146144

147145
@Ta5kBuilder
148-
fun deactivate() {
146+
fun pause() {
149147
if (state != State.RUNNING) return
150-
if (unpausable) return
151148
state = State.PAUSED
152149
}
153150

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class BuildTask @Ta5kBuilder constructor(
123123
val resultsWithoutPending = results.filterNot { result ->
124124
result.blockPos in pendingInteractions.map { it.expectedPos }
125125
}
126+
val sortedResults = resultsWithoutPending.sorted()
127+
sortedResults
126128
val bestResult = resultsWithoutPending.minOrNull() ?: return@listen
127129
when (bestResult) {
128130
is BuildResult.Done,
@@ -141,7 +143,7 @@ class BuildTask @Ta5kBuilder constructor(
141143
// but the player position does not perfectly match the simulated position
142144
// hacky fix for now is to walk "closer" but it wont work in every situation
143145
val interaction = object : InteractionConfig {
144-
override val attackReach = interact.attackReach
146+
override val attackReach = 3.0
145147
override val interactReach = interact.interactReach - 1
146148
override val scanReach = interact.scanReach
147149
override val strictRayCast = interact.strictRayCast
@@ -161,6 +163,7 @@ class BuildTask @Ta5kBuilder constructor(
161163
is BuildResult.Contextual -> {
162164
if (pendingInteractions.size >= build.maxPendingInteractions) return@listen
163165

166+
// info("Swapping interaction to ${bestResult.context.expectedPos} ${bestResult.context.distance}")
164167
currentInteraction = bestResult.context
165168
}
166169

@@ -195,7 +198,8 @@ class BuildTask @Ta5kBuilder constructor(
195198
pendingInteractions.add(context)
196199
}
197200

198-
listen<WorldEvent.BlockUpdate.Server> { event ->
201+
listen<WorldEvent.BlockUpdate.Server>(alwaysListen = true) { event ->
202+
// info("Update at ${event.pos.toShortString()}: ${event.newState.block.name.string}")
199203
pendingInteractions.firstOrNull { it.expectedPos == event.pos }?.let { context ->
200204
pendingInteractions.remove(context)
201205
if (!context.targetState.matches(event.newState, event.pos, world)) return@let

0 commit comments

Comments
 (0)