who am i, wire? converted all non-spell actions to the new iotas

This commit is contained in:
gamma-delta 2022-06-14 01:02:20 -05:00
parent 71c3cade9b
commit 2917a3b358
133 changed files with 953 additions and 852 deletions

View file

@ -4,6 +4,6 @@ The "flavor text" words for things in this mod and the internal names are differ
- A "Hex" is a `Cast`, cast through a [`CastingHarness`](api/spell/casting/CastingHarness.kt) - A "Hex" is a `Cast`, cast through a [`CastingHarness`](api/spell/casting/CastingHarness.kt)
- A "Pattern" is a [`HexPattern`](api/spell/math/HexPattern.kt) - A "Pattern" is a [`HexPattern`](api/spell/math/HexPattern.kt)
- An "Action" is an [`Operator`](api/spell/Operator.kt) - An "Action" is an [`Operator`](api/spell/Action.kt)
- An action that pushes a spell is a [`Spell`](api/spell/SpellOperator.kt) - An action that pushes a spell is a [`Spell`](api/spell/SpellAction.kt)

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api package at.petrak.hexcasting.api
import at.petrak.hexcasting.api.spell.Operator import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.math.EulerPathFinder import at.petrak.hexcasting.api.spell.math.EulerPathFinder
import at.petrak.hexcasting.api.spell.math.HexDir import at.petrak.hexcasting.api.spell.math.HexDir
import at.petrak.hexcasting.api.spell.math.HexPattern import at.petrak.hexcasting.api.spell.math.HexPattern
@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentMap
* operator (the diamond) are `"qaq"` and `"ede"`. * operator (the diamond) are `"qaq"` and `"ede"`.
*/ */
object PatternRegistry { object PatternRegistry {
private val operatorLookup = ConcurrentHashMap<ResourceLocation, Operator>() private val actionLookup = ConcurrentHashMap<ResourceLocation, Action>()
private val specialHandlers: ConcurrentLinkedDeque<SpecialHandlerEntry> = ConcurrentLinkedDeque() private val specialHandlers: ConcurrentLinkedDeque<SpecialHandlerEntry> = ConcurrentLinkedDeque()
// Map signatures to the "preferred" direction they start in and their operator ID. // Map signatures to the "preferred" direction they start in and their operator ID.
@ -41,12 +41,12 @@ object PatternRegistry {
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
@Throws(RegisterPatternException::class) @Throws(RegisterPatternException::class)
fun mapPattern(pattern: HexPattern, id: ResourceLocation, operator: Operator, isPerWorld: Boolean = false) { fun mapPattern(pattern: HexPattern, id: ResourceLocation, action: Action, isPerWorld: Boolean = false) {
this.operatorLookup[id]?.let { this.actionLookup[id]?.let {
throw RegisterPatternException("The operator with id `$id` was already registered to: $it") throw RegisterPatternException("The operator with id `$id` was already registered to: $it")
} }
this.operatorLookup[id] = operator this.actionLookup[id] = action
if (isPerWorld) { if (isPerWorld) {
this.perWorldPatternLookup[id] = PerWorldEntry(pattern, id) this.perWorldPatternLookup[id] = PerWorldEntry(pattern, id)
} else { } else {
@ -73,14 +73,14 @@ object PatternRegistry {
* Internal use only. * Internal use only.
*/ */
@JvmStatic @JvmStatic
fun matchPattern(pat: HexPattern, overworld: ServerLevel): Operator = fun matchPattern(pat: HexPattern, overworld: ServerLevel): Action =
matchPatternAndID(pat, overworld).first matchPatternAndID(pat, overworld).first
/** /**
* Internal use only. * Internal use only.
*/ */
@JvmStatic @JvmStatic
fun matchPatternAndID(pat: HexPattern, overworld: ServerLevel): Pair<Operator, ResourceLocation> { fun matchPatternAndID(pat: HexPattern, overworld: ServerLevel): Pair<Action, ResourceLocation> {
// Pipeline: // Pipeline:
// patterns are registered here every time the game boots // patterns are registered here every time the game boots
// when we try to look // when we try to look
@ -92,7 +92,7 @@ object PatternRegistry {
// Is it global? // Is it global?
val sig = pat.anglesSignature() val sig = pat.anglesSignature()
this.regularPatternLookup[sig]?.let { this.regularPatternLookup[sig]?.let {
val op = this.operatorLookup[it.opId] ?: throw MishapInvalidPattern() val op = this.actionLookup[it.opId] ?: throw MishapInvalidPattern()
return op to it.opId return op to it.opId
} }
@ -101,7 +101,7 @@ object PatternRegistry {
val perWorldPatterns: Save = val perWorldPatterns: Save =
ds.computeIfAbsent(Save.Companion::load, { Save.create(overworld.seed) }, TAG_SAVED_DATA) ds.computeIfAbsent(Save.Companion::load, { Save.create(overworld.seed) }, TAG_SAVED_DATA)
perWorldPatterns.lookup[sig]?.let { perWorldPatterns.lookup[sig]?.let {
val op = this.operatorLookup[it.first]!! val op = this.actionLookup[it.first]!!
return op to it.first return op to it.first
} }
@ -125,12 +125,12 @@ object PatternRegistry {
@JvmStatic @JvmStatic
fun lookupPattern(opId: ResourceLocation): PatternEntry { fun lookupPattern(opId: ResourceLocation): PatternEntry {
this.perWorldPatternLookup[opId]?.let { this.perWorldPatternLookup[opId]?.let {
return PatternEntry(it.prototype, this.operatorLookup[it.opId]!!, true) return PatternEntry(it.prototype, this.actionLookup[it.opId]!!, true)
} }
for ((sig, entry) in this.regularPatternLookup) { for ((sig, entry) in this.regularPatternLookup) {
if (entry.opId == opId) { if (entry.opId == opId) {
val pattern = HexPattern.fromAngles(sig, entry.preferredStart) val pattern = HexPattern.fromAngles(sig, entry.preferredStart)
return PatternEntry(pattern, this.operatorLookup[entry.opId]!!, false) return PatternEntry(pattern, this.actionLookup[entry.opId]!!, false)
} }
} }
@ -153,7 +153,7 @@ object PatternRegistry {
* In the base mod, this is used for number patterns. * In the base mod, this is used for number patterns.
*/ */
fun interface SpecialHandler { fun interface SpecialHandler {
fun handlePattern(pattern: HexPattern): Operator? fun handlePattern(pattern: HexPattern): Action?
} }
data class SpecialHandlerEntry(val id: ResourceLocation, val handler: SpecialHandler) data class SpecialHandlerEntry(val id: ResourceLocation, val handler: SpecialHandler)
@ -164,7 +164,7 @@ object PatternRegistry {
private data class PerWorldEntry(val prototype: HexPattern, val opId: ResourceLocation) private data class PerWorldEntry(val prototype: HexPattern, val opId: ResourceLocation)
// Fake class we pretend to use internally // Fake class we pretend to use internally
data class PatternEntry(val prototype: HexPattern, val operator: Operator, val isPerWorld: Boolean) data class PatternEntry(val prototype: HexPattern, val action: Action, val isPerWorld: Boolean)
/** /**
* Maps angle sigs to resource locations and their preferred start dir so we can look them up in the main registry * Maps angle sigs to resource locations and their preferred start dir so we can look them up in the main registry

View file

@ -8,11 +8,11 @@ import net.minecraft.world.phys.Vec3
/** /**
* Manipulates the stack in some way, usually by popping some number of values off the stack * Manipulates the stack in some way, usually by popping some number of values off the stack
* and pushing one new value. * and pushing one new value.
* For a more "traditional" pop arguments, push return experience, see [ConstManaOperator]. * For a more "traditional" pop arguments, push return experience, see [ConstManaAction].
* *
* Implementors MUST NOT mutate the context. * Implementors MUST NOT mutate the context.
*/ */
interface Operator { interface Action {
/** /**
* Operate on the stack. Return the new stack and any side effects of the cast. * Operate on the stack. Return the new stack and any side effects of the cast.
* *
@ -39,12 +39,12 @@ interface Operator {
* *
* The pattern itself may modify its effects based on whether the user is enlightened or not, regardless of what this value is. * The pattern itself may modify its effects based on whether the user is enlightened or not, regardless of what this value is.
*/ */
val alwaysProcessGreatSpell: Boolean get() = this is SpellOperator val alwaysProcessGreatSpell: Boolean get() = this is SpellAction
/** /**
* Can this Great Pattern give you Blind Diversion? * Can this Great Pattern give you Blind Diversion?
*/ */
val causesBlindDiversion: Boolean get() = this is SpellOperator val causesBlindDiversion: Boolean get() = this is SpellAction
companion object { companion object {
// I see why vzakii did this: you can't raycast out to infinity! // I see why vzakii did this: you can't raycast out to infinity!
@ -56,7 +56,7 @@ interface Operator {
origin.add(look.normalize().scale(MAX_DISTANCE)) origin.add(look.normalize().scale(MAX_DISTANCE))
@JvmStatic @JvmStatic
fun makeConstantOp(x: Iota): Operator = object : ConstManaOperator { fun makeConstantOp(x: Iota): Action = object : ConstManaAction {
override val argc: Int override val argc: Int
get() = 0 get() = 0

View file

@ -9,7 +9,7 @@ import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
/** /**
* A SimpleOperator that always costs the same amount of mana. * A SimpleOperator that always costs the same amount of mana.
*/ */
interface ConstManaOperator : Operator { interface ConstManaAction : Action {
val argc: Int val argc: Int
val manaCost: Int val manaCost: Int
get() = 0 get() = 0
@ -25,7 +25,7 @@ interface ConstManaOperator : Operator {
if (this.argc > stack.size) if (this.argc > stack.size)
throw MishapNotEnoughArgs(this.argc, stack.size) throw MishapNotEnoughArgs(this.argc, stack.size)
val args = stack.takeLast(this.argc) val args = stack.takeLast(this.argc)
for (_i in 0 until this.argc) stack.removeLast() repeat(this.argc) { stack.removeLast() }
val newData = this.execute(args, ctx) val newData = this.execute(args, ctx)
stack.addAll(newData) stack.addAll(newData)

View file

@ -6,7 +6,6 @@ import at.petrak.hexcasting.api.spell.iota.*
import at.petrak.hexcasting.api.spell.math.HexPattern import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import com.mojang.datafixers.util.Either import com.mojang.datafixers.util.Either
import com.mojang.math.Vector3f import com.mojang.math.Vector3f
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
@ -16,37 +15,17 @@ import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.entity.npc.Villager import net.minecraft.world.entity.npc.Villager
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
import java.util.function.DoubleUnaryOperator
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.roundToInt import kotlin.math.roundToInt
import kotlin.math.roundToLong import kotlin.math.roundToLong
fun numOrVec(datum: Iota, reverseIdx: Int): Either<Double, Vec3> =
when (datum) {
is DoubleIota -> Either.left(datum.double)
is Vec3Iota -> Either.right(datum.vec3)
else -> throw MishapInvalidIota(
datum,
reverseIdx,
"hexcasting.mishap.invalid_value.numvec".asTranslatedComponent
)
}
fun numOrList(datum: Iota, reverseIdx: Int): Either<Double, SpellList> =
when (datum) {
is DoubleIota -> Either.left(datum.double)
is ListIota -> Either.right(datum.list)
else -> throw MishapInvalidIota(
datum,
reverseIdx,
"hexcasting.mishap.invalid_value.numlist".asTranslatedComponent
)
}
fun List<Iota>.getDouble(idx: Int, argc: Int = 0): Double { fun List<Iota>.getDouble(idx: Int, argc: Int = 0): Double {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) } val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is DoubleIota) { if (x is DoubleIota) {
return x.double return x.double
} else { } else {
// TODO: I'm not sure this calculation is correct
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "double") throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "double")
} }
} }
@ -129,7 +108,7 @@ fun List<Iota>.getLivingEntity(idx: Int, argc: Int = 0): LivingEntity {
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "entity.living") throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "entity.living")
} }
fun List<Iota>.getPositiveDoubleB(idx: Int, argc: Int = 0): Double { fun List<Iota>.getPositiveDouble(idx: Int, argc: Int = 0): Double {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) } val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is DoubleIota) { if (x is DoubleIota) {
val double = x.double val double = x.double
@ -172,7 +151,7 @@ fun List<Iota>.getLong(idx: Int, argc: Int = 0): Long {
return rounded return rounded
} }
} }
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "int") // shh we're lying throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int") // shh we're lying
} }
fun List<Iota>.getPositiveInt(idx: Int, argc: Int = 0): Int { fun List<Iota>.getPositiveInt(idx: Int, argc: Int = 0): Int {
@ -180,11 +159,23 @@ fun List<Iota>.getPositiveInt(idx: Int, argc: Int = 0): Int {
if (x is DoubleIota) { if (x is DoubleIota) {
val double = x.double val double = x.double
val rounded = double.roundToInt() val rounded = double.roundToInt()
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded > 0) { if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded >= 0) {
return rounded return rounded
} }
} }
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "int.positive") throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive")
}
fun List<Iota>.getPositiveIntUnder(idx: Int, max: Int, argc: Int = 0): Int {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is DoubleIota) {
val double = x.double
val rounded = double.roundToInt()
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded in 0 until max) {
return rounded
}
}
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive.lessthan", max)
} }
fun List<Iota>.getIntBetween(idx: Int, min: Int, max: Int, argc: Int = 0): Int { fun List<Iota>.getIntBetween(idx: Int, min: Int, max: Int, argc: Int = 0): Int {
@ -199,44 +190,65 @@ fun List<Iota>.getIntBetween(idx: Int, min: Int, max: Int, argc: Int = 0): Int {
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "double.between", min, max) throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "double.between", min, max)
} }
inline val Boolean.asSpellResult get() = listOf(DoubleIota(if (this) 1.0 else 0.0)) fun List<Iota>.getBlockPos(idx: Int, argc: Int = 0): BlockPos {
inline val Double.asSpellResult get() = listOf(DoubleIota(this)) val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
inline val Number.asSpellResult get() = listOf(DoubleIota(this.toDouble())) if (x is Vec3Iota) {
return BlockPos(x.vec3)
inline val SpellList.asSpellResult get() = listOf(ListIota(this))
inline val List<Iota>.asSpellResult get() = listOf(ListIota(this))
inline val BlockPos.asSpellResult get() = listOf(Vec3Iota(Vec3.atCenterOf(this)))
inline val Vector3f.asSpellResult get() = listOf(Vec3Iota(Vec3(this)))
inline val Vec3.asSpellResult get() = listOf(Vec3Iota(this))
inline val Entity?.asSpellResult get() = listOf(if (this == null) NullIota.INSTANCE else EntityIota(this))
inline val HexPattern.asSpellResult get() = listOf(PatternIota(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 Iota && other is Iota -> this.payload.tolerantEquals(other.payload, recursionsLeft)
this is Iota -> this.payload.tolerantEquals(other, recursionsLeft)
other is Iota -> 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
} }
this is Entity && other is Entity -> this.uuid == other.uuid
else -> this == other throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "vector")
}
fun List<Iota>.getNumOrVec(idx: Int, argc: Int = 0): Either<Double, Vec3> {
val datum = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
return when (datum) {
is DoubleIota -> Either.left(datum.double)
is Vec3Iota -> Either.right(datum.vec3)
else -> throw MishapInvalidIota.of(
datum,
if (argc == 0) idx else argc - (idx + 1),
"numvec"
)
} }
} }
fun List<Iota>.getLongOrList(idx: Int, argc: Int = 0): Either<Long, SpellList> {
val datum = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (datum is DoubleIota) {
val double = datum.double
val rounded = double.roundToLong()
if (abs(double - rounded) <= DoubleIota.TOLERANCE) {
return Either.left(rounded)
}
} else if (datum is ListIota) {
return Either.right(datum.list)
}
throw MishapInvalidIota.of(
datum,
if (argc == 0) idx else argc - (idx + 1),
"numlist"
)
}
// TODO do we make this work on lists
// there should probably be some way to abstract function application over lists, vecs, and numbers,
// and i bet it's fucking monads
fun aplKinnie(operatee: Either<Double, Vec3>, fn: DoubleUnaryOperator): Iota =
operatee.map(
{ num -> DoubleIota(fn.applyAsDouble(num)) },
{ vec -> Vec3Iota(Vec3(fn.applyAsDouble(vec.x), fn.applyAsDouble(vec.y), fn.applyAsDouble(vec.z))) }
)
inline val Boolean.asActionResult get() = listOf(DoubleIota(if (this) 1.0 else 0.0))
inline val Double.asActionResult get() = listOf(DoubleIota(this))
inline val Number.asActionResult get() = listOf(DoubleIota(this.toDouble()))
inline val SpellList.asActionResult get() = listOf(ListIota(this))
inline val List<Iota>.asActionResult get() = listOf(ListIota(this))
inline val BlockPos.asActionResult get() = listOf(Vec3Iota(Vec3.atCenterOf(this)))
inline val Vector3f.asActionResult get() = listOf(Vec3Iota(Vec3(this)))
inline val Vec3.asActionResult get() = listOf(Vec3Iota(this))
inline val Entity?.asActionResult get() = listOf(if (this == null) NullIota.INSTANCE else EntityIota(this))
inline val HexPattern.asActionResult get() = listOf(PatternIota(this))

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.casting.OperatorSideEffect
import at.petrak.hexcasting.api.spell.casting.SpellContinuation import at.petrak.hexcasting.api.spell.casting.SpellContinuation
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
interface SpellOperator : Operator { interface SpellAction : Action {
val argc: Int val argc: Int
fun hasCastingSound(ctx: CastingContext): Boolean = true fun hasCastingSound(ctx: CastingContext): Boolean = true

View file

@ -69,6 +69,19 @@ sealed class SpellList : Iterable<Iota> {
override fun iterator() = SpellListIterator(this) override fun iterator() = SpellListIterator(this)
/**
* Note this is O(n), probably.
*/
fun size(): Int {
var size = 0
var ptr = this
while (ptr.nonEmpty) {
ptr = ptr.cdr
size++
}
return size
}
class SpellListIterator(var list: SpellList) : Iterator<Iota> { class SpellListIterator(var list: SpellList) : Iterator<Iota> {
override fun hasNext() = list.nonEmpty override fun hasNext() = list.nonEmpty
override operator fun next(): Iota { override operator fun next(): Iota {

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.api.spell.casting
import at.petrak.hexcasting.api.HexAPI.modLoc import at.petrak.hexcasting.api.HexAPI.modLoc
import at.petrak.hexcasting.api.mod.HexConfig import at.petrak.hexcasting.api.mod.HexConfig
import at.petrak.hexcasting.api.spell.Operator import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.mishaps.MishapEntityTooFarAway import at.petrak.hexcasting.api.spell.mishaps.MishapEntityTooFarAway
import at.petrak.hexcasting.api.spell.mishaps.MishapEvalTooDeep import at.petrak.hexcasting.api.spell.mishaps.MishapEvalTooDeep
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway
@ -76,6 +76,10 @@ data class CastingContext(
assertVecInWorld(vec) assertVecInWorld(vec)
} }
fun assertVecInRange(pos: BlockPos) {
assertVecInRange(Vec3.atCenterOf(pos))
}
/** /**
* Check to make sure an entity is in range. Will not mishap for players. * Check to make sure an entity is in range. Will not mishap for players.
*/ */
@ -94,7 +98,7 @@ data class CastingContext(
if (sentinel.hasSentinel if (sentinel.hasSentinel
&& sentinel.extendsRange && sentinel.extendsRange
&& world.dimension() == sentinel.dimension && world.dimension() == sentinel.dimension
&& vec.distanceToSqr(sentinel.position) < Operator.MAX_DISTANCE_FROM_SENTINEL * Operator.MAX_DISTANCE_FROM_SENTINEL && vec.distanceToSqr(sentinel.position) < Action.MAX_DISTANCE_FROM_SENTINEL * Action.MAX_DISTANCE_FROM_SENTINEL
) )
return true return true
@ -107,7 +111,7 @@ data class CastingContext(
return this.spellCircle.aabb.contains(vec) return this.spellCircle.aabb.contains(vec)
} }
if (vec.distanceToSqr(this.caster.position()) < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE) if (vec.distanceToSqr(this.caster.position()) < Action.MAX_DISTANCE * Action.MAX_DISTANCE)
return true return true
return false return false

View file

@ -8,7 +8,7 @@ import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.mod.HexConfig import at.petrak.hexcasting.api.mod.HexConfig
import at.petrak.hexcasting.api.mod.HexItemTags import at.petrak.hexcasting.api.mod.HexItemTags
import at.petrak.hexcasting.api.mod.HexStatistics import at.petrak.hexcasting.api.mod.HexStatistics
import at.petrak.hexcasting.api.spell.Operator import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.SpellList import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.Widget import at.petrak.hexcasting.api.spell.Widget
@ -141,19 +141,19 @@ class CastingHarness private constructor(
* handle it functionally. * handle it functionally.
*/ */
fun updateWithPattern(newPat: HexPattern, world: ServerLevel, continuation: SpellContinuation): CastResult { fun updateWithPattern(newPat: HexPattern, world: ServerLevel, continuation: SpellContinuation): CastResult {
var operatorIdPair: Pair<Operator, ResourceLocation>? = null var actionIdPair: Pair<Action, ResourceLocation>? = null
try { try {
// Don't catch this one // Don't catch this one
operatorIdPair = PatternRegistry.matchPatternAndID(newPat, world) actionIdPair = PatternRegistry.matchPatternAndID(newPat, world)
if (this.ctx.spellCircle == null && !HexConfig.server().isActionAllowed(operatorIdPair.second)) { if (this.ctx.spellCircle == null && !HexConfig.server().isActionAllowed(actionIdPair.second)) {
throw MishapDisallowedSpell() throw MishapDisallowedSpell()
} else if (this.ctx.spellCircle != null } else if (this.ctx.spellCircle != null
&& !HexConfig.server().isActionAllowedInCircles(operatorIdPair.second) && !HexConfig.server().isActionAllowedInCircles(actionIdPair.second)
) { ) {
throw MishapDisallowedSpell("disallowed_circle") throw MishapDisallowedSpell("disallowed_circle")
} }
val pattern = operatorIdPair.first val pattern = actionIdPair.first
val unenlightened = pattern.isGreat && !ctx.isCasterEnlightened val unenlightened = pattern.isGreat && !ctx.isCasterEnlightened
@ -208,7 +208,7 @@ class CastingHarness private constructor(
continuation, continuation,
null, null,
mishap.resolutionType(ctx), mishap.resolutionType(ctx),
listOf(OperatorSideEffect.DoMishap(mishap, Mishap.Context(newPat, operatorIdPair?.second))), listOf(OperatorSideEffect.DoMishap(mishap, Mishap.Context(newPat, actionIdPair?.second))),
) )
} catch (exception: Exception) { } catch (exception: Exception) {
exception.printStackTrace() exception.printStackTrace()
@ -219,7 +219,7 @@ class CastingHarness private constructor(
listOf( listOf(
OperatorSideEffect.DoMishap( OperatorSideEffect.DoMishap(
MishapError(exception), MishapError(exception),
Mishap.Context(newPat, operatorIdPair?.second) Mishap.Context(newPat, actionIdPair?.second)
) )
) )
) )

View file

@ -20,11 +20,20 @@ public class DoubleIota extends Iota {
return HexUtils.fixNAN((Double) this.payload); return HexUtils.fixNAN((Double) this.payload);
} }
@Override
public boolean isTruthy() {
return this.getDouble() != 0.0;
}
@Override @Override
public boolean toleratesOther(Iota that) { public boolean toleratesOther(Iota that) {
return typesMatch(this, that) return typesMatch(this, that)
&& that instanceof DoubleIota dd && that instanceof DoubleIota dd
&& Math.abs(this.getDouble() - dd.getDouble()) < TOLERANCE; && tolerates(this.getDouble(), dd.getDouble());
}
public static boolean tolerates(double a, double b) {
return Math.abs(a - b) < TOLERANCE;
} }
@Override @Override

View file

@ -22,6 +22,11 @@ public class GarbageIota extends Iota {
super(HexIotaTypes.GARBAGE, NULL_SUBSTITUTE); super(HexIotaTypes.GARBAGE, NULL_SUBSTITUTE);
} }
@Override
public boolean isTruthy() {
return false;
}
@Override @Override
public boolean toleratesOther(Iota that) { public boolean toleratesOther(Iota that) {
return typesMatch(this, that); return typesMatch(this, that);

View file

@ -16,14 +16,20 @@ public abstract class Iota {
this.payload = payload; this.payload = payload;
} }
public @NotNull Object getPayload() { public @NotNull
Object getPayload() {
return payload; return payload;
} }
public @NotNull IotaType<?> getType() { public @NotNull
IotaType<?> getType() {
return this.type; return this.type;
} }
public boolean isTruthy() {
return true;
}
/** /**
* Compare this to another object, within a tolerance. * Compare this to another object, within a tolerance.
* <p> * <p>
@ -36,7 +42,8 @@ public abstract class Iota {
* <p> * <p>
* You probably don't want to call this directly; use {@link HexIotaTypes#serialize}. * You probably don't want to call this directly; use {@link HexIotaTypes#serialize}.
*/ */
abstract public @NotNull Tag serialize(); abstract public @NotNull
Tag serialize();
public Component display() { public Component display() {
return this.type.display(this.serialize()); return this.type.display(this.serialize());

View file

@ -30,6 +30,11 @@ public class ListIota extends Iota {
return (SpellList) this.payload; return (SpellList) this.payload;
} }
@Override
public boolean isTruthy() {
return this.getList().getNonEmpty();
}
@Override @Override
public boolean toleratesOther(Iota that) { public boolean toleratesOther(Iota that) {
if (!typesMatch(this, that)) { if (!typesMatch(this, that)) {

View file

@ -22,6 +22,11 @@ public class NullIota extends Iota {
super(HexIotaTypes.NULL, NULL_SUBSTITUTE); super(HexIotaTypes.NULL, NULL_SUBSTITUTE);
} }
@Override
public boolean isTruthy() {
return false;
}
@Override @Override
public boolean toleratesOther(Iota that) { public boolean toleratesOther(Iota that) {
return typesMatch(this, that); return typesMatch(this, that);

View file

@ -2,8 +2,7 @@ package at.petrak.hexcasting.common.casting;
import at.petrak.hexcasting.api.PatternRegistry; import at.petrak.hexcasting.api.PatternRegistry;
import at.petrak.hexcasting.api.misc.ManaConstants; import at.petrak.hexcasting.api.misc.ManaConstants;
import at.petrak.hexcasting.api.spell.Operator; import at.petrak.hexcasting.api.spell.Action;
import at.petrak.hexcasting.api.spell.iota.Iota;
import at.petrak.hexcasting.api.spell.Widget; import at.petrak.hexcasting.api.spell.Widget;
import at.petrak.hexcasting.api.spell.math.HexAngle; import at.petrak.hexcasting.api.spell.math.HexAngle;
import at.petrak.hexcasting.api.spell.math.HexDir; import at.petrak.hexcasting.api.spell.math.HexDir;
@ -352,29 +351,29 @@ public class RegisterPatterns {
PatternRegistry.mapPattern(HexPattern.fromAngles("d", HexDir.EAST), modLoc("const/null"), Widget.NULL); PatternRegistry.mapPattern(HexPattern.fromAngles("d", HexDir.EAST), modLoc("const/null"), Widget.NULL);
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqea", HexDir.NORTH_WEST), modLoc("const/vec/px"), PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqea", HexDir.NORTH_WEST), modLoc("const/vec/px"),
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(1.0, 0.0, 0.0)))); Action.makeConstantOp(LegacySpellDatum.make(new Vec3(1.0, 0.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqew", HexDir.NORTH_WEST), modLoc("const/vec/py"), PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqew", HexDir.NORTH_WEST), modLoc("const/vec/py"),
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 1.0, 0.0)))); Action.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 1.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqed", HexDir.NORTH_WEST), modLoc("const/vec/pz"), PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqed", HexDir.NORTH_WEST), modLoc("const/vec/pz"),
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, 1.0)))); Action.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, 1.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqa", HexDir.SOUTH_WEST), modLoc("const/vec/nx"), PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqa", HexDir.SOUTH_WEST), modLoc("const/vec/nx"),
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(-1.0, 0.0, 0.0)))); Action.makeConstantOp(LegacySpellDatum.make(new Vec3(-1.0, 0.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqw", HexDir.SOUTH_WEST), modLoc("const/vec/ny"), PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqw", HexDir.SOUTH_WEST), modLoc("const/vec/ny"),
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, -1.0, 0.0)))); Action.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, -1.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqd", HexDir.SOUTH_WEST), modLoc("const/vec/nz"), PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqd", HexDir.SOUTH_WEST), modLoc("const/vec/nz"),
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, -1.0)))); Action.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, -1.0))));
// Yep, this is what I spend the "plain hexagon" pattern on. // Yep, this is what I spend the "plain hexagon" pattern on.
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqq", HexDir.NORTH_WEST), modLoc("const/vec/0"), PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqq", HexDir.NORTH_WEST), modLoc("const/vec/0"),
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, 0.0)))); Action.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("qdwdq", HexDir.NORTH_EAST), modLoc("const/double/pi"), PatternRegistry.mapPattern(HexPattern.fromAngles("qdwdq", HexDir.NORTH_EAST), modLoc("const/double/pi"),
Operator.makeConstantOp(LegacySpellDatum.make(Math.PI))); Action.makeConstantOp(LegacySpellDatum.make(Math.PI)));
PatternRegistry.mapPattern(HexPattern.fromAngles("eawae", HexDir.NORTH_WEST), modLoc("const/double/tau"), PatternRegistry.mapPattern(HexPattern.fromAngles("eawae", HexDir.NORTH_WEST), modLoc("const/double/tau"),
Operator.makeConstantOp(LegacySpellDatum.make(HexUtils.TAU))); Action.makeConstantOp(LegacySpellDatum.make(HexUtils.TAU)));
// e // e
PatternRegistry.mapPattern(HexPattern.fromAngles("aaq", HexDir.EAST), modLoc("const/double/e"), PatternRegistry.mapPattern(HexPattern.fromAngles("aaq", HexDir.EAST), modLoc("const/double/e"),
Operator.makeConstantOp(LegacySpellDatum.make(Math.E))); Action.makeConstantOp(LegacySpellDatum.make(Math.E)));
// == Entities == // == Entities ==
@ -490,7 +489,7 @@ public class RegisterPatterns {
if (negate) { if (negate) {
accumulator = -accumulator; accumulator = -accumulator;
} }
return Operator.makeConstantOp(LegacySpellDatum.make(accumulator)); return Action.makeConstantOp(LegacySpellDatum.make(accumulator));
} else { } else {
return null; return null;
} }

View file

@ -1,23 +1,27 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.misc.ManaConstants import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import net.minecraft.world.level.ClipContext import net.minecraft.world.level.ClipContext
import net.minecraft.world.phys.HitResult import net.minecraft.world.phys.HitResult
import net.minecraft.world.phys.Vec3
object OpBlockAxisRaycast : ConstManaOperator { object OpBlockAxisRaycast : ConstManaAction {
override val argc = 2 override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100 override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val origin: Vec3 = args.getChecked(0, argc) val origin = args.getVec3(0, argc)
val look: Vec3 = args.getChecked(1, argc) val look = args.getVec3(1, argc)
val blockHitResult = ctx.world.clip( val blockHitResult = ctx.world.clip(
ClipContext( ClipContext(
origin, origin,
Operator.raycastEnd(origin, look), Action.raycastEnd(origin, look),
ClipContext.Block.COLLIDER, ClipContext.Block.COLLIDER,
ClipContext.Fluid.NONE, ClipContext.Fluid.NONE,
ctx.caster ctx.caster
@ -25,9 +29,9 @@ object OpBlockAxisRaycast : ConstManaOperator {
) )
return if (blockHitResult.type == HitResult.Type.BLOCK) { return if (blockHitResult.type == HitResult.Type.BLOCK) {
blockHitResult.direction.step().asSpellResult blockHitResult.direction.step().asActionResult
} else { } else {
null.asSpellResult listOf(NullIota.INSTANCE)
} }
} }
} }

View file

@ -1,23 +1,27 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.misc.ManaConstants import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import net.minecraft.world.level.ClipContext import net.minecraft.world.level.ClipContext
import net.minecraft.world.phys.HitResult import net.minecraft.world.phys.HitResult
import net.minecraft.world.phys.Vec3
object OpBlockRaycast : ConstManaOperator { object OpBlockRaycast : ConstManaAction {
override val argc = 2 override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100 override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val origin: Vec3 = args.getChecked(0, argc) val origin = args.getVec3(0, argc)
val look: Vec3 = args.getChecked(1, argc) val look = args.getVec3(1, argc)
val blockHitResult = ctx.world.clip( val blockHitResult = ctx.world.clip(
ClipContext( ClipContext(
origin, origin,
Operator.raycastEnd(origin, look), Action.raycastEnd(origin, look),
ClipContext.Block.COLLIDER, ClipContext.Block.COLLIDER,
ClipContext.Fluid.NONE, ClipContext.Fluid.NONE,
ctx.caster ctx.caster
@ -28,9 +32,10 @@ object OpBlockRaycast : ConstManaOperator {
// the position on the bhr is the position of the specific *hit point*, which is actually on the outside of the 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) // 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 // so we return the block pos instead
blockHitResult.blockPos.asSpellResult // TODO some action that has the "weird" version?
blockHitResult.blockPos.asActionResult
} else { } else {
Widget.NULL.asSpellResult listOf(NullIota.INSTANCE)
} }
} }
} }

View file

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

View file

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

View file

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

View file

@ -1,19 +1,23 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.misc.ManaConstants import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import net.minecraft.world.entity.projectile.ProjectileUtil import net.minecraft.world.entity.projectile.ProjectileUtil
import net.minecraft.world.phys.AABB import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.Vec3
object OpEntityRaycast : ConstManaOperator { object OpEntityRaycast : ConstManaAction {
override val argc = 2 override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100 override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val origin: Vec3 = args.getChecked(0, argc) val origin = args.getVec3(0, argc)
val look: Vec3 = args.getChecked(1, argc) val look = args.getVec3(1, argc)
val endp = Operator.raycastEnd(origin, look) val endp = Action.raycastEnd(origin, look)
val entityHitResult = ProjectileUtil.getEntityHitResult( val entityHitResult = ProjectileUtil.getEntityHitResult(
ctx.caster, ctx.caster,
@ -25,9 +29,9 @@ object OpEntityRaycast : ConstManaOperator {
) )
return if (entityHitResult != null && ctx.isEntityInRange(entityHitResult.entity)) { return if (entityHitResult != null && ctx.isEntityInRange(entityHitResult.entity)) {
entityHitResult.entity.asSpellResult entityHitResult.entity.asActionResult
} else { } else {
null.asSpellResult listOf(NullIota.INSTANCE)
} }
} }
} }

View file

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

View file

@ -1,12 +1,12 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
object OpRead : ConstManaOperator { object OpRead : ConstManaAction {
override val argc = 0 override val argc = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {

View file

@ -1,12 +1,12 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
object OpReadable : ConstManaOperator { object OpReadable : ConstManaAction {
override val argc = 0 override val argc = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
@ -15,12 +15,12 @@ object OpReadable : ConstManaOperator {
} }
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
?: return false.asSpellResult ?: return false.asActionResult
datumHolder.readIota(ctx.world) datumHolder.readIota(ctx.world)
?: datumHolder.emptyIota() ?: datumHolder.emptyIota()
?: return false.asSpellResult ?: return false.asActionResult
return true.asSpellResult return true.asActionResult
} }
} }

View file

@ -1,21 +1,20 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getItemEntity
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.entity.item.ItemEntity
object OpTheCoolerRead : ConstManaOperator { object OpTheCoolerRead : ConstManaAction {
override val argc = 1 override val argc = 1
override fun execute( override fun execute(
args: List<Iota>, args: List<Iota>,
ctx: CastingContext ctx: CastingContext
): List<Iota> { ): List<Iota> {
val target = args.getChecked<ItemEntity>(0, argc) val target = args.getItemEntity(0, argc)
ctx.assertEntityInRange(target) ctx.assertEntityInRange(target)

View file

@ -1,30 +1,29 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getItemEntity
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.entity.item.ItemEntity
object OpTheCoolerReadable : ConstManaOperator { object OpTheCoolerReadable : ConstManaAction {
override val argc = 1 override val argc = 1
override fun execute( override fun execute(
args: List<Iota>, args: List<Iota>,
ctx: CastingContext ctx: CastingContext
): List<Iota> { ): List<Iota> {
val target = args.getChecked<ItemEntity>(0, argc) val target = args.getItemEntity(0, argc)
ctx.assertEntityInRange(target) ctx.assertEntityInRange(target)
val stack = target.item val stack = target.item
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack) val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack)
?: return false.asSpellResult ?: return false.asActionResult
if (datumHolder.readIota(ctx.world) == null && datumHolder.emptyIota() == null) if (datumHolder.readIota(ctx.world) == null && datumHolder.emptyIota() == null)
return false.asSpellResult return false.asActionResult
return true.asSpellResult return true.asActionResult
} }
} }

View file

@ -1,13 +1,13 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
object OpWritable : ConstManaOperator { object OpWritable : ConstManaAction {
override val argc = 1 override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
@ -19,15 +19,15 @@ object OpWritable : ConstManaOperator {
datumHolder != null && datumHolder.writeIota(datum, true) datumHolder != null && datumHolder.writeIota(datum, true)
} }
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) ?: return false.asSpellResult val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) ?: return false.asActionResult
if (!datumHolder.writeIota(datum, true)) if (!datumHolder.writeIota(datum, true))
return false.asSpellResult return false.asActionResult
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster) val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)
if (trueName != null) if (trueName != null)
return false.asSpellResult return false.asActionResult
return true.asSpellResult return true.asActionResult
} }
} }

