diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt index 849a43ba2..8c605d9fb 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt @@ -50,7 +50,20 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) { // ...and execute it. // TODO there used to be error checking code here; I'm pretty sure any and all mishaps should already // get caught and folded into CastResult by evaluate. - val image2 = next.evaluate(continuation.next, world, this) + val image2 = next.evaluate(continuation.next, world, this).let { result -> + // if stack is unable to be serialized, have the result be an error + if (result.newData != null && IotaType.isTooLargeToSerialize(result.newData.stack)) { + result.copy( + newData = null, + sideEffects = listOf(OperatorSideEffect.DoMishap(MishapStackSize(), Mishap.Context(null, null))), + resolutionType = ResolvedPatternType.ERRORED, + sound = HexEvalSounds.MISHAP, + ) + } else { + result + } + } + // Then write all pertinent data back to the harness for the next iteration. if (image2.newData != null) { this.image = image2.newData diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapStackSize.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapStackSize.kt new file mode 100644 index 000000000..571e39bcd --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapStackSize.kt @@ -0,0 +1,24 @@ +package at.petrak.hexcasting.api.casting.mishaps + +import at.petrak.hexcasting.api.casting.eval.CastingEnvironment +import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType +import at.petrak.hexcasting.api.casting.iota.GarbageIota +import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.api.pigment.FrozenPigment +import at.petrak.hexcasting.common.lib.HexDamageTypes +import net.minecraft.world.item.DyeColor + +class MishapStackSize() : Mishap() { + override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment = + dyeColor(DyeColor.BLACK) + + override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.ERRORED + + override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList) { + stack.clear() + stack.add(GarbageIota()) + } + + override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = + error("stack_size") +} diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 index 470c006c0..918892880 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 @@ -901,6 +901,7 @@ invalid_spell_datum_type: "Tried to use a value of invalid type as a SpellDatum: %s (class %s). This is a bug in the mod.", unknown: "threw an exception (%s). This is a bug in the mod.", shame: "Shame on you!", + stack_size: "Exceeded the size limit of the stack", invalid_value: { "": "expected %s at index %s of the stack, but got %s",