Skip to content
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
Expand Up @@ -17,9 +17,9 @@ import net.minecraft.nbt.CompoundTag
interface SpellAction : Action {
val argc: Int

fun hasCastingSound(ctx: CastingEnvironment): Boolean = true
fun hasCastingSound(env: CastingEnvironment): Boolean = true

fun awardsCastingStat(ctx: CastingEnvironment): Boolean = true
fun awardsCastingStat(env: CastingEnvironment): Boolean = true

@Throws(Mishap::class)
fun execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import net.minecraft.world.entity.Entity
/**
* The state of a casting VM, containing the stack and all
*/
data class CastingImage private constructor(
data class CastingImage(
val stack: List<Iota>,

val parenCount: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import java.lang.RuntimeException

abstract class Mishap : RuntimeException() {
/** Mishaps spray half-red, half-this-color. */
abstract fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment
abstract fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment

open fun particleSpray(ctx: CastingEnvironment): ParticleSpray {
open fun particleSpray(env: CastingEnvironment): ParticleSpray {
return ParticleSpray(
ctx.mishapSprayPos().add(0.0, 0.2, 0.0),
env.mishapSprayPos().add(0.0, 0.2, 0.0),
Vec3(0.0, 2.0, 0.0),
0.2, Math.PI / 4, 40)
}

open fun resolutionType(ctx: CastingEnvironment): ResolvedPatternType = ResolvedPatternType.ERRORED
open fun resolutionType(env: CastingEnvironment): ResolvedPatternType = ResolvedPatternType.ERRORED

/**
* Execute the actual effect, not any sfx.
Expand All @@ -40,21 +40,21 @@ abstract class Mishap : RuntimeException() {
*/
abstract fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>)

protected abstract fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component?
protected abstract fun errorMessage(env: CastingEnvironment, errorCtx: Context): Component?

fun executeReturnStack(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>): List<Iota> {
execute(ctx, errorCtx, stack)
fun executeReturnStack(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>): List<Iota> {
execute(env, errorCtx, stack)
return stack
}

/**
* Every error message should be prefixed with the name of the action...
*/
fun errorMessageWithName(ctx: CastingEnvironment, errorCtx: Context): Component? {
fun errorMessageWithName(env: CastingEnvironment, errorCtx: Context): Component? {
return if (errorCtx.name != null) {
"hexcasting.mishap".asTranslatedComponent(errorCtx.name, this.errorMessage(ctx, errorCtx) ?: return null)
"hexcasting.mishap".asTranslatedComponent(errorCtx.name, this.errorMessage(env, errorCtx) ?: return null)
} else {
this.errorMessage(ctx, errorCtx)
this.errorMessage(env, errorCtx)
}
}

Expand All @@ -72,8 +72,8 @@ abstract class Mishap : RuntimeException() {
protected fun actionName(name: Component?): Component =
name ?: "hexcasting.spell.null".asTranslatedComponent.lightPurple

protected fun blockAtPos(ctx: CastingEnvironment, pos: BlockPos): Component {
return ctx.world.getBlockState(pos).block.name
protected fun blockAtPos(env: CastingEnvironment, pos: BlockPos): Component {
return env.world.getBlockState(pos).block.name
}

data class Context(val pattern: HexPattern?, val name: Component?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import net.minecraft.world.entity.Mob
import net.minecraft.world.item.DyeColor

class MishapAlreadyBrainswept(val mob: Mob) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GREEN)

override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
mob.hurt(mob.damageSources().source(HexDamageTypes.OVERCAST, ctx.castingEntity), mob.health)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
mob.hurt(mob.damageSources().source(HexDamageTypes.OVERCAST, env.castingEntity), mob.health)
}

override fun particleSpray(ctx: CastingEnvironment) =
override fun particleSpray(env: CastingEnvironment) =
ParticleSpray.burst(mob.eyePosition, 1.0)

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("already_brainswept")

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import net.minecraft.world.level.Level
import net.minecraft.world.phys.Vec3

class MishapBadBlock(val pos: BlockPos, val expected: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: 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, Level.ExplosionInteraction.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, Level.ExplosionInteraction.NONE)
}

override fun particleSpray(ctx: CastingEnvironment) =
override fun particleSpray(env: CastingEnvironment) =
ParticleSpray.burst(Vec3.atCenterOf(pos), 1.0)

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
error("bad_block", expected, this.pos.toShortString(), blockAtPos(ctx, this.pos))
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("bad_block", expected, this.pos.toShortString(), blockAtPos(env, this.pos))

companion object {
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import net.minecraft.world.item.DyeColor
import net.minecraft.world.phys.Vec3

class MishapBadBrainsweep(val mob: Mob, val pos: BlockPos) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GREEN)

override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
trulyHurt(mob, mob.damageSources().source(HexDamageTypes.OVERCAST, ctx.castingEntity), 1f)
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
trulyHurt(mob, mob.damageSources().source(HexDamageTypes.OVERCAST, env.castingEntity), 1f)
}

override fun particleSpray(ctx: CastingEnvironment): ParticleSpray {
override fun particleSpray(env: CastingEnvironment): ParticleSpray {
return ParticleSpray.burst(Vec3.atCenterOf(pos), 1.0)
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
error("bad_brainsweep", blockAtPos(ctx, this.pos))
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("bad_brainsweep", blockAtPos(env, this.pos))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor

class MishapBadCaster: Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.RED)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("bad_caster")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.item.DyeColor

class MishapBadEntity(val entity: Entity, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.yeetHeldItemsTowards(entity.position())
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("bad_entity", wanted, entity.displayName.plainCopy().aqua)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.item.DyeColor

class MishapBadItem(val item: ItemEntity, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN)

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)
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = if (item.item.isEmpty)
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) = if (item.item.isEmpty)
error("no_item", wanted)
else
error("bad_item", wanted, item.item.count, item.item.displayName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import net.minecraft.world.item.DyeColor
import net.minecraft.world.phys.Vec3

class MishapBadLocation(val location: Vec3, val type: String = "too_far") : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.MAGENTA)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.yeetHeldItemsTowards(this.location)
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context): Component =
error("location_$type", Vec3Iota.display(location))
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.ItemStack

class MishapBadOffhandItem(val item: ItemStack?, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.dropHeldItems()
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = if (item?.isEmpty == false)
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) = if (item?.isEmpty == false)
error("bad_item.offhand", wanted, item.count, item.displayName)
else
error("no_item.offhand", wanted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class MishapDisallowedSpell(val type: String, val actionKey: ResourceLocation?)
@Deprecated("Provide the type (disallowed or disallowed_circle) and the action key that caused the mishap")
constructor(type: String = "disallowed") : this(type, null) {}

override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK)

override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID
override fun resolutionType(env: CastingEnvironment) = ResolvedPatternType.INVALID

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
// NO-OP
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? {
override fun errorMessage(env: CastingEnvironment, errorCtx: Context): Component? {
if (actionKey == null) return error(type + "_generic")
return error(type, "hexcasting.action.$actionKey".asTranslatedComponent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import net.minecraft.world.phys.Vec3

class MishapDivideByZero(val operand1: Component, val operand2: Component, val suffix: String = "divide") : Mishap() {

override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.RED)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
stack.add(GarbageIota())
env.mishapEnvironment.damage(0.5f)
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("divide_by_zero.$suffix", operand1, operand2)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import net.minecraft.world.entity.Entity
import net.minecraft.world.item.DyeColor

class MishapEntityTooFarAway(val entity: Entity) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.PINK)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.yeetHeldItemsTowards(entity.position())
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context): Component =
error("entity_too_far", entity.displayName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor

class MishapEvalTooMuch : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLUE)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.drown()
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("eval_too_much")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import net.minecraft.world.entity.Entity
import net.minecraft.world.item.DyeColor

class MishapImmuneEntity(val entity: Entity) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLUE)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
env.mishapEnvironment.yeetHeldItemsTowards(entity.position())
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("immune_entity", entity.displayName.plainCopy().aqua)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor

class MishapInternalException(val exception: Exception) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
// NO-OP
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
override fun errorMessage(env: CastingEnvironment, errorCtx: Context) =
error("unknown", exception)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class MishapInvalidIota(
val reverseIdx: Int,
val expected: Component
) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
stack[stack.size - 1 - reverseIdx] = GarbageIota();
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? {
override fun errorMessage(env: CastingEnvironment, errorCtx: Context): Component? {
val perpKey = HexIotaTypes.REGISTRY.getKey(perpetrator.getType())

// this translation key is preferred because it includes the namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import net.minecraft.world.item.DyeColor
* The value failed some kind of predicate.
*/
class MishapInvalidOperatorArgs(val perpetrators: List<Iota>) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY)

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
Expand All @@ -22,7 +22,7 @@ class MishapInvalidOperatorArgs(val perpetrators: List<Iota>) : Mishap() {
}
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component {
override fun errorMessage(env: CastingEnvironment, errorCtx: Context): Component {
return if (perpetrators.size == 1) {
error(
"invalid_operator_args.one",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class MishapInvalidPattern(val pattern: HexPattern?) : Mishap() {
@Deprecated("Provide the pattern that caused the mishap as an argument")
constructor() : this(null) {}

override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
override fun accentColor(env: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.YELLOW)

override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID
override fun resolutionType(env: CastingEnvironment) = ResolvedPatternType.INVALID

override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
stack.add(GarbageIota())
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? {
override fun errorMessage(env: CastingEnvironment, errorCtx: Context): Component? {
if (pattern == null) return error("invalid_pattern_generic")
return error("invalid_pattern", PatternIota.display(pattern))
}
Expand Down
Loading
Loading