Skip to content

Commit 6c5798b

Browse files
committed
Implement subIotas for ContinuationIota
1 parent 73cc6f2 commit 6c5798b

File tree

6 files changed

+28
-0
lines changed

6 files changed

+28
-0
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/ContinuationFrame.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface ContinuationFrame {
4747
*/
4848
fun size(): Int
4949
fun depth(): Int
50+
fun subIotas(): Iterable<Iota>?
5051

5152
val type: Type<*>
5253

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameEvaluate.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : Cont
7070

7171
override fun size() = size
7272
override fun depth() = depth
73+
override fun subIotas(): Iterable<Iota> = list
7374

7475
override val type: ContinuationFrame.Type<*> = TYPE
7576

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameFinishEval.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ object FrameFinishEval : ContinuationFrame {
3737

3838
override fun size() = 0
3939
override fun depth() = 0
40+
override fun subIotas(): Iterable<Iota>? = null
4041

4142
@JvmField
4243
val TYPE: ContinuationFrame.Type<FrameFinishEval> = object : ContinuationFrame.Type<FrameFinishEval> {

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ data class FrameForEach(
120120

121121
override fun size() = size
122122
override fun depth() = depth
123+
override fun subIotas(): Iterable<Iota> =
124+
if (baseStack != null)
125+
listOf(data, code, acc, baseStack).flatten()
126+
else
127+
listOf(data, code, acc).flatten()
123128

124129
override val type: ContinuationFrame.Type<*> = TYPE
125130

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/SpellContinuation.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package at.petrak.hexcasting.api.casting.eval.vm
22

3+
import at.petrak.hexcasting.api.casting.iota.Iota
34
import at.petrak.hexcasting.api.utils.NBTBuilder
45
import at.petrak.hexcasting.api.utils.getList
56
import net.minecraft.nbt.CompoundTag
@@ -14,15 +15,28 @@ sealed interface SpellContinuation {
1415
object Done : SpellContinuation {
1516
override fun size(): Int = 0
1617
override fun depth(): Int = 0
18+
override fun subIotas(): Iterable<Iota>? = null
1719
}
1820

1921
data class NotDone(val frame: ContinuationFrame, val next: SpellContinuation) : SpellContinuation {
2022
override fun size(): Int = frame.size() + next.size()
2123
override fun depth(): Int = max(frame.depth(), next.depth())
24+
override fun subIotas(): Iterable<Iota> {
25+
val list: MutableList<Iterable<Iota>> = mutableListOf()
26+
var current: SpellContinuation = this
27+
while (current is NotDone) {
28+
val subIotas = current.frame.subIotas()
29+
if (subIotas != null)
30+
list.add(subIotas)
31+
current = current.next
32+
}
33+
return list.flatten()
34+
}
2235
}
2336

2437
fun pushFrame(frame: ContinuationFrame): SpellContinuation = NotDone(frame, this)
2538

39+
fun subIotas(): Iterable<Iota>?
2640
fun size(): Int
2741
fun depth(): Int
2842

Common/src/main/java/at/petrak/hexcasting/api/casting/iota/ContinuationIota.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.minecraft.network.chat.Component;
1414
import net.minecraft.server.level.ServerLevel;
1515
import org.jetbrains.annotations.NotNull;
16+
import org.jetbrains.annotations.Nullable;
1617

1718
import java.util.List;
1819

@@ -56,6 +57,11 @@ public boolean executable() {
5657
return true;
5758
}
5859

60+
@Override
61+
public @Nullable Iterable<Iota> subIotas() {
62+
return this.getContinuation().subIotas();
63+
}
64+
5965
@Override
6066
public int size() {
6167
return Math.min(this.getContinuation().size(), 1);

0 commit comments

Comments
 (0)