you can now actually get enlightened. lol lmao

This commit is contained in:
petrak@ 2023-06-20 11:34:02 -05:00
parent 8b2995d2c4
commit 430ca3582e
33 changed files with 97 additions and 53 deletions

View file

@ -83,6 +83,13 @@ public abstract class CastingEnvironment {
public abstract Vec3 mishapSprayPos();
/**
* Return whether this env can cast great spells.
*/
public boolean isEnlightened() {
return false;
}
/**
* Attempt to extract the given amount of media. Returns the amount of media left in the cost.
* <p>

View file

@ -74,7 +74,9 @@ public class CircleCastEnv extends CastingEnvironment {
for (var sideEffect : result.getSideEffects()) {
if (sideEffect instanceof OperatorSideEffect.DoMishap doMishap) {
var msg = doMishap.getMishap().errorMessageWithName(this, doMishap.getErrorCtx());
imp.postMishap(msg);
if (msg != null) {
imp.postMishap(msg);
}
}
}
}

View file

@ -204,7 +204,9 @@ public abstract class PlayerBasedCastEnv extends CastingEnvironment {
protected void sendMishapMsgToPlayer(OperatorSideEffect.DoMishap mishap) {
var msg = mishap.getMishap().errorMessageWithName(this, mishap.getErrorCtx());
this.caster.sendSystemMessage(msg);
if (msg != null) {
this.caster.sendSystemMessage(msg);
}
}
@Override

View file

@ -1,6 +1,5 @@
package at.petrak.hexcasting.api.casting.eval.sideeffects
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
import at.petrak.hexcasting.api.casting.ParticleSpray
import at.petrak.hexcasting.api.casting.RenderedSpell
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM
@ -24,8 +23,6 @@ sealed class OperatorSideEffect {
override fun performEffect(harness: CastingVM): Boolean {
harness.env.caster?.sendSystemMessage("hexcasting.message.cant_great_spell".asTranslatedComponent)
if (awardStat)
HexAdvancementTriggers.FAIL_GREAT_SPELL_TRIGGER.trigger(harness.env.caster)
return true
}

View file

@ -13,6 +13,7 @@ import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.api.casting.mishaps.Mishap;
import at.petrak.hexcasting.api.casting.mishaps.MishapEvalTooMuch;
import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidPattern;
import at.petrak.hexcasting.api.casting.mishaps.MishapUnenlightened;
import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.api.utils.HexUtils;
@ -85,8 +86,12 @@ public class PatternIota extends Iota {
HexTags.Actions.REQUIRES_ENLIGHTENMENT);
castedName = HexAPI.instance().getActionI18n(key, reqsEnlightenment);
action = Objects.requireNonNull(IXplatAbstractions.INSTANCE.getActionRegistry().get(key)).action();
if (reqsEnlightenment && !vm.getEnv().isEnlightened()) {
// this gets caught down below
throw new MishapUnenlightened();
}
} else if (lookup instanceof PatternShapeMatch.Special special) {
castedName = special.handler.getName();
action = special.handler.act();

View file

@ -37,16 +37,16 @@ abstract class Mishap : Throwable() {
*
* You can also mess up the stack with this.
*/
abstract fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>)
abstract fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>)
protected abstract fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component
protected abstract fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component?
/**
* Every error message should be prefixed with the name of the action...
*/
public fun errorMessageWithName(ctx: CastingEnvironment, errorCtx: Context): Component {
fun errorMessageWithName(ctx: CastingEnvironment, errorCtx: Context): Component? {
return if (errorCtx.name != null) {
"hexcasting.mishap".asTranslatedComponent(errorCtx.name, this.errorMessage(ctx, errorCtx))
"hexcasting.mishap".asTranslatedComponent(errorCtx.name, this.errorMessage(ctx, errorCtx) ?: return null)
} else {
this.errorMessage(ctx, errorCtx)
}

View file

@ -12,8 +12,8 @@ class MishapAlreadyBrainswept(val mob: Mob) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GREEN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
mob.hurt(HexDamageSources.overcastDamageFrom(ctx.caster), mob.health)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
mob.hurt(HexDamageSources.overcastDamageFrom(env.caster), mob.health)
}
override fun particleSpray(ctx: CastingEnvironment) =

View file

@ -15,8 +15,8 @@ class MishapBadBlock(val pos: BlockPos, val expected: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.LIME)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.world.explode(null, pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, 0.25f, Explosion.BlockInteraction.NONE)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.world.explode(null, pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, 0.25f, Explosion.BlockInteraction.NONE)
}
override fun particleSpray(ctx: CastingEnvironment) =

View file

@ -14,8 +14,8 @@ class MishapBadBrainsweep(val mob: Mob, val pos: BlockPos) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GREEN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
trulyHurt(mob, HexDamageSources.overcastDamageFrom(ctx.caster), 1f)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
trulyHurt(mob, HexDamageSources.overcastDamageFrom(env.caster), 1f)
}
override fun particleSpray(ctx: CastingEnvironment): ParticleSpray {

View file

@ -14,8 +14,8 @@ class MishapBadEntity(val entity: Entity, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.mishapEnvironment.yeetHeldItemsTowards(entity.position())
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.yeetHeldItemsTowards(entity.position())
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =

View file

@ -12,7 +12,7 @@ class MishapBadItem(val item: ItemEntity, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
item.deltaMovement = item.deltaMovement.add((Math.random() - 0.5) * 0.05, 0.75, (Math.random() - 0.5) * 0.05)
}

View file

@ -12,8 +12,8 @@ class MishapBadLocation(val location: Vec3, val type: String = "too_far") : Mish
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.MAGENTA)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.mishapEnvironment.yeetHeldItemsTowards(this.location)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.yeetHeldItemsTowards(this.location)
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component =

View file

@ -13,8 +13,8 @@ class MishapBadOffhandItem(val item: ItemStack, val hand: InteractionHand?, val
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.mishapEnvironment.dropHeldItems()
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.dropHeldItems()
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = if (item.isEmpty)

View file

@ -12,7 +12,7 @@ class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() {
override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
// NO-OP
}

View file

@ -16,9 +16,9 @@ class MishapDivideByZero(val operand1: Component, val operand2: Component, val s
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.RED)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
stack.add(GarbageIota())
ctx.mishapEnvironment.damage(0.5f)
env.mishapEnvironment.damage(0.5f)
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =

View file

@ -11,8 +11,8 @@ class MishapEntityTooFarAway(val entity: Entity) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.PINK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.mishapEnvironment.yeetHeldItemsTowards(entity.position())
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.yeetHeldItemsTowards(entity.position())
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component =

View file

@ -9,8 +9,8 @@ class MishapEvalTooMuch : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLUE)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.mishapEnvironment.drown()
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.drown()
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =

View file

@ -11,8 +11,8 @@ class MishapImmuneEntity(val entity: Entity) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLUE)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.mishapEnvironment.yeetHeldItemsTowards(entity.position())
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.yeetHeldItemsTowards(entity.position())
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =

View file

@ -9,7 +9,7 @@ class MishapInternalException(val exception: Exception) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
// NO-OP
}

View file

@ -19,7 +19,7 @@ class MishapInvalidIota(
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
stack[stack.size - 1 - reverseIdx] = GarbageIota();
}

View file

@ -13,7 +13,7 @@ class MishapInvalidPattern : Mishap() {
override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
stack.add(GarbageIota())
}

View file

@ -12,7 +12,7 @@ class MishapInvalidSpellDatumType(val perpetrator: Any) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
// NO-OP
}

View file

@ -12,7 +12,7 @@ class MishapLocationInWrongDimension(val properDimension: ResourceLocation) : Mi
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.MAGENTA)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
stack.add(GarbageIota())
}

View file

@ -10,8 +10,8 @@ class MishapNoAkashicRecord(val pos: BlockPos) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.PURPLE)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.mishapEnvironment.removeXp(100)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.removeXp(100)
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =

View file

@ -10,7 +10,7 @@ class MishapNotEnoughArgs(val expected: Int, val got: Int) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.LIGHT_GRAY)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
repeat(expected - got) { stack.add(GarbageIota()) }
}

View file

@ -15,9 +15,9 @@ class MishapOthersName(val confidant: Player) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
val seconds = if (this.confidant == ctx.caster) 5 else 60;
ctx.mishapEnvironment.blind(seconds * 20)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
val seconds = if (this.confidant == env.caster) 5 else 60;
env.mishapEnvironment.blind(seconds * 20)
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =

View file

@ -10,8 +10,8 @@ class MishapShameOnYou() : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
val caster = ctx.caster
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
val caster = env.caster
if (caster != null) {
// FIXME: handle null caster case
Mishap.trulyHurt(caster, HexDamageSources.SHAME, 69420f)

View file

@ -10,7 +10,7 @@ class MishapTooManyCloseParens : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.ORANGE)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
// TODO this is a kinda shitty mishap
if (errorCtx.pattern != null)
stack.add(PatternIota(errorCtx.pattern))

View file

@ -0,0 +1,31 @@
package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
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.sounds.SoundEvents
import net.minecraft.sounds.SoundSource
import net.minecraft.world.item.DyeColor
class MishapUnenlightened : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.RED)
override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.dropHeldItems()
env.caster?.sendSystemMessage("hexcasting.message.cant_great_spell".asTranslatedComponent, true)
// add some non-zero level of juice I guess
val pos = env.mishapSprayPos()
env.world.playSound(null, pos.x, pos.y, pos.z, SoundEvents.GLASS_BREAK, SoundSource.PLAYERS, 0.5f, 0.7f)
HexAdvancementTriggers.FAIL_GREAT_SPELL_TRIGGER.trigger(env.caster)
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = null
}

View file

@ -14,7 +14,7 @@ class MishapUnescapedValue(
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
// TODO
/*
val idx = stack.indexOfLast { it.getType() == DatumType.LIST }

View file

@ -15,8 +15,8 @@ class MishapBoolDirectrixEmptyStack(
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.world.destroyBlock(this.pos, true)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.world.destroyBlock(this.pos, true)
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component =

View file

@ -16,8 +16,8 @@ class MishapBoolDirectrixNotBool(
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
ctx.world.destroyBlock(this.pos, true)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.world.destroyBlock(this.pos, true)
}
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component =

View file

@ -23,8 +23,8 @@ class MishapNoSpellCircle : Mishap() {
}
}
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
val caster = ctx.caster
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
val caster = env.caster
if (caster != null) {
// FIXME: handle null caster case
dropAll(caster, caster.inventory.items)