@@ -59,9 +59,7 @@ import com.lambda.util.BlockUtils.blockState
5959import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
6060import com.lambda.util.BlockUtils.hasFluid
6161import com.lambda.util.BlockUtils.instantBreakable
62- import com.lambda.util.BlockUtils.isEmpty
6362import com.lambda.util.BlockUtils.isNotEmpty
64- import com.lambda.util.Communication.info
6563import com.lambda.util.Communication.warn
6664import com.lambda.util.math.distSq
6765import com.lambda.util.math.vec3d
@@ -70,6 +68,10 @@ import com.lambda.util.player.copyPlayer
7068import com.lambda.util.player.gamemode
7169import com.lambda.util.world.WorldUtils.isLoaded
7270import com.lambda.util.world.raycast.RayCastUtils.blockResult
71+ import kotlinx.coroutines.Dispatchers
72+ import kotlinx.coroutines.async
73+ import kotlinx.coroutines.awaitAll
74+ import kotlinx.coroutines.runBlocking
7375import net.minecraft.block.BlockState
7476import net.minecraft.block.FallingBlock
7577import net.minecraft.block.OperatorBlock
@@ -86,7 +88,6 @@ import net.minecraft.item.Item
8688import net.minecraft.item.ItemPlacementContext
8789import net.minecraft.item.ItemStack
8890import net.minecraft.item.ItemUsageContext
89- import net.minecraft.item.Items
9091import net.minecraft.registry.tag.ItemTags.DIAMOND_TOOL_MATERIALS
9192import net.minecraft.registry.tag.ItemTags.GOLD_TOOL_MATERIALS
9293import net.minecraft.registry.tag.ItemTags.IRON_TOOL_MATERIALS
@@ -109,28 +110,34 @@ object BuildSimulator {
109110 rotation : RotationConfig = TaskFlowModule .rotation,
110111 inventory : InventoryConfig = TaskFlowModule .inventory,
111112 build : BuildConfig = TaskFlowModule .build,
112- ) = runSafe {
113- structure.entries.flatMap { (pos, target) ->
114- val preProcessing = target.getProcessingInfo(pos) ? : return @flatMap emptySet()
115- checkRequirements(pos, target, build).let {
116- if (it.isEmpty()) return @let
117- return @flatMap it
118- }
119- checkPostProcessResults(pos, eye, preProcessing, target, interactionConfig, build.placing, rotation, inventory).let {
120- if (it.isEmpty()) return @let
121- return @flatMap it
122- }
123- checkPlaceResults(pos, eye, preProcessing, target, build.placing, interactionConfig, rotation, inventory).let {
124- if (it.isEmpty()) return @let
125- return @flatMap it
126- }
127- checkBreakResults(pos, eye, preProcessing, build.breaking, interactionConfig, rotation, inventory, build).let {
128- if (it.isEmpty()) return @let
129- return @flatMap it
130- }
131- warn(" Nothing matched $pos $target " )
132- emptySet()
133- }.toSet()
113+ ): Set <BuildResult > = runSafe {
114+ runBlocking(Dispatchers .Default ) {
115+ structure.entries
116+ .map { (pos, target) ->
117+ async {
118+ val preProcessing = target.getProcessingInfo(pos) ? : return @async emptySet()
119+
120+ checkRequirements(pos, target, build).let { results ->
121+ if (results.isNotEmpty()) return @async results
122+ }
123+ checkPostProcessResults(pos, eye, preProcessing, target, interactionConfig, build.placing, rotation, inventory).let { results ->
124+ if (results.isNotEmpty()) return @async results
125+ }
126+ checkPlaceResults(pos, eye, preProcessing, target, build.placing, interactionConfig, rotation, inventory).let { results ->
127+ if (results.isNotEmpty()) return @async results
128+ }
129+ checkBreakResults(pos, eye, preProcessing, build.breaking, interactionConfig, rotation, inventory, build).let { results ->
130+ if (results.isNotEmpty()) return @async results
131+ }
132+
133+ warn(" Nothing matched $pos $target " )
134+ emptySet()
135+ }
136+ }
137+ .awaitAll()
138+ .flatMap { it }
139+ .toSet()
140+ }
134141 } ? : emptySet()
135142
136143 private fun SafeContext.checkRequirements (
0 commit comments