From 6c5798b821c7295aa9ba27b35de3b7f1d5aa6777 Mon Sep 17 00:00:00 2001 From: Skye Date: Thu, 28 Nov 2024 17:44:50 +0900 Subject: [PATCH] Implement subIotas for ContinuationIota --- .../api/casting/eval/vm/ContinuationFrame.kt | 1 + .../api/casting/eval/vm/FrameEvaluate.kt | 1 + .../api/casting/eval/vm/FrameFinishEval.kt | 1 + .../hexcasting/api/casting/eval/vm/FrameForEach.kt | 5 +++++ .../api/casting/eval/vm/SpellContinuation.kt | 14 ++++++++++++++ .../api/casting/iota/ContinuationIota.java | 6 ++++++ 6 files changed, 28 insertions(+) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/ContinuationFrame.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/ContinuationFrame.kt index f0f3fda6f..8b2f669f5 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/ContinuationFrame.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/ContinuationFrame.kt @@ -47,6 +47,7 @@ interface ContinuationFrame { */ fun size(): Int fun depth(): Int + fun subIotas(): Iterable? val type: Type<*> diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameEvaluate.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameEvaluate.kt index 34dd0548d..ccd0cb26c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameEvaluate.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameEvaluate.kt @@ -70,6 +70,7 @@ data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : Cont override fun size() = size override fun depth() = depth + override fun subIotas(): Iterable = list override val type: ContinuationFrame.Type<*> = TYPE diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameFinishEval.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameFinishEval.kt index 90370dd14..94cd7b408 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameFinishEval.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameFinishEval.kt @@ -37,6 +37,7 @@ object FrameFinishEval : ContinuationFrame { override fun size() = 0 override fun depth() = 0 + override fun subIotas(): Iterable? = null @JvmField val TYPE: ContinuationFrame.Type = object : ContinuationFrame.Type { diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt index c377e0f3f..eb84b2d7f 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt @@ -120,6 +120,11 @@ data class FrameForEach( override fun size() = size override fun depth() = depth + override fun subIotas(): Iterable = + if (baseStack != null) + listOf(data, code, acc, baseStack).flatten() + else + listOf(data, code, acc).flatten() override val type: ContinuationFrame.Type<*> = TYPE diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/SpellContinuation.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/SpellContinuation.kt index 4f600886a..52e8fc669 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/SpellContinuation.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/SpellContinuation.kt @@ -1,5 +1,6 @@ package at.petrak.hexcasting.api.casting.eval.vm +import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.utils.NBTBuilder import at.petrak.hexcasting.api.utils.getList import net.minecraft.nbt.CompoundTag @@ -14,15 +15,28 @@ sealed interface SpellContinuation { object Done : SpellContinuation { override fun size(): Int = 0 override fun depth(): Int = 0 + override fun subIotas(): Iterable? = null } data class NotDone(val frame: ContinuationFrame, val next: SpellContinuation) : SpellContinuation { override fun size(): Int = frame.size() + next.size() override fun depth(): Int = max(frame.depth(), next.depth()) + override fun subIotas(): Iterable { + val list: MutableList> = mutableListOf() + var current: SpellContinuation = this + while (current is NotDone) { + val subIotas = current.frame.subIotas() + if (subIotas != null) + list.add(subIotas) + current = current.next + } + return list.flatten() + } } fun pushFrame(frame: ContinuationFrame): SpellContinuation = NotDone(frame, this) + fun subIotas(): Iterable? fun size(): Int fun depth(): Int diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/ContinuationIota.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/ContinuationIota.java index 3cd023206..e97ca66ba 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/ContinuationIota.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/ContinuationIota.java @@ -13,6 +13,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -56,6 +57,11 @@ public boolean executable() { return true; } + @Override + public @Nullable Iterable subIotas() { + return this.getContinuation().subIotas(); + } + @Override public int size() { return Math.min(this.getContinuation().size(), 1);