Skip to content

Commit b7c9113

Browse files
committed
Make requests data classes so we can debug them better
1 parent e38cdb3 commit b7c9113

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

common/src/main/kotlin/com/lambda/interaction/material/transfer/SlotTransfer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SlotTransfer @Ta5kBuilder constructor(
5656
listen<TickEvent.Pre> {
5757
val current = player.currentScreenHandler
5858
if (current != screen) {
59-
failure("Screen has changed. Expected ${screen::class.simpleName} (revision ${screen.revision}, got ${current::class.simpleName} (revision ${current.revision})")
59+
failure("Screen has changed. Expected ${screen::class.simpleName} (revision ${screen.revision}) but got ${current::class.simpleName} (revision ${current.revision})")
6060
return@listen
6161
}
6262

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import com.lambda.interaction.request.Request
2222
import com.lambda.interaction.request.rotation.visibilty.RotationTarget
2323
import com.lambda.threading.runSafe
2424

25-
class RotationRequest(
25+
data class RotationRequest(
2626
val target: RotationTarget,
27-
priority: Priority,
27+
val prio: Priority,
2828
val mode: RotationMode,
2929
var keepTicks: Int = 3,
3030
var decayTicks: Int = 0,
3131
val turnSpeed: () -> Double = { 180.0 },
3232
val speedMultiplier: Double = 1.0
33-
) : Request(priority) {
33+
) : Request(prio) {
3434

3535
constructor(
3636
target: RotationTarget,

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ import net.minecraft.util.math.Direction
3333
/**
3434
* An abstract class representing a rotation target, which can be either a block or an entity.
3535
*/
36-
abstract class RequestedHit private constructor(
37-
val sides: Set<Direction>,
38-
val reach: Double
39-
) {
36+
abstract class RequestedHit {
37+
abstract val sides: Set<Direction>
38+
abstract val reach: Double
4039

4140
/**
4241
* Verifies if the given [HitResult] satisfies the criteria of this
@@ -80,8 +79,11 @@ abstract class RequestedHit private constructor(
8079
* @param entity The [LivingEntity] to be hit.
8180
* @param reach The maximum distance for the hit.
8281
*/
83-
class Entity(val entity: LivingEntity, reach: Double) : RequestedHit(ALL_SIDES, reach) {
84-
82+
data class Entity(
83+
val entity: LivingEntity,
84+
override val reach: Double,
85+
override val sides: Set<Direction> = ALL_SIDES
86+
) : RequestedHit() {
8587
override fun getBoundingBoxes() =
8688
listOf(entity.boundingBox)
8789

@@ -96,8 +98,11 @@ abstract class RequestedHit private constructor(
9698
* @param sides The set of directions for which the hit is requested.
9799
* @param reach The maximum distance for the hit.
98100
*/
99-
class Block(val blockPos: BlockPos, sides: Set<Direction>, reach: Double) : RequestedHit(sides, reach) {
100-
101+
data class Block(
102+
val blockPos: BlockPos,
103+
override val sides: Set<Direction>,
104+
override val reach: Double
105+
) : RequestedHit() {
101106
override fun getBoundingBoxes(): List<Box> = runSafe {
102107
val state = blockPos.blockState(world)
103108
val voxelShape = state.getOutlineShape(world, blockPos)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import com.lambda.util.collections.cached
3131
* @param verify A lambda to check the active rotation.
3232
* @param buildRotation A lambda that builds the rotation.
3333
*/
34-
class RotationTarget(
34+
data class RotationTarget(
3535
val hit: RequestedHit? = null,
3636
val verify: RotationTarget.() -> Boolean = { hit?.verifyRotation() ?: true },
3737
private val buildRotation: SafeContext.() -> Rotation?,

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class BuildTask @Ta5kBuilder constructor(
6666
private var currentPlacement: PlaceContext? = null
6767
private var placements = 0
6868
private var breaks = 0
69-
private var inScope = 0
7069

7170
override fun SafeContext.onStart() {
7271
(blueprint as? DynamicBlueprint)?.create()
@@ -83,12 +82,10 @@ class BuildTask @Ta5kBuilder constructor(
8382
}
8483

8584
currentPlacement?.let { context ->
86-
if (!context.rotation.done) return@listen
87-
if (inScope++ < 1) return@listen // ToDo: Should not be needed but timings are wrong
85+
if (build.rotateForPlace && !context.rotation.done) return@listen
8886
context.place(interact.swingHand)
8987
pendingPlacements.add(context)
9088
currentPlacement = null
91-
inScope = 0
9289
}
9390

9491
(blueprint as? DynamicBlueprint)?.update()
@@ -161,12 +158,10 @@ class BuildTask @Ta5kBuilder constructor(
161158
}
162159

163160
onRotate {
164-
if (currentPlacement == null) return@onRotate
165161
if (!build.rotateForPlace) return@onRotate
162+
val rotateTo = currentPlacement?.rotation ?: return@onRotate
166163

167-
rotation.request(
168-
currentPlacement?.rotation ?: return@onRotate
169-
)
164+
rotation.request(rotateTo)
170165
}
171166

172167
listen<MovementEvent.InputUpdate> {

0 commit comments

Comments
 (0)