Skip to content

Commit

Permalink
Make playerless sentinels mishap (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamsTheNerd authored Nov 5, 2024
2 parents 77f5cfe + eafa509 commit eb0ab95
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Iota>) {
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
error("bad_caster")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +20,9 @@ class OpCreateSentinel(val extendsRange: Boolean) : SpellAction {
args: List<Iota>,
env: CastingEnvironment
): SpellAction.Result {
if (env.castingEntity !is ServerPlayer)
throw MishapBadCaster()

val target = args.getVec3(0, argc)
env.assertVecInRange(target)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,6 +17,9 @@ object OpDestroySentinel : SpellAction {
args: List<Iota>,
env: CastingEnvironment
): SpellAction.Result {
if (env.castingEntity !is ServerPlayer)
throw MishapBadCaster()

val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer)

// TODO why can't you remove things from other dimensions?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,6 +15,9 @@ object OpGetSentinelPos : ConstMediaAction {
override val argc = 0
override val mediaCost: Long = MediaConstants.DUST_UNIT / 10
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
if (env.castingEntity !is ServerPlayer)
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +18,9 @@ object OpGetSentinelWayfind : ConstMediaAction {
override val argc = 1
override val mediaCost: Long = MediaConstants.DUST_UNIT / 10
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
if (env.castingEntity !is ServerPlayer)
throw MishapBadCaster()

val from = args.getVec3(0, argc)

val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer) ?: return listOf(NullIota())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit eb0ab95

Please sign in to comment.