From 92b668fd2e04a9c48bec3db5f8a0f8a2344400bd Mon Sep 17 00:00:00 2001 From: Skye Date: Sat, 2 Nov 2024 14:55:20 +0900 Subject: [PATCH 1/2] Make playerless sentinels mishap --- .../api/casting/mishaps/MishapBadCaster.kt | 17 +++++++++++++++++ .../actions/spells/sentinel/OpCreateSentinel.kt | 4 ++++ .../spells/sentinel/OpDestroySentinel.kt | 4 ++++ .../actions/spells/sentinel/OpGetSentinelPos.kt | 4 ++++ .../spells/sentinel/OpGetSentinelWayfind.kt | 4 ++++ .../assets/hexcasting/lang/en_us.flatten.json5 | 1 + 6 files changed, 34 insertions(+) create mode 100644 Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapBadCaster.kt diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapBadCaster.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapBadCaster.kt new file mode 100644 index 0000000000..99199f9561 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapBadCaster.kt @@ -0,0 +1,17 @@ +package at.petrak.hexcasting.api.casting.mishaps + +import at.petrak.hexcasting.api.casting.eval.CastingEnvironment +import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.api.pigment.FrozenPigment +import net.minecraft.world.item.DyeColor + +class MishapBadCaster: Mishap() { + override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment = + dyeColor(DyeColor.RED) + + override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList) { + } + + override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = + error("bad_caster") +} \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt index 1c0b2793cd..b7a8a9ab70 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt @@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.casting.castables.SpellAction import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.getVec3 import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.api.casting.mishaps.MishapBadCaster import at.petrak.hexcasting.api.misc.MediaConstants import at.petrak.hexcasting.api.player.Sentinel import at.petrak.hexcasting.xplat.IXplatAbstractions @@ -19,6 +20,9 @@ class OpCreateSentinel(val extendsRange: Boolean) : SpellAction { args: List, env: CastingEnvironment ): SpellAction.Result { + if (env.castingEntity == null) + throw MishapBadCaster() + val target = args.getVec3(0, argc) env.assertVecInRange(target) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt index 97aaf692c4..06e57a1838 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt @@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.RenderedSpell import at.petrak.hexcasting.api.casting.castables.SpellAction import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.api.casting.mishaps.MishapBadCaster import at.petrak.hexcasting.api.casting.mishaps.MishapLocationInWrongDimension import at.petrak.hexcasting.api.misc.MediaConstants import at.petrak.hexcasting.xplat.IXplatAbstractions @@ -16,6 +17,9 @@ object OpDestroySentinel : SpellAction { args: List, env: CastingEnvironment ): SpellAction.Result { + if (env.castingEntity == null) + throw MishapBadCaster() + val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer) // TODO why can't you remove things from other dimensions? diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt index b038aa92bf..447363c6c5 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt @@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.castables.ConstMediaAction import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.NullIota +import at.petrak.hexcasting.api.casting.mishaps.MishapBadCaster import at.petrak.hexcasting.api.casting.mishaps.MishapLocationInWrongDimension import at.petrak.hexcasting.api.misc.MediaConstants import at.petrak.hexcasting.xplat.IXplatAbstractions @@ -14,6 +15,9 @@ object OpGetSentinelPos : ConstMediaAction { override val argc = 0 override val mediaCost: Long = MediaConstants.DUST_UNIT / 10 override fun execute(args: List, env: CastingEnvironment): List { + if (env.castingEntity == null) + throw MishapBadCaster() + val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer) ?: return listOf(NullIota()) if (sentinel.dimension != env.world.dimension()) throw MishapLocationInWrongDimension(sentinel.dimension.location()) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt index 87eb1547cb..9d58ab44c8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt @@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.getVec3 import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.NullIota +import at.petrak.hexcasting.api.casting.mishaps.MishapBadCaster import at.petrak.hexcasting.api.casting.mishaps.MishapLocationInWrongDimension import at.petrak.hexcasting.api.misc.MediaConstants import at.petrak.hexcasting.xplat.IXplatAbstractions @@ -17,6 +18,9 @@ object OpGetSentinelWayfind : ConstMediaAction { override val argc = 1 override val mediaCost: Long = MediaConstants.DUST_UNIT / 10 override fun execute(args: List, env: CastingEnvironment): List { + if (env.castingEntity == null) + throw MishapBadCaster() + val from = args.getVec3(0, argc) val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer) ?: return listOf(NullIota()) 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 7b98d7825d..7807a6e802 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 @@ -921,6 +921,7 @@ 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", + bad_caster: "Tried to execute a pattern that requires a greater mind", invalid_value: { "": "expected %s at index %s of the stack, but got %s", From eafa5092252f7465eb65a64ff3d289a93522d47d Mon Sep 17 00:00:00 2001 From: SamsTheNerd Date: Tue, 5 Nov 2024 17:02:58 -0500 Subject: [PATCH 2/2] change playerless sentinel check to check for a player and not just an entity --- .../common/casting/actions/spells/sentinel/OpCreateSentinel.kt | 2 +- .../common/casting/actions/spells/sentinel/OpDestroySentinel.kt | 2 +- .../common/casting/actions/spells/sentinel/OpGetSentinelPos.kt | 2 +- .../casting/actions/spells/sentinel/OpGetSentinelWayfind.kt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt index b7a8a9ab70..3b45740587 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt @@ -20,7 +20,7 @@ class OpCreateSentinel(val extendsRange: Boolean) : SpellAction { args: List, env: CastingEnvironment ): SpellAction.Result { - if (env.castingEntity == null) + if (env.castingEntity !is ServerPlayer) throw MishapBadCaster() val target = args.getVec3(0, argc) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt index 06e57a1838..43785a2adb 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt @@ -17,7 +17,7 @@ object OpDestroySentinel : SpellAction { args: List, env: CastingEnvironment ): SpellAction.Result { - if (env.castingEntity == null) + if (env.castingEntity !is ServerPlayer) throw MishapBadCaster() val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt index 447363c6c5..fa56812ca5 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt @@ -15,7 +15,7 @@ object OpGetSentinelPos : ConstMediaAction { override val argc = 0 override val mediaCost: Long = MediaConstants.DUST_UNIT / 10 override fun execute(args: List, env: CastingEnvironment): List { - if (env.castingEntity == null) + if (env.castingEntity !is ServerPlayer) throw MishapBadCaster() val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer) ?: return listOf(NullIota()) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt index 9d58ab44c8..cad52447ed 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt @@ -18,7 +18,7 @@ object OpGetSentinelWayfind : ConstMediaAction { override val argc = 1 override val mediaCost: Long = MediaConstants.DUST_UNIT / 10 override fun execute(args: List, env: CastingEnvironment): List { - if (env.castingEntity == null) + if (env.castingEntity !is ServerPlayer) throw MishapBadCaster() val from = args.getVec3(0, argc)