Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
Expand All @@ -81,17 +82,13 @@ public static CompoundTag serialize(Iota iota) {
}

public static boolean isTooLargeToSerialize(Iterable<Iota> examinee) {
return isTooLargeToSerialize(examinee, 1);
}

private static boolean isTooLargeToSerialize(Iterable<Iota> 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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public interface ServerConfigAccess {

int maxOpCount();

int maxStackSize();

int maxSpellCircleLength();

boolean isActionAllowed(ResourceLocation actionID);
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,11 +13,11 @@ object OpDuplicateN : ConstMediaAction {
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
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] })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IotaType<?>, ResourceLocation> r) {
for (var e : TYPES.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> actionDenyList = List.of();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -325,6 +328,11 @@ public int maxOpCount() {
return maxOpCount;
}

@Override
public int maxStackSize() {
return maxStackSize;
}

@Override
public int maxSpellCircleLength() {
return maxSpellCircleLength;
Expand Down
10 changes: 10 additions & 0 deletions Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<? extends String>> actionDenyList;
private static ForgeConfigSpec.ConfigValue<List<? extends String>> circleActionDenyList;
Expand All @@ -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."
Expand Down Expand Up @@ -256,6 +261,11 @@ public int maxOpCount() {
return maxOpCount.get();
}

@Override
public int maxStackSize() {
return maxStackSize.get();
}

@Override
public int maxSpellCircleLength() {
return maxSpellCircleLength.get();
Expand Down
Loading