Skip to content

Commit b1c029b

Browse files
More informative mishaps (#951)
2 parents 8fda9f9 + e25f500 commit b1c029b

File tree

5 files changed

+67
-19
lines changed

5 files changed

+67
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
3737
- Re-added the slate limit for spell circles, by Stickia in [#909](https://github.com/FallingColors/HexMod/pull/909).
3838
- Renamed Inverse Tangent Purification II to Inverse Tangent Distillation, by Robotgiggle in [#921](https://github.com/FallingColors/HexMod/pull/921).
3939
- Massively improved ru_ru translations, by JustS-js and LedinecMing in [#832](https://github.com/FallingColors/HexMod/pull/832).
40+
- Changed the invalid-pattern mishap to display the offending pattern, by Robotgiggle in [#951](https://github.com/FallingColors/HexMod/pull/951).
41+
- Changed the invalid-iota mishap to display the type of the offending iota along with the iota itself, by Robotgiggle in [#951](https://github.com/FallingColors/HexMod/pull/951).
4042

4143
### Fixed
4244

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/MishapInvalidIota.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.iota.GarbageIota
55
import at.petrak.hexcasting.api.casting.iota.Iota
66
import at.petrak.hexcasting.api.pigment.FrozenPigment
77
import at.petrak.hexcasting.api.utils.asTranslatedComponent
8+
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
89
import net.minecraft.network.chat.Component
910
import net.minecraft.world.item.DyeColor
1011

@@ -23,11 +24,17 @@ class MishapInvalidIota(
2324
stack[stack.size - 1 - reverseIdx] = GarbageIota();
2425
}
2526

26-
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
27-
error(
27+
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? {
28+
val perpKey = HexIotaTypes.REGISTRY.getKey(perpetrator.getType())
29+
val perpDesc = Component.translatableWithFallback(
30+
"hexcasting.iota.${perpKey}.desc",
31+
"hexcasting.mishap.invalid_value.class.${perpKey?.getPath()}"
32+
)
33+
return error(
2834
"invalid_value", expected, reverseIdx,
29-
perpetrator.display()
35+
perpDesc, perpetrator.display()
3036
)
37+
}
3138

3239
companion object {
3340
@JvmStatic

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ 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?) : Mishap() {
14+
@Deprecated("Provide the pattern that caused the mishap as an argument")
15+
constructor() : this(null) {}
16+
1117
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
1218
dyeColor(DyeColor.YELLOW)
1319

@@ -17,6 +23,8 @@ class MishapInvalidPattern : Mishap() {
1723
stack.add(GarbageIota())
1824
}
1925

20-
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
21-
error("invalid_pattern")
26+
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? {
27+
if (pattern == null) return error("invalid_pattern_generic")
28+
return error("invalid_pattern", PatternIota.display(pattern))
29+
}
2230
}

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

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -969,22 +969,51 @@
969969
escape: "Consideration",
970970
undo: "Evanition",
971971
},
972-
972+
973973
"iota.hexcasting:": {
974-
"null": "Null",
975-
double: "Number",
976-
boolean: "Boolean",
977-
entity: "Entity",
978-
list: "List",
979-
pattern: "Pattern",
980-
garbage: "Garbage",
981-
vec3: "Vector",
974+
null: {
975+
"": "Null",
976+
desc: "a null value",
977+
},
978+
double: {
979+
"": "Number",
980+
desc: "a number",
981+
},
982+
boolean: {
983+
"": "Boolean",
984+
desc: "a boolean",
985+
},
986+
entity: {
987+
"": "Entity",
988+
desc: "an entity",
989+
},
990+
list: {
991+
"": "List",
992+
desc: "a list",
993+
},
994+
pattern: {
995+
"": "Pattern",
996+
desc: "a pattern",
997+
},
998+
garbage: {
999+
"": "Garbage",
1000+
desc: "garbage",
1001+
},
1002+
vec3: {
1003+
"": "Vector",
1004+
desc: "a vector",
1005+
},
1006+
continution: {
1007+
"": "Continuation",
1008+
desc: "a jump iota",
1009+
},
9821010
},
9831011

9841012
mishap: {
9851013
"": "%s: %s",
9861014

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

9901019
not_enough_args: "expected %s or more arguments but the stack was only %s tall",
@@ -1034,15 +1063,17 @@
10341063
bad_caster: "Tried to execute a pattern that requires a greater mind",
10351064

10361065
invalid_value: {
1037-
"": "expected %s at index %s of the stack, but got %s",
1066+
"": "expected %s at index %s of the stack, but got %s: %s",
10381067

10391068
class: {
10401069
double: "a number",
10411070
boolean: "a boolean",
10421071
vector: "a vector",
10431072
list: "a list",
1044-
widget: "an influence",
10451073
pattern: "a pattern",
1074+
continuation: "a jump iota",
1075+
garbage: "garbage",
1076+
null: "null",
10461077

10471078
entity: {
10481079
"": "an entity",

0 commit comments

Comments
 (0)