@@ -38,105 +38,105 @@ import java.util.*
3838 * as an extension of the [SimInfo] class to allow easy access through the DSL style sim builder.
3939 */
4040interface SimInfo : Automated {
41- val pos: BlockPos
42- val state: BlockState
41+ val pos: BlockPos
42+ val state: BlockState
4343 val targetState: TargetState
44- val pov: Vec3d
44+ val pov: Vec3d
4545 val dependencyStack: Stack <Sim <* >>
46- val concurrentResults: MutableSet <BuildResult >
46+ val concurrentResults: MutableSet <BuildResult >
4747
4848 @SimDsl
4949 context(_: AutomatedSafeContext , _: Sim <* >)
5050 suspend fun sim ()
5151
52- companion object {
53- /* *
54- * Creates a [SimInfo], checks its basic requirements, and runs the [simBuilder] block.
55- */
56- @SimDsl
57- context(_: BuildSimulator )
58- suspend fun AutomatedSafeContext.sim (
59- pos : BlockPos ,
60- state : BlockState ,
61- targetState : TargetState ,
62- pov : Vec3d ,
63- concurrentResults : MutableSet <BuildResult >
64- ) = getTypedInfo(
65- pos,
66- state,
67- targetState,
68- pov,
69- Stack (),
70- concurrentResults
52+ companion object {
53+ /* *
54+ * Creates a [SimInfo], checks its basic requirements, and runs the [simBuilder] block.
55+ */
56+ @SimDsl
57+ context(_: BuildSimulator )
58+ suspend fun AutomatedSafeContext.sim (
59+ pos : BlockPos ,
60+ state : BlockState ,
61+ targetState : TargetState ,
62+ pov : Vec3d ,
63+ concurrentResults : MutableSet <BuildResult >
64+ ) = getTypedInfo(
65+ pos,
66+ state,
67+ targetState,
68+ pov,
69+ Stack (),
70+ concurrentResults
7171 ).takeIf { it?.hasBasicRequirements() == true }?.sim()
7272
73- /* *
74- * Creates a new [SimInfo] using the current [SimInfo]'s [dependencyStack] and [concurrentResults],
75- * checks its basic requirements, and runs the [simBuilder] block. As simulations tend to make use of
76- * concurrency, a new stack is created and the dependencies from the previous stack are added.
77- */
78- @SimDsl
79- context(automatedSafeContext: AutomatedSafeContext , _: Sim <* >)
80- suspend fun SimInfo.sim (
81- pos : BlockPos = this.pos,
82- state : BlockState = this.state,
83- targetState : TargetState = this.targetState,
84- pov : Vec3d = this.pov
85- ) = automatedSafeContext.getTypedInfo(
86- pos,
87- state,
88- targetState,
89- pov,
90- Stack <Sim <* >>().apply { addAll(dependencyStack) },
91- concurrentResults
73+ /* *
74+ * Creates a new [SimInfo] using the current [SimInfo]'s [dependencyStack] and [concurrentResults],
75+ * checks its basic requirements, and runs the [simBuilder] block. As simulations tend to make use of
76+ * concurrency, a new stack is created and the dependencies from the previous stack are added.
77+ */
78+ @SimDsl
79+ context(automatedSafeContext: AutomatedSafeContext , _: Sim <* >)
80+ suspend fun SimInfo.sim (
81+ pos : BlockPos = this.pos,
82+ state : BlockState = this.state,
83+ targetState : TargetState = this.targetState,
84+ pov : Vec3d = this.pov
85+ ) = automatedSafeContext.getTypedInfo(
86+ pos,
87+ state,
88+ targetState,
89+ pov,
90+ Stack <Sim <* >>().apply { addAll(dependencyStack) },
91+ concurrentResults
9292 ).takeIf { it?.hasBasicRequirements() == true }?.sim()
9393
94- @SimDsl
95- private fun AutomatedSafeContext.getTypedInfo (
96- pos : BlockPos ,
97- state : BlockState ,
98- targetState : TargetState ,
99- pov : Vec3d ,
100- dependencyStack : Stack <Sim <* >>,
101- concurrentResults : MutableSet <BuildResult >
102- ): SimInfo ? {
103- if (! targetState.isEmpty()) {
104- getProcessingInfo(state, targetState, pos)?.let { preProcessing ->
105- return if (preProcessing.info.omitInteraction) null
106- else object : InteractSimInfo , Automated by this {
107- override val pos = pos
108- override val state = state
109- override val targetState = targetState
110- override val pov = pov
111- override val dependencyStack = dependencyStack
112- override val concurrentResults = concurrentResults
113- override val preProcessing = preProcessing
114- override val expectedState = preProcessing.info.expectedState
115- override val item = preProcessing.info.item
116- override val placing = preProcessing.info.placing
94+ @SimDsl
95+ private fun AutomatedSafeContext.getTypedInfo (
96+ pos : BlockPos ,
97+ state : BlockState ,
98+ targetState : TargetState ,
99+ pov : Vec3d ,
100+ dependencyStack : Stack <Sim <* >>,
101+ concurrentResults : MutableSet <BuildResult >
102+ ): SimInfo ? {
103+ if (! targetState.isEmpty()) {
104+ getProcessingInfo(state, targetState, pos)?.let { preProcessing ->
105+ return if (preProcessing.info.omitInteraction) null
106+ else object : InteractSimInfo , Automated by this {
107+ override val pos = pos
108+ override val state = state
109+ override val targetState = targetState
110+ override val pov = pov
111+ override val dependencyStack = dependencyStack
112+ override val concurrentResults = concurrentResults
113+ override val preProcessing = preProcessing
114+ override val expectedState = preProcessing.info.expectedState
115+ override val item = preProcessing.info.item
116+ override val placing = preProcessing.info.placing
117117
118- context(_: AutomatedSafeContext , _: Sim <* >)
119- override suspend fun sim () = simInteraction()
118+ context(_: AutomatedSafeContext , _: Sim <* >)
119+ override suspend fun sim () = simInteraction()
120120
121- override fun AutomatedSafeContext.matchesTarget (state : BlockState , completely : Boolean ) =
122- expectedState.matches(state, if (! completely) preProcessing.info.ignore else emptySet())
123- }
124- }
125- }
121+ override fun AutomatedSafeContext.matchesTarget (state : BlockState , completely : Boolean ) =
122+ expectedState.matches(state, if (! completely) preProcessing.info.ignore else emptySet())
123+ }
124+ }
125+ }
126126
127- return object : BreakSimInfo , Automated by this {
128- override val pos = pos
129- override val state = state
130- override val targetState = targetState
131- override val pov = pov
132- override val dependencyStack = dependencyStack
133- override val concurrentResults = concurrentResults
127+ return object : BreakSimInfo , Automated by this {
128+ override val pos = pos
129+ override val state = state
130+ override val targetState = targetState
131+ override val pov = pov
132+ override val dependencyStack = dependencyStack
133+ override val concurrentResults = concurrentResults
134134
135- context(_: AutomatedSafeContext , _: Sim <* >)
136- override suspend fun sim () = simBreak()
137- }
138- }
139- }
135+ context(_: AutomatedSafeContext , _: Sim <* >)
136+ override suspend fun sim () = simBreak()
137+ }
138+ }
139+ }
140140}
141141
142142interface InteractSimInfo : SimInfo {
0 commit comments