Skip to content

Commit 30d40f8

Browse files
committed
Make MishapInvalidPattern display the offending pattern
1 parent c64e5d7 commit 30d40f8

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/iota/PatternIota.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public boolean toleratesOther(Iota that) {
9898
castedName = special.handler::getName;
9999
action = special.handler.act();
100100
} else if (lookup instanceof PatternShapeMatch.Nothing) {
101-
throw new MishapInvalidPattern();
101+
throw new MishapInvalidPattern(this.getPattern());
102102
} else throw new IllegalStateException();
103103

104104
// do the actual calculation!!

Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapInvalidPattern.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
44
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
55
import at.petrak.hexcasting.api.casting.iota.GarbageIota
66
import at.petrak.hexcasting.api.casting.iota.Iota
7+
import at.petrak.hexcasting.api.casting.iota.PatternIota
8+
import at.petrak.hexcasting.api.casting.math.HexPattern
79
import at.petrak.hexcasting.api.pigment.FrozenPigment
10+
import net.minecraft.network.chat.Component
811
import net.minecraft.world.item.DyeColor
912

10-
class MishapInvalidPattern : Mishap() {
13+
class MishapInvalidPattern(val pattern: HexPattern? = null) : Mishap() {
1114
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
1215
dyeColor(DyeColor.YELLOW)
1316

@@ -17,6 +20,8 @@ class MishapInvalidPattern : Mishap() {
1720
stack.add(GarbageIota())
1821
}
1922

20-
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
21-
error("invalid_pattern")
23+
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? {
24+
if (pattern == null) return error("invalid_pattern_generic")
25+
else return error("invalid_pattern", PatternIota.display(pattern))
26+
}
2227
}

Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,8 @@
984984
mishap: {
985985
"": "%s: %s",
986986

987-
invalid_pattern: "That pattern isn't associated with any action",
987+
invalid_pattern: "The pattern %s isn't associated with any action",
988+
invalid_pattern_generic: "That pattern isn't associated with any action",
988989
unescaped: "Expected to evaluate a pattern, but evaluated %s instead",
989990

990991
not_enough_args: "expected %s or more arguments but the stack was only %s tall",

0 commit comments

Comments
 (0)