Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make playerless sentinels mishap #777

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading