Skip to content

Commit eb0ab95

Browse files
authored
Make playerless sentinels mishap (#777)
2 parents 77f5cfe + eafa509 commit eb0ab95

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package at.petrak.hexcasting.api.casting.mishaps
2+
3+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
4+
import at.petrak.hexcasting.api.casting.iota.Iota
5+
import at.petrak.hexcasting.api.pigment.FrozenPigment
6+
import net.minecraft.world.item.DyeColor
7+
8+
class MishapBadCaster: Mishap() {
9+
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
10+
dyeColor(DyeColor.RED)
11+
12+
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
13+
}
14+
15+
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
16+
error("bad_caster")
17+
}

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpCreateSentinel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.casting.castables.SpellAction
66
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
77
import at.petrak.hexcasting.api.casting.getVec3
88
import at.petrak.hexcasting.api.casting.iota.Iota
9+
import at.petrak.hexcasting.api.casting.mishaps.MishapBadCaster
910
import at.petrak.hexcasting.api.misc.MediaConstants
1011
import at.petrak.hexcasting.api.player.Sentinel
1112
import at.petrak.hexcasting.xplat.IXplatAbstractions
@@ -19,6 +20,9 @@ class OpCreateSentinel(val extendsRange: Boolean) : SpellAction {
1920
args: List<Iota>,
2021
env: CastingEnvironment
2122
): SpellAction.Result {
23+
if (env.castingEntity !is ServerPlayer)
24+
throw MishapBadCaster()
25+
2226
val target = args.getVec3(0, argc)
2327
env.assertVecInRange(target)
2428

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpDestroySentinel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.RenderedSpell
55
import at.petrak.hexcasting.api.casting.castables.SpellAction
66
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
77
import at.petrak.hexcasting.api.casting.iota.Iota
8+
import at.petrak.hexcasting.api.casting.mishaps.MishapBadCaster
89
import at.petrak.hexcasting.api.casting.mishaps.MishapLocationInWrongDimension
910
import at.petrak.hexcasting.api.misc.MediaConstants
1011
import at.petrak.hexcasting.xplat.IXplatAbstractions
@@ -16,6 +17,9 @@ object OpDestroySentinel : SpellAction {
1617
args: List<Iota>,
1718
env: CastingEnvironment
1819
): SpellAction.Result {
20+
if (env.castingEntity !is ServerPlayer)
21+
throw MishapBadCaster()
22+
1923
val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer)
2024

2125
// TODO why can't you remove things from other dimensions?

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelPos.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
55
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
66
import at.petrak.hexcasting.api.casting.iota.Iota
77
import at.petrak.hexcasting.api.casting.iota.NullIota
8+
import at.petrak.hexcasting.api.casting.mishaps.MishapBadCaster
89
import at.petrak.hexcasting.api.casting.mishaps.MishapLocationInWrongDimension
910
import at.petrak.hexcasting.api.misc.MediaConstants
1011
import at.petrak.hexcasting.xplat.IXplatAbstractions
@@ -14,6 +15,9 @@ object OpGetSentinelPos : ConstMediaAction {
1415
override val argc = 0
1516
override val mediaCost: Long = MediaConstants.DUST_UNIT / 10
1617
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
18+
if (env.castingEntity !is ServerPlayer)
19+
throw MishapBadCaster()
20+
1721
val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer) ?: return listOf(NullIota())
1822
if (sentinel.dimension != env.world.dimension())
1923
throw MishapLocationInWrongDimension(sentinel.dimension.location())

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/sentinel/OpGetSentinelWayfind.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
66
import at.petrak.hexcasting.api.casting.getVec3
77
import at.petrak.hexcasting.api.casting.iota.Iota
88
import at.petrak.hexcasting.api.casting.iota.NullIota
9+
import at.petrak.hexcasting.api.casting.mishaps.MishapBadCaster
910
import at.petrak.hexcasting.api.casting.mishaps.MishapLocationInWrongDimension
1011
import at.petrak.hexcasting.api.misc.MediaConstants
1112
import at.petrak.hexcasting.xplat.IXplatAbstractions
@@ -17,6 +18,9 @@ object OpGetSentinelWayfind : ConstMediaAction {
1718
override val argc = 1
1819
override val mediaCost: Long = MediaConstants.DUST_UNIT / 10
1920
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
21+
if (env.castingEntity !is ServerPlayer)
22+
throw MishapBadCaster()
23+
2024
val from = args.getVec3(0, argc)
2125

2226
val sentinel = IXplatAbstractions.INSTANCE.getSentinel(env.castingEntity as? ServerPlayer) ?: return listOf(NullIota())

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@
921921
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.",
922922
unknown: "threw an exception (%s). This is a bug in the mod.",
923923
stack_size: "Exceeded the size limit of the stack",
924+
bad_caster: "Tried to execute a pattern that requires a greater mind",
924925

925926
invalid_value: {
926927
"": "expected %s at index %s of the stack, but got %s",

0 commit comments

Comments
 (0)