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 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..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; @@ -69,7 +70,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,17 +82,13 @@ 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) + if (iota.depth() > HexIotaTypes.MAX_SERIALIZATION_DEPTH) 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/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..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 @@ -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. Note that list iotas count as all their contents plus one.", + }, maxSpellCircleLength: { "": "Max Spell Circle Length", "@Tooltip": "The maximum number of slates in a spell circle", 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..7e69e217c3 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,10 @@ 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. " + + "Note that list iotas count as all their contents plus one.") + .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 +261,11 @@ public int maxOpCount() { return maxOpCount.get(); } + @Override + public int maxStackSize() { + return maxStackSize.get(); + } + @Override public int maxSpellCircleLength() { return maxSpellCircleLength.get();