Skip to content

Commit 1480c56

Browse files
committed
initial simulation separation and dependency result structure
1 parent 1099c72 commit 1480c56

34 files changed

+1824
-1389
lines changed

src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import kotlin.math.sqrt
4141
import kotlin.random.Random
4242

4343
data class BreakContext(
44-
override val result: BlockHitResult,
45-
override val rotation: RotationRequest,
44+
override val hitResult: BlockHitResult,
45+
override val rotationRequest: RotationRequest,
4646
override var hotbarIndex: Int,
4747
var itemSelection: StackSelection,
4848
var instantBreak: Boolean,
@@ -53,7 +53,7 @@ data class BreakContext(
5353
private val baseColor = Color(222, 0, 0, 25)
5454
private val sideColor = Color(222, 0, 0, 100)
5555

56-
override val blockPos: BlockPos = result.blockPos
56+
override val blockPos: BlockPos = hitResult.blockPos
5757
override val expectedState = cachedState.emptyState
5858

5959
val random = Random.nextDouble()
@@ -66,9 +66,9 @@ data class BreakContext(
6666
}.thenBy {
6767
when (sortMode) {
6868
BreakConfig.SortMode.Tool,
69-
BreakConfig.SortMode.Closest -> player.eyePos.distance(it.result.pos, it.cachedState.block)
70-
BreakConfig.SortMode.Farthest -> -player.eyePos.distance(it.result.pos, it.cachedState.block)
71-
BreakConfig.SortMode.Rotation -> it.rotation.target.angleDistance
69+
BreakConfig.SortMode.Closest -> player.eyePos.distance(it.hitResult.pos, it.cachedState.block)
70+
BreakConfig.SortMode.Farthest -> -player.eyePos.distance(it.hitResult.pos, it.cachedState.block)
71+
BreakConfig.SortMode.Rotation -> it.rotationRequest.target.angleDistance
7272
BreakConfig.SortMode.Random -> it.random
7373
}
7474
}.thenByDescending {
@@ -92,14 +92,14 @@ data class BreakContext(
9292
}
9393

9494
override fun ShapeBuilder.buildRenderer() {
95-
box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(result.side))
95+
box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(hitResult.side))
9696
}
9797

9898
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
9999
group("Break Context") {
100100
text(blockPos.getLogContextBuilder())
101-
text(result.getLogContextBuilder())
102-
text(rotation.getLogContextBuilder())
101+
text(hitResult.getLogContextBuilder())
102+
text(rotationRequest.getLogContextBuilder())
103103
value("Hotbar Index", hotbarIndex)
104104
value("Instant Break", instantBreak)
105105
value("Cached State", cachedState)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import net.minecraft.util.hit.BlockHitResult
2626
import net.minecraft.util.math.BlockPos
2727

2828
abstract class BuildContext : Comparable<BuildContext>, Drawable, Automated {
29-
abstract val result: BlockHitResult
30-
abstract val rotation: RotationRequest
29+
abstract val hitResult: BlockHitResult
30+
abstract val rotationRequest: RotationRequest
3131
abstract val hotbarIndex: Int
3232
abstract val cachedState: BlockState
3333
abstract val expectedState: BlockState
3434
abstract val blockPos: BlockPos
3535

3636
val distance by lazy {
37-
runSafe { player.eyePos.distanceTo(result.pos) } ?: Double.MAX_VALUE
37+
runSafe { player.eyePos.distanceTo(hitResult.pos) } ?: Double.MAX_VALUE
3838
}
3939
}

src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import net.minecraft.util.math.BlockPos
3535
import java.awt.Color
3636

3737
class InteractionContext(
38-
override val result: BlockHitResult,
39-
override val rotation: RotationRequest,
38+
override val hitResult: BlockHitResult,
39+
override val rotationRequest: RotationRequest,
4040
override var hotbarIndex: Int,
4141
override var cachedState: BlockState,
4242
override val expectedState: BlockState,
@@ -45,7 +45,7 @@ class InteractionContext(
4545
private val baseColor = Color(35, 254, 79, 25)
4646
private val sideColor = Color(35, 254, 79, 100)
4747

48-
override val blockPos: BlockPos = result.blockPos
48+
override val blockPos: BlockPos = hitResult.blockPos
4949

5050
override fun compareTo(other: BuildContext) =
5151
when {
@@ -54,7 +54,7 @@ class InteractionContext(
5454
}.thenByDescending {
5555
it.cachedState.fluidState.level
5656
}.thenBy {
57-
it.rotation.target.angleDistance
57+
it.rotationRequest.target.angleDistance
5858
}.thenBy {
5959
it.hotbarIndex == HotbarManager.serverSlot
6060
}.thenBy {
@@ -65,20 +65,20 @@ class InteractionContext(
6565
}
6666

6767
override fun ShapeBuilder.buildRenderer() {
68-
box(blockPos, expectedState, baseColor, sideColor, result.side.mask)
68+
box(blockPos, expectedState, baseColor, sideColor, hitResult.side.mask)
6969
}
7070

7171
fun requestDependencies(request: InteractRequest): Boolean {
7272
val hotbarRequest = submit(HotbarRequest(hotbarIndex, request), false)
73-
val validRotation = if (request.interactConfig.rotate) submit(rotation, false).done else true
73+
val validRotation = if (request.interactConfig.rotate) submit(rotationRequest, false).done else true
7474
return hotbarRequest.done && validRotation
7575
}
7676

7777
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
7878
group("Interaction Context") {
7979
text(blockPos.getLogContextBuilder())
80-
text(result.getLogContextBuilder())
81-
text(rotation.getLogContextBuilder())
80+
text(hitResult.getLogContextBuilder())
81+
text(rotationRequest.getLogContextBuilder())
8282
value("Hotbar Index", hotbarIndex)
8383
value("Cached State", cachedState)
8484
value("Expected State", expectedState)

src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import net.minecraft.util.math.BlockPos
3636
import java.awt.Color
3737

3838
data class PlaceContext(
39-
override val result: BlockHitResult,
40-
override val rotation: RotationRequest,
39+
override val hitResult: BlockHitResult,
40+
override val rotationRequest: RotationRequest,
4141
override var hotbarIndex: Int,
4242
override val blockPos: BlockPos,
4343
override var cachedState: BlockState,
@@ -61,7 +61,7 @@ data class PlaceContext(
6161
}.thenBy {
6262
it.sneak == (mc.player?.isSneaking ?: false)
6363
}.thenBy {
64-
it.rotation.target.angleDistance
64+
it.rotationRequest.target.angleDistance
6565
}.thenBy {
6666
it.hotbarIndex == HotbarManager.serverSlot
6767
}.thenBy {
@@ -74,22 +74,22 @@ data class PlaceContext(
7474
}
7575

7676
override fun ShapeBuilder.buildRenderer() {
77-
box(blockPos, expectedState, baseColor, sideColor, result.side.mask)
77+
box(blockPos, expectedState, baseColor, sideColor, hitResult.side.mask)
7878
}
7979

8080
fun requestDependencies(request: PlaceRequest): Boolean {
8181
val hotbarRequest = submit(HotbarRequest(hotbarIndex, this), false)
8282
val validRotation = if (request.placeConfig.rotateForPlace) {
83-
submit(rotation, false).done && currentDirIsValid
83+
submit(rotationRequest, false).done && currentDirIsValid
8484
} else true
8585
return hotbarRequest.done && validRotation
8686
}
8787

8888
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
8989
group("Place Context") {
9090
text(blockPos.getLogContextBuilder())
91-
text(result.getLogContextBuilder())
92-
text(rotation.getLogContextBuilder())
91+
text(hitResult.getLogContextBuilder())
92+
text(rotationRequest.getLogContextBuilder())
9393
value("Hotbar Index", hotbarIndex)
9494
value("Cached State", cachedState)
9595
value("Expected State", expectedState)

0 commit comments

Comments
 (0)