View file

@ -1,16 +1,16 @@
package at.petrak.hexcasting.common.casting.operators package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
// we make this a spell cause imo it's a little ... anticlimactic for it to just make no noise // we make this a spell cause imo it's a little ... anticlimactic for it to just make no noise
object OpWrite : SpellOperator { object OpWrite : SpellAction {
override val argc = 1 override val argc = 1
override fun execute( override fun execute(
args: List<Iota>, args: List<Iota>,

View file

@ -1,32 +1,29 @@
package at.petrak.hexcasting.common.casting.operators.akashic package at.petrak.hexcasting.common.casting.operators.akashic
import at.petrak.hexcasting.api.misc.ManaConstants import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getBlockPos
import at.petrak.hexcasting.api.spell.math.HexPattern import at.petrak.hexcasting.api.spell.getPattern
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import at.petrak.hexcasting.api.spell.mishaps.MishapNoAkashicRecord import at.petrak.hexcasting.api.spell.mishaps.MishapNoAkashicRecord
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicRecord import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicRecord
import net.minecraft.core.BlockPos
import net.minecraft.world.phys.Vec3
object OpAkashicRead : ConstManaOperator { object OpAkashicRead : ConstManaAction {
override val argc = 2 override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT override val manaCost = ManaConstants.DUST_UNIT
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val pos = args.getChecked<Vec3>(0, argc) val pos = args.getBlockPos(0, argc)
val key = args.getChecked<HexPattern>(1, argc) val key = args.getPattern(1, argc)
val bpos = BlockPos(pos) val tile = ctx.world.getBlockEntity(pos)
val tile = ctx.world.getBlockEntity(bpos)
if (tile !is BlockEntityAkashicRecord) { if (tile !is BlockEntityAkashicRecord) {
throw MishapNoAkashicRecord(bpos) throw MishapNoAkashicRecord(pos)
} }
val datum = tile.lookupPattern(key, ctx.world) val datum = tile.lookupPattern(key, ctx.world)
return listOf(datum ?: LegacySpellDatum.make(Widget.NULL)) return listOf(datum ?: NullIota.INSTANCE)
} }
} }

View file

@ -3,16 +3,15 @@ package at.petrak.hexcasting.common.casting.operators.akashic
import at.petrak.hexcasting.api.misc.ManaConstants import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.math.HexPattern import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.spell.mishaps.MishapNoAkashicRecord import at.petrak.hexcasting.api.spell.mishaps.MishapNoAkashicRecord
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicRecord import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicRecord
import at.petrak.hexcasting.common.lib.HexSounds import at.petrak.hexcasting.common.lib.HexSounds
import net.minecraft.core.BlockPos
import net.minecraft.sounds.SoundSource import net.minecraft.sounds.SoundSource
import net.minecraft.world.phys.Vec3
object OpAkashicWrite : SpellOperator { object OpAkashicWrite : SpellAction {
override val argc = 3 override val argc = 3
override val isGreat = true override val isGreat = true
@ -23,16 +22,15 @@ object OpAkashicWrite : SpellOperator {
args: List<Iota>, args: List<Iota>,
ctx: CastingContext ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> { ): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pos = args.getChecked<Vec3>(0, argc) val pos = args.getBlockPos(0, argc)
val key = args.getChecked<HexPattern>(1, argc) val key = args.getPattern(1, argc)
val datum = args[2] val datum = args.get(2)
ctx.assertVecInRange(pos) ctx.assertVecInRange(pos)
val bpos = BlockPos(pos) val tile = ctx.world.getBlockEntity(pos)
val tile = ctx.world.getBlockEntity(bpos)
if (tile !is BlockEntityAkashicRecord) { if (tile !is BlockEntityAkashicRecord) {
throw MishapNoAkashicRecord(bpos) throw MishapNoAkashicRecord(pos)
} }
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster) val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)

View file

@ -1,13 +1,12 @@
package at.petrak.hexcasting.common.casting.operators.circles package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
class OpCircleBounds(val max: Boolean) : ConstManaOperator { class OpCircleBounds(val max: Boolean) : ConstManaAction {
override val argc = 0 override val argc = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {

View file

@ -1,13 +1,12 @@
package at.petrak.hexcasting.common.casting.operators.circles package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
object OpImpetusDir : ConstManaOperator { object OpImpetusDir : ConstManaAction {
override val argc = 0 override val argc = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {

View file

@ -1,19 +1,17 @@
package at.petrak.hexcasting.common.casting.operators.circles package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
import net.minecraft.world.phys.Vec3
object OpImpetusPos : ConstManaOperator { object OpImpetusPos : ConstManaAction {
override val argc = 0 override val argc = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
if (ctx.spellCircle == null) if (ctx.spellCircle == null)
throw MishapNoSpellCircle() throw MishapNoSpellCircle()
return Vec3.atCenterOf(ctx.spellCircle.impetusPos).asSpellResult return ctx.spellCircle.impetusPos.asSpellResult
} }
} }

View file

@ -1,19 +1,28 @@
package at.petrak.hexcasting.common.casting.operators.eval package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.ContinuationFrame import at.petrak.hexcasting.api.spell.casting.ContinuationFrame
import at.petrak.hexcasting.api.spell.casting.SpellContinuation import at.petrak.hexcasting.api.spell.casting.SpellContinuation
import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.iota.Iota
object OpEval : Operator { object OpEval : Action {
override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, local: Iota, ctx: CastingContext): OperationResult { override fun operate(
val instrs: SpellList = stack.getChecked(stack.lastIndex) continuation: SpellContinuation,
stack: MutableList<Iota>,
local: Iota,
ctx: CastingContext
): OperationResult {
val instrs = stack.getList(stack.lastIndex)
stack.removeLastOrNull() stack.removeLastOrNull()
ctx.incDepth() ctx.incDepth()
// if not installed already... // if not installed already...
val newCont = if (continuation is SpellContinuation.NotDone && continuation.frame is ContinuationFrame.FinishEval) { val newCont =
if (continuation is SpellContinuation.NotDone && continuation.frame is ContinuationFrame.FinishEval) {
continuation continuation
} else { } else {
continuation.pushFrame(ContinuationFrame.FinishEval) // install a break-boundary after eval continuation.pushFrame(ContinuationFrame.FinishEval) // install a break-boundary after eval

View file

@ -1,12 +1,12 @@
package at.petrak.hexcasting.common.casting.operators.eval package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.OperationResult import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.SpellContinuation import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpEvalDelay : Operator { object OpEvalDelay : Action {
override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, local: Iota, ctx: CastingContext): OperationResult { override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, local: Iota, ctx: CastingContext): OperationResult {
return OperationResult(continuation, stack, local, listOf()) return OperationResult(continuation, stack, local, listOf())
} }

View file

@ -1,12 +1,15 @@
package at.petrak.hexcasting.common.casting.operators.eval package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.ContinuationFrame import at.petrak.hexcasting.api.spell.casting.ContinuationFrame
import at.petrak.hexcasting.api.spell.casting.SpellContinuation import at.petrak.hexcasting.api.spell.casting.SpellContinuation
import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
object OpForEach : Operator { object OpForEach : Action {
override fun operate( override fun operate(
continuation: SpellContinuation, continuation: SpellContinuation,
stack: MutableList<Iota>, stack: MutableList<Iota>,
@ -16,8 +19,8 @@ object OpForEach : Operator {
if (stack.size < 2) if (stack.size < 2)
throw MishapNotEnoughArgs(2, stack.size) throw MishapNotEnoughArgs(2, stack.size)
val instrs: SpellList = stack.getChecked(stack.lastIndex - 1) val instrs = stack.getList(stack.lastIndex - 1)
val datums: SpellList = stack.getChecked(stack.lastIndex) val datums = stack.getList(stack.lastIndex)
stack.removeLastOrNull() stack.removeLastOrNull()
stack.removeLastOrNull() stack.removeLastOrNull()

View file

@ -2,11 +2,11 @@ package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.OperationResult import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.SpellContinuation import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpHalt : Operator { object OpHalt : Action {
override fun operate( override fun operate(
continuation: SpellContinuation, continuation: SpellContinuation,
stack: MutableList<Iota>, stack: MutableList<Iota>,

View file

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

View file

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

View file

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

View file

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

View file

@ -1,15 +1,19 @@
package at.petrak.hexcasting.common.casting.operators.lists package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import kotlin.math.roundToInt import kotlin.math.roundToInt
object OpIndex : ConstManaOperator { object OpIndex : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val list = args.getChecked<SpellList>(0, argc).toMutableList() val list = args.getList(0, argc).toMutableList()
val index = args.getChecked<Double>(1, argc) val index = args.getDouble(1, argc)
val x = list.getOrElse(index.roundToInt()) { LegacySpellDatum.make(Widget.NULL) } val x = list.getOrElse(index.roundToInt()) { NullIota.INSTANCE }
return listOf(x) return listOf(x)
} }
} }

View file

@ -1,15 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.lists package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.iota.Iota
object OpIndexOf : ConstManaOperator { object OpIndexOf : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val list = args.getChecked<SpellList>(0, argc).toMutableList() val list = args.getList(0, argc).toMutableList()
val value = args[1] val value = args[1]
return list.indexOfFirst(value::tolerantEquals).asSpellResult return list.indexOfFirst { Iota.tolerates(value, it) }.asActionResult
} }
} }

View file

@ -1,35 +1,32 @@
package at.petrak.hexcasting.common.casting.operators.lists package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.SpellContinuation import at.petrak.hexcasting.api.spell.casting.SpellContinuation
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota import at.petrak.hexcasting.api.spell.getPositiveIntUnder
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import kotlin.math.abs
import kotlin.math.roundToInt
object OpLastNToList : Operator { object OpLastNToList : Action {
override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, local: Iota, ctx: CastingContext): OperationResult { override fun operate(
continuation: SpellContinuation,
stack: MutableList<Iota>,
local: Iota,
ctx: CastingContext
): OperationResult {
if (stack.isEmpty()) if (stack.isEmpty())
throw MishapNotEnoughArgs(1, 0) throw MishapNotEnoughArgs(1, 0)
val arg = stack.takeLast(1).getChecked<Double>(0) val yoinkCount = stack.takeLast(1).getPositiveIntUnder(0, stack.size - 1)
val datum = stack[stack.lastIndex]
stack.removeLast() stack.removeLast()
if (arg < 0 || arg > stack.size || abs(arg.roundToInt() - arg) >= 0.05f) {
throw MishapInvalidIota(
datum,
0,
"hexcasting.mishap.invalid_value.int.between".asTranslatedComponent(0, stack.size)
)
}
val output = mutableListOf<Iota>() val output = mutableListOf<Iota>()
output.addAll(stack.takeLast(arg.toInt())) output.addAll(stack.takeLast(yoinkCount))
val endSize = stack.size - output.toList().size val endSize = stack.size - output.toList().size
while (stack.size != endSize) { while (stack.size != endSize) {
stack.removeLast() stack.removeLast()
} }
stack.addAll(output.asSpellResult) stack.addAll(output.asActionResult)
return OperationResult(continuation, stack, local, listOf()) return OperationResult(continuation, stack, local, listOf())
} }

View file

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

View file

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

View file

@ -1,18 +1,20 @@
package at.petrak.hexcasting.common.casting.operators.lists package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.getPositiveIntUnder
import at.petrak.hexcasting.api.spell.iota.Iota
object OpRemove : ConstManaOperator { object OpRemove : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val list = args.getChecked<SpellList>(0, argc).toMutableList() val list = args.getList(0, argc).toMutableList()
val index = args.getChecked<Double>(1, argc).toInt() val index = args.getPositiveIntUnder(1, list.size, argc)
if (index < 0 || index >= list.size)
return list
list.removeAt(index) list.removeAt(index)
return list.asSpellResult return list.asActionResult
} }
} }

View file

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

View file

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

View file

@ -1,22 +1,24 @@
package at.petrak.hexcasting.common.casting.operators.lists package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.util.Mth import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.getPositiveIntUnder
import at.petrak.hexcasting.api.spell.iota.Iota
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.roundToInt
object OpSlice : ConstManaOperator { object OpSlice : ConstManaAction {
override val argc = 3 override val argc = 3
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val list = args.getChecked<SpellList>(0, argc).toList() val list = args.getList(0, argc).toList()
val index1 = Mth.clamp(args.getChecked<Double>(1, argc).roundToInt(), 0, list.size) val index1 = args.getPositiveIntUnder(1, list.size, argc)
val index2 = Mth.clamp(args.getChecked<Double>(2, argc).roundToInt(), 0, list.size) val index2 = args.getPositiveIntUnder(2, list.size, argc)
if (index1 == index2) if (index1 == index2)
return emptyList<Iota>().asSpellResult return emptyList<Iota>().asActionResult
return list.subList(min(index1, index2), max(index1, index2)).asSpellResult return list.subList(min(index1, index2), max(index1, index2)).asActionResult
} }
} }

View file

@ -1,15 +1,14 @@
package at.petrak.hexcasting.common.casting.operators.lists package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.iota.Iota
object OpSplat : ConstManaOperator { object OpSplat : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> = override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> =
args.getChecked<SpellList>(0, argc).toMutableList() args.getList(0, argc).toList()
} }

View file

@ -1,15 +1,19 @@
package at.petrak.hexcasting.common.casting.operators.lists package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.ListIota
import at.petrak.hexcasting.api.spell.iota.NullIota
object OpUnCons : ConstManaOperator { object OpUnCons : ConstManaAction {
override val argc = 1 override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val list = args.getChecked<SpellList>(0, argc) val list = args.getList(0, argc)
if (list.nonEmpty) { if (list.nonEmpty) {
return spellListOf(list.cdr, list.car) return listOf(ListIota(list.cdr), list.car)
} }
return spellListOf(list, Widget.NULL) return listOf(args[0], NullIota.INSTANCE)
} }
} }

View file

@ -1,12 +1,12 @@
package at.petrak.hexcasting.common.casting.operators.local package at.petrak.hexcasting.common.casting.operators.local
import at.petrak.hexcasting.api.spell.OperationResult import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.SpellContinuation import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpPeekLocal : Operator { object OpPeekLocal : Action {
override fun operate( override fun operate(
continuation: SpellContinuation, continuation: SpellContinuation,
stack: MutableList<Iota>, stack: MutableList<Iota>,

View file

@ -1,13 +1,13 @@
package at.petrak.hexcasting.common.casting.operators.local package at.petrak.hexcasting.common.casting.operators.local
import at.petrak.hexcasting.api.spell.OperationResult import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.spell.casting.SpellContinuation import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpPushLocal : Operator { object OpPushLocal : Action {
override fun operate( override fun operate(
continuation: SpellContinuation, continuation: SpellContinuation,
stack: MutableList<Iota>, stack: MutableList<Iota>,

View file

@ -1,19 +1,19 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.numOrVec import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getNumOrVec
import at.petrak.hexcasting.api.spell.iota.Iota
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
object OpAbsLen : ConstManaOperator { object OpAbsLen : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val x = numOrVec(args[0], 0) val x = args.getNumOrVec(0, argc)
return x.map({ num -> num.absoluteValue }, { vec -> vec.length() }).asSpellResult return x.map({ num -> num.absoluteValue }, { vec -> vec.length() }).asActionResult
} }
} }

View file

@ -1,29 +1,30 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.numOrVec import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.spellListOf import at.petrak.hexcasting.api.spell.getNumOrVec
import at.petrak.hexcasting.api.spell.iota.Iota
object OpAdd : ConstManaOperator { object OpAdd : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val lhs = numOrVec(args[0], 1) val lhs = args.getNumOrVec(0, argc)
val rhs = numOrVec(args[1], 0) val rhs = args.getNumOrVec(1, argc)
return spellListOf( return lhs.map(
lhs.map({ lnum -> { lnum ->
rhs.map( rhs.map(
{ rnum -> lnum + rnum }, { rvec -> rvec.add(lnum, lnum, lnum) } { rnum -> (lnum + rnum).asActionResult }, { rvec -> rvec.add(lnum, lnum, lnum).asActionResult }
) )
}, { lvec -> },
{ lvec ->
rhs.map( rhs.map(
{ rnum -> lvec.add(rnum, rnum, rnum) }, { rvec -> lvec.add(rvec) } { rnum -> lvec.add(rnum, rnum, rnum).asActionResult }, { rvec -> lvec.add(rvec).asActionResult }
) )
}) }
) )
} }
} }

View file

@ -1,18 +1,19 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.aplKinnie
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getNumOrVec
import at.petrak.hexcasting.api.spell.iota.Iota
import kotlin.math.ceil import kotlin.math.ceil
object OpCeil : ConstManaOperator { object OpCeil : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val value = args.getChecked<Double>(0, argc) val value = args.getNumOrVec(0, argc)
return ceil(value).asSpellResult // i hate this fucking syntax what the hell is ::ceil are you a goddamn homestuck ::c
return listOf(aplKinnie(value, ::ceil))
} }
} }

View file

@ -1,21 +1,21 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import net.minecraft.core.Direction import net.minecraft.core.Direction
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpCoerceToAxial : ConstManaOperator { object OpCoerceToAxial : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val vec = args.getChecked<Vec3>(0, argc) val vec = args.getVec3(0, argc)
if (vec == Vec3.ZERO) if (vec == Vec3.ZERO)
return vec.asSpellResult return vec.asActionResult
return Vec3.atLowerCornerOf(Direction.getNearest(vec.x, vec.y, vec.z).normal).asSpellResult return Vec3.atLowerCornerOf(Direction.getNearest(vec.x, vec.y, vec.z).normal).asActionResult
} }
} }

View file

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

View file

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

View file

@ -1,45 +1,42 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.numOrVec import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getNumOrVec
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import at.petrak.hexcasting.api.spell.spellListOf
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpDivCross : ConstManaOperator { object OpDivCross : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val lhs = numOrVec(args[0], 1) val lhs = args.getNumOrVec(0, argc)
val rhs = numOrVec(args[1], 0) val rhs = args.getNumOrVec(1, argc)
val theMishap = MishapDivideByZero.of(args[0], args[1])
return spellListOf( return lhs.map(
lhs.map({ lnum -> { lnum ->
rhs.map( rhs.map(
{ rnum -> { rnum ->
if (rnum == 0.0) if (rnum == 0.0) throw theMishap // throw theMishap throw theMishap badumbadum
throw MishapDivideByZero.of(lnum, rnum) (lnum / rnum).asActionResult
lnum / rnum
}, },
{ rvec -> { rvec ->
if (rvec.x == 0.0 || rvec.y == 0.0 || rvec.z == 0.0) if (rvec.x == 0.0 || rvec.y == 0.0 || rvec.z == 0.0) throw theMishap
throw MishapDivideByZero.of(lnum, rvec) Vec3(lnum / rvec.x, lnum / rvec.y, lnum / rvec.z).asActionResult
Vec3(lnum / rvec.x, lnum / rvec.y, lnum / rvec.z)
} }
) )
}, { lvec -> }, { lvec ->
rhs.map( rhs.map(
{ rnum -> { rnum ->
if (lvec == Vec3.ZERO) if (lvec == Vec3.ZERO) throw theMishap
throw MishapDivideByZero.of(lvec, rnum) lvec.scale(1.0 / rnum).asActionResult
lvec.scale(1.0 / rnum)
}, },
{ rvec -> lvec.cross(rvec) } { rvec -> lvec.cross(rvec).asActionResult }
) )
}) })
)
} }
} }

View file

@ -1,18 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.aplKinnie
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getNumOrVec
import at.petrak.hexcasting.api.spell.iota.Iota
import kotlin.math.floor import kotlin.math.floor
object OpFloor : ConstManaOperator { object OpFloor : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val value = args.getChecked<Double>(0, argc) val value = args.getNumOrVec(0, argc)
return floor(value).asSpellResult return listOf(aplKinnie(value, ::floor))
} }
} }

View file

@ -1,22 +1,22 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import kotlin.math.log import kotlin.math.log
object OpLog : ConstManaOperator { object OpLog : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val value = args.getChecked<Double>(0, argc) val value = args.getDouble(0, argc)
val base = args.getChecked<Double>(1, argc) val base = args.getDouble(1, argc)
if (value <= 0.0 || base <= 0.0 || base == 1.0) if (value <= 0.0 || base <= 0.0 || base == 1.0)
throw MishapDivideByZero.of(value, base, "logarithm") throw MishapDivideByZero.of(args[0], args[1], "logarithm")
return log(value, base).asSpellResult return log(value, base).asActionResult
} }
} }

View file

@ -1,21 +1,22 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
object OpModulo : ConstManaOperator { object OpModulo : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val l = args.getChecked<Double>(0, argc) // TODO: some wAckY vector operation to go in the vector x vector overload
val r = args.getChecked<Double>(1, argc) val l = args.getDouble(0, argc)
val r = args.getDouble(1, argc)
if (r == 0.0) if (r == 0.0)
throw MishapDivideByZero.of(l, r) throw MishapDivideByZero.of(args[0], args[1])
return (l % r).asSpellResult return (l % r).asActionResult
} }
} }

View file

@ -1,29 +1,29 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.numOrVec import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.spellListOf
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getNumOrVec
import at.petrak.hexcasting.api.spell.iota.Iota
object OpMulDot : ConstManaOperator { object OpMulDot : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val lhs = numOrVec(args[0], 1) val lhs = args.getNumOrVec(0, OpAdd.argc)
val rhs = numOrVec(args[1], 0) val rhs = args.getNumOrVec(1, OpAdd.argc)
return spellListOf( return lhs.map(
lhs.map({ lnum -> { lnum ->
rhs.map( rhs.map(
{ rnum -> lnum * rnum }, { rvec -> rvec.scale(lnum) } { rnum -> (lnum * rnum).asActionResult }, { rvec -> rvec.scale(lnum).asActionResult }
) )
}, { lvec -> }, { lvec ->
rhs.map( rhs.map(
{ rnum -> lvec.multiply(rnum, rnum, rnum) }, { rvec -> lvec.dot(rvec) } { rnum -> lvec.scale(rnum).asActionResult }, { rvec -> lvec.dot(rvec).asActionResult }
) )
}) })
)
} }
} }

View file

@ -1,49 +1,49 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.numOrVec import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getNumOrVec
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import at.petrak.hexcasting.api.spell.spellListOf
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
import kotlin.math.pow import kotlin.math.pow
object OpPowProj : ConstManaOperator { object OpPowProj : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val lhs = numOrVec(args[0], 1) val lhs = args.getNumOrVec(0, OpAdd.argc)
val rhs = numOrVec(args[1], 0) val rhs = args.getNumOrVec(1, OpAdd.argc)
val theMishap = MishapDivideByZero.of(args[0], args[1], "exponent")
return spellListOf( return lhs.map(
lhs.map({ lnum -> { lnum ->
rhs.map( rhs.map(
{ rnum -> { rnum ->
if (rnum == 0.0 && lnum == 0.0) if (rnum == 0.0 && lnum == 0.0)
throw MishapDivideByZero.of(lnum, rnum, "exponent") throw theMishap
lnum.pow(rnum) lnum.pow(rnum).asActionResult
}, { rvec -> }, { rvec ->
if (lnum == 0.0 && (rvec.x == 0.0 || rvec.y == 0.0 || rvec.z == 0.0)) if (lnum == 0.0 && (rvec.x == 0.0 || rvec.y == 0.0 || rvec.z == 0.0))
throw MishapDivideByZero.of(lnum, rvec, "exponent") throw theMishap
Vec3(lnum.pow(rvec.x), lnum.pow(rvec.y), lnum.pow(rvec.z)) Vec3(lnum.pow(rvec.x), lnum.pow(rvec.y), lnum.pow(rvec.z)).asActionResult
} }
) )
}, { lvec -> }, { lvec ->
rhs.map( rhs.map(
{ rnum -> { rnum ->
if (rnum == 0.0 && (lvec.x == 0.0 || lvec.y == 0.0 || lvec.z == 0.0)) if (rnum == 0.0 && (lvec.x == 0.0 || lvec.y == 0.0 || lvec.z == 0.0))
throw MishapDivideByZero.of(lvec, rnum, "exponent") throw theMishap
Vec3(lvec.x.pow(rnum), lvec.y.pow(rnum), lvec.z.pow(rnum)) Vec3(lvec.x.pow(rnum), lvec.y.pow(rnum), lvec.z.pow(rnum)).asActionResult
}, },
{ rvec -> { rvec ->
if (lvec == Vec3.ZERO) if (lvec == Vec3.ZERO)
throw MishapDivideByZero.of(lvec, rvec, "project") throw MishapDivideByZero.of(args[0], args[1], "project")
rvec.scale(rvec.dot(lvec) / lvec.dot(lvec)) rvec.scale(rvec.dot(lvec) / lvec.dot(lvec)).asActionResult
} }
) )
}) })
)
} }
} }

