@@ -60,6 +60,7 @@ import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
6060import com.lambda.util.BlockUtils.instantBreakable
6161import com.lambda.util.BlockUtils.isEmpty
6262import com.lambda.util.BlockUtils.isNotEmpty
63+ import com.lambda.util.BlockUtils.item
6364import com.lambda.util.BlockUtils.vecOf
6465import com.lambda.util.Communication.warn
6566import com.lambda.util.item.ItemStackUtils.equal
@@ -70,6 +71,7 @@ import com.lambda.util.player.gamemode
7071import com.lambda.util.world.raycast.RayCastUtils.blockResult
7172import net.minecraft.block.BlockState
7273import net.minecraft.block.OperatorBlock
74+ import net.minecraft.block.enums.SlabType
7375import net.minecraft.block.pattern.CachedBlockPosition
7476import net.minecraft.enchantment.Enchantments
7577import net.minecraft.item.BlockItem
@@ -98,7 +100,7 @@ object BuildSimulator {
98100 ) = runSafe {
99101 structure.entries.flatMap { (pos, target) ->
100102 val preProcessing = target.getProcessingInfo()
101- checkRequirements(pos, preProcessing, target, build).let {
103+ checkRequirements(pos, target, build).let {
102104 if (it.isEmpty()) return @let
103105 return @flatMap it
104106 }
@@ -121,7 +123,6 @@ object BuildSimulator {
121123
122124 private fun SafeContext.checkRequirements (
123125 pos : BlockPos ,
124- preProcessing : PreProcessingInfo ,
125126 target : TargetState ,
126127 build : BuildConfig
127128 ): Set <BuildResult > {
@@ -289,6 +290,7 @@ object BuildSimulator {
289290
290291 val interactBlock: (BlockState , Set <Direction >? , Item ? , Boolean ) -> Unit =
291292 { expectedState, side, item, placing ->
293+ // ToDo: Refactor this function chain into a better solution
292294 interactWithBlock(
293295 pos,
294296 state,
@@ -311,15 +313,37 @@ object BuildSimulator {
311313 val mismatchedProperties = state.properties.filter { state.get(it) != targetState.blockState.get(it) }
312314 mismatchedProperties.forEach { property ->
313315 when (property) {
314- Properties .EYE -> run eye@ {
315- if (state.get(Properties .EYE )) return @eye
316+ Properties .EYE -> {
317+ if (state.get(Properties .EYE )) return @forEach
316318 val expectedState = state.with (Properties .EYE , true )
317319 interactBlock(expectedState, null , null , false )
318320 }
319- Properties .OPEN -> run open@ {
321+ Properties .INVERTED -> {
322+ val expectedState = state.with (Properties .INVERTED , ! state.get(Properties .INVERTED ))
323+ interactBlock(expectedState, null , null , false )
324+ }
325+ Properties .DELAY -> {
326+ val expectedState = state.with (Properties .DELAY , state.cycle(Properties .DELAY ).get(Properties .DELAY ))
327+ interactBlock(expectedState, null , null , false )
328+ }
329+ Properties .COMPARATOR_MODE -> {
330+ val expectedState = state.with (Properties .COMPARATOR_MODE , state.cycle(Properties .COMPARATOR_MODE ).get(Properties .COMPARATOR_MODE ))
331+ interactBlock(expectedState, null , null , false )
332+ }
333+ Properties .OPEN -> {
320334 val expectedState = state.with (Properties .OPEN , ! state.get(Properties .OPEN ))
321335 interactBlock(expectedState, null , null , false )
322336 }
337+ Properties .SLAB_TYPE -> {
338+ if (targetState.blockState.get(Properties .SLAB_TYPE ) != SlabType .DOUBLE ) return @forEach
339+ val slabType = state.get(Properties .SLAB_TYPE )
340+ val side = when (slabType) {
341+ SlabType .TOP -> Direction .DOWN
342+ else -> Direction .UP
343+ }
344+ val expectedState = state.with (Properties .SLAB_TYPE , SlabType .DOUBLE )
345+ interactBlock(expectedState, setOf (side), state.block.item, true )
346+ }
323347 }
324348 }
325349
@@ -406,28 +430,14 @@ object BuildSimulator {
406430 }
407431 }
408432
409- return if (placing) checkPlaceOn(pos, validHits, preProcessing, targetState, place, rotation, interact, inventory)
410- else checkInteractOn(pos, item, validHits, expectedState, state, rotation, interact, inventory)
411- }
412-
413- private fun SafeContext.checkInteractOn (
414- pos : BlockPos ,
415- item : Item ,
416- validHits : MutableList <CheckedHit >,
417- expectedState : BlockState ,
418- currentState : BlockState ,
419- rotation : RotationConfig ,
420- interact : InteractionConfig ,
421- inventory : InventoryConfig
422- ): BuildResult ? {
423433 interact.pointSelection.select(validHits)?.let { checkedHit ->
424434 val checkedResult = checkedHit.hit
425435 val rotationTarget = lookAt(checkedHit.targetRotation, 0.001 )
426436 val context = InteractionContext (
427437 checkedResult.blockResult ? : return null ,
428438 RotationRequest (rotationTarget, rotation),
429439 player.inventory.selectedSlot,
430- currentState ,
440+ state ,
431441 expectedState
432442 )
433443
@@ -504,12 +514,8 @@ object BuildSimulator {
504514 return PlaceResult .NotItemBlock (pos, optimalStack)
505515 }
506516
507- val checked = blockItem.getPlacementContext(context)
508- if (checked == null ) {
509- return PlaceResult .ScaffoldExceeded (pos, context)
510- } else {
511- context = checked
512- }
517+ context = blockItem.getPlacementContext(context)
518+ ? : return PlaceResult .ScaffoldExceeded (pos, context)
513519
514520 lateinit var resultState: BlockState
515521 var rot = fakePlayer.rotation
0 commit comments