equality tolerance - but it's everywhere now

also fix mishaps for arguments
This commit is contained in:
yrsegal@gmail.com 2022-05-20 16:56:33 +01:00
parent a17dc3e90a
commit 153b2b9667
101 changed files with 446 additions and 562 deletions

View file

@ -1,8 +1,6 @@
package at.petrak.hexcasting.api.spell
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import net.minecraft.world.phys.Vec3
/**
@ -39,27 +37,6 @@ interface Operator {
fun raycastEnd(origin: Vec3, look: Vec3): Vec3 =
origin.add(look.normalize().scale(MAX_DISTANCE))
/**
* Try to get a value of the given type.
*/
@JvmStatic
inline fun <reified T : Any> List<SpellDatum<*>>.getChecked(idx: Int): T {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x.payload is T)
return x.payload
else
throw MishapInvalidIota.ofClass(x, idx, T::class.java)
}
@JvmStatic
fun spellListOf(vararg vs: Any): List<SpellDatum<*>> {
val out = ArrayList<SpellDatum<*>>(vs.size)
for (v in vs) {
out.add(SpellDatum.make(v))
}
return out
}
@JvmStatic
fun makeConstantOp(x: SpellDatum<*>): Operator = object : ConstManaOperator {
override val argc: Int
@ -70,3 +47,4 @@ interface Operator {
}
}
}

View file

@ -0,0 +1,95 @@
@file:JvmName("OperatorUtils")
package at.petrak.hexcasting.api.spell
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import com.mojang.datafixers.util.Either
import com.mojang.math.Vector3f
import net.minecraft.core.BlockPos
import net.minecraft.network.chat.TranslatableComponent
import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.Vec3
import kotlin.math.abs
fun GetNumOrVec(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, Vec3> =
when (datum.payload) {
is Double -> Either.left(datum.payload)
is Vec3 -> Either.right(datum.payload)
else -> throw MishapInvalidIota(
datum,
reverseIdx,
TranslatableComponent("hexcasting.mishap.invalid_value.numvec")
)
}
fun GetNumOrList(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, SpellList> =
when (datum.payload) {
is Double -> Either.left(datum.payload)
is SpellList -> Either.right(datum.payload)
else -> throw MishapInvalidIota(
datum,
reverseIdx,
TranslatableComponent("hexcasting.mishap.invalid_value.numlist")
)
}
fun spellListOf(vararg vs: Any): List<SpellDatum<*>> {
val out = ArrayList<SpellDatum<*>>(vs.size)
for (v in vs) {
out.add(SpellDatum.make(v))
}
return out
}
inline fun <reified T : Any> List<SpellDatum<*>>.getChecked(idx: Int, argc: Int = 0): T {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x.payload is T)
return x.payload
else
throw MishapInvalidIota.ofClass(x, if (argc == 0) idx else argc - (idx + 1), T::class.java)
}
inline val Boolean.asSpellResult get() = spellListOf(if (this) 1.0 else 0.0)
inline val Double.asSpellResult get() = spellListOf(this)
inline val Number.asSpellResult get() = spellListOf(this.toDouble())
inline val SpellList.asSpellResult get() = spellListOf(this)
inline val List<SpellDatum<*>>.asSpellResult get() = spellListOf(this)
inline val Widget.asSpellResult get() = spellListOf(this)
inline val BlockPos.asSpellResult get() = spellListOf(Vec3.atCenterOf(this))
inline val Vector3f.asSpellResult get() = spellListOf(Vec3(this))
inline val Vec3.asSpellResult get() = spellListOf(this)
inline val Entity?.asSpellResult get() = spellListOf(this ?: Widget.NULL)
inline val HexPattern.asSpellResult get() = spellListOf(this)
private const val TOLERANCE = 0.0001
fun Any.tolerantEquals(other: Any) = tolerantEquals(other, 64)
private fun Any.tolerantEquals(other: Any, recursionsLeft: Int): Boolean {
return when {
this is SpellDatum<*> && other is SpellDatum<*> -> this.payload.tolerantEquals(other.payload, recursionsLeft)
this is SpellDatum<*> -> this.payload.tolerantEquals(other, recursionsLeft)
other is SpellDatum<*> -> this.tolerantEquals(other.payload, recursionsLeft)
this is HexPattern && other is HexPattern -> this.angles == other.angles
this is Double && other is Double -> abs(this - other) < TOLERANCE
this is Vec3 && other is Vec3 -> this.subtract(other).lengthSqr() < TOLERANCE * TOLERANCE
this is SpellList && other is SpellList -> {
val castA = this.toList()
val castB = other.toList()
if (castA.size != castB.size || recursionsLeft == 0)
return false
for (i in castA.indices)
if (!castA[i].payload.tolerantEquals(castB[i].payload, recursionsLeft - 1))
return false
true
}
else -> this == other
}
}

View file

@ -15,7 +15,6 @@ import net.minecraft.server.level.ServerLevel
import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.Vec3
import java.util.*
import kotlin.math.abs
/**
* Data allowed into a spell.
@ -100,21 +99,6 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
else -> DatumType.OTHER
}
// Todo: make more things use this
fun equalsWithDoubleTolerance(other: SpellDatum<*>): Boolean {
if (this == other) {
return true
}
val tolerance = 0.0001
if (this.payload is Double && other.payload is Double) {
return abs(this.payload - other.payload) < tolerance
}
if (this.payload is Vec3 && other.payload is Vec3) {
return this.payload.distanceToSqr(other.payload) < tolerance * tolerance
}
return false
}
companion object {
@JvmStatic
fun make(payload: Any): SpellDatum<*> =

View file

@ -63,9 +63,9 @@ sealed class SpellList: Iterable<SpellDatum<*>> {
override fun toString() = toList().toString()
override fun iterator() = Iterator(this)
override fun iterator() = SpellListIterator(this)
class Iterator(var list: SpellList): kotlin.collections.Iterator<SpellDatum<*>> {
class SpellListIterator(var list: SpellList): Iterator<SpellDatum<*>> {
override fun hasNext() = list.nonEmpty
override operator fun next(): SpellDatum<*> {
val car = list.car

View file

@ -1,6 +1,5 @@
package at.petrak.hexcasting.api.spell
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.casting.CastingContext
/**
@ -17,5 +16,5 @@ enum class Widget : ConstManaOperator {
get() = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> =
spellListOf(this)
this.asSpellResult
}

View file

@ -129,13 +129,13 @@ public class RegisterPatterns {
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("dwa", HexDir.NORTH_WEST), modLoc("xor"),
OpBoolXor.INSTANCE);
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("e", HexDir.SOUTH_EAST), modLoc("greater"),
new OpCompare((a, b) -> a > b));
new OpCompare(false, (a, b) -> a > b));
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("q", HexDir.SOUTH_WEST), modLoc("less"),
new OpCompare((a, b) -> a < b));
new OpCompare(false, (a, b) -> a < b));
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("ee", HexDir.SOUTH_EAST), modLoc("greater_eq"),
new OpCompare((a, b) -> a >= b));
new OpCompare(true, (a, b) -> a >= b));
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qq", HexDir.SOUTH_WEST), modLoc("less_eq"),
new OpCompare((a, b) -> a <= b));
new OpCompare(true, (a, b) -> a <= b));
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("ad", HexDir.EAST), modLoc("equals"),
new OpEquality(false));
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("da", HexDir.EAST), modLoc("not_equals"),

View file

@ -1,11 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.level.ClipContext
import net.minecraft.world.phys.HitResult
@ -15,8 +11,8 @@ object OpBlockAxisRaycast : ConstManaOperator {
override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val origin: Vec3 = args.getChecked(0)
val look: Vec3 = args.getChecked(1)
val origin: Vec3 = args.getChecked(0, argc)
val look: Vec3 = args.getChecked(1, argc)
val blockHitResult = ctx.world.clip(
ClipContext(
@ -28,12 +24,10 @@ object OpBlockAxisRaycast : ConstManaOperator {
)
)
return Operator.spellListOf(
if (blockHitResult.type == HitResult.Type.BLOCK) {
Vec3(blockHitResult.direction.step())
} else {
Widget.NULL
}
)
return if (blockHitResult.type == HitResult.Type.BLOCK) {
blockHitResult.direction.step().asSpellResult
} else {
null.asSpellResult
}
}
}

View file

@ -1,11 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.level.ClipContext
import net.minecraft.world.phys.HitResult
@ -15,8 +11,8 @@ object OpBlockRaycast : ConstManaOperator {
override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val origin: Vec3 = args.getChecked(0)
val look: Vec3 = args.getChecked(1)
val origin: Vec3 = args.getChecked(0, argc)
val look: Vec3 = args.getChecked(1, argc)
val blockHitResult = ctx.world.clip(
ClipContext(
@ -28,19 +24,13 @@ object OpBlockRaycast : ConstManaOperator {
)
)
return Operator.spellListOf(
if (blockHitResult.type == HitResult.Type.BLOCK) {
// the position on the bhr is the position of the specific *hit point*, which is actually on the outside of the block
// this is weird (for example, casting OpBreakBlock at this position will not break the block we're looking at)
// so we return the block pos instead
Vec3(
blockHitResult.blockPos.x.toDouble() + 0.5,
blockHitResult.blockPos.y.toDouble() + 0.5,
blockHitResult.blockPos.z.toDouble() + 0.5
)
} else {
Widget.NULL
}
)
return if (blockHitResult.type == HitResult.Type.BLOCK) {
// the position on the bhr is the position of the specific *hit point*, which is actually on the outside of the block
// this is weird (for example, casting OpBreakBlock at this position will not break the block we're looking at)
// so we return the block pos instead
blockHitResult.blockPos.asSpellResult
} else {
Widget.NULL.asSpellResult
}
}
}

View file

@ -1,18 +1,18 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import net.minecraft.world.entity.Entity
object OpEntityHeight : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val e: Entity = args.getChecked(0)
val e: Entity = args.getChecked(0, argc)
ctx.assertEntityInRange(e)
return spellListOf(e.bbHeight.toDouble())
return e.bbHeight.asSpellResult
}
}

View file

@ -1,18 +1,18 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import net.minecraft.world.entity.Entity
object OpEntityLook : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val e: Entity = args.getChecked(0)
val e: Entity = args.getChecked(0, argc)
ctx.assertEntityInRange(e)
return spellListOf(e.lookAngle)
return e.lookAngle.asSpellResult
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.player.Player
@ -12,10 +12,10 @@ object OpEntityPos : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val e: Entity = args.getChecked(0)
val e: Entity = args.getChecked(0, argc)
ctx.assertEntityInRange(e)
// If this is a player, "expected behavior" is to get the *eye* position so raycasts don't immediately
// hit the ground.
return spellListOf(if (e is Player) e.eyePosition else e.position())
return if (e is Player) e.eyePosition.asSpellResult else e.position().asSpellResult
}
}

View file

@ -1,11 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.entity.projectile.ProjectileUtil
import net.minecraft.world.phys.AABB
@ -15,8 +11,8 @@ object OpEntityRaycast : ConstManaOperator {
override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val origin: Vec3 = args.getChecked(0)
val look: Vec3 = args.getChecked(1)
val origin: Vec3 = args.getChecked(0, argc)
val look: Vec3 = args.getChecked(1, argc)
val endp = Operator.raycastEnd(origin, look)
val entityHitResult = ProjectileUtil.getEntityHitResult(
@ -28,13 +24,10 @@ object OpEntityRaycast : ConstManaOperator {
1_000_000.0
)
val out = if (entityHitResult != null && ctx.isEntityInRange(entityHitResult.entity)) {
entityHitResult.entity
return if (entityHitResult != null && ctx.isEntityInRange(entityHitResult.entity)) {
entityHitResult.entity.asSpellResult
} else {
null
null.asSpellResult
}
return Operator.spellListOf(
out ?: Widget.NULL
)
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.common.misc.PlayerPositionRecorder
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.Entity
@ -13,14 +13,14 @@ object OpEntityVelocity : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val e: Entity = args.getChecked(0)
val e: Entity = args.getChecked(0, argc)
ctx.assertEntityInRange(e)
// Player velocity is jank. Really jank. This is the best we can do.
if (e is ServerPlayer) {
return spellListOf(PlayerPositionRecorder.getMotion(e))
return PlayerPositionRecorder.getMotion(e).asSpellResult
}
return spellListOf(e.deltaMovement)
return e.deltaMovement.asSpellResult
}
}

View file

@ -1,8 +1,8 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.xplat.IXplatAbstractions
@ -15,12 +15,12 @@ object OpReadable : ConstManaOperator {
}
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
?: return spellListOf(0.0)
?: return false.asSpellResult
datumHolder.readDatum(ctx.world)
?: datumHolder.emptyDatum()
?: return spellListOf(0.0)
?: return false.asSpellResult
return spellListOf(1.0)
return true.asSpellResult
}
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem
@ -15,7 +15,7 @@ object OpTheCoolerRead : ConstManaOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): List<SpellDatum<*>> {
val target = args.getChecked<ItemEntity>(0)
val target = args.getChecked<ItemEntity>(0, argc)
ctx.assertEntityInRange(target)

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.entity.item.ItemEntity
@ -15,16 +15,16 @@ object OpTheCoolerReadable : ConstManaOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): List<SpellDatum<*>> {
val target = args.getChecked<ItemEntity>(0)
val target = args.getChecked<ItemEntity>(0, argc)
ctx.assertEntityInRange(target)
val stack = target.item
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack)
?: return spellListOf(0.0)
?: return false.asSpellResult
if (datumHolder.readDatum(ctx.world) == null && datumHolder.emptyDatum() == null)
return spellListOf(0.0)
return false.asSpellResult
return spellListOf(1.0)
return true.asSpellResult
}
}

View file

@ -1,8 +1,8 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
import at.petrak.hexcasting.xplat.IXplatAbstractions
@ -19,15 +19,15 @@ object OpWritable : ConstManaOperator {
datumHolder != null && datumHolder.writeDatum(datum, true)
}
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) ?: return spellListOf(0.0)
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) ?: return false.asSpellResult
if (!datumHolder.writeDatum(datum, true))
return spellListOf(0.0)
return false.asSpellResult
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)
if (trueName != null)
return spellListOf(0.0)
return false.asSpellResult
return spellListOf(1.0)
return true.asSpellResult
}
}

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.akashic
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext
@ -17,8 +17,8 @@ object OpAkashicRead : ConstManaOperator {
override val manaCost = ManaConstants.DUST_UNIT
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val pos = args.getChecked<Vec3>(0)
val key = args.getChecked<HexPattern>(1)
val pos = args.getChecked<Vec3>(0, argc)
val key = args.getChecked<HexPattern>(1, argc)
val bpos = BlockPos(pos)
val tile = ctx.world.getBlockEntity(bpos)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.akashic
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -23,8 +23,8 @@ object OpAkashicWrite : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pos = args.getChecked<Vec3>(0)
val key = args.getChecked<HexPattern>(1)
val pos = args.getChecked<Vec3>(0, argc)
val key = args.getChecked<HexPattern>(1, argc)
val datum = args[2]
ctx.assertVecInRange(pos)

View file

@ -1,8 +1,8 @@
package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
import net.minecraft.world.phys.Vec3
@ -16,11 +16,9 @@ class OpCircleBounds(val max: Boolean) : ConstManaOperator {
val aabb = ctx.spellCircle.aabb
return Operator.spellListOf(
if (max)
Vec3(aabb.maxX - 0.5, aabb.maxY - 0.5, aabb.maxZ - 0.5)
else
Vec3(aabb.minX + 0.5, aabb.minY + 0.5, aabb.minZ + 0.5)
)
return if (max)
Vec3(aabb.maxX - 0.5, aabb.maxY - 0.5, aabb.maxZ - 0.5).asSpellResult
else
Vec3(aabb.minX + 0.5, aabb.minY + 0.5, aabb.minZ + 0.5).asSpellResult
}
}

View file

@ -2,11 +2,10 @@ package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
import net.minecraft.world.phys.Vec3
object OpImpetusDir : ConstManaOperator {
override val argc = 0
@ -18,6 +17,6 @@ object OpImpetusDir : ConstManaOperator {
val pos = ctx.spellCircle.impetusPos
val bs = ctx.world.getBlockState(pos)
val dir = bs.getValue(BlockAbstractImpetus.FACING)
return Operator.spellListOf(Vec3(dir.step()))
return dir.step().asSpellResult
}
}

View file

@ -1,8 +1,8 @@
package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
import net.minecraft.world.phys.Vec3
@ -14,6 +14,6 @@ object OpImpetusPos : ConstManaOperator {
if (ctx.spellCircle == null)
throw MishapNoSpellCircle()
return Operator.spellListOf(Vec3.atCenterOf(ctx.spellCircle.impetusPos))
return Vec3.atCenterOf(ctx.spellCircle.impetusPos).asSpellResult
}
}

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext

View file

@ -1,18 +1,14 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpAppend : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val list = args.getChecked<SpellList>(0).toMutableList()
val list = args.getChecked<SpellList>(0, argc).toMutableList()
val datum = args[1]
list.add(datum)
return spellListOf(list)
return list.asSpellResult
}
}

View file

@ -1,18 +1,14 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpConcat : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val lhs = args.getChecked<SpellList>(0).toMutableList()
val rhs = args.getChecked<SpellList>(1)
val lhs = args.getChecked<SpellList>(0, argc).toMutableList()
val rhs = args.getChecked<SpellList>(1, argc)
lhs.addAll(rhs)
return spellListOf(lhs)
return lhs.asSpellResult
}
}

View file

@ -1,17 +1,13 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpCons : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val bottom = args.getChecked<SpellList>(0)
val bottom = args.getChecked<SpellList>(0, argc)
val top = args[1]
return spellListOf(SpellList.LPair(top, bottom))
return SpellList.LPair(top, bottom).asSpellResult
}
}

View file

@ -1,13 +1,13 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpEmptyList : ConstManaOperator {
override val argc = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
return spellListOf(emptyList<SpellDatum<*>>()) // sorry for taking all the easy impls, hudeler
return emptyList<SpellDatum<*>>().asSpellResult // sorry for taking all the easy impls, hudeler
}
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext
@ -11,8 +11,8 @@ import kotlin.math.roundToInt
object OpIndex : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val list = args.getChecked<SpellList>(0).toMutableList()
val index = args.getChecked<Double>(1)
val list = args.getChecked<SpellList>(0, argc).toMutableList()
val index = args.getChecked<Double>(1, argc)
val x = list.getOrElse(index.roundToInt()) { SpellDatum.make(Widget.NULL) }
return listOf(x)
}

View file

@ -1,10 +1,6 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpIndexOf : ConstManaOperator {
@ -12,8 +8,8 @@ object OpIndexOf : ConstManaOperator {
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val list = args.getChecked<SpellList>(0).toMutableList()
val list = args.getChecked<SpellList>(0, argc).toMutableList()
val value = args[1]
return spellListOf(list.indexOf(value).toDouble())
return list.indexOfFirst(value::tolerantEquals).asSpellResult
}
}

View file

@ -1,10 +1,6 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
@ -32,7 +28,7 @@ object OpLastNToList : Operator {
while (stack.size != endSize) {
stack.removeLast()
}
stack.addAll(spellListOf(output))
stack.addAll(output.asSpellResult)
return OperationResult(stack, local, listOf())
}

View file

@ -1,16 +1,12 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
// it's still called beancounter's distillation in my heart
object OpListSize : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
return spellListOf(args.getChecked<SpellList>(0).toList().size.toDouble()) // mmm one-liner
return args.getChecked<SpellList>(0, argc).toList().size.asSpellResult // mmm one-liner
}
}

View file

@ -1,19 +1,15 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import kotlin.math.roundToInt
object OpModifyInPlace : ConstManaOperator {
override val argc = 3
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val list = args.getChecked<SpellList>(0)
val index = args.getChecked<Double>(1).roundToInt()
val list = args.getChecked<SpellList>(0, argc)
val index = args.getChecked<Double>(1, argc).roundToInt()
val iota = args[2]
return spellListOf(list.modifyAt(index) { SpellList.LPair(iota, it.cdr) })
return list.modifyAt(index) { SpellList.LPair(iota, it.cdr) }.asSpellResult
}
}

View file

@ -1,10 +1,6 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpRemove : ConstManaOperator {
@ -12,11 +8,11 @@ object OpRemove : ConstManaOperator {
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val list = args.getChecked<SpellList>(0).toMutableList()
val index = args.getChecked<Double>(1).toInt()
val list = args.getChecked<SpellList>(0, argc).toMutableList()
val index = args.getChecked<Double>(1, argc).toInt()
if (index < 0 || index >= list.size)
return list
list.removeAt(index)
return spellListOf(list)
return list.asSpellResult
}
}

View file

@ -1,15 +1,11 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpReverski : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
return spellListOf(args.getChecked<SpellList>(0).toList().asReversed()) // okay kotlin kinda pogged for this
return args.getChecked<SpellList>(0, argc).toList().asReversed().asSpellResult // okay kotlin kinda pogged for this
}
}

View file

@ -1,13 +1,13 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpSingleton : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
return spellListOf(listOf(args[0])) // god i love one-liners
return listOf(args[0]).asSpellResult // god i love one-liners
}
}

View file

@ -1,10 +1,6 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.util.Mth
import kotlin.math.max
@ -14,13 +10,13 @@ import kotlin.math.roundToInt
object OpSlice : ConstManaOperator {
override val argc = 3
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val list = args.getChecked<SpellList>(0).toList()
val index1 = Mth.clamp(args.getChecked<Double>(1).roundToInt(), 0, list.size)
val index2 = Mth.clamp(args.getChecked<Double>(2).roundToInt(), 0, list.size)
val list = args.getChecked<SpellList>(0, argc).toList()
val index1 = Mth.clamp(args.getChecked<Double>(1, argc).roundToInt(), 0, list.size)
val index2 = Mth.clamp(args.getChecked<Double>(2, argc).roundToInt(), 0, list.size)
if (index1 == index2)
return spellListOf(listOf<SpellDatum<*>>())
return emptyList<SpellDatum<*>>().asSpellResult
return spellListOf(list.subList(min(index1, index2), max(index1, index2)))
return list.subList(min(index1, index2), max(index1, index2)).asSpellResult
}
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext
@ -11,5 +11,5 @@ object OpSplat : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> =
args.getChecked<SpellList>(0).toMutableList()
args.getChecked<SpellList>(0, argc).toMutableList()
}

View file

@ -1,17 +1,12 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpUnCons : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val list = args.getChecked<SpellList>(0)
val list = args.getChecked<SpellList>(0, argc)
if (list.nonEmpty) {
return spellListOf(list.cdr, list.car)
}

View file

@ -1,32 +0,0 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import com.mojang.datafixers.util.Either
import net.minecraft.network.chat.TranslatableComponent
import net.minecraft.world.phys.Vec3
object MathOpUtils {
fun GetNumOrVec(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, Vec3> =
when (datum.payload) {
is Double -> Either.left(datum.payload)
is Vec3 -> Either.right(datum.payload)
else -> throw MishapInvalidIota(
datum,
reverseIdx,
TranslatableComponent("hexcasting.mishap.invalid_value.numvec")
)
}
fun GetNumOrList(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, SpellList> =
when (datum.payload) {
is Double -> Either.left(datum.payload)
is SpellList -> Either.right(datum.payload)
else -> throw MishapInvalidIota(
datum,
reverseIdx,
TranslatableComponent("hexcasting.mishap.invalid_value.numlist")
)
}
}

View file

@ -1,8 +1,9 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.GetNumOrVec
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import kotlin.math.absoluteValue
@ -11,10 +12,8 @@ object OpAbsLen : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val x = MathOpUtils.GetNumOrVec(args[0], 0)
val x = GetNumOrVec(args[0], 0)
return spellListOf(
x.map({ num -> num.absoluteValue }, { vec -> vec.length() })
)
return x.map({ num -> num.absoluteValue }, { vec -> vec.length() }).asSpellResult
}
}

View file

@ -1,17 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.GetNumOrVec
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.spellListOf
object OpAdd : ConstManaOperator {
override val argc: Int
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val lhs = MathOpUtils.GetNumOrVec(args[0], 1)
val rhs = MathOpUtils.GetNumOrVec(args[1], 0)
val lhs = GetNumOrVec(args[0], 1)
val rhs = GetNumOrVec(args[1], 0)
return spellListOf(
lhs.map({ lnum ->

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import kotlin.math.ceil
object OpCeil : ConstManaOperator {
@ -12,7 +12,7 @@ object OpCeil : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val value = args.getChecked<Double>(0)
return spellListOf(ceil(value))
val value = args.getChecked<Double>(0, argc)
return ceil(value).asSpellResult
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import net.minecraft.core.Direction
import net.minecraft.world.phys.Vec3
@ -13,9 +13,9 @@ object OpCoerceToAxial : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val vec = args.getChecked<Vec3>(0)
val vec = args.getChecked<Vec3>(0, argc)
if (vec == Vec3.ZERO)
return spellListOf(vec)
return spellListOf(Vec3.atLowerCornerOf(Direction.getNearest(vec.x, vec.y, vec.z).normal))
return vec.asSpellResult
return Vec3.atLowerCornerOf(Direction.getNearest(vec.x, vec.y, vec.z).normal).asSpellResult
}
}

View file

@ -1,18 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import net.minecraft.world.phys.Vec3
object OpConstructVec : ConstManaOperator {
override val argc = 3
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val x = args.getChecked<Double>(0)
val y = args.getChecked<Double>(1)
val z = args.getChecked<Double>(2)
return spellListOf(Vec3(x, y, z))
val x = args.getChecked<Double>(0, argc)
val y = args.getChecked<Double>(1, argc)
val z = args.getChecked<Double>(2, argc)
return Vec3(x, y, z).asSpellResult
}
}

View file

@ -1,16 +1,16 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.spellListOf
import net.minecraft.world.phys.Vec3
object OpDeconstructVec : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val v = args.getChecked<Vec3>(0)
val v = args.getChecked<Vec3>(0, argc)
return spellListOf(v.x, v.y, v.z)
}
}

View file

@ -1,10 +1,11 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.GetNumOrVec
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import at.petrak.hexcasting.api.spell.spellListOf
import net.minecraft.world.phys.Vec3
object OpDivCross : ConstManaOperator {
@ -12,8 +13,8 @@ object OpDivCross : ConstManaOperator {
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val lhs = MathOpUtils.GetNumOrVec(args[0], 1)
val rhs = MathOpUtils.GetNumOrVec(args[1], 0)
val lhs = GetNumOrVec(args[0], 1)
val rhs = GetNumOrVec(args[1], 0)
return spellListOf(
lhs.map({ lnum ->

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import kotlin.math.floor
object OpFloor : ConstManaOperator {
@ -12,7 +12,7 @@ object OpFloor : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val value = args.getChecked<Double>(0)
return spellListOf(floor(value))
val value = args.getChecked<Double>(0, argc)
return floor(value).asSpellResult
}
}

View file

@ -1,11 +1,11 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import at.petrak.hexcasting.api.spell.spellListOf
import kotlin.math.log
object OpLog : ConstManaOperator {
@ -13,8 +13,8 @@ object OpLog : ConstManaOperator {
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val value = args.getChecked<Double>(0)
val base = args.getChecked<Double>(1)
val value = args.getChecked<Double>(0, argc)
val base = args.getChecked<Double>(1, argc)
if (value <= 0.0 || base <= 0.0 || base == 1.0)
throw MishapDivideByZero.of(value, base, "logarithm")
return spellListOf(log(value, base))

View file

@ -1,7 +1,8 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.GetNumOrVec
import at.petrak.hexcasting.api.spell.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
@ -10,8 +11,8 @@ object OpMulDot : ConstManaOperator {
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val lhs = MathOpUtils.GetNumOrVec(args[0], 1)
val rhs = MathOpUtils.GetNumOrVec(args[1], 0)
val lhs = GetNumOrVec(args[0], 1)
val rhs = GetNumOrVec(args[1], 0)
return spellListOf(
lhs.map({ lnum ->

View file

@ -1,10 +1,11 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.GetNumOrVec
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import at.petrak.hexcasting.api.spell.spellListOf
import net.minecraft.world.phys.Vec3
import kotlin.math.pow
@ -13,8 +14,8 @@ object OpPowProj : ConstManaOperator {
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val lhs = MathOpUtils.GetNumOrVec(args[0], 1)
val rhs = MathOpUtils.GetNumOrVec(args[1], 0)
val lhs = GetNumOrVec(args[0], 1)
val rhs = GetNumOrVec(args[1], 0)
return spellListOf(
lhs.map({ lnum ->

View file

@ -1,8 +1,8 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpRandom : ConstManaOperator {
@ -10,6 +10,6 @@ object OpRandom : ConstManaOperator {
get() = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
return spellListOf(ctx.world.random.nextDouble())
return ctx.world.random.nextDouble().asSpellResult
}
}

View file

@ -1,9 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.GetNumOrVec
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.spellListOf
import net.minecraft.world.phys.Vec3
object OpSub : ConstManaOperator {
@ -11,8 +12,8 @@ object OpSub : ConstManaOperator {
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val lhs = MathOpUtils.GetNumOrVec(args[0], 1)
val rhs = MathOpUtils.GetNumOrVec(args[1], 0)
val lhs = GetNumOrVec(args[0], 1)
val rhs = GetNumOrVec(args[1], 0)
return spellListOf(
lhs.map({ lnum ->

View file

@ -1,28 +1,23 @@
package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.common.casting.operators.math.MathOpUtils
import kotlin.math.roundToInt
object OpAnd : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val firstParam = MathOpUtils.GetNumOrList(args[0], 0)
val firstParam = GetNumOrList(args[0], 0)
if (firstParam.right().isPresent) {
val list1 = firstParam.right().get()
val list2 = args.getChecked<SpellList>(1)
return spellListOf(list1.filter { x -> list2.any { x.equalsWithDoubleTolerance(it) } })
val list2 = args.getChecked<SpellList>(1, argc)
return list1.filter { x -> list2.any(x::tolerantEquals) }.asSpellResult
}
val num1 = firstParam.left().get().roundToInt()
val num2 = args.getChecked<Double>(1).roundToInt()
return spellListOf((num1 and num2).toDouble())
val num2 = args.getChecked<Double>(1, argc).roundToInt()
return (num1 and num2).asSpellResult
}
}

View file

@ -1,17 +1,17 @@
package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import kotlin.math.roundToInt
object OpNot : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val num = args.getChecked<Double>(0).roundToInt()
return spellListOf((num.inv()).toDouble())
val num = args.getChecked<Double>(0, argc).roundToInt()
return num.inv().asSpellResult
}
}

View file

@ -1,28 +1,24 @@
package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.common.casting.operators.math.MathOpUtils
import kotlin.math.roundToInt
object OpOr : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val firstParam = MathOpUtils.GetNumOrList(args[0], 0)
val firstParam = GetNumOrList(args[0], 0)
if (firstParam.right().isPresent) {
val list1 = firstParam.right().get()
val list2 = args.getChecked<SpellList>(1)
return spellListOf(list1 + list2.filter { x -> list1.none { x.equalsWithDoubleTolerance(it) } })
val list2 = args.getChecked<SpellList>(1, argc)
val out = list1 + list2.filter { x -> list1.none(x::tolerantEquals) }
return out.asSpellResult
}
val num1 = firstParam.left().get().roundToInt()
val num2 = args.getChecked<Double>(1).roundToInt()
return spellListOf((num1 or num2).toDouble())
val num2 = args.getChecked<Double>(1, argc).roundToInt()
return (num1 or num2).asSpellResult
}
}

View file

@ -1,24 +1,12 @@
package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpToSet : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val payload = args.getChecked<SpellList>(0)
// augh
val out = mutableListOf<SpellDatum<*>>()
// i am not sure of a better way to do this
for (v in payload) {
if (out.none { it.equalsWithDoubleTolerance(v) }) {
out.add(v)
}
}
return out
return args.getChecked<SpellList>(0, argc).toSet().toList().asSpellResult
}
}

View file

@ -1,30 +1,24 @@
package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.common.casting.operators.math.MathOpUtils
import kotlin.math.roundToInt
object OpXor : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val firstParam = MathOpUtils.GetNumOrList(args[0], 0)
val firstParam = GetNumOrList(args[0], 0)
if (firstParam.right().isPresent) {
val list1 = firstParam.right().get()
val list2 = args.getChecked<SpellList>(1)
return spellListOf(
list1.filter { x1 -> list2.none { x1.equalsWithDoubleTolerance(it) } }
+ list2.filter { x2 -> list1.none { x2.equalsWithDoubleTolerance(it) } })
val list2 = args.getChecked<SpellList>(1, argc)
val out = list1.filter { x1 -> list2.none(x1::tolerantEquals) } + list2.filter { x2 -> list1.none(x2::tolerantEquals) }
return out.asSpellResult
}
val num1 = firstParam.left().get().roundToInt()
val num2 = args.getChecked<Double>(1).roundToInt()
return spellListOf((num1 xor num2).toDouble())
val num2 = args.getChecked<Double>(1, argc).roundToInt()
return (num1 xor num2).asSpellResult
}
}

View file

@ -1,24 +1,23 @@
package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.Widget
import net.minecraft.world.phys.Vec3
object OpBoolIdentityKindOf : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
return spellListOf(
when (val payload = args[0].payload) {
Widget.NULL -> 0.0
0.0, Vec3.ZERO -> Widget.NULL
is SpellList -> if (payload.nonEmpty) payload else Widget.NULL
else -> payload
}
)
val payload = args[0].payload
if (payload == Widget.NULL)
return 0.asSpellResult
if (payload.tolerantEquals(0.0) || payload.tolerantEquals(1.0))
return null.asSpellResult
if (payload is SpellList)
return if (payload.nonEmpty) payload.asSpellResult else null.asSpellResult
return spellListOf(payload)
}
}

View file

@ -1,11 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.Widget
import net.minecraft.world.phys.Vec3
object OpBoolNot : ConstManaOperator {
@ -13,7 +9,7 @@ object OpBoolNot : ConstManaOperator {
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val payload = args[0].payload
val falsy = payload == Widget.NULL || payload == 0.0 || payload == Vec3.ZERO || (payload is SpellList && !payload.nonEmpty)
return spellListOf(if (falsy) 1.0 else 0.0)
val falsy = payload == Widget.NULL || payload.tolerantEquals(0.0) || payload.tolerantEquals(Vec3.ZERO) || (payload is SpellList && !payload.nonEmpty)
return falsy.asSpellResult
}
}

View file

@ -1,20 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import java.util.function.BiPredicate
class OpCompare(val cmp: BiPredicate<Double, Double>) : ConstManaOperator {
class OpCompare(val acceptsEqual: Boolean, val cmp: BiPredicate<Double, Double>) : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val lhs = args.getChecked<Double>(0)
val rhs = args.getChecked<Double>(1)
return spellListOf(
if (cmp.test(lhs, rhs)) 1.0 else 0.0
)
val lhs = args.getChecked<Double>(0, argc)
val rhs = args.getChecked<Double>(1, argc)
if (lhs.tolerantEquals(rhs))
return acceptsEqual.asSpellResult
return cmp.test(lhs, rhs).asSpellResult
}
}

View file

@ -1,12 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.phys.Vec3
import kotlin.math.abs
import at.petrak.hexcasting.api.spell.tolerantEquals
class OpEquality(val invert: Boolean) : ConstManaOperator {
override val argc = 2
@ -15,24 +13,6 @@ class OpEquality(val invert: Boolean) : ConstManaOperator {
val lhs = args[0]
val rhs = args[1]
return spellListOf(if (checkEquals(lhs.payload, rhs.payload) != invert) 1.0 else 0.0)
}
private fun checkEquals(a: Any, b: Any, recursionsLeft: Int = 64): Boolean {
return when {
a is Double && b is Double -> abs(a - b) < 0.0001
a is Vec3 && b is Vec3 -> a.subtract(b).lengthSqr() < 0.0000001
a is SpellList && b is SpellList -> {
val castA = a.toList()
val castB = b.toList()
if (castA.size != castB.size || recursionsLeft == 0)
return false
for (i in castA.indices)
if (!checkEquals(castA[i].payload, castB[i].payload, recursionsLeft - 1))
return false
true
}
else -> a == b
}
return (lhs.tolerantEquals(rhs) != invert).asSpellResult
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import net.minecraft.network.chat.TranslatableComponent
import kotlin.math.acos
@ -14,13 +14,13 @@ object OpArcCos : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val value = args.getChecked<Double>(0)
val value = args.getChecked<Double>(0, argc)
if (value < -1 || value > 1)
throw MishapInvalidIota(
SpellDatum.make(value),
0,
TranslatableComponent("hexcasting.mishap.invalid_value.double.between", -1, 1)
)
return spellListOf(acos(value))
return acos(value).asSpellResult
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import net.minecraft.network.chat.TranslatableComponent
import kotlin.math.asin
@ -14,13 +14,13 @@ object OpArcSin : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val value = args.getChecked<Double>(0)
val value = args.getChecked<Double>(0, argc)
if (value < -1 || value > 1)
throw MishapInvalidIota(
SpellDatum.make(value),
0,
TranslatableComponent("hexcasting.mishap.invalid_value.double.between", -1, 1)
)
return spellListOf(asin(value))
return asin(value).asSpellResult
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import kotlin.math.atan
object OpArcTan : ConstManaOperator {
@ -12,7 +12,7 @@ object OpArcTan : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val value = args.getChecked<Double>(0)
return spellListOf(atan(value))
val value = args.getChecked<Double>(0, argc)
return atan(value).asSpellResult
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import kotlin.math.cos
object OpCos : ConstManaOperator {
@ -12,7 +12,7 @@ object OpCos : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val angle = args.getChecked<Double>(0)
return spellListOf(cos(angle))
val angle = args.getChecked<Double>(0, argc)
return cos(angle).asSpellResult
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import kotlin.math.sin
object OpSin : ConstManaOperator {
@ -12,7 +12,7 @@ object OpSin : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val angle = args.getChecked<Double>(0)
return spellListOf(sin(angle))
val angle = args.getChecked<Double>(0, argc)
return sin(angle).asSpellResult
}
}

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import kotlin.math.cos
import kotlin.math.tan
@ -14,9 +14,9 @@ object OpTan : ConstManaOperator {
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val angle = args.getChecked<Double>(0)
val angle = args.getChecked<Double>(0, argc)
if (cos(angle) == 0.0)
throw MishapDivideByZero.tan(angle)
return spellListOf(tan(angle))
return tan(angle).asSpellResult
}
}

View file

@ -1,8 +1,8 @@
package at.petrak.hexcasting.common.casting.operators.selectors
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpGetCaster : ConstManaOperator {
@ -10,6 +10,6 @@ object OpGetCaster : ConstManaOperator {
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
ctx.assertEntityInRange(ctx.caster)
return Operator.spellListOf(ctx.caster)
return ctx.caster.asSpellResult
}
}

View file

@ -2,10 +2,10 @@ package at.petrak.hexcasting.common.casting.operators.selectors
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.MAX_DISTANCE
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.spellListOf
import net.minecraft.util.Mth
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.LivingEntity
@ -22,8 +22,8 @@ import java.util.function.Predicate
class OpGetEntitiesBy(val checker: Predicate<Entity>, val negate: Boolean) : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val pos = args.getChecked<Vec3>(0)
val maybeRadius = args.getChecked<Double>(1)
val pos = args.getChecked<Vec3>(0, argc)
val maybeRadius = args.getChecked<Double>(1, argc)
ctx.assertVecInRange(pos)
val radius = Mth.clamp(maybeRadius, 0.0, MAX_DISTANCE)

View file

@ -1,11 +1,10 @@
package at.petrak.hexcasting.common.casting.operators.selectors
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.Vec3
@ -14,13 +13,13 @@ import java.util.function.Predicate
class OpGetEntityAt(val checker: Predicate<Entity>) : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val pos = args.getChecked<Vec3>(0)
val pos = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(pos)
val aabb = AABB(pos.add(Vec3(-0.5, -0.5, -0.5)), pos.add(Vec3(0.5, 0.5, 0.5)))
val entitiesGot = ctx.world.getEntities(null, aabb)
{ checker.test(it) && ctx.isEntityInRange(it) && it.isAlive && !it.isSpectator }
val entity = entitiesGot.getOrNull(0) ?: Widget.NULL
return spellListOf(entity)
val entity = entitiesGot.getOrNull(0)
return entity.asSpellResult
}
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -18,8 +18,8 @@ object OpAddMotion : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Entity>(0)
val motion = args.getChecked<Vec3>(1)
val target = args.getChecked<Entity>(0, argc)
val motion = args.getChecked<Vec3>(1, argc)
ctx.assertEntityInRange(target)
var motionForCost = motion.lengthSqr()
if (ctx.hasBeenGivenMotion(target))

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -19,9 +19,9 @@ object OpBeep : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val instrument = args.getChecked<Double>(1).toInt().coerceIn(0, NoteBlockInstrument.values().size - 1)
val note = args.getChecked<Double>(2).toInt().coerceIn(0, 24)
val target = args.getChecked<Vec3>(0, argc)
val instrument = args.getChecked<Double>(1, argc).toInt().coerceIn(0, NoteBlockInstrument.values().size - 1)
val note = args.getChecked<Double>(2, argc).toInt().coerceIn(0, 24)
ctx.assertVecInRange(target)
return Triple(

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -22,8 +22,8 @@ object OpBlink : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Entity>(0)
val delta = args.getChecked<Double>(1)
val target = args.getChecked<Entity>(0, argc)
val delta = args.getChecked<Double>(1, argc)
ctx.assertEntityInRange(target)
if (!target.canChangeDimensions())

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.mod.HexConfig
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -20,7 +20,7 @@ object OpBreakBlock : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pos = args.getChecked<Vec3>(0)
val pos = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(pos)
val centered = Vec3.atCenterOf(BlockPos(pos))

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -22,7 +22,7 @@ class OpConjure(val light: Boolean) : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -25,7 +25,7 @@ object OpCreateWater : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(

View file

@ -2,7 +2,6 @@ package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
@ -24,7 +23,7 @@ object OpDestroyWater : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(
@ -53,7 +52,7 @@ object OpDestroyWater : SpellOperator {
while (todo.isNotEmpty() && successes <= MAX_DESTROY_COUNT) {
val here = todo.removeFirst()
val distFromFocus =
ctx.caster.position().distanceToSqr(Vec3(here.x.toDouble(), here.y.toDouble(), here.z.toDouble()))
ctx.caster.position().distanceToSqr(Vec3.atCenterOf(here))
if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here) && ctx.world.mayInteract(ctx.caster, here)) {
// never seen this pos in my life
val fluid = ctx.world.getFluidState(here)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -20,7 +20,7 @@ object OpEdifySapling : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pos = args.getChecked<Vec3>(0)
val pos = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(pos)
val bpos = BlockPos(pos)

View file

@ -1,11 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.core.BlockPos
import net.minecraft.util.Mth
@ -20,8 +16,8 @@ class OpExplode(val fire: Boolean) : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pos = args.getChecked<Vec3>(0)
val strength = args.getChecked<Double>(1)
val pos = args.getChecked<Vec3>(0, argc)
val strength = args.getChecked<Double>(1, argc)
ctx.assertVecInRange(pos)
return Triple(
Spell(pos, strength, this.fire),

View file

@ -2,7 +2,6 @@ package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.mixin.accessor.AccessorUseOnContext
import net.minecraft.core.BlockPos
@ -23,7 +22,7 @@ object OpExtinguish : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(
@ -47,15 +46,9 @@ object OpExtinguish : SpellOperator {
while (todo.isNotEmpty() && successes <= MAX_DESTROY_COUNT) {
val here = todo.removeFirst()
val distFromFocus =
ctx.caster.position().distanceToSqr(Vec3(here.x.toDouble(), here.y.toDouble(), here.z.toDouble()))
ctx.caster.position().distanceToSqr(Vec3.atCenterOf(here))
val distFromTarget =
target.distanceTo(
Vec3(
here.x.toDouble(),
here.y.toDouble(),
here.z.toDouble()
)
) // max distance to prevent runaway shenanigans
target.distanceTo(Vec3.atCenterOf(here)) // max distance to prevent runaway shenanigans
if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here) && distFromTarget < 10 && ctx.world.mayInteract(
ctx.caster,
here
@ -71,13 +64,13 @@ object OpExtinguish : SpellOperator {
is CampfireBlock -> {
if (blockstate.getValue(CampfireBlock.LIT)) { // check if campfire is lit before putting it out
val wilson = Items.WOODEN_SHOVEL // summon shovel from the ether to do our bidding
val hereVec = (Vec3(here.x.toDouble(), here.y.toDouble(), here.z.toDouble()))
val hereVec = Vec3.atCenterOf(here)
wilson.useOn(
AccessorUseOnContext.`hex$new`(
ctx.world,
null,
InteractionHand.MAIN_HAND,
ItemStack(wilson.asItem()),
ItemStack(wilson),
BlockHitResult(hereVec, Direction.UP, here, false)
)
); true

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -25,7 +25,7 @@ object OpIgnite : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.mod.HexItemTags
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -25,7 +25,7 @@ object OpMakeBattery : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val entity = args.getChecked<ItemEntity>(0)
val entity = args.getChecked<ItemEntity>(0, argc)
val (handStack, hand) = ctx.getHeldItemToOperateOn { it.`is`(HexItemTags.PHIAL_BASE) }

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -21,8 +21,8 @@ class OpMakePackagedSpell<T : ItemPackagedHex>(val itemType: T, val cost: Int) :
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val entity = args.getChecked<ItemEntity>(0)
val patterns = args.getChecked<SpellList>(1).toList()
val entity = args.getChecked<ItemEntity>(0, argc)
val patterns = args.getChecked<SpellList>(1, argc).toList()
val (handStack, hand) = ctx.getHeldItemToOperateOn {
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(it)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -25,7 +25,7 @@ object OpPlaceBlock : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pos = args.getChecked<Vec3>(0)
val pos = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(pos)
return Triple(
Spell(pos),

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -27,13 +27,13 @@ class OpPotionEffect(
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<LivingEntity>(0)
val target = args.getChecked<LivingEntity>(0, argc)
if (target is ArmorStand)
throw MishapInvalidIota.ofClass(SpellDatum.make(target), 0, LivingEntity::class.java)
val duration = max(args.getChecked(1), 0.0)
val duration = max(args.getChecked(1, argc), 0.0)
ctx.assertEntityInRange(target)
val potency = if (this.allowPotency)
max(args.getChecked(2), 1.0)
max(args.getChecked(2, argc), 1.0)
else 1.0
val cost = this.baseCost * duration * if (potencyCubic) {

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -34,7 +34,7 @@ object OpRecharge : SpellOperator {
"rechargable"
)
val entity = args.getChecked<ItemEntity>(0)
val entity = args.getChecked<ItemEntity>(0, argc)
ctx.assertEntityInRange(entity)
if (!ManaHelper.isManaItem(entity.item)) {

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -23,7 +23,7 @@ object OpTheOnlyReasonAnyoneDownloadedPsi : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells.great
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -28,8 +28,8 @@ object OpBrainsweep : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val sacrifice = args.getChecked<Villager>(0)
val pos = args.getChecked<Vec3>(1)
val sacrifice = args.getChecked<Villager>(0, argc)
val pos = args.getChecked<Vec3>(1, argc)
ctx.assertVecInRange(pos)
ctx.assertEntityInRange(sacrifice)

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.spells.great
import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -25,7 +25,7 @@ object OpCreateLava : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.spells.great
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.player.FlightAbility
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -22,9 +22,9 @@ object OpFlight : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<ServerPlayer>(0)
val timeRaw = max(args.getChecked(1), 0.0)
val radiusRaw = max(args.getChecked(2), 0.0)
val target = args.getChecked<ServerPlayer>(0, argc)
val timeRaw = max(args.getChecked(1, argc), 0.0)
val radiusRaw = max(args.getChecked(2, argc), 0.0)
ctx.assertEntityInRange(target)
// Convert to ticks

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells.great
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -20,7 +20,7 @@ object OpLightning : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(
Spell(target),

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.spells.great
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -21,8 +21,8 @@ object OpTeleport : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val teleportee = args.getChecked<Entity>(0)
val delta = args.getChecked<Vec3>(1)
val teleportee = args.getChecked<Entity>(0, argc)
val delta = args.getChecked<Vec3>(1, argc)
ctx.assertEntityInRange(teleportee)
if (!teleportee.canChangeDimensions())

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.common.casting.operators.spells.sentinel
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.player.Sentinel
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
@ -20,7 +20,7 @@ class OpCreateSentinel(val extendsRange: Boolean) : SpellOperator {
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val target = args.getChecked<Vec3>(0)
val target = args.getChecked<Vec3>(0, argc)
ctx.assertVecInRange(target)
return Triple(

View file

@ -2,9 +2,8 @@ package at.petrak.hexcasting.common.casting.operators.spells.sentinel
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationInWrongDimension
import at.petrak.hexcasting.xplat.IXplatAbstractions
@ -16,11 +15,9 @@ object OpGetSentinelPos : ConstManaOperator {
val sentinel = IXplatAbstractions.INSTANCE.getSentinel(ctx.caster)
if (sentinel.dimension != ctx.world.dimension())
throw MishapLocationInWrongDimension(sentinel.dimension.location())
return spellListOf(
if (sentinel.hasSentinel)
sentinel.position
else
Widget.NULL
)
return if (sentinel.hasSentinel)
sentinel.position.asSpellResult
else
null.asSpellResult
}
}

View file

@ -2,11 +2,10 @@ package at.petrak.hexcasting.common.casting.operators.spells.sentinel
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationInWrongDimension
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.phys.Vec3
@ -15,18 +14,16 @@ object OpGetSentinelWayfind : ConstManaOperator {
override val argc = 1
override val manaCost = ManaConstants.DUST_UNIT / 10
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val from = args.getChecked<Vec3>(0)
val from = args.getChecked<Vec3>(0, argc)
val sentinel = IXplatAbstractions.INSTANCE.getSentinel(ctx.caster)
if (sentinel.dimension != ctx.world.dimension())
throw MishapLocationInWrongDimension(sentinel.dimension.location())
val sentinelPos = if (!sentinel.hasSentinel)
return spellListOf(Widget.NULL)
return if (!sentinel.hasSentinel)
null.asSpellResult
else
sentinel.position
return spellListOf(sentinelPos.subtract(from).normalize())
sentinel.position.subtract(from).normalize().asSpellResult
}
}

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.common.casting.operators.stack
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.OperatorSideEffect

View file

@ -1,17 +1,17 @@
package at.petrak.hexcasting.common.casting.operators.stack
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.spellListOf
object OpDuplicate : ConstManaOperator {
override val argc: Int
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val datum = args.getChecked<Any>(0)
val datum = args.getChecked<Any>(0, argc)
return spellListOf(datum, datum)
}
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.stack
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
@ -14,7 +14,7 @@ object OpDuplicateN : ConstManaOperator {
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val countDouble = args.getChecked<Double>(1)
val countDouble = args.getChecked<Double>(1, argc)
if (abs(countDouble.roundToInt() - countDouble) >= 0.05f)
throw MishapInvalidIota(

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.stack
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota

Some files were not shown because too many files have changed in this diff Show more