View file

@ -1,15 +1,15 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
object OpRandom : ConstManaOperator { object OpRandom : ConstManaAction {
override val argc: Int override val argc: Int
get() = 0 get() = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return ctx.world.random.nextDouble().asSpellResult return ctx.world.random.nextDouble().asActionResult
} }
} }

View file

@ -1,30 +1,30 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.numOrVec import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.spellListOf import at.petrak.hexcasting.api.spell.getNumOrVec
import at.petrak.hexcasting.api.spell.iota.Iota
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpSub : ConstManaOperator { object OpSub : ConstManaAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val lhs = numOrVec(args[0], 1) val lhs = args.getNumOrVec(0, OpAdd.argc)
val rhs = numOrVec(args[1], 0) val rhs = args.getNumOrVec(1, OpAdd.argc)
return spellListOf( return lhs.map({ lnum ->
lhs.map({ lnum ->
rhs.map( rhs.map(
{ rnum -> lnum - rnum }, { rvec -> Vec3(lnum - rvec.x, lnum - rvec.y, lnum - rvec.z) } { rnum -> (lnum - rnum).asActionResult },
{ rvec -> Vec3(lnum - rvec.x, lnum - rvec.y, lnum - rvec.z).asActionResult }
) )
}, { lvec -> }, { lvec ->
rhs.map( rhs.map(
{ rnum -> lvec.subtract(rnum, rnum, rnum) }, { rvec -> lvec.subtract(rvec) } { rnum -> lvec.subtract(rnum, rnum, rnum).asActionResult },
{ rvec -> lvec.subtract(rvec).asActionResult }
) )
}) })
)
} }
} }

View file

@ -2,22 +2,23 @@ package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import kotlin.math.roundToInt import at.petrak.hexcasting.api.spell.iota.Iota
object OpAnd : ConstManaOperator { object OpAnd : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val firstParam = numOrList(args[0], 0) val firstParam = args.getLongOrList(0, argc)
if (firstParam.right().isPresent) { return firstParam.map(
val list1 = firstParam.right().get() { num1 ->
val list2 = args.getChecked<SpellList>(1, argc) val num2 = args.getLong(1, argc)
return list1.filter { x -> list2.any(x::tolerantEquals) }.asSpellResult (num1 and num2).asActionResult
},
{ list1 ->
val list2 = args.getList(1, argc)
list1.filter { x -> list2.any { Iota.tolerates(x, it) } }.asActionResult
} }
)
val num1 = firstParam.left().get().roundToInt()
val num2 = args.getChecked<Double>(1, argc).roundToInt()
return (num1 and num2).asSpellResult
} }
} }

View file

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

View file

@ -2,23 +2,23 @@ package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import kotlin.math.roundToInt import at.petrak.hexcasting.api.spell.iota.Iota
object OpOr : ConstManaOperator { object OpOr : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val firstParam = numOrList(args[0], 0) val firstParam = args.getLongOrList(0, argc)
if (firstParam.right().isPresent) { return firstParam.map(
val list1 = firstParam.right().get() { num1 ->
val list2 = args.getChecked<SpellList>(1, argc) val num2 = args.getLong(1, argc)
val out = list1 + list2.filter { x -> list1.none(x::tolerantEquals) } (num1 or num2).asActionResult
return out.asSpellResult },
{ list1 ->
val list2 = args.getList(1, argc)
list1 + list2.filter { x -> list1.none { Iota.tolerates(x, it) } }.asActionResult
} }
)
val num1 = firstParam.left().get().roundToInt()
val num2 = args.getChecked<Double>(1, argc).roundToInt()
return (num1 or num2).asSpellResult
} }
} }

View file

@ -1,12 +1,24 @@
package at.petrak.hexcasting.common.casting.operators.math.bit package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.iota.Iota
object OpToSet : ConstManaOperator { object OpToSet : ConstManaAction {
override val argc = 1 override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return args.getChecked<SpellList>(0, argc).toSet().toList().asSpellResult val list = args.getList(0, argc)
val out = mutableListOf<Iota>()
for (subiota in list) {
if (out.none { Iota.tolerates(it, subiota) }) {
out.add(subiota)
}
}
return out.asActionResult
} }
} }

View file

@ -2,23 +2,32 @@ package at.petrak.hexcasting.common.casting.operators.math.bit
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import kotlin.math.roundToInt import at.petrak.hexcasting.api.spell.iota.Iota
object OpXor : ConstManaOperator { object OpXor : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val firstParam = numOrList(args[0], 0) val firstParam = args.getLongOrList(0, argc)
if (firstParam.right().isPresent) { return firstParam.map(
val list1 = firstParam.right().get() { num1 ->
val list2 = args.getChecked<SpellList>(1, argc) val num2 = args.getLong(1, argc)
val out = list1.filter { x1 -> list2.none(x1::tolerantEquals) } + list2.filter { x2 -> list1.none(x2::tolerantEquals) } (num1 xor num2).asActionResult
return out.asSpellResult },
{ list1 ->
val list2 = args.getList(1, argc)
val out =
list1.filter { x1 ->
list2.none {
Iota.tolerates(
x1,
it
)
} }
} + list2.filter { x2 -> list1.none { Iota.tolerates(x2, it) } }
val num1 = firstParam.left().get().roundToInt() out.asActionResult
val num2 = args.getChecked<Double>(1, argc).roundToInt() }
return (num1 xor num2).asSpellResult )
} }
} }

View file

@ -1,19 +1,15 @@
package at.petrak.hexcasting.common.casting.operators.math.logic package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
object OpBoolAnd : ConstManaOperator { object OpBoolAnd : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return listOf( return listOf(
if (args[0].payload == Widget.NULL) if (args[0].isTruthy) args[1] else args[0]
LegacySpellDatum.make(Widget.NULL)
else
args[1]
) )
} }
} }

View file

@ -1,23 +1,15 @@
package at.petrak.hexcasting.common.casting.operators.math.logic package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
object OpBoolIdentityKindOf : ConstManaOperator { // TODO we need a whole-ass cleanup of our truthiness
object OpBoolIdentityKindOf : ConstManaAction {
override val argc = 1 override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val payload = args[0].payload return (args[0].isTruthy).asActionResult
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,16 +1,14 @@
package at.petrak.hexcasting.common.casting.operators.math.logic package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.phys.Vec3 import at.petrak.hexcasting.api.spell.iota.Iota
object OpBoolNot : ConstManaOperator { object OpBoolNot : ConstManaAction {
override val argc = 1 override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val payload = args[0].payload return (!args[0].isTruthy).asActionResult
val falsy =
payload == Widget.NULL || payload.tolerantEquals(0.0) || payload.tolerantEquals(Vec3.ZERO) || (payload is SpellList && !payload.nonEmpty)
return falsy.asSpellResult
} }
} }

View file

@ -1,19 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math.logic package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
object OpBoolOr : ConstManaOperator { object OpBoolOr : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return listOf( return listOf(
if (args[0].payload == Widget.NULL) if (args[0].isTruthy)
args[1]
else
args[0] args[0]
else
args[1]
) )
} }
} }

View file

@ -1,21 +1,24 @@
package at.petrak.hexcasting.common.casting.operators.math.logic package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
object OpBoolXor : ConstManaOperator { object OpBoolXor : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val a = args[0]
val b = args[1]
return listOf( return listOf(
if (args[0].payload != Widget.NULL && args[1].payload == Widget.NULL) if (a.isTruthy && !b.isTruthy)
args[0] a
else if (args[0].payload == Widget.NULL && args[1].payload != Widget.NULL) else if (!a.isTruthy && b.isTruthy)
args[1] b
else else
LegacySpellDatum.make(Widget.NULL) NullIota.INSTANCE
) )
} }
} }

View file

@ -1,18 +1,22 @@
package at.petrak.hexcasting.common.casting.operators.math.logic package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota
import java.util.function.BiPredicate import java.util.function.BiPredicate
class OpCompare(val acceptsEqual: Boolean, val cmp: BiPredicate<Double, Double>) : ConstManaOperator { class OpCompare(val acceptsEqual: Boolean, val cmp: BiPredicate<Double, Double>) : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val lhs = args.getChecked<Double>(0, argc) val lhs = args.getDouble(0, argc)
val rhs = args.getChecked<Double>(1, argc) val rhs = args.getDouble(1, argc)
if (lhs.tolerantEquals(rhs)) if (DoubleIota.tolerates(lhs, rhs))
return acceptsEqual.asSpellResult return acceptsEqual.asActionResult
return cmp.test(lhs, rhs).asSpellResult return cmp.test(lhs, rhs).asActionResult
} }
} }

View file

@ -1,18 +1,17 @@
package at.petrak.hexcasting.common.casting.operators.math.logic package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.tolerantEquals import at.petrak.hexcasting.api.spell.iota.Iota
class OpEquality(val invert: Boolean) : ConstManaOperator { class OpEquality(val invert: Boolean) : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val lhs = args[0] val lhs = args[0]
val rhs = args[1] val rhs = args[1]
return (lhs.tolerantEquals(rhs) != invert).asSpellResult return (Iota.tolerates(lhs, rhs) != invert).asActionResult
} }
} }

View file

@ -1,26 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math.trig package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getDoubleBetween
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import kotlin.math.acos import kotlin.math.acos
object OpArcCos : ConstManaOperator { object OpArcCos : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val value = args.getChecked<Double>(0, argc) val value = args.getDoubleBetween(0, -1.0, 1.0, argc)
if (value < -1 || value > 1) return acos(value).asActionResult
throw MishapInvalidIota(
LegacySpellDatum.make(value),
0,
"hexcasting.mishap.invalid_value.double.between".asTranslatedComponent(-1, 1)
)
return acos(value).asSpellResult
} }
} }

View file

@ -1,26 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math.trig package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getDoubleBetween
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import kotlin.math.asin import kotlin.math.asin
object OpArcSin : ConstManaOperator { object OpArcSin : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val value = args.getChecked<Double>(0, argc) val value = args.getDoubleBetween(0, -1.0, 1.0, OpArcCos.argc)
if (value < -1 || value > 1) return asin(value).asActionResult
throw MishapInvalidIota(
LegacySpellDatum.make(value),
0,
"hexcasting.mishap.invalid_value.double.between".asTranslatedComponent(-1, 1)
)
return asin(value).asSpellResult
} }
} }

View file

@ -1,18 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math.trig package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.iota.Iota
import kotlin.math.atan import kotlin.math.atan
object OpArcTan : ConstManaOperator { object OpArcTan : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val value = args.getChecked<Double>(0, argc) val value = args.getDouble(0, argc)
return atan(value).asSpellResult return atan(value).asActionResult
} }
} }

View file

@ -0,0 +1,19 @@
package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.iota.Iota
import kotlin.math.atan2
object OpArcTan2 : ConstManaAction {
override val argc: Int
get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val y = args.getDouble(0, argc)
val x = args.getDouble(1, argc)
return atan2(y, x).asActionResult
}
}

View file

@ -1,18 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math.trig package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.iota.Iota
import kotlin.math.cos import kotlin.math.cos
object OpCos : ConstManaOperator { object OpCos : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val angle = args.getChecked<Double>(0, argc) val angle = args.getDouble(0, argc)
return cos(angle).asSpellResult return cos(angle).asActionResult
} }
} }

View file

@ -1,18 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.math.trig package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.iota.Iota
import kotlin.math.sin import kotlin.math.sin
object OpSin : ConstManaOperator { object OpSin : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val angle = args.getChecked<Double>(0, argc) val angle = args.getDouble(0, argc)
return sin(angle).asSpellResult return sin(angle).asActionResult
} }
} }

View file

@ -1,22 +1,23 @@
package at.petrak.hexcasting.common.casting.operators.math.trig package at.petrak.hexcasting.common.casting.operators.math.trig
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getDouble
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.tan import kotlin.math.tan
object OpTan : ConstManaOperator { object OpTan : ConstManaAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val angle = args.getChecked<Double>(0, argc) val angle = args.getDouble(0, argc)
if (cos(angle) == 0.0) if (cos(angle) == 0.0)
throw MishapDivideByZero.tan(angle) throw MishapDivideByZero.tan(args[0] as DoubleIota)
return tan(angle).asSpellResult return tan(angle).asActionResult
} }
} }

View file

@ -1,15 +1,15 @@
package at.petrak.hexcasting.common.casting.operators.selectors package at.petrak.hexcasting.common.casting.operators.selectors
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
object OpGetCaster : ConstManaOperator { object OpGetCaster : ConstManaAction {
override val argc = 0 override val argc = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
ctx.assertEntityInRange(ctx.caster) ctx.assertEntityInRange(ctx.caster)
return ctx.caster.asSpellResult return ctx.caster.asActionResult
} }
} }

View file

@ -1,12 +1,12 @@
package at.petrak.hexcasting.common.casting.operators.selectors package at.petrak.hexcasting.common.casting.operators.selectors
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.Operator.Companion.MAX_DISTANCE import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getPositiveDouble
import at.petrak.hexcasting.api.spell.spellListOf import at.petrak.hexcasting.api.spell.getVec3
import net.minecraft.util.Mth import at.petrak.hexcasting.api.spell.iota.EntityIota
import at.petrak.hexcasting.api.spell.iota.Iota
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.animal.Animal import net.minecraft.world.entity.animal.Animal
@ -18,29 +18,26 @@ import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
import java.util.function.Predicate import java.util.function.Predicate
class OpGetEntitiesBy(val checker: Predicate<Entity>, val negate: Boolean) : ConstManaOperator { class OpGetEntitiesBy(val checker: Predicate<Entity>, val negate: Boolean) : ConstManaAction {
override val argc = 2 override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val pos = args.getChecked<Vec3>(0, argc) val pos = args.getVec3(0, argc)
val maybeRadius = args.getChecked<Double>(1, argc) val radius = args.getPositiveDouble(1, argc)
ctx.assertVecInRange(pos) ctx.assertVecInRange(pos)
val radius = Mth.clamp(maybeRadius, 0.0, MAX_DISTANCE)
val aabb = AABB(pos.add(Vec3(-radius, -radius, -radius)), pos.add(Vec3(radius, radius, radius))) val aabb = AABB(pos.add(Vec3(-radius, -radius, -radius)), pos.add(Vec3(radius, radius, radius)))
val entitiesGot = ctx.world.getEntities( val entitiesGot = ctx.world.getEntities(null, aabb) {
null, isReasonablySelectable(ctx, it)
aabb && it.distanceToSqr(pos) <= radius * radius
) { && (checker.test(it) != negate)
(checker.test(it) != negate) && ctx.isEntityInRange(it) && it.isAlive && !it.isSpectator && it.distanceToSqr( }.sortedBy { it.distanceToSqr(pos) }
pos return entitiesGot.map(::EntityIota).asActionResult
) <= radius * radius
} }
.sortedBy { it.distanceToSqr(pos) }
return spellListOf(entitiesGot)
}
companion object { companion object {
fun isReasonablySelectable(ctx: CastingContext, e: Entity) =
ctx.isEntityInRange(e) && e.isAlive && !e.isSpectator
@JvmStatic @JvmStatic
fun isAnimal(e: Entity): Boolean = e is Animal || e is WaterAnimal fun isAnimal(e: Entity): Boolean = e is Animal || e is WaterAnimal

View file

@ -1,25 +1,26 @@
package at.petrak.hexcasting.common.casting.operators.selectors package at.petrak.hexcasting.common.casting.operators.selectors
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaAction
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.AABB import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
import java.util.function.Predicate import java.util.function.Predicate
class OpGetEntityAt(val checker: Predicate<Entity>) : ConstManaOperator { class OpGetEntityAt(val checker: Predicate<Entity>) : ConstManaAction {
override val argc = 1 override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> { override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val pos = args.getChecked<Vec3>(0, argc) val pos = args.getVec3(0, argc)
ctx.assertVecInRange(pos) 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 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) val entitiesGot = ctx.world.getEntities(null, aabb) {
{ checker.test(it) && ctx.isEntityInRange(it) && it.isAlive && !it.isSpectator } OpGetEntitiesBy.isReasonablySelectable(ctx, it) && checker.test(it)
}.sortedBy { it.distanceToSqr(pos) }
val entity = entitiesGot.getOrNull(0) val entity = entitiesGot.getOrNull(0)
return entity.asSpellResult return entity.asActionResult
} }
} }

View file

@ -5,12 +5,12 @@ import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpAddMotion : SpellOperator { object OpAddMotion : SpellAction {
override val argc: Int override val argc: Int
get() = 2 get() = 2

View file

@ -5,14 +5,14 @@ import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.common.network.MsgBeepAck import at.petrak.hexcasting.common.network.MsgBeepAck
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument import net.minecraft.world.level.block.state.properties.NoteBlockInstrument
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpBeep : SpellOperator { object OpBeep : SpellAction {
override val argc = 3 override val argc = 3
override fun execute( override fun execute(

View file

@ -12,7 +12,7 @@ import net.minecraft.world.entity.Entity
import kotlin.math.max import kotlin.math.max
import kotlin.math.roundToInt import kotlin.math.roundToInt
object OpBlink : SpellOperator { object OpBlink : SpellAction {
override val argc = 2 override val argc = 2
override fun execute( override fun execute(
args: List<Iota>, args: List<Iota>,

View file

@ -8,7 +8,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpBreakBlock : SpellOperator { object OpBreakBlock : SpellAction {
override val argc: Int override val argc: Int
get() = 1 get() = 1

View file

@ -5,12 +5,12 @@ import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
object OpColorize : SpellOperator { object OpColorize : SpellAction {
override val argc = 0 override val argc = 0
override fun execute( override fun execute(

View file

@ -13,7 +13,7 @@ import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.context.DirectionalPlaceContext import net.minecraft.world.item.context.DirectionalPlaceContext
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
class OpConjure(val light: Boolean) : SpellOperator { class OpConjure(val light: Boolean) : SpellAction {
override val argc = 1 override val argc = 1
override fun execute( override fun execute(
args: List<Iota>, args: List<Iota>,

View file

@ -15,7 +15,7 @@ import net.minecraft.world.level.block.LayeredCauldronBlock
import net.minecraft.world.level.material.Fluids import net.minecraft.world.level.material.Fluids
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpCreateWater : SpellOperator { object OpCreateWater : SpellAction {
override val argc = 1 override val argc = 1
override fun execute( override fun execute(
args: List<Iota>, args: List<Iota>,

View file

@ -17,7 +17,7 @@ import net.minecraft.world.level.material.Fluids
import net.minecraft.world.level.material.Material import net.minecraft.world.level.material.Material
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpDestroyWater : SpellOperator { object OpDestroyWater : SpellAction {
override val argc = 1 override val argc = 1
override fun execute( override fun execute(
args: List<Iota>, args: List<Iota>,
@ -53,7 +53,7 @@ object OpDestroyWater : SpellOperator {
val here = todo.removeFirst() val here = todo.removeFirst()
val distFromFocus = val distFromFocus =
ctx.caster.position().distanceToSqr(Vec3.atCenterOf(here)) ctx.caster.position().distanceToSqr(Vec3.atCenterOf(here))
if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here) && ctx.world.mayInteract(ctx.caster, here)) { if (distFromFocus < Action.MAX_DISTANCE * Action.MAX_DISTANCE && seen.add(here) && ctx.world.mayInteract(ctx.caster, here)) {
// never seen this pos in my life // never seen this pos in my life
val fluid = ctx.world.getFluidState(here) val fluid = ctx.world.getFluidState(here)
if (fluid != Fluids.EMPTY.defaultFluidState()) { if (fluid != Fluids.EMPTY.defaultFluidState()) {

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadBlock import at.petrak.hexcasting.api.spell.mishaps.MishapBadBlock
import at.petrak.hexcasting.common.misc.AkashicTreeGrower import at.petrak.hexcasting.common.misc.AkashicTreeGrower
@ -13,7 +13,7 @@ import net.minecraft.core.BlockPos
import net.minecraft.tags.BlockTags import net.minecraft.tags.BlockTags
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
object OpEdifySapling : SpellOperator { object OpEdifySapling : SpellAction {
override val argc = 1 override val argc = 1
override fun execute( override fun execute(

View file

@ -4,12 +4,12 @@ import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.iota.Iota import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
class OpErase : SpellOperator { class OpErase : SpellAction {
override val argc = 0 override val argc = 0
override fun execute( override fun execute(

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