Skip to content

Commit fe55e53

Browse files
Make MishapDisallowedSpell properly display the offending action (#970)
2 parents 5ed1141 + 50f53da commit fe55e53

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
3939
- Massively improved ru_ru translations, by JustS-js and LedinecMing in [#832](https://github.com/FallingColors/HexMod/pull/832).
4040
- Changed the invalid-pattern mishap to display the offending pattern, by Robotgiggle in [#951](https://github.com/FallingColors/HexMod/pull/951).
4141
- 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).
42+
- Changed the disallowed-action mishap to properly display the offending action, by Robotgiggle in [#970](https://github.com/FallingColors/HexMod/pull/970).
4243

4344
### Fixed
4445

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void precheckAction(PatternShapeMatch match) throws Mishap {
189189
ResourceLocation key = actionKey(match);
190190

191191
if (!HexConfig.server().isActionAllowed(key)) {
192-
throw new MishapDisallowedSpell();
192+
throw new MishapDisallowedSpell("disallowed", key);
193193
}
194194
}
195195

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void precheckAction(PatternShapeMatch match) throws Mishap {
7272
ResourceLocation key = actionKey(match);
7373

7474
if (!HexConfig.server().isActionAllowedInCircles(key)) {
75-
throw new MishapDisallowedSpell("disallowed_circle");
75+
throw new MishapDisallowedSpell("disallowed_circle", key);
7676
}
7777
}
7878

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ 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.Iota
66
import at.petrak.hexcasting.api.pigment.FrozenPigment
7+
import at.petrak.hexcasting.api.utils.asTranslatedComponent
8+
import net.minecraft.resources.ResourceLocation;
9+
import net.minecraft.network.chat.Component
710
import net.minecraft.world.item.DyeColor
811

9-
class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() {
12+
class MishapDisallowedSpell(val type: String, val actionKey: ResourceLocation?) : Mishap() {
13+
@Deprecated("Provide the type (disallowed or disallowed_circle) and the action key that caused the mishap")
14+
constructor(type: String = "disallowed") : this(type, null) {}
15+
1016
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
1117
dyeColor(DyeColor.BLACK)
1218

@@ -16,6 +22,8 @@ class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() {
1622
// NO-OP
1723
}
1824

19-
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
20-
error(type)
25+
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? {
26+
if (actionKey == null) return error(type + "_generic")
27+
return error(type, "hexcasting.action.$actionKey".asTranslatedComponent)
28+
}
2129
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,10 @@
10551055
},
10561056

10571057
no_akashic_record: "No Akashic Record at %s",
1058-
disallowed: "has been disallowed by the server admins",
1059-
disallowed_circle: "has been disallowed in spell circles by the server admins",
1058+
disallowed: "%s has been disallowed by the server admins",
1059+
disallowed_generic: "That pattern has been disallowed by the server admins",
1060+
disallowed_circle: "%s has been disallowed in spell circles by the server admins",
1061+
disallowed_circle_generic: "That pattern has been disallowed in spell circles by the server admins",
10601062
invalid_spell_datum_type: "Tried to use a value of invalid type as a SpellDatum: %s (class %s). This is a bug in the mod.",
10611063
unknown: "threw an exception (%s). This is a bug in the mod.",
10621064
stack_size: "Exceeded the size limit of the stack",

0 commit comments

Comments
 (0)