From aa0ca0a1dfc74a8426fccf7491698135ef71d3d0 Mon Sep 17 00:00:00 2001 From: Robotgiggle Date: Fri, 21 Nov 2025 01:40:13 -0500 Subject: [PATCH 1/2] Fix MishapDisallowedSpell to properly display the offending action --- .../api/casting/eval/CastingEnvironment.java | 2 +- .../api/casting/eval/env/CircleCastEnv.java | 2 +- .../api/casting/mishaps/MishapDisallowedSpell.kt | 14 +++++++++++--- .../assets/hexcasting/lang/en_us.flatten.json5 | 6 ++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java index d465c877fa..2345eb4267 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java @@ -189,7 +189,7 @@ public void precheckAction(PatternShapeMatch match) throws Mishap { ResourceLocation key = actionKey(match); if (!HexConfig.server().isActionAllowed(key)) { - throw new MishapDisallowedSpell(); + throw new MishapDisallowedSpell("disallowed", key); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java index 1fb6698bf7..333deaa813 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java @@ -72,7 +72,7 @@ public void precheckAction(PatternShapeMatch match) throws Mishap { ResourceLocation key = actionKey(match); if (!HexConfig.server().isActionAllowedInCircles(key)) { - throw new MishapDisallowedSpell("disallowed_circle"); + throw new MishapDisallowedSpell("disallowed_circle", key); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapDisallowedSpell.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapDisallowedSpell.kt index d3118e5590..c55772107e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapDisallowedSpell.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapDisallowedSpell.kt @@ -4,9 +4,15 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.pigment.FrozenPigment +import at.petrak.hexcasting.api.utils.asTranslatedComponent +import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.chat.Component import net.minecraft.world.item.DyeColor -class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() { +class MishapDisallowedSpell(val type: String, val actionKey: ResourceLocation?) : Mishap() { + @Deprecated("Provide the type (disallowed or disallowed_circle) and the action key that caused the mishap") + constructor(type: String = "disallowed") : this(type, null) {} + override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment = dyeColor(DyeColor.BLACK) @@ -16,6 +22,8 @@ class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() { // NO-OP } - override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = - error(type) + override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? { + if (actionKey == null) return error(type + "_generic") + return error(type, "hexcasting.action.$actionKey".asTranslatedComponent) + } } 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 7935f10419..37e8a218fa 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 @@ -1055,8 +1055,10 @@ }, no_akashic_record: "No Akashic Record at %s", - disallowed: "has been disallowed by the server admins", - disallowed_circle: "has been disallowed in spell circles by the server admins", + disallowed: "%s has been disallowed by the server admins", + disallowed_generic: "That pattern has been disallowed by the server admins", + disallowed_circle: "%s has been disallowed in spell circles by the server admins", + disallowed_circle_generic: "That pattern has been disallowed in spell circles by the server admins", 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.", unknown: "threw an exception (%s). This is a bug in the mod.", stack_size: "Exceeded the size limit of the stack", From 50f53da39eabcc272ac527f2076a82f3f541631b Mon Sep 17 00:00:00 2001 From: Robotgiggle Date: Fri, 21 Nov 2025 01:53:57 -0500 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffece28434..524e0c552a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - Massively improved ru_ru translations, by JustS-js and LedinecMing in [#832](https://github.com/FallingColors/HexMod/pull/832). - Changed the invalid-pattern mishap to display the offending pattern, by Robotgiggle in [#951](https://github.com/FallingColors/HexMod/pull/951). - 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). +- Changed the disallowed-action mishap to properly display the offending action, by Robotgiggle in [#970](https://github.com/FallingColors/HexMod/pull/970). ### Fixed