From 84a8b1ef7fc19166aafab36e0f2f4b32aa6f90fc Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:19:17 -0500 Subject: [PATCH 1/6] Don't start at 1 when counting stack size --- .../at/petrak/hexcasting/api/casting/iota/IotaType.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java index 4712027425..7ce708f483 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java @@ -69,7 +69,7 @@ public static CompoundTag serialize(Iota iota) { } // We check if it's too big on serialization; if it is we just return a garbage. - if (isTooLargeToSerialize(List.of(iota), 0)) { + if (isTooLargeToSerialize(List.of(iota))) { // Garbage will never be too large so we just recurse return serialize(new GarbageIota()); } @@ -81,11 +81,7 @@ public static CompoundTag serialize(Iota iota) { } public static boolean isTooLargeToSerialize(Iterable examinee) { - return isTooLargeToSerialize(examinee, 1); - } - - private static boolean isTooLargeToSerialize(Iterable examinee, int startingCount) { - int totalSize = startingCount; + int totalSize = 0; for (Iota iota : examinee) { if (iota.depth() >= HexIotaTypes.MAX_SERIALIZATION_DEPTH) return true; From b6616b10cc3ff3f4dee0dc71cec9f558eb55c003 Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:23:09 -0500 Subject: [PATCH 2/6] Use > rather than >= when checking stack size and list depth --- .../java/at/petrak/hexcasting/api/casting/iota/IotaType.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java index 7ce708f483..2a1c6876f4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java @@ -83,11 +83,11 @@ public static CompoundTag serialize(Iota iota) { public static boolean isTooLargeToSerialize(Iterable examinee) { int totalSize = 0; for (Iota iota : examinee) { - if (iota.depth() >= HexIotaTypes.MAX_SERIALIZATION_DEPTH) + if (iota.depth() > HexIotaTypes.MAX_SERIALIZATION_DEPTH) return true; totalSize += iota.size(); } - return totalSize >= HexIotaTypes.MAX_SERIALIZATION_TOTAL; + return totalSize > HexIotaTypes.MAX_SERIALIZATION_TOTAL; } /** From 5ea9f28b5936a4324840da4caa132f669c116bc8 Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:24:25 -0500 Subject: [PATCH 3/6] Make stack limit configurable --- .../at/petrak/hexcasting/api/casting/iota/IotaType.java | 3 ++- .../java/at/petrak/hexcasting/api/mod/HexConfig.java | 3 +++ .../common/casting/actions/stack/OpDuplicateN.kt | 8 ++++---- .../petrak/hexcasting/common/lib/hex/HexIotaTypes.java | 1 - .../at/petrak/hexcasting/fabric/FabricHexConfig.java | 8 ++++++++ .../java/at/petrak/hexcasting/forge/ForgeHexConfig.java | 9 +++++++++ 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java index 2a1c6876f4..c21b7db12b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/iota/IotaType.java @@ -1,6 +1,7 @@ package at.petrak.hexcasting.api.casting.iota; import at.petrak.hexcasting.api.HexAPI; +import at.petrak.hexcasting.api.mod.HexConfig; import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.common.lib.hex.HexIotaTypes; import net.minecraft.ChatFormatting; @@ -87,7 +88,7 @@ public static boolean isTooLargeToSerialize(Iterable examinee) { return true; totalSize += iota.size(); } - return totalSize > HexIotaTypes.MAX_SERIALIZATION_TOTAL; + return totalSize > HexConfig.server().maxStackSize(); } /** diff --git a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java index 31bbf5379b..97b12e6cc1 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java @@ -73,6 +73,8 @@ public interface ServerConfigAccess { int maxOpCount(); + int maxStackSize(); + int maxSpellCircleLength(); boolean isActionAllowed(ResourceLocation actionID); @@ -95,6 +97,7 @@ public interface ServerConfigAccess { double traderScrollChance(); int DEFAULT_MAX_OP_COUNT = 100_000; + int DEFAULT_MAX_STACK_SIZE = 1024; int DEFAULT_MAX_SPELL_CIRCLE_LENGTH = 1024; int DEFAULT_OP_BREAK_HARVEST_LEVEL = 3; diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpDuplicateN.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpDuplicateN.kt index ca92c7f082..402347b4ce 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpDuplicateN.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpDuplicateN.kt @@ -4,7 +4,7 @@ import at.petrak.hexcasting.api.casting.castables.ConstMediaAction import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.getPositiveInt import at.petrak.hexcasting.api.casting.iota.Iota -import at.petrak.hexcasting.common.lib.hex.HexIotaTypes +import at.petrak.hexcasting.api.mod.HexConfig object OpDuplicateN : ConstMediaAction { override val argc: Int @@ -13,11 +13,11 @@ object OpDuplicateN : ConstMediaAction { override fun execute(args: List, env: CastingEnvironment): List { var count = args.getPositiveInt(1, argc) - if (count > HexIotaTypes.MAX_SERIALIZATION_TOTAL) { + if (count > HexConfig.server().maxStackSize()) { // If we throw here, the message will point to us, which usually doesn't happen. - // So ensure that this check has no user-facing effects, just cap to MAX_SERIALIZATION_TOTAL, + // So ensure that this check has no user-facing effects, just cap to maxStackSize plus 1, // which will unconditionally trigger Too Many Iotas after we return. - count = HexIotaTypes.MAX_SERIALIZATION_TOTAL + count = HexConfig.server().maxStackSize() + 1 } return (List(count) { args[0] }) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexIotaTypes.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexIotaTypes.java index 0526e9ac56..eace25f133 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexIotaTypes.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexIotaTypes.java @@ -23,7 +23,6 @@ public class HexIotaTypes { KEY_TYPE = HexAPI.MOD_ID + ":type", KEY_DATA = HexAPI.MOD_ID + ":data"; public static final int MAX_SERIALIZATION_DEPTH = 256; - public static final int MAX_SERIALIZATION_TOTAL = 1024; public static void registerTypes(BiConsumer, ResourceLocation> r) { for (var e : TYPES.entrySet()) { diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java index 8fc4d8465d..f5560f34c5 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java @@ -205,6 +205,8 @@ public static final class Server implements HexConfig.ServerConfigAccess, Config @ConfigEntry.Gui.Tooltip private int maxOpCount = DEFAULT_MAX_OP_COUNT; @ConfigEntry.Gui.Tooltip + private int maxStackSize = DEFAULT_MAX_STACK_SIZE; + @ConfigEntry.Gui.Tooltip private int maxSpellCircleLength = DEFAULT_MAX_SPELL_CIRCLE_LENGTH; @ConfigEntry.Gui.Tooltip private List actionDenyList = List.of(); @@ -262,6 +264,7 @@ public static final class Server implements HexConfig.ServerConfigAccess, Config public void validatePostLoad() throws ValidationException { this.opBreakHarvestLevel = Mth.clamp(this.opBreakHarvestLevel, 0, 4); this.maxOpCount = Math.max(this.maxOpCount, 0); + this.maxStackSize = Math.max(this.maxStackSize, 0); this.maxSpellCircleLength = Math.max(this.maxSpellCircleLength, 4); this.globalCostScaling = Math.max(this.globalCostScaling, 0); this.traderScrollChance = Mth.clamp(this.traderScrollChance, 0.0, 1.0); @@ -325,6 +328,11 @@ public int maxOpCount() { return maxOpCount; } + @Override + public int maxStackSize() { + return maxStackSize; + } + @Override public int maxSpellCircleLength() { return maxSpellCircleLength; diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java index 510e7eb8b7..639ff895ba 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java @@ -173,6 +173,7 @@ public boolean staticActiveSlates() { public static class Server implements HexConfig.ServerConfigAccess { private static ForgeConfigSpec.IntValue opBreakHarvestLevel; private static ForgeConfigSpec.IntValue maxOpCount; + private static ForgeConfigSpec.IntValue maxStackSize; private static ForgeConfigSpec.IntValue maxSpellCircleLength; private static ForgeConfigSpec.ConfigValue> actionDenyList; private static ForgeConfigSpec.ConfigValue> circleActionDenyList; @@ -192,6 +193,9 @@ public Server(ForgeConfigSpec.Builder builder) { "hanging the server.") .defineInRange("maxOpCount", DEFAULT_MAX_OP_COUNT, 0, Integer.MAX_VALUE); + maxStackSize = builder.comment("The maximum number of iotas that can exist on the stack at once.") + .defineInRange("maxStackSize", DEFAULT_MAX_STACK_SIZE, 0, Integer.MAX_VALUE); + opBreakHarvestLevel = builder.comment( "The harvest level of the Break Block spell.", "0 = wood, 1 = stone, 2 = iron, 3 = diamond, 4 = netherite." @@ -256,6 +260,11 @@ public int maxOpCount() { return maxOpCount.get(); } + @Override + public int maxStackSize() { + return maxStackSize.get(); + } + @Override public int maxSpellCircleLength() { return maxSpellCircleLength.get(); From 3f769848ac6fe3bb061f32de2331b89412987773 Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:41:11 -0500 Subject: [PATCH 4/6] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 396709fa89..07467f5768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added - Added the `requires_enlightenment_in_parens` tag for patterns that should mishap without enlightenment even while parenthesized ([#1290](https://github.com/FallingColors/HexMod/pull/1290)) @Robotgiggle +- Added a config option to control the maximum number of iotas that can fit on the stack at once ([#1372](https://github.com/FallingColors/HexMod/pull/1372)) @Robotgiggle ### Changed @@ -29,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - Fixed an error when trying to cast a Great Spell that no longer exists, such as when an addon has been removed ([#1335](https://github.com/FallingColors/HexMod/pull/1335)) @Robotgiggle - Fixed a broken translation key when referring to a jump iota in a mishap message ([#1350](https://github.com/FallingColors/HexMod/pull/1350)) @hauveli - Fixed Thoth's Gambit counting one extra pattern towards the pattern limit every iteration ([#1352](https://github.com/FallingColors/HexMod/pull/1352)) @Robotgiggle +- Fixed the maximum number of iotas that can fit on the stack being 1022 rather than the intended 1024 ([#1372](https://github.com/FallingColors/HexMod/pull/1372)) @Robotgiggle ## `0.11.4` - 2026-08-26 From a3aba7241016be7d87bb30c973950398becdc389 Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:43:45 -0500 Subject: [PATCH 5/6] Add lang for fabric config --- .../main/resources/assets/hexcasting/lang/en_us.flatten.json5 | 4 ++++ 1 file changed, 4 insertions(+) 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 61940e2450..ca45d18300 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 @@ -387,6 +387,10 @@ "": "Max Action Count", "@Tooltip": "The maximum number of actions that can be executed in one tick, to avoid hanging the server.", }, + maxStackSize: { + "": "Max Stack Size", + "@Tooltip": "The maximum number of iotas that can exist on the stack at once.", + }, maxSpellCircleLength: { "": "Max Spell Circle Length", "@Tooltip": "The maximum number of slates in a spell circle", From 8cdf3d5cbdc438561d79d41c245c03b22cd88157 Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Mon, 23 Nov 2026 03:28:11 -0500 Subject: [PATCH 6/6] Mention that lists include their contents --- .../main/resources/assets/hexcasting/lang/en_us.flatten.json5 | 2 +- .../main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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 ca45d18300..d56b033931 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 @@ -389,7 +389,7 @@ }, maxStackSize: { "": "Max Stack Size", - "@Tooltip": "The maximum number of iotas that can exist on the stack at once.", + "@Tooltip": "The maximum number of iotas that can exist on the stack at once. Note that list iotas count as all their contents plus one.", }, maxSpellCircleLength: { "": "Max Spell Circle Length", diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java index 639ff895ba..7e69e217c3 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java @@ -193,7 +193,8 @@ public Server(ForgeConfigSpec.Builder builder) { "hanging the server.") .defineInRange("maxOpCount", DEFAULT_MAX_OP_COUNT, 0, Integer.MAX_VALUE); - maxStackSize = builder.comment("The maximum number of iotas that can exist on the stack at once.") + maxStackSize = builder.comment("The maximum number of iotas that can exist on the stack at once. " + + "Note that list iotas count as all their contents plus one.") .defineInRange("maxStackSize", DEFAULT_MAX_STACK_SIZE, 0, Integer.MAX_VALUE); opBreakHarvestLevel = builder.comment(