@@ -23,7 +23,7 @@ import com.lambda.config.groups.InventoryConfig
2323import com.lambda.context.SafeContext
2424import com.lambda.interaction.construction.blueprint.Blueprint
2525import com.lambda.interaction.construction.context.BreakContext
26- import com.lambda.interaction.construction.context.InteractContext
26+ import com.lambda.interaction.construction.context.InteractionContext
2727import com.lambda.interaction.construction.context.PlaceContext
2828import com.lambda.interaction.construction.processing.PreProcessingInfo
2929import 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 }
0 commit comments