@@ -22,22 +22,27 @@ import com.lambda.config.groups.HotbarSettings
2222import com.lambda.config.groups.InteractionSettings
2323import com.lambda.config.groups.InventorySettings
2424import com.lambda.config.groups.RotationSettings
25+ import com.lambda.context.SafeContext
2526import com.lambda.event.events.TickEvent
2627import com.lambda.event.listener.SafeListener.Companion.listen
27- import com.lambda.interaction.construction.blueprint.Blueprint.Companion.toStructure
2828import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
2929import com.lambda.interaction.construction.context.BuildContext
30+ import com.lambda.interaction.construction.context.PlaceContext
3031import com.lambda.interaction.construction.result.PlaceResult
3132import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
3233import com.lambda.interaction.construction.verify.TargetState
3334import com.lambda.interaction.request.Request.Companion.submit
3435import com.lambda.interaction.request.placing.PlaceRequest
3536import com.lambda.module.Module
3637import com.lambda.module.tag.ModuleTag
38+ import com.lambda.util.BlockUtils.blockPos
39+ import com.lambda.util.BlockUtils.blockState
3740import com.lambda.util.KeyCode
3841import com.lambda.util.KeyboardUtils.isKeyPressed
3942import com.lambda.util.NamedEnum
43+ import com.lambda.util.math.distSq
4044import com.lambda.util.world.raycast.InteractionMask
45+ import net.minecraft.util.math.BlockPos
4146import net.minecraft.util.math.Direction
4247import java.util.concurrent.ConcurrentLinkedQueue
4348
@@ -55,6 +60,7 @@ object Scaffold : Module(
5560 Inventory (" Inventory" )
5661 }
5762
63+ private val bridgeRange by setting(" Bridge Range" , 5 , 0 .. 5 , 1 , " The range at which blocks can be placed to help build support for the player" ).group(Group .General )
5864 private val descend by setting(" Descend" , KeyCode .UNBOUND , " Lower the place position by one to allow the player to lower y level" ).group(Group .General )
5965 private val buildConfig = BuildSettings (this , Group .Build )
6066 private val rotationConfig = RotationSettings (this , Group .Rotation )
@@ -66,19 +72,34 @@ object Scaffold : Module(
6672
6773 init {
6874 listen<TickEvent .Pre > {
69- player
70- .blockPos
71- .offset(Direction .DOWN , if (isKeyPressed(descend.code)) 2 else 1 )
72- .toStructure(TargetState .Solid )
75+ val beneath = player.blockPos.offset(Direction .DOWN , if (isKeyPressed(descend.code)) 2 else 1 )
76+ val placements = getPlacements(beneath)
77+ if (placements == null ) return @listen
78+ placements
79+ .associate { it to TargetState .Solid }
7380 .toBlueprint()
7481 .simulate(player.eyePos, interactionConfig, rotationConfig, inventoryConfig, buildConfig)
7582 .filterIsInstance<PlaceResult .Place >()
7683 .let { results ->
7784 val contexts = results
7885 .map { it.context }
7986 .distinctBy { it.blockPos }
87+ .sortedWith { o1, o2 -> getBridgeCompareBy(beneath).compare(o1, o2) }
8088 submit(PlaceRequest (contexts, buildConfig, rotationConfig, hotbarConfig, pendingActions))
8189 }
8290 }
8391 }
92+
93+ private fun SafeContext.getPlacements (beneath : BlockPos ): List <BlockPos >? {
94+ if (blockState(beneath).isSolidBlock(world, beneath)) return null
95+
96+ return BlockPos
97+ .iterateOutwards(beneath, bridgeRange, bridgeRange, bridgeRange)
98+ .map { it.blockPos }
99+ }
100+
101+ private fun getBridgeCompareBy (blockPos : BlockPos ) =
102+ compareBy<PlaceContext > {
103+ it.blockPos.toCenterPos() distSq blockPos.toCenterPos()
104+ }
84105}
0 commit comments