Skip to content

Commit 6d1ef93

Browse files
committed
build sim function signature cleanup and proper interaction related naming
1 parent 2ab4142 commit 6d1ef93

File tree

6 files changed

+45
-41
lines changed

6 files changed

+45
-41
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import net.minecraft.util.math.BlockPos
3434
import net.minecraft.util.math.Vec3d
3535
import java.awt.Color
3636

37-
class InteractContext(
37+
class InteractionContext(
3838
override val pov: Vec3d,
3939
override val result: BlockHitResult,
4040
override val rotation: RotationRequest,
@@ -51,7 +51,7 @@ class InteractContext(
5151

5252
override fun compareTo(other: BuildContext) =
5353
when {
54-
other is InteractContext -> compareBy<BuildContext> {
54+
other is InteractionContext -> compareBy<BuildContext> {
5555
BlockUtils.fluids.indexOf(it.checkedState.fluidState.fluid)
5656
}.thenByDescending {
5757
it.checkedState.fluidState.level

common/src/main/kotlin/com/lambda/interaction/construction/result/InteractResult.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
package com.lambda.interaction.construction.result
1919

2020
import com.lambda.context.SafeContext
21-
import com.lambda.interaction.construction.context.InteractContext
21+
import com.lambda.interaction.construction.context.InteractionContext
2222
import net.minecraft.util.math.BlockPos
2323

2424
sealed class InteractResult : BuildResult() {
2525
data class Interact(
2626
override val blockPos: BlockPos,
27-
override val context: InteractContext
27+
override val context: InteractionContext
2828
) : Contextual, Drawable, InteractResult() {
2929
override val rank = Rank.INTERACT_SUCCESS
3030

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.lambda.config.groups.InventoryConfig
2323
import com.lambda.context.SafeContext
2424
import com.lambda.interaction.construction.blueprint.Blueprint
2525
import com.lambda.interaction.construction.context.BreakContext
26-
import com.lambda.interaction.construction.context.InteractContext
26+
import com.lambda.interaction.construction.context.InteractionContext
2727
import com.lambda.interaction.construction.context.PlaceContext
2828
import com.lambda.interaction.construction.processing.PreProcessingInfo
2929
import com.lambda.interaction.construction.processing.ProcessorRegistry.getProcessingInfo
@@ -96,11 +96,11 @@ object BuildSimulator {
9696
) = runSafe {
9797
structure.entries.flatMap { (pos, target) ->
9898
val preProcessing = target.getProcessingInfo()
99-
checkRequirements(pos, target, eye, preProcessing, build, interact, rotation, inventory).let {
99+
checkRequirements(pos, eye, preProcessing, target, build, interact, rotation, inventory).let {
100100
if (it.isEmpty()) return@let
101101
return@flatMap it
102102
}
103-
checkPlaceResults(pos, target, eye, preProcessing, build.placing, interact, rotation, inventory).let {
103+
checkPlaceResults(pos, eye, preProcessing, target, build.placing, interact, rotation, inventory).let {
104104
if (it.isEmpty()) return@let
105105
return@flatMap it
106106
}
@@ -115,9 +115,9 @@ object BuildSimulator {
115115

116116
private fun SafeContext.checkRequirements(
117117
pos: BlockPos,
118-
target: TargetState,
119118
eye: Vec3d,
120119
preProcessing: PreProcessingInfo,
120+
target: TargetState,
121121
build: BuildConfig,
122122
interact: InteractionConfig,
123123
rotation: RotationConfig,
@@ -165,8 +165,12 @@ object BuildSimulator {
165165

166166
/* the state requires post-processing */
167167
if (target.matches(state, pos, world, ignoredProperties = preProcessing.ignore)) {
168-
acc.addAll(checkPostProcessResults(target, state, pos, eye, preProcessing, interact, build.placing, rotation, inventory))
169-
if (acc.isNotEmpty()) return acc
168+
checkPostProcessResults(pos, eye, preProcessing, state, target, interact, build.placing, rotation, inventory).let { postProcessResults ->
169+
if (postProcessResults.isNotEmpty()) {
170+
acc.addAll(postProcessResults)
171+
return acc
172+
}
173+
}
170174
}
171175

172176
/* block is unbreakable, so it cant be broken or replaced */
@@ -180,9 +184,9 @@ object BuildSimulator {
180184

181185
private fun SafeContext.checkPlaceResults(
182186
pos: BlockPos,
183-
target: TargetState,
184187
eye: Vec3d,
185188
preProcessing: PreProcessingInfo,
189+
target: TargetState,
186190
place: PlaceConfig,
187191
interact: InteractionConfig,
188192
rotation: RotationConfig,
@@ -265,7 +269,7 @@ object BuildSimulator {
265269
return@forEach
266270
}
267271

268-
checkPlaceOn(pos, validHits, target, eye, preProcessing, place, rotation, interact, inventory)?.let { placeResult ->
272+
checkPlaceOn(pos, validHits, eye, preProcessing, target, place, rotation, interact, inventory)?.let { placeResult ->
269273
acc.add(placeResult)
270274
}
271275
}
@@ -274,11 +278,11 @@ object BuildSimulator {
274278
}
275279

276280
private fun SafeContext.checkPostProcessResults(
277-
targetState: TargetState,
278-
state: BlockState,
279281
pos: BlockPos,
280282
eye: Vec3d,
281283
preProcessing: PreProcessingInfo,
284+
state: BlockState,
285+
targetState: TargetState,
282286
interact: InteractionConfig,
283287
place: PlaceConfig,
284288
rotation: RotationConfig,
@@ -293,12 +297,12 @@ object BuildSimulator {
293297
interactWithBlock(
294298
pos,
295299
state,
296-
expectedState,
297-
targetState,
298300
eye,
299301
side,
300-
preProcessing,
301302
item ?: player.inventory.mainHandStack.item,
303+
expectedState,
304+
targetState,
305+
preProcessing,
302306
placing,
303307
interact,
304308
place,
@@ -334,12 +338,12 @@ object BuildSimulator {
334338
private fun SafeContext.interactWithBlock(
335339
pos: BlockPos,
336340
state: BlockState,
337-
expectedState: BlockState,
338-
targetState: TargetState,
339341
eye: Vec3d,
340342
sides: Set<Direction>?,
341-
preProcessing: PreProcessingInfo,
342343
item: Item,
344+
expectedState: BlockState,
345+
targetState: TargetState,
346+
preProcessing: PreProcessingInfo,
343347
placing: Boolean,
344348
interact: InteractionConfig,
345349
place: PlaceConfig,
@@ -407,26 +411,26 @@ object BuildSimulator {
407411
}
408412
}
409413

410-
return if (placing) checkPlaceOn(pos, validHits, targetState, eye, preProcessing, place, rotation, interact, inventory)
411-
else checkInteractOn(pos, validHits, state, expectedState, targetState, item, eye, rotation, interact, inventory)
414+
return if (placing) checkPlaceOn(pos, validHits, eye, preProcessing, targetState, place, rotation, interact, inventory)
415+
else checkInteractOn(pos, eye, item, validHits, expectedState, targetState, state, rotation, interact, inventory)
412416
}
413417

414418
private fun SafeContext.checkInteractOn(
415419
pos: BlockPos,
420+
eye: Vec3d,
421+
item: Item,
416422
validHits: MutableList<CheckedHit>,
417-
currentState: BlockState,
418423
expectedState: BlockState,
419424
targetState: TargetState,
420-
item: Item,
421-
eye: Vec3d,
425+
currentState: BlockState,
422426
rotation: RotationConfig,
423427
interact: InteractionConfig,
424428
inventory: InventoryConfig
425429
): BuildResult? {
426430
interact.pointSelection.select(validHits)?.let { checkedHit ->
427431
val checkedResult = checkedHit.hit
428432
val rotationTarget = lookAt(checkedHit.targetRotation, 0.001)
429-
val context = InteractContext(
433+
val context = InteractionContext(
430434
eye,
431435
checkedResult.blockResult ?: return null,
432436
RotationRequest(rotationTarget, rotation),
@@ -461,16 +465,16 @@ object BuildSimulator {
461465
private fun SafeContext.checkPlaceOn(
462466
pos: BlockPos,
463467
validHits: MutableList<CheckedHit>,
464-
target: TargetState,
465468
eye: Vec3d,
466469
preProcessing: PreProcessingInfo,
470+
targetState: TargetState,
467471
place: PlaceConfig,
468472
rotation: RotationConfig,
469473
interact: InteractionConfig,
470474
inventory: InventoryConfig
471475
): BuildResult? {
472476
interact.pointSelection.select(validHits)?.let { checkedHit ->
473-
val optimalStack = target.getStack(world, pos)
477+
val optimalStack = targetState.getStack(world, pos)
474478

475479
// ToDo: For each hand and sneak or not?
476480
val fakePlayer = copyPlayer(player).apply {
@@ -528,9 +532,9 @@ object BuildSimulator {
528532
resultState = blockItem.getPlacementState(context)
529533
?: return@placeState PlaceResult.BlockedByEntity(pos)
530534

531-
if (!target.matches(resultState, pos, world, preProcessing.ignore)) {
535+
if (!targetState.matches(resultState, pos, world, preProcessing.ignore)) {
532536
return@placeState PlaceResult.NoIntegrity(
533-
pos, resultState, context, (target as? TargetState.State)?.blockState
537+
pos, resultState, context, (targetState as? TargetState.State)?.blockState
534538
)
535539
} else {
536540
return@placeState null
@@ -599,15 +603,15 @@ object BuildSimulator {
599603
blockState(blockHit.blockPos.offset(blockHit.side)),
600604
player.inventory.selectedSlot,
601605
context.blockPos,
602-
target,
606+
targetState,
603607
shouldSneak,
604608
false,
605609
currentDirIsInvalid,
606610
)
607611

608612
val currentHandStack = player.getStackInHand(Hand.MAIN_HAND)
609-
if (target is TargetState.Stack && !target.itemStack.equal(currentHandStack)) {
610-
return BuildResult.WrongStack(pos, placeContext, target.itemStack, inventory)
613+
if (targetState is TargetState.Stack && !targetState.itemStack.equal(currentHandStack)) {
614+
return BuildResult.WrongStack(pos, placeContext, targetState.itemStack, inventory)
611615
}
612616

613617
if (optimalStack.item != currentHandStack.item) {
@@ -652,7 +656,7 @@ object BuildSimulator {
652656

653657
/* liquid needs to be submerged first to be broken */
654658
if (!state.fluidState.isEmpty && state.isReplaceable) {
655-
val submerge = checkPlaceResults(pos, TargetState.Solid, eye, preProcessing, build.placing, interact, rotation, inventory)
659+
val submerge = checkPlaceResults(pos, eye, preProcessing, TargetState.Solid, build.placing, interact, rotation, inventory)
656660
acc.add(BreakResult.Submerge(pos, state, submerge))
657661
acc.addAll(submerge)
658662
return acc
@@ -667,7 +671,7 @@ object BuildSimulator {
667671
acc.add(BreakResult.BlockedByLiquid(pos, state))
668672
adjacentLiquids.forEach { liquidPos ->
669673
val submerge = if (blockState(liquidPos).isReplaceable) {
670-
checkPlaceResults(liquidPos, TargetState.Solid, eye, preProcessing, build.placing, interact, rotation, inventory)
674+
checkPlaceResults(liquidPos, eye, preProcessing, TargetState.Solid, build.placing, interact, rotation, inventory)
671675
} else {
672676
checkBreakResults(liquidPos, eye, preProcessing, breaking, interact, rotation, inventory, build)
673677
}

common/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package com.lambda.interaction.request.interacting
1919

2020
import com.lambda.config.groups.InteractionConfig
2121
import com.lambda.interaction.construction.context.BuildContext
22-
import com.lambda.interaction.construction.context.InteractContext
22+
import com.lambda.interaction.construction.context.InteractionContext
2323

2424
data class InteractionInfo(
25-
val context: InteractContext,
25+
val context: InteractionContext,
2626
val pendingInteractionsList: MutableCollection<BuildContext>,
2727
val interact: InteractionConfig
2828
)

common/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import com.lambda.event.events.MovementEvent
2424
import com.lambda.event.events.TickEvent
2525
import com.lambda.event.events.UpdateManagerEvent
2626
import com.lambda.event.listener.SafeListener.Companion.listen
27-
import com.lambda.interaction.construction.context.InteractContext
27+
import com.lambda.interaction.construction.context.InteractionContext
2828
import com.lambda.interaction.request.RequestHandler
2929
import com.lambda.interaction.request.breaking.BreakManager
3030
import com.lambda.interaction.request.interacting.InteractedBlockHandler.addPendingInteract
@@ -46,7 +46,7 @@ object InteractionManager : RequestHandler<InteractionRequest>(
4646
onOpen = { activeRequest?.let { processRequest(it) } }
4747
) {
4848
private var activeRequest: InteractionRequest? = null
49-
private var potentialInteractions = mutableListOf<InteractContext>()
49+
private var potentialInteractions = mutableListOf<InteractionContext>()
5050

5151
private var interactionsThisTick = 0
5252
private var maxInteractionsThisTick = 0

common/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import com.lambda.Lambda.mc
2121
import com.lambda.config.groups.BuildConfig
2222
import com.lambda.config.groups.InteractionConfig
2323
import com.lambda.interaction.construction.context.BuildContext
24-
import com.lambda.interaction.construction.context.InteractContext
24+
import com.lambda.interaction.construction.context.InteractionContext
2525
import com.lambda.interaction.request.Request
2626
import com.lambda.interaction.request.hotbar.HotbarConfig
2727
import com.lambda.interaction.request.rotating.RotationConfig
2828
import com.lambda.util.BlockUtils.matches
2929
import net.minecraft.util.math.BlockPos
3030

3131
data class InteractionRequest(
32-
val contexts: Collection<InteractContext>,
32+
val contexts: Collection<InteractionContext>,
3333
val onInteract: ((BlockPos) -> Unit)?,
3434
val pendingInteractionsList: MutableCollection<BuildContext>,
3535
val interact: InteractionConfig,

0 commit comments

Comments
 (0)