Skip to content

Commit 7dd5283

Browse files
committed
more cleanup
1 parent 2585445 commit 7dd5283

File tree

18 files changed

+91
-105
lines changed

18 files changed

+91
-105
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ package com.lambda.interaction.construction.context
2020
import com.lambda.context.SafeContext
2121
import com.lambda.graphics.renderer.esp.DirectionMask
2222
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
23-
import com.lambda.interaction.construction.verify.TargetState
2423
import com.lambda.interaction.request.breaking.BreakRequest
2524
import com.lambda.interaction.request.hotbar.HotbarManager
2625
import com.lambda.interaction.request.hotbar.HotbarRequest
2726
import com.lambda.interaction.request.rotating.RotationRequest
27+
import com.lambda.util.BlockUtils.emptyState
2828
import net.minecraft.block.BlockState
2929
import net.minecraft.block.FallingBlock
3030
import net.minecraft.util.hit.BlockHitResult
@@ -36,21 +36,18 @@ data class BreakContext(
3636
override val rotation: RotationRequest,
3737
override var hotbarIndex: Int,
3838
override var cachedState: BlockState,
39-
override val targetState: TargetState,
4039
var instantBreak: Boolean
4140
) : BuildContext() {
4241
private val baseColor = Color(222, 0, 0, 25)
4342
private val sideColor = Color(222, 0, 0, 100)
4443

45-
override val expectedPos: BlockPos
46-
get() = result.blockPos
47-
48-
override val expectedState: BlockState = cachedState.fluidState.blockState
44+
override val blockPos: BlockPos = result.blockPos
45+
override val expectedState: BlockState = cachedState.emptyState
4946

5047
override fun compareTo(other: BuildContext): Int {
5148
return when (other) {
5249
is BreakContext -> compareByDescending<BreakContext> {
53-
if (it.cachedState.block is FallingBlock) it.expectedPos.y else 0
50+
if (it.cachedState.block is FallingBlock) it.blockPos.y else 0
5451
}.thenBy {
5552
it.instantBreak
5653
}.thenBy {
@@ -64,8 +61,8 @@ data class BreakContext(
6461
}
6562

6663
override fun SafeContext.buildRenderer() {
67-
withState(cachedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side))
68-
withState(cachedState, expectedPos, sideColor, result.side)
64+
withState(cachedState, blockPos, baseColor, DirectionMask.ALL.exclude(result.side))
65+
withState(cachedState, blockPos, sideColor, result.side)
6966
}
7067

7168
fun requestDependencies(breakRequest: BreakRequest, minKeepTicks: Int = 0): Boolean {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.lambda.interaction.construction.context
1919

2020
import com.lambda.Lambda.mc
2121
import com.lambda.interaction.construction.result.Drawable
22-
import com.lambda.interaction.construction.verify.TargetState
2322
import com.lambda.interaction.request.rotating.RotationRequest
2423
import net.minecraft.block.BlockState
2524
import net.minecraft.util.hit.BlockHitResult
@@ -29,10 +28,9 @@ abstract class BuildContext : Comparable<BuildContext>, Drawable {
2928
abstract val result: BlockHitResult
3029
abstract val rotation: RotationRequest
3130
abstract val hotbarIndex: Int
32-
abstract val expectedPos: BlockPos
3331
abstract val cachedState: BlockState
3432
abstract val expectedState: BlockState
35-
abstract val targetState: TargetState
33+
abstract val blockPos: BlockPos
3634

3735
val distance by lazy {
3836
mc.player?.eyePos?.distanceTo(result.pos) ?: Double.MAX_VALUE

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.lambda.interaction.construction.context
2020
import com.lambda.context.SafeContext
2121
import com.lambda.graphics.renderer.esp.DirectionMask
2222
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
23-
import com.lambda.interaction.construction.verify.TargetState
2423
import com.lambda.interaction.request.hotbar.HotbarManager
2524
import com.lambda.interaction.request.hotbar.HotbarRequest
2625
import com.lambda.interaction.request.interacting.InteractionRequest
@@ -36,14 +35,14 @@ class InteractionContext(
3635
override val result: BlockHitResult,
3736
override val rotation: RotationRequest,
3837
override var hotbarIndex: Int,
39-
override val expectedPos: BlockPos,
4038
override val cachedState: BlockState,
4139
override val expectedState: BlockState,
42-
override val targetState: TargetState,
4340
) : BuildContext() {
4441
private val baseColor = Color(35, 254, 79, 25)
4542
private val sideColor = Color(35, 254, 79, 100)
4643

44+
override val blockPos: BlockPos = result.blockPos
45+
4746
override fun compareTo(other: BuildContext) =
4847
when {
4948
other is InteractionContext -> compareBy<BuildContext> {
@@ -62,7 +61,7 @@ class InteractionContext(
6261
}
6362

6463
override fun SafeContext.buildRenderer() {
65-
withState(expectedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side.opposite))
64+
withState(expectedState, blockPos, baseColor, DirectionMask.ALL.exclude(result.side.opposite))
6665
withState(blockState(result.blockPos), result.blockPos, sideColor, result.side)
6766
}
6867

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.lambda.Lambda.mc
2121
import com.lambda.context.SafeContext
2222
import com.lambda.graphics.renderer.esp.DirectionMask
2323
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
24-
import com.lambda.interaction.construction.verify.TargetState
2524
import com.lambda.interaction.request.hotbar.HotbarManager
2625
import com.lambda.interaction.request.hotbar.HotbarRequest
2726
import com.lambda.interaction.request.placing.PlaceRequest
@@ -37,10 +36,9 @@ data class PlaceContext(
3736
override val result: BlockHitResult,
3837
override val rotation: RotationRequest,
3938
override val hotbarIndex: Int,
40-
override val expectedPos: BlockPos,
39+
override val blockPos: BlockPos,
4140
override val cachedState: BlockState,
4241
override val expectedState: BlockState,
43-
override val targetState: TargetState,
4442
val sneak: Boolean,
4543
val insideBlock: Boolean,
4644
val currentDirIsInvalid: Boolean = false
@@ -70,7 +68,7 @@ data class PlaceContext(
7068
}
7169

7270
override fun SafeContext.buildRenderer() {
73-
withState(expectedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side.opposite))
71+
withState(expectedState, blockPos, baseColor, DirectionMask.ALL.exclude(result.side.opposite))
7472
withState(blockState(result.blockPos), result.blockPos, sideColor, result.side)
7573
}
7674

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ object BuildSimulator {
271271
return@forEach
272272
}
273273

274-
checkPlaceOn(pos, validHits, eye, preProcessing, target, place, rotation, interact, inventory)?.let { placeResult ->
274+
checkPlaceOn(pos, validHits, preProcessing, target, place, rotation, interact, inventory)?.let { placeResult ->
275275
acc.add(placeResult)
276276
}
277277
}
@@ -413,16 +413,15 @@ object BuildSimulator {
413413
}
414414
}
415415

416-
return if (placing) checkPlaceOn(pos, validHits, eye, preProcessing, targetState, place, rotation, interact, inventory)
417-
else checkInteractOn(pos, item, validHits, expectedState, targetState, state, rotation, interact, inventory)
416+
return if (placing) checkPlaceOn(pos, validHits, preProcessing, targetState, place, rotation, interact, inventory)
417+
else checkInteractOn(pos, item, validHits, expectedState, state, rotation, interact, inventory)
418418
}
419419

420420
private fun SafeContext.checkInteractOn(
421421
pos: BlockPos,
422422
item: Item,
423423
validHits: MutableList<CheckedHit>,
424424
expectedState: BlockState,
425-
targetState: TargetState,
426425
currentState: BlockState,
427426
rotation: RotationConfig,
428427
interact: InteractionConfig,
@@ -435,10 +434,8 @@ object BuildSimulator {
435434
checkedResult.blockResult ?: return null,
436435
RotationRequest(rotationTarget, rotation),
437436
player.inventory.selectedSlot,
438-
pos,
439437
currentState,
440-
expectedState,
441-
targetState
438+
expectedState
442439
)
443440

444441
val stackSelection = item.select()
@@ -463,7 +460,6 @@ object BuildSimulator {
463460
private fun SafeContext.checkPlaceOn(
464461
pos: BlockPos,
465462
validHits: MutableList<CheckedHit>,
466-
eye: Vec3d,
467463
preProcessing: PreProcessingInfo,
468464
targetState: TargetState,
469465
place: PlaceConfig,
@@ -596,9 +592,8 @@ object BuildSimulator {
596592
RotationRequest(rotationRequest, rotation),
597593
player.inventory.selectedSlot,
598594
context.blockPos,
595+
blockState(context.blockPos),
599596
resultState,
600-
blockState(blockHit.blockPos.offset(blockHit.side)),
601-
targetState,
602597
shouldSneak,
603598
false,
604599
currentDirIsInvalid
@@ -699,7 +694,6 @@ object BuildSimulator {
699694
rotationRequest,
700695
player.inventory.selectedSlot,
701696
state,
702-
TargetState.Empty,
703697
instantBreakable(state, pos, breaking.breakThreshold)
704698
)
705699
acc.add(BreakResult.Break(pos, breakContext))
@@ -744,10 +738,10 @@ object BuildSimulator {
744738
val bestHit = interact.pointSelection.select(validHits) ?: return acc
745739
val blockHit = bestHit.hit.blockResult ?: return acc
746740
val target = lookAt(bestHit.targetRotation, 0.001)
747-
val request = RotationRequest(target, rotation)
741+
val rotationRequest = RotationRequest(target, rotation)
748742
val instant = instantBreakable(state, pos, breaking.breakThreshold)
749743

750-
val breakContext = BreakContext(blockHit, request, player.inventory.selectedSlot, state, TargetState.Empty, instant)
744+
val breakContext = BreakContext(blockHit, rotationRequest, player.inventory.selectedSlot, state, instant)
751745

752746
if (gamemode.isCreative) {
753747
acc.add(BreakResult.Break(pos, breakContext))

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ data class BreakInfo(
7575
}
7676

7777
fun internalOnCancel() {
78-
request.onCancel?.invoke(context.expectedPos)
78+
request.onCancel?.invoke(context.blockPos)
7979
}
8080

8181
fun updateInfo(context: BreakContext, request: BreakRequest) {
@@ -103,11 +103,11 @@ data class BreakInfo(
103103
world: ClientWorld,
104104
stage: Int = getBreakTextureProgress(player, world)
105105
) {
106-
world.setBlockBreakingInfo(player.id, context.expectedPos, stage)
106+
world.setBlockBreakingInfo(player.id, context.blockPos, stage)
107107
}
108108

109109
private fun getBreakTextureProgress(player: PlayerEntity, world: ClientWorld): Int {
110-
val breakDelta = context.cachedState.calcItemBlockBreakingDelta(player, world, context.expectedPos, player.mainHandStack)
110+
val breakDelta = context.cachedState.calcItemBlockBreakingDelta(player, world, context.blockPos, player.mainHandStack)
111111
val progress = (breakDelta * breakingTicks) / getBreakThreshold()
112112
return if (progress > 0.0f) (progress * 10.0f).toInt() else -1
113113
}
@@ -127,7 +127,7 @@ data class BreakInfo(
127127
interaction.sendSequencedPacket(world) { sequence: Int ->
128128
PlayerActionC2SPacket(
129129
action,
130-
context.expectedPos,
130+
context.blockPos,
131131
context.result.side,
132132
sequence
133133
)

0 commit comments

Comments
 (0)