who am i, wire? converted all non-spell actions to the new iotas
This commit is contained in:
parent
71c3cade9b
commit
2917a3b358
133 changed files with 953 additions and 852 deletions
|
@ -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 "Pattern" is a [`HexPattern`](api/spell/math/HexPattern.kt)
|
||||
- An "Action" is an [`Operator`](api/spell/Operator.kt)
|
||||
- An action that pushes a spell is a [`Spell`](api/spell/SpellOperator.kt)
|
||||
- An "Action" is an [`Operator`](api/spell/Action.kt)
|
||||
- An action that pushes a spell is a [`Spell`](api/spell/SpellAction.kt)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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.HexDir
|
||||
import at.petrak.hexcasting.api.spell.math.HexPattern
|
||||
|
@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentMap
|
|||
* operator (the diamond) are `"qaq"` and `"ede"`.
|
||||
*/
|
||||
object PatternRegistry {
|
||||
private val operatorLookup = ConcurrentHashMap<ResourceLocation, Operator>()
|
||||
private val actionLookup = ConcurrentHashMap<ResourceLocation, Action>()
|
||||
private val specialHandlers: ConcurrentLinkedDeque<SpecialHandlerEntry> = ConcurrentLinkedDeque()
|
||||
|
||||
// Map signatures to the "preferred" direction they start in and their operator ID.
|
||||
|
@ -41,12 +41,12 @@ object PatternRegistry {
|
|||
@JvmStatic
|
||||
@JvmOverloads
|
||||
@Throws(RegisterPatternException::class)
|
||||
fun mapPattern(pattern: HexPattern, id: ResourceLocation, operator: Operator, isPerWorld: Boolean = false) {
|
||||
this.operatorLookup[id]?.let {
|
||||
fun mapPattern(pattern: HexPattern, id: ResourceLocation, action: Action, isPerWorld: Boolean = false) {
|
||||
this.actionLookup[id]?.let {
|
||||
throw RegisterPatternException("The operator with id `$id` was already registered to: $it")
|
||||
}
|
||||
|
||||
this.operatorLookup[id] = operator
|
||||
this.actionLookup[id] = action
|
||||
if (isPerWorld) {
|
||||
this.perWorldPatternLookup[id] = PerWorldEntry(pattern, id)
|
||||
} else {
|
||||
|
@ -73,14 +73,14 @@ object PatternRegistry {
|
|||
* Internal use only.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun matchPattern(pat: HexPattern, overworld: ServerLevel): Operator =
|
||||
fun matchPattern(pat: HexPattern, overworld: ServerLevel): Action =
|
||||
matchPatternAndID(pat, overworld).first
|
||||
|
||||
/**
|
||||
* Internal use only.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun matchPatternAndID(pat: HexPattern, overworld: ServerLevel): Pair<Operator, ResourceLocation> {
|
||||
fun matchPatternAndID(pat: HexPattern, overworld: ServerLevel): Pair<Action, ResourceLocation> {
|
||||
// Pipeline:
|
||||
// patterns are registered here every time the game boots
|
||||
// when we try to look
|
||||
|
@ -92,7 +92,7 @@ object PatternRegistry {
|
|||
// Is it global?
|
||||
val sig = pat.anglesSignature()
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ object PatternRegistry {
|
|||
val perWorldPatterns: Save =
|
||||
ds.computeIfAbsent(Save.Companion::load, { Save.create(overworld.seed) }, TAG_SAVED_DATA)
|
||||
perWorldPatterns.lookup[sig]?.let {
|
||||
val op = this.operatorLookup[it.first]!!
|
||||
val op = this.actionLookup[it.first]!!
|
||||
return op to it.first
|
||||
}
|
||||
|
||||
|
@ -125,12 +125,12 @@ object PatternRegistry {
|
|||
@JvmStatic
|
||||
fun lookupPattern(opId: ResourceLocation): PatternEntry {
|
||||
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) {
|
||||
if (entry.opId == opId) {
|
||||
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.
|
||||
*/
|
||||
fun interface SpecialHandler {
|
||||
fun handlePattern(pattern: HexPattern): Operator?
|
||||
fun handlePattern(pattern: HexPattern): Action?
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
// 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
|
||||
|
|
|
@ -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
|
||||
* 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.
|
||||
*/
|
||||
interface Operator {
|
||||
interface Action {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
val alwaysProcessGreatSpell: Boolean get() = this is SpellOperator
|
||||
val alwaysProcessGreatSpell: Boolean get() = this is SpellAction
|
||||
|
||||
/**
|
||||
* Can this Great Pattern give you Blind Diversion?
|
||||
*/
|
||||
val causesBlindDiversion: Boolean get() = this is SpellOperator
|
||||
val causesBlindDiversion: Boolean get() = this is SpellAction
|
||||
|
||||
companion object {
|
||||
// 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))
|
||||
|
||||
@JvmStatic
|
||||
fun makeConstantOp(x: Iota): Operator = object : ConstManaOperator {
|
||||
fun makeConstantOp(x: Iota): Action = object : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 0
|
||||
|
|
@ -9,7 +9,7 @@ import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
|
|||
/**
|
||||
* A SimpleOperator that always costs the same amount of mana.
|
||||
*/
|
||||
interface ConstManaOperator : Operator {
|
||||
interface ConstManaAction : Action {
|
||||
val argc: Int
|
||||
val manaCost: Int
|
||||
get() = 0
|
||||
|
@ -25,7 +25,7 @@ interface ConstManaOperator : Operator {
|
|||
if (this.argc > stack.size)
|
||||
throw MishapNotEnoughArgs(this.argc, stack.size)
|
||||
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)
|
||||
stack.addAll(newData)
|
||||
|
|
@ -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.mishaps.MishapInvalidIota
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
|
||||
import at.petrak.hexcasting.api.utils.asTranslatedComponent
|
||||
import com.mojang.datafixers.util.Either
|
||||
import com.mojang.math.Vector3f
|
||||
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.npc.Villager
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import java.util.function.DoubleUnaryOperator
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
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 {
|
||||
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
|
||||
if (x is DoubleIota) {
|
||||
return x.double
|
||||
} else {
|
||||
// TODO: I'm not sure this calculation is correct
|
||||
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")
|
||||
}
|
||||
|
||||
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) }
|
||||
if (x is DoubleIota) {
|
||||
val double = x.double
|
||||
|
@ -172,7 +151,7 @@ fun List<Iota>.getLong(idx: Int, argc: Int = 0): Long {
|
|||
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 {
|
||||
|
@ -180,11 +159,23 @@ fun List<Iota>.getPositiveInt(idx: Int, argc: Int = 0): Int {
|
|||
if (x is DoubleIota) {
|
||||
val double = x.double
|
||||
val rounded = double.roundToInt()
|
||||
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded > 0) {
|
||||
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded >= 0) {
|
||||
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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
inline val Boolean.asSpellResult get() = listOf(DoubleIota(if (this) 1.0 else 0.0))
|
||||
inline val Double.asSpellResult get() = listOf(DoubleIota(this))
|
||||
inline val Number.asSpellResult get() = listOf(DoubleIota(this.toDouble()))
|
||||
fun List<Iota>.getBlockPos(idx: Int, argc: Int = 0): BlockPos {
|
||||
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
|
||||
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))
|
||||
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "vector")
|
||||
}
|
||||
|
||||
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
|
||||
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))
|
||||
|
|
|
@ -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.mishaps.MishapNotEnoughArgs
|
||||
|
||||
interface SpellOperator : Operator {
|
||||
interface SpellAction : Action {
|
||||
val argc: Int
|
||||
|
||||
fun hasCastingSound(ctx: CastingContext): Boolean = true
|
|
@ -69,6 +69,19 @@ sealed class SpellList : Iterable<Iota> {
|
|||
|
||||
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> {
|
||||
override fun hasNext() = list.nonEmpty
|
||||
override operator fun next(): Iota {
|
||||
|
|
|
@ -2,7 +2,7 @@ package at.petrak.hexcasting.api.spell.casting
|
|||
|
||||
import at.petrak.hexcasting.api.HexAPI.modLoc
|
||||
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.MishapEvalTooDeep
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway
|
||||
|
@ -76,6 +76,10 @@ data class CastingContext(
|
|||
assertVecInWorld(vec)
|
||||
}
|
||||
|
||||
fun assertVecInRange(pos: BlockPos) {
|
||||
assertVecInRange(Vec3.atCenterOf(pos))
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to make sure an entity is in range. Will not mishap for players.
|
||||
*/
|
||||
|
@ -94,7 +98,7 @@ data class CastingContext(
|
|||
if (sentinel.hasSentinel
|
||||
&& sentinel.extendsRange
|
||||
&& 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
|
||||
|
||||
|
@ -107,7 +111,7 @@ data class CastingContext(
|
|||
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 false
|
||||
|
|
|
@ -8,7 +8,7 @@ import at.petrak.hexcasting.api.misc.HexDamageSources
|
|||
import at.petrak.hexcasting.api.mod.HexConfig
|
||||
import at.petrak.hexcasting.api.mod.HexItemTags
|
||||
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.SpellList
|
||||
import at.petrak.hexcasting.api.spell.Widget
|
||||
|
@ -141,19 +141,19 @@ class CastingHarness private constructor(
|
|||
* handle it functionally.
|
||||
*/
|
||||
fun updateWithPattern(newPat: HexPattern, world: ServerLevel, continuation: SpellContinuation): CastResult {
|
||||
var operatorIdPair: Pair<Operator, ResourceLocation>? = null
|
||||
var actionIdPair: Pair<Action, ResourceLocation>? = null
|
||||
try {
|
||||
// Don't catch this one
|
||||
operatorIdPair = PatternRegistry.matchPatternAndID(newPat, world)
|
||||
if (this.ctx.spellCircle == null && !HexConfig.server().isActionAllowed(operatorIdPair.second)) {
|
||||
actionIdPair = PatternRegistry.matchPatternAndID(newPat, world)
|
||||
if (this.ctx.spellCircle == null && !HexConfig.server().isActionAllowed(actionIdPair.second)) {
|
||||
throw MishapDisallowedSpell()
|
||||
} else if (this.ctx.spellCircle != null
|
||||
&& !HexConfig.server().isActionAllowedInCircles(operatorIdPair.second)
|
||||
&& !HexConfig.server().isActionAllowedInCircles(actionIdPair.second)
|
||||
) {
|
||||
throw MishapDisallowedSpell("disallowed_circle")
|
||||
}
|
||||
|
||||
val pattern = operatorIdPair.first
|
||||
val pattern = actionIdPair.first
|
||||
|
||||
val unenlightened = pattern.isGreat && !ctx.isCasterEnlightened
|
||||
|
||||
|
@ -208,7 +208,7 @@ class CastingHarness private constructor(
|
|||
continuation,
|
||||
null,
|
||||
mishap.resolutionType(ctx),
|
||||
listOf(OperatorSideEffect.DoMishap(mishap, Mishap.Context(newPat, operatorIdPair?.second))),
|
||||
listOf(OperatorSideEffect.DoMishap(mishap, Mishap.Context(newPat, actionIdPair?.second))),
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
|
@ -219,7 +219,7 @@ class CastingHarness private constructor(
|
|||
listOf(
|
||||
OperatorSideEffect.DoMishap(
|
||||
MishapError(exception),
|
||||
Mishap.Context(newPat, operatorIdPair?.second)
|
||||
Mishap.Context(newPat, actionIdPair?.second)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -20,11 +20,20 @@ public class DoubleIota extends Iota {
|
|||
return HexUtils.fixNAN((Double) this.payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTruthy() {
|
||||
return this.getDouble() != 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toleratesOther(Iota that) {
|
||||
return typesMatch(this, that)
|
||||
&& 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
|
||||
|
|
|
@ -22,6 +22,11 @@ public class GarbageIota extends Iota {
|
|||
super(HexIotaTypes.GARBAGE, NULL_SUBSTITUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTruthy() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toleratesOther(Iota that) {
|
||||
return typesMatch(this, that);
|
||||
|
|
|
@ -16,14 +16,20 @@ public abstract class Iota {
|
|||
this.payload = payload;
|
||||
}
|
||||
|
||||
public @NotNull Object getPayload() {
|
||||
public @NotNull
|
||||
Object getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public @NotNull IotaType<?> getType() {
|
||||
public @NotNull
|
||||
IotaType<?> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean isTruthy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare this to another object, within a tolerance.
|
||||
* <p>
|
||||
|
@ -36,7 +42,8 @@ public abstract class Iota {
|
|||
* <p>
|
||||
* 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() {
|
||||
return this.type.display(this.serialize());
|
||||
|
|
|
@ -30,6 +30,11 @@ public class ListIota extends Iota {
|
|||
return (SpellList) this.payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTruthy() {
|
||||
return this.getList().getNonEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toleratesOther(Iota that) {
|
||||
if (!typesMatch(this, that)) {
|
||||
|
|
|
@ -22,6 +22,11 @@ public class NullIota extends Iota {
|
|||
super(HexIotaTypes.NULL, NULL_SUBSTITUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTruthy() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toleratesOther(Iota that) {
|
||||
return typesMatch(this, that);
|
||||
|
|
|
@ -2,8 +2,7 @@ package at.petrak.hexcasting.common.casting;
|
|||
|
||||
import at.petrak.hexcasting.api.PatternRegistry;
|
||||
import at.petrak.hexcasting.api.misc.ManaConstants;
|
||||
import at.petrak.hexcasting.api.spell.Operator;
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota;
|
||||
import at.petrak.hexcasting.api.spell.Action;
|
||||
import at.petrak.hexcasting.api.spell.Widget;
|
||||
import at.petrak.hexcasting.api.spell.math.HexAngle;
|
||||
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("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"),
|
||||
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"),
|
||||
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"),
|
||||
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"),
|
||||
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"),
|
||||
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.
|
||||
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"),
|
||||
Operator.makeConstantOp(LegacySpellDatum.make(Math.PI)));
|
||||
Action.makeConstantOp(LegacySpellDatum.make(Math.PI)));
|
||||
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
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aaq", HexDir.EAST), modLoc("const/double/e"),
|
||||
Operator.makeConstantOp(LegacySpellDatum.make(Math.E)));
|
||||
Action.makeConstantOp(LegacySpellDatum.make(Math.E)));
|
||||
|
||||
// == Entities ==
|
||||
|
||||
|
@ -490,7 +489,7 @@ public class RegisterPatterns {
|
|||
if (negate) {
|
||||
accumulator = -accumulator;
|
||||
}
|
||||
return Operator.makeConstantOp(LegacySpellDatum.make(accumulator));
|
||||
return Action.makeConstantOp(LegacySpellDatum.make(accumulator));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
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.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.phys.HitResult
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpBlockAxisRaycast : ConstManaOperator {
|
||||
object OpBlockAxisRaycast : ConstManaAction {
|
||||
override val argc = 2
|
||||
override val manaCost = ManaConstants.DUST_UNIT / 100
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val origin: Vec3 = args.getChecked(0, argc)
|
||||
val look: Vec3 = args.getChecked(1, argc)
|
||||
val origin = args.getVec3(0, argc)
|
||||
val look = args.getVec3(1, argc)
|
||||
|
||||
val blockHitResult = ctx.world.clip(
|
||||
ClipContext(
|
||||
origin,
|
||||
Operator.raycastEnd(origin, look),
|
||||
Action.raycastEnd(origin, look),
|
||||
ClipContext.Block.COLLIDER,
|
||||
ClipContext.Fluid.NONE,
|
||||
ctx.caster
|
||||
|
@ -25,9 +29,9 @@ object OpBlockAxisRaycast : ConstManaOperator {
|
|||
)
|
||||
|
||||
return if (blockHitResult.type == HitResult.Type.BLOCK) {
|
||||
blockHitResult.direction.step().asSpellResult
|
||||
blockHitResult.direction.step().asActionResult
|
||||
} else {
|
||||
null.asSpellResult
|
||||
listOf(NullIota.INSTANCE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
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.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.phys.HitResult
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpBlockRaycast : ConstManaOperator {
|
||||
object OpBlockRaycast : ConstManaAction {
|
||||
override val argc = 2
|
||||
override val manaCost = ManaConstants.DUST_UNIT / 100
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val origin: Vec3 = args.getChecked(0, argc)
|
||||
val look: Vec3 = args.getChecked(1, argc)
|
||||
val origin = args.getVec3(0, argc)
|
||||
val look = args.getVec3(1, argc)
|
||||
|
||||
val blockHitResult = ctx.world.clip(
|
||||
ClipContext(
|
||||
origin,
|
||||
Operator.raycastEnd(origin, look),
|
||||
Action.raycastEnd(origin, look),
|
||||
ClipContext.Block.COLLIDER,
|
||||
ClipContext.Fluid.NONE,
|
||||
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
|
||||
// this is weird (for example, casting OpBreakBlock at this position will not break the block we're looking at)
|
||||
// so we return the block pos instead
|
||||
blockHitResult.blockPos.asSpellResult
|
||||
// TODO some action that has the "weird" version?
|
||||
blockHitResult.blockPos.asActionResult
|
||||
} else {
|
||||
Widget.NULL.asSpellResult
|
||||
listOf(NullIota.INSTANCE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import net.minecraft.world.entity.Entity
|
||||
import at.petrak.hexcasting.api.spell.getEntity
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpEntityHeight : ConstManaOperator {
|
||||
object OpEntityHeight : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
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)
|
||||
return e.bbHeight.asSpellResult
|
||||
return e.bbHeight.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import net.minecraft.world.entity.Entity
|
||||
import at.petrak.hexcasting.api.spell.getEntity
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpEntityLook : ConstManaOperator {
|
||||
object OpEntityLook : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
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)
|
||||
return e.lookAngle.asSpellResult
|
||||
return e.lookAngle.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import net.minecraft.world.entity.Entity
|
||||
import at.petrak.hexcasting.api.spell.getEntity
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import net.minecraft.world.entity.player.Player
|
||||
|
||||
object OpEntityPos : ConstManaOperator {
|
||||
object OpEntityPos : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
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)
|
||||
// If this is a player, "expected behavior" is to get the *eye* position so raycasts don't immediately
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
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.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.phys.AABB
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpEntityRaycast : ConstManaOperator {
|
||||
object OpEntityRaycast : ConstManaAction {
|
||||
override val argc = 2
|
||||
override val manaCost = ManaConstants.DUST_UNIT / 100
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val origin: Vec3 = args.getChecked(0, argc)
|
||||
val look: Vec3 = args.getChecked(1, argc)
|
||||
val endp = Operator.raycastEnd(origin, look)
|
||||
val origin = args.getVec3(0, argc)
|
||||
val look = args.getVec3(1, argc)
|
||||
val endp = Action.raycastEnd(origin, look)
|
||||
|
||||
val entityHitResult = ProjectileUtil.getEntityHitResult(
|
||||
ctx.caster,
|
||||
|
@ -25,9 +29,9 @@ object OpEntityRaycast : ConstManaOperator {
|
|||
)
|
||||
|
||||
return if (entityHitResult != null && ctx.isEntityInRange(entityHitResult.entity)) {
|
||||
entityHitResult.entity.asSpellResult
|
||||
entityHitResult.entity.asActionResult
|
||||
} else {
|
||||
null.asSpellResult
|
||||
listOf(NullIota.INSTANCE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.getEntity
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.common.misc.PlayerPositionRecorder
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.world.entity.Entity
|
||||
|
||||
object OpEntityVelocity : ConstManaOperator {
|
||||
object OpEntityVelocity : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
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)
|
||||
|
||||
// Player velocity is jank. Really jank. This is the best we can do.
|
||||
if (e is ServerPlayer) {
|
||||
return PlayerPositionRecorder.getMotion(e).asSpellResult
|
||||
return PlayerPositionRecorder.getMotion(e).asActionResult
|
||||
}
|
||||
|
||||
return e.deltaMovement.asSpellResult
|
||||
return e.deltaMovement.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
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.mishaps.MishapBadOffhandItem
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||
|
||||
object OpRead : ConstManaOperator {
|
||||
object OpRead : ConstManaAction {
|
||||
override val argc = 0
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.iota.Iota
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||
|
||||
object OpReadable : ConstManaOperator {
|
||||
object OpReadable : ConstManaAction {
|
||||
override val argc = 0
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
|
@ -15,12 +15,12 @@ object OpReadable : ConstManaOperator {
|
|||
}
|
||||
|
||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
||||
?: return false.asSpellResult
|
||||
?: return false.asActionResult
|
||||
|
||||
datumHolder.readIota(ctx.world)
|
||||
?: datumHolder.emptyIota()
|
||||
?: return false.asSpellResult
|
||||
?: return false.asActionResult
|
||||
|
||||
return true.asSpellResult
|
||||
return true.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
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.xplat.IXplatAbstractions
|
||||
import net.minecraft.world.entity.item.ItemEntity
|
||||
|
||||
object OpTheCoolerRead : ConstManaOperator {
|
||||
object OpTheCoolerRead : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
override fun execute(
|
||||
args: List<Iota>,
|
||||
ctx: CastingContext
|
||||
): List<Iota> {
|
||||
val target = args.getChecked<ItemEntity>(0, argc)
|
||||
val target = args.getItemEntity(0, argc)
|
||||
|
||||
ctx.assertEntityInRange(target)
|
||||
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.getItemEntity
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||
import net.minecraft.world.entity.item.ItemEntity
|
||||
|
||||
object OpTheCoolerReadable : ConstManaOperator {
|
||||
object OpTheCoolerReadable : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
override fun execute(
|
||||
args: List<Iota>,
|
||||
ctx: CastingContext
|
||||
): List<Iota> {
|
||||
val target = args.getChecked<ItemEntity>(0, argc)
|
||||
val target = args.getItemEntity(0, argc)
|
||||
ctx.assertEntityInRange(target)
|
||||
|
||||
val stack = target.item
|
||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack)
|
||||
?: return false.asSpellResult
|
||||
?: return false.asActionResult
|
||||
|
||||
if (datumHolder.readIota(ctx.world) == null && datumHolder.emptyIota() == null)
|
||||
return false.asSpellResult
|
||||
return false.asActionResult
|
||||
|
||||
return true.asSpellResult
|
||||
return true.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package at.petrak.hexcasting.common.casting.operators
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||
|
||||
object OpWritable : ConstManaOperator {
|
||||
object OpWritable : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
|
@ -19,15 +19,15 @@ object OpWritable : ConstManaOperator {
|
|||
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))
|
||||
return false.asSpellResult
|
||||
return false.asActionResult
|
||||
|
||||
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)
|
||||
if (trueName != null)
|
||||
return false.asSpellResult
|
||||
return false.asActionResult
|
||||
|
||||
return true.asSpellResult
|
||||
return true.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
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.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.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
|
||||
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
|
||||
object OpWrite : SpellOperator {
|
||||
object OpWrite : SpellAction {
|
||||
override val argc = 1
|
||||
override fun execute(
|
||||
args: List<Iota>,
|
||||
|
|
|
@ -1,32 +1,29 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.akashic
|
||||
|
||||
import at.petrak.hexcasting.api.misc.ManaConstants
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.Widget
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.getChecked
|
||||
import at.petrak.hexcasting.api.spell.math.HexPattern
|
||||
import at.petrak.hexcasting.api.spell.getBlockPos
|
||||
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.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 manaCost = ManaConstants.DUST_UNIT
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val pos = args.getChecked<Vec3>(0, argc)
|
||||
val key = args.getChecked<HexPattern>(1, argc)
|
||||
val pos = args.getBlockPos(0, argc)
|
||||
val key = args.getPattern(1, argc)
|
||||
|
||||
val bpos = BlockPos(pos)
|
||||
val tile = ctx.world.getBlockEntity(bpos)
|
||||
val tile = ctx.world.getBlockEntity(pos)
|
||||
if (tile !is BlockEntityAkashicRecord) {
|
||||
throw MishapNoAkashicRecord(bpos)
|
||||
throw MishapNoAkashicRecord(pos)
|
||||
}
|
||||
|
||||
val datum = tile.lookupPattern(key, ctx.world)
|
||||
return listOf(datum ?: LegacySpellDatum.make(Widget.NULL))
|
||||
return listOf(datum ?: NullIota.INSTANCE)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,15 @@ package at.petrak.hexcasting.common.casting.operators.akashic
|
|||
import at.petrak.hexcasting.api.misc.ManaConstants
|
||||
import at.petrak.hexcasting.api.spell.*
|
||||
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.mishaps.MishapNoAkashicRecord
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
|
||||
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicRecord
|
||||
import at.petrak.hexcasting.common.lib.HexSounds
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpAkashicWrite : SpellOperator {
|
||||
object OpAkashicWrite : SpellAction {
|
||||
override val argc = 3
|
||||
|
||||
override val isGreat = true
|
||||
|
@ -23,16 +22,15 @@ object OpAkashicWrite : SpellOperator {
|
|||
args: List<Iota>,
|
||||
ctx: CastingContext
|
||||
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
|
||||
val pos = args.getChecked<Vec3>(0, argc)
|
||||
val key = args.getChecked<HexPattern>(1, argc)
|
||||
val datum = args[2]
|
||||
val pos = args.getBlockPos(0, argc)
|
||||
val key = args.getPattern(1, argc)
|
||||
val datum = args.get(2)
|
||||
|
||||
ctx.assertVecInRange(pos)
|
||||
|
||||
val bpos = BlockPos(pos)
|
||||
val tile = ctx.world.getBlockEntity(bpos)
|
||||
val tile = ctx.world.getBlockEntity(pos)
|
||||
if (tile !is BlockEntityAkashicRecord) {
|
||||
throw MishapNoAkashicRecord(bpos)
|
||||
throw MishapNoAkashicRecord(pos)
|
||||
}
|
||||
|
||||
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
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.mishaps.MishapNoSpellCircle
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
class OpCircleBounds(val max: Boolean) : ConstManaOperator {
|
||||
class OpCircleBounds(val max: Boolean) : ConstManaAction {
|
||||
override val argc = 0
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.circles
|
||||
|
||||
import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.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.mishaps.MishapNoSpellCircle
|
||||
|
||||
object OpImpetusDir : ConstManaOperator {
|
||||
object OpImpetusDir : ConstManaAction {
|
||||
override val argc = 0
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.circles
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
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 net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpImpetusPos : ConstManaOperator {
|
||||
object OpImpetusPos : ConstManaAction {
|
||||
override val argc = 0
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
if (ctx.spellCircle == null)
|
||||
throw MishapNoSpellCircle()
|
||||
|
||||
return Vec3.atCenterOf(ctx.spellCircle.impetusPos).asSpellResult
|
||||
return ctx.spellCircle.impetusPos.asSpellResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,32 @@
|
|||
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.ContinuationFrame
|
||||
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 {
|
||||
override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, local: Iota, ctx: CastingContext): OperationResult {
|
||||
val instrs: SpellList = stack.getChecked(stack.lastIndex)
|
||||
object OpEval : Action {
|
||||
override fun operate(
|
||||
continuation: SpellContinuation,
|
||||
stack: MutableList<Iota>,
|
||||
local: Iota,
|
||||
ctx: CastingContext
|
||||
): OperationResult {
|
||||
val instrs = stack.getList(stack.lastIndex)
|
||||
stack.removeLastOrNull()
|
||||
|
||||
ctx.incDepth()
|
||||
|
||||
// if not installed already...
|
||||
val newCont = if (continuation is SpellContinuation.NotDone && continuation.frame is ContinuationFrame.FinishEval) {
|
||||
continuation
|
||||
} else {
|
||||
continuation.pushFrame(ContinuationFrame.FinishEval) // install a break-boundary after eval
|
||||
}
|
||||
val newCont =
|
||||
if (continuation is SpellContinuation.NotDone && continuation.frame is ContinuationFrame.FinishEval) {
|
||||
continuation
|
||||
} else {
|
||||
continuation.pushFrame(ContinuationFrame.FinishEval) // install a break-boundary after eval
|
||||
}
|
||||
|
||||
val frame = ContinuationFrame.Evaluate(instrs)
|
||||
return OperationResult(newCont.pushFrame(frame), stack, local, listOf())
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.eval
|
||||
|
||||
import at.petrak.hexcasting.api.spell.OperationResult
|
||||
import at.petrak.hexcasting.api.spell.Operator
|
||||
import at.petrak.hexcasting.api.spell.Action
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
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 {
|
||||
return OperationResult(continuation, stack, local, listOf())
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
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.ContinuationFrame
|
||||
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
|
||||
|
||||
object OpForEach : Operator {
|
||||
object OpForEach : Action {
|
||||
override fun operate(
|
||||
continuation: SpellContinuation,
|
||||
stack: MutableList<Iota>,
|
||||
|
@ -16,8 +19,8 @@ object OpForEach : Operator {
|
|||
if (stack.size < 2)
|
||||
throw MishapNotEnoughArgs(2, stack.size)
|
||||
|
||||
val instrs: SpellList = stack.getChecked(stack.lastIndex - 1)
|
||||
val datums: SpellList = stack.getChecked(stack.lastIndex)
|
||||
val instrs = stack.getList(stack.lastIndex - 1)
|
||||
val datums = stack.getList(stack.lastIndex)
|
||||
stack.removeLastOrNull()
|
||||
stack.removeLastOrNull()
|
||||
|
||||
|
|
|
@ -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.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.SpellContinuation
|
||||
|
||||
object OpHalt : Operator {
|
||||
object OpHalt : Action {
|
||||
override fun operate(
|
||||
continuation: SpellContinuation,
|
||||
stack: MutableList<Iota>,
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
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.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 fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val list = args.getChecked<SpellList>(0, argc).toMutableList()
|
||||
val datum = args[1]
|
||||
val list = args.getList(0, argc).toMutableList()
|
||||
val datum = args.getIota(1)
|
||||
list.add(datum)
|
||||
return list.asSpellResult
|
||||
return list.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
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.getList
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpConcat : ConstManaOperator {
|
||||
object OpConcat : ConstManaAction {
|
||||
override val argc = 2
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val lhs = args.getChecked<SpellList>(0, argc).toMutableList()
|
||||
val rhs = args.getChecked<SpellList>(1, argc)
|
||||
val lhs = args.getList(0, argc).toMutableList()
|
||||
val rhs = args.getList(1, argc)
|
||||
lhs.addAll(rhs)
|
||||
return lhs.asSpellResult
|
||||
return lhs.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
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.getList
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpCons : ConstManaOperator {
|
||||
object OpCons : ConstManaAction {
|
||||
override val argc = 2
|
||||
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]
|
||||
return SpellList.LPair(top, bottom).asSpellResult
|
||||
return SpellList.LPair(top, bottom).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.lists
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
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
|
||||
|
||||
object OpEmptyList : ConstManaOperator {
|
||||
object OpEmptyList : ConstManaAction {
|
||||
override val argc = 0
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
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.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
|
||||
|
||||
object OpIndex : ConstManaOperator {
|
||||
object OpIndex : ConstManaAction {
|
||||
override val argc = 2
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val list = args.getChecked<SpellList>(0, argc).toMutableList()
|
||||
val index = args.getChecked<Double>(1, argc)
|
||||
val x = list.getOrElse(index.roundToInt()) { LegacySpellDatum.make(Widget.NULL) }
|
||||
val list = args.getList(0, argc).toMutableList()
|
||||
val index = args.getDouble(1, argc)
|
||||
val x = list.getOrElse(index.roundToInt()) { NullIota.INSTANCE }
|
||||
return listOf(x)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
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.getList
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpIndexOf : ConstManaOperator {
|
||||
object OpIndexOf : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
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]
|
||||
return list.indexOfFirst(value::tolerantEquals).asSpellResult
|
||||
return list.indexOfFirst { Iota.tolerates(value, it) }.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,32 @@
|
|||
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.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.utils.asTranslatedComponent
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OpLastNToList : Operator {
|
||||
override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, local: Iota, ctx: CastingContext): OperationResult {
|
||||
object OpLastNToList : Action {
|
||||
override fun operate(
|
||||
continuation: SpellContinuation,
|
||||
stack: MutableList<Iota>,
|
||||
local: Iota,
|
||||
ctx: CastingContext
|
||||
): OperationResult {
|
||||
if (stack.isEmpty())
|
||||
throw MishapNotEnoughArgs(1, 0)
|
||||
val arg = stack.takeLast(1).getChecked<Double>(0)
|
||||
val datum = stack[stack.lastIndex]
|
||||
val yoinkCount = stack.takeLast(1).getPositiveIntUnder(0, stack.size - 1)
|
||||
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>()
|
||||
output.addAll(stack.takeLast(arg.toInt()))
|
||||
output.addAll(stack.takeLast(yoinkCount))
|
||||
val endSize = stack.size - output.toList().size
|
||||
while (stack.size != endSize) {
|
||||
stack.removeLast()
|
||||
}
|
||||
stack.addAll(output.asSpellResult)
|
||||
stack.addAll(output.asActionResult)
|
||||
|
||||
return OperationResult(continuation, stack, local, listOf())
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
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.getList
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
// it's still called beancounter's distillation in my heart
|
||||
object OpListSize : ConstManaOperator {
|
||||
object OpListSize : ConstManaAction {
|
||||
override val argc = 1
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ package at.petrak.hexcasting.common.casting.operators.lists
|
|||
|
||||
import at.petrak.hexcasting.api.spell.*
|
||||
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 fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val list = args.getChecked<SpellList>(0, argc)
|
||||
val index = args.getChecked<Double>(1, argc).roundToInt()
|
||||
val iota = args[2]
|
||||
return list.modifyAt(index) { SpellList.LPair(iota, it.cdr) }.asSpellResult
|
||||
val list = args.getList(0, argc)
|
||||
val index = args.getPositiveIntUnder(1, list.size(), argc)
|
||||
val iota = args.getIota(2)
|
||||
return list.modifyAt(index) { SpellList.LPair(iota, it.cdr) }.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
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.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
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val list = args.getChecked<SpellList>(0, argc).toMutableList()
|
||||
val index = args.getChecked<Double>(1, argc).toInt()
|
||||
if (index < 0 || index >= list.size)
|
||||
return list
|
||||
val list = args.getList(0, argc).toMutableList()
|
||||
val index = args.getPositiveIntUnder(1, list.size, argc)
|
||||
list.removeAt(index)
|
||||
return list.asSpellResult
|
||||
return list.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
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.getList
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpReverski : ConstManaOperator {
|
||||
object OpReverski : ConstManaAction {
|
||||
override val argc = 1
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.lists
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getIota
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpSingleton : ConstManaOperator {
|
||||
object OpSingleton : ConstManaAction {
|
||||
override val argc = 1
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
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 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.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OpSlice : ConstManaOperator {
|
||||
object OpSlice : ConstManaAction {
|
||||
override val argc = 3
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val list = args.getChecked<SpellList>(0, argc).toList()
|
||||
val index1 = Mth.clamp(args.getChecked<Double>(1, argc).roundToInt(), 0, list.size)
|
||||
val index2 = Mth.clamp(args.getChecked<Double>(2, argc).roundToInt(), 0, list.size)
|
||||
val list = args.getList(0, argc).toList()
|
||||
val index1 = args.getPositiveIntUnder(1, list.size, argc)
|
||||
val index2 = args.getPositiveIntUnder(2, list.size, argc)
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.lists
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
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.ConstManaAction
|
||||
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
|
||||
get() = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> =
|
||||
args.getChecked<SpellList>(0, argc).toMutableList()
|
||||
args.getList(0, argc).toList()
|
||||
}
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
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.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 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) {
|
||||
return spellListOf(list.cdr, list.car)
|
||||
return listOf(ListIota(list.cdr), list.car)
|
||||
}
|
||||
return spellListOf(list, Widget.NULL)
|
||||
return listOf(args[0], NullIota.INSTANCE)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.local
|
||||
|
||||
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.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
|
||||
|
||||
object OpPeekLocal : Operator {
|
||||
object OpPeekLocal : Action {
|
||||
override fun operate(
|
||||
continuation: SpellContinuation,
|
||||
stack: MutableList<Iota>,
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.local
|
||||
|
||||
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.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
|
||||
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
|
||||
|
||||
object OpPushLocal : Operator {
|
||||
object OpPushLocal : Action {
|
||||
override fun operate(
|
||||
continuation: SpellContinuation,
|
||||
stack: MutableList<Iota>,
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.numOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getNumOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
object OpAbsLen : ConstManaOperator {
|
||||
object OpAbsLen : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,30 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.numOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
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.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
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val lhs = numOrVec(args[0], 1)
|
||||
val rhs = numOrVec(args[1], 0)
|
||||
val lhs = args.getNumOrVec(0, argc)
|
||||
val rhs = args.getNumOrVec(1, argc)
|
||||
|
||||
return spellListOf(
|
||||
lhs.map({ lnum ->
|
||||
return lhs.map(
|
||||
{ lnum ->
|
||||
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(
|
||||
{ rnum -> lvec.add(rnum, rnum, rnum) }, { rvec -> lvec.add(rvec) }
|
||||
{ rnum -> lvec.add(rnum, rnum, rnum).asActionResult }, { rvec -> lvec.add(rvec).asActionResult }
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
import at.petrak.hexcasting.api.spell.aplKinnie
|
||||
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
|
||||
|
||||
object OpCeil : ConstManaOperator {
|
||||
object OpCeil : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val value = args.getChecked<Double>(0, argc)
|
||||
return ceil(value).asSpellResult
|
||||
val value = args.getNumOrVec(0, argc)
|
||||
// i hate this fucking syntax what the hell is ::ceil are you a goddamn homestuck ::c
|
||||
return listOf(aplKinnie(value, ::ceil))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.getVec3
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpCoerceToAxial : ConstManaOperator {
|
||||
object OpCoerceToAxial : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
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)
|
||||
return vec.asSpellResult
|
||||
return Vec3.atLowerCornerOf(Direction.getNearest(vec.x, vec.y, vec.z).normal).asSpellResult
|
||||
return vec.asActionResult
|
||||
return Vec3.atLowerCornerOf(Direction.getNearest(vec.x, vec.y, vec.z).normal).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.getDouble
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpConstructVec : ConstManaOperator {
|
||||
object OpConstructVec : ConstManaAction {
|
||||
override val argc = 3
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val x = args.getChecked<Double>(0, argc)
|
||||
val y = args.getChecked<Double>(1, argc)
|
||||
val z = args.getChecked<Double>(2, argc)
|
||||
return Vec3(x, y, z).asSpellResult
|
||||
val x = args.getDouble(0, argc)
|
||||
val y = args.getDouble(1, argc)
|
||||
val z = args.getDouble(2, argc)
|
||||
return Vec3(x, y, z).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.getChecked
|
||||
import at.petrak.hexcasting.api.spell.spellListOf
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import at.petrak.hexcasting.api.spell.getVec3
|
||||
import at.petrak.hexcasting.api.spell.iota.DoubleIota
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpDeconstructVec : ConstManaOperator {
|
||||
object OpDeconstructVec : ConstManaAction {
|
||||
override val argc = 1
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val v = args.getChecked<Vec3>(0, argc)
|
||||
return spellListOf(v.x, v.y, v.z)
|
||||
val v = args.getVec3(0, argc)
|
||||
return listOf(DoubleIota(v.x), DoubleIota(v.y), DoubleIota(v.z))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,45 +1,42 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.numOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
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.getNumOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
|
||||
import at.petrak.hexcasting.api.spell.spellListOf
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpDivCross : ConstManaOperator {
|
||||
object OpDivCross : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val lhs = numOrVec(args[0], 1)
|
||||
val rhs = numOrVec(args[1], 0)
|
||||
val lhs = args.getNumOrVec(0, argc)
|
||||
val rhs = args.getNumOrVec(1, argc)
|
||||
val theMishap = MishapDivideByZero.of(args[0], args[1])
|
||||
|
||||
return spellListOf(
|
||||
lhs.map({ lnum ->
|
||||
return lhs.map(
|
||||
{ lnum ->
|
||||
rhs.map(
|
||||
{ rnum ->
|
||||
if (rnum == 0.0)
|
||||
throw MishapDivideByZero.of(lnum, rnum)
|
||||
lnum / rnum
|
||||
if (rnum == 0.0) throw theMishap // throw theMishap throw theMishap badumbadum
|
||||
(lnum / rnum).asActionResult
|
||||
},
|
||||
{ rvec ->
|
||||
if (rvec.x == 0.0 || rvec.y == 0.0 || rvec.z == 0.0)
|
||||
throw MishapDivideByZero.of(lnum, rvec)
|
||||
Vec3(lnum / rvec.x, lnum / rvec.y, lnum / rvec.z)
|
||||
if (rvec.x == 0.0 || rvec.y == 0.0 || rvec.z == 0.0) throw theMishap
|
||||
Vec3(lnum / rvec.x, lnum / rvec.y, lnum / rvec.z).asActionResult
|
||||
}
|
||||
)
|
||||
}, { lvec ->
|
||||
rhs.map(
|
||||
{ rnum ->
|
||||
if (lvec == Vec3.ZERO)
|
||||
throw MishapDivideByZero.of(lvec, rnum)
|
||||
lvec.scale(1.0 / rnum)
|
||||
if (lvec == Vec3.ZERO) throw theMishap
|
||||
lvec.scale(1.0 / rnum).asActionResult
|
||||
},
|
||||
{ rvec -> lvec.cross(rvec) }
|
||||
{ rvec -> lvec.cross(rvec).asActionResult }
|
||||
)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
import at.petrak.hexcasting.api.spell.aplKinnie
|
||||
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
|
||||
|
||||
object OpFloor : ConstManaOperator {
|
||||
object OpFloor : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val value = args.getChecked<Double>(0, argc)
|
||||
return floor(value).asSpellResult
|
||||
val value = args.getNumOrVec(0, argc)
|
||||
return listOf(aplKinnie(value, ::floor))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.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 kotlin.math.log
|
||||
|
||||
object OpLog : ConstManaOperator {
|
||||
object OpLog : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val value = args.getChecked<Double>(0, argc)
|
||||
val base = args.getChecked<Double>(1, argc)
|
||||
val value = args.getDouble(0, argc)
|
||||
val base = args.getDouble(1, argc)
|
||||
if (value <= 0.0 || base <= 0.0 || base == 1.0)
|
||||
throw MishapDivideByZero.of(value, base, "logarithm")
|
||||
return log(value, base).asSpellResult
|
||||
throw MishapDivideByZero.of(args[0], args[1], "logarithm")
|
||||
return log(value, base).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.getDouble
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
|
||||
|
||||
object OpModulo : ConstManaOperator {
|
||||
object OpModulo : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val l = args.getChecked<Double>(0, argc)
|
||||
val r = args.getChecked<Double>(1, argc)
|
||||
// TODO: some wAckY vector operation to go in the vector x vector overload
|
||||
val l = args.getDouble(0, argc)
|
||||
val r = args.getDouble(1, argc)
|
||||
if (r == 0.0)
|
||||
throw MishapDivideByZero.of(l, r)
|
||||
return (l % r).asSpellResult
|
||||
throw MishapDivideByZero.of(args[0], args[1])
|
||||
return (l % r).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.numOrVec
|
||||
import at.petrak.hexcasting.api.spell.spellListOf
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
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.getNumOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpMulDot : ConstManaOperator {
|
||||
object OpMulDot : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val lhs = numOrVec(args[0], 1)
|
||||
val rhs = numOrVec(args[1], 0)
|
||||
val lhs = args.getNumOrVec(0, OpAdd.argc)
|
||||
val rhs = args.getNumOrVec(1, OpAdd.argc)
|
||||
|
||||
return spellListOf(
|
||||
lhs.map({ lnum ->
|
||||
return lhs.map(
|
||||
{ lnum ->
|
||||
rhs.map(
|
||||
{ rnum -> lnum * rnum }, { rvec -> rvec.scale(lnum) }
|
||||
{ rnum -> (lnum * rnum).asActionResult }, { rvec -> rvec.scale(lnum).asActionResult }
|
||||
)
|
||||
}, { lvec ->
|
||||
rhs.map(
|
||||
{ rnum -> lvec.multiply(rnum, rnum, rnum) }, { rvec -> lvec.dot(rvec) }
|
||||
{ rnum -> lvec.scale(rnum).asActionResult }, { rvec -> lvec.dot(rvec).asActionResult }
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.numOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
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.getNumOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
|
||||
import at.petrak.hexcasting.api.spell.spellListOf
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import kotlin.math.pow
|
||||
|
||||
object OpPowProj : ConstManaOperator {
|
||||
object OpPowProj : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val lhs = numOrVec(args[0], 1)
|
||||
val rhs = numOrVec(args[1], 0)
|
||||
val lhs = args.getNumOrVec(0, OpAdd.argc)
|
||||
val rhs = args.getNumOrVec(1, OpAdd.argc)
|
||||
val theMishap = MishapDivideByZero.of(args[0], args[1], "exponent")
|
||||
|
||||
return spellListOf(
|
||||
lhs.map({ lnum ->
|
||||
return lhs.map(
|
||||
{ lnum ->
|
||||
rhs.map(
|
||||
{ rnum ->
|
||||
if (rnum == 0.0 && lnum == 0.0)
|
||||
throw MishapDivideByZero.of(lnum, rnum, "exponent")
|
||||
lnum.pow(rnum)
|
||||
throw theMishap
|
||||
lnum.pow(rnum).asActionResult
|
||||
}, { rvec ->
|
||||
if (lnum == 0.0 && (rvec.x == 0.0 || rvec.y == 0.0 || rvec.z == 0.0))
|
||||
throw MishapDivideByZero.of(lnum, rvec, "exponent")
|
||||
Vec3(lnum.pow(rvec.x), lnum.pow(rvec.y), lnum.pow(rvec.z))
|
||||
throw theMishap
|
||||
Vec3(lnum.pow(rvec.x), lnum.pow(rvec.y), lnum.pow(rvec.z)).asActionResult
|
||||
}
|
||||
)
|
||||
}, { lvec ->
|
||||
rhs.map(
|
||||
{ rnum ->
|
||||
if (rnum == 0.0 && (lvec.x == 0.0 || lvec.y == 0.0 || lvec.z == 0.0))
|
||||
throw MishapDivideByZero.of(lvec, rnum, "exponent")
|
||||
Vec3(lvec.x.pow(rnum), lvec.y.pow(rnum), lvec.z.pow(rnum))
|
||||
throw theMishap
|
||||
Vec3(lvec.x.pow(rnum), lvec.y.pow(rnum), lvec.z.pow(rnum)).asActionResult
|
||||
},
|
||||
{ rvec ->
|
||||
if (lvec == Vec3.ZERO)
|
||||
throw MishapDivideByZero.of(lvec, rvec, "project")
|
||||
rvec.scale(rvec.dot(lvec) / lvec.dot(lvec))
|
||||
throw MishapDivideByZero.of(args[0], args[1], "project")
|
||||
rvec.scale(rvec.dot(lvec) / lvec.dot(lvec)).asActionResult
|
||||
}
|
||||
)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.iota.Iota
|
||||
|
||||
object OpRandom : ConstManaOperator {
|
||||
object OpRandom : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 0
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
return ctx.world.random.nextDouble().asSpellResult
|
||||
return ctx.world.random.nextDouble().asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.numOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
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.spellListOf
|
||||
import at.petrak.hexcasting.api.spell.getNumOrVec
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpSub : ConstManaOperator {
|
||||
object OpSub : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val lhs = numOrVec(args[0], 1)
|
||||
val rhs = numOrVec(args[1], 0)
|
||||
val lhs = args.getNumOrVec(0, OpAdd.argc)
|
||||
val rhs = args.getNumOrVec(1, OpAdd.argc)
|
||||
|
||||
return spellListOf(
|
||||
lhs.map({ lnum ->
|
||||
rhs.map(
|
||||
{ rnum -> lnum - rnum }, { rvec -> Vec3(lnum - rvec.x, lnum - rvec.y, lnum - rvec.z) }
|
||||
)
|
||||
}, { lvec ->
|
||||
rhs.map(
|
||||
{ rnum -> lvec.subtract(rnum, rnum, rnum) }, { rvec -> lvec.subtract(rvec) }
|
||||
)
|
||||
})
|
||||
)
|
||||
return lhs.map({ lnum ->
|
||||
rhs.map(
|
||||
{ rnum -> (lnum - rnum).asActionResult },
|
||||
{ rvec -> Vec3(lnum - rvec.x, lnum - rvec.y, lnum - rvec.z).asActionResult }
|
||||
)
|
||||
}, { lvec ->
|
||||
rhs.map(
|
||||
{ rnum -> lvec.subtract(rnum, rnum, rnum).asActionResult },
|
||||
{ rvec -> lvec.subtract(rvec).asActionResult }
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.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 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) {
|
||||
val list1 = firstParam.right().get()
|
||||
val list2 = args.getChecked<SpellList>(1, argc)
|
||||
return list1.filter { x -> list2.any(x::tolerantEquals) }.asSpellResult
|
||||
}
|
||||
|
||||
val num1 = firstParam.left().get().roundToInt()
|
||||
val num2 = args.getChecked<Double>(1, argc).roundToInt()
|
||||
return (num1 and num2).asSpellResult
|
||||
return firstParam.map(
|
||||
{ num1 ->
|
||||
val num2 = args.getLong(1, argc)
|
||||
(num1 and num2).asActionResult
|
||||
},
|
||||
{ list1 ->
|
||||
val list2 = args.getList(1, argc)
|
||||
list1.filter { x -> list2.any { Iota.tolerates(x, it) } }.asActionResult
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.bit
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.getChecked
|
||||
import kotlin.math.roundToInt
|
||||
import at.petrak.hexcasting.api.spell.getLong
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpNot : ConstManaOperator {
|
||||
object OpNot : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.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 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) {
|
||||
val list1 = firstParam.right().get()
|
||||
val list2 = args.getChecked<SpellList>(1, argc)
|
||||
val out = list1 + list2.filter { x -> list1.none(x::tolerantEquals) }
|
||||
return out.asSpellResult
|
||||
}
|
||||
|
||||
val num1 = firstParam.left().get().roundToInt()
|
||||
val num2 = args.getChecked<Double>(1, argc).roundToInt()
|
||||
return (num1 or num2).asSpellResult
|
||||
return firstParam.map(
|
||||
{ num1 ->
|
||||
val num2 = args.getLong(1, argc)
|
||||
(num1 or num2).asActionResult
|
||||
},
|
||||
{ list1 ->
|
||||
val list2 = args.getList(1, argc)
|
||||
list1 + list2.filter { x -> list1.none { Iota.tolerates(x, it) } }.asActionResult
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
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.getList
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpToSet : ConstManaOperator {
|
||||
object OpToSet : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.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 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) {
|
||||
val list1 = firstParam.right().get()
|
||||
val list2 = args.getChecked<SpellList>(1, argc)
|
||||
val out = list1.filter { x1 -> list2.none(x1::tolerantEquals) } + list2.filter { x2 -> list1.none(x2::tolerantEquals) }
|
||||
return out.asSpellResult
|
||||
}
|
||||
|
||||
val num1 = firstParam.left().get().roundToInt()
|
||||
val num2 = args.getChecked<Double>(1, argc).roundToInt()
|
||||
return (num1 xor num2).asSpellResult
|
||||
return firstParam.map(
|
||||
{ num1 ->
|
||||
val num2 = args.getLong(1, argc)
|
||||
(num1 xor num2).asActionResult
|
||||
},
|
||||
{ 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) } }
|
||||
out.asActionResult
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.logic
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.Widget
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
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 fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
return listOf(
|
||||
if (args[0].payload == Widget.NULL)
|
||||
LegacySpellDatum.make(Widget.NULL)
|
||||
else
|
||||
args[1]
|
||||
if (args[0].isTruthy) args[1] else args[0]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,15 @@
|
|||
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.iota.Iota
|
||||
|
||||
object OpBoolIdentityKindOf : ConstManaOperator {
|
||||
// TODO we need a whole-ass cleanup of our truthiness
|
||||
object OpBoolIdentityKindOf : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val payload = args[0].payload
|
||||
|
||||
if (payload == Widget.NULL)
|
||||
return 0.asSpellResult
|
||||
|
||||
if (payload.tolerantEquals(0.0) || payload.tolerantEquals(1.0))
|
||||
return null.asSpellResult
|
||||
|
||||
if (payload is SpellList)
|
||||
return if (payload.nonEmpty) payload.asSpellResult else null.asSpellResult
|
||||
|
||||
return spellListOf(payload)
|
||||
return (args[0].isTruthy).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
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 net.minecraft.world.phys.Vec3
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpBoolNot : ConstManaOperator {
|
||||
object OpBoolNot : ConstManaAction {
|
||||
override val argc = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val payload = args[0].payload
|
||||
val falsy =
|
||||
payload == Widget.NULL || payload.tolerantEquals(0.0) || payload.tolerantEquals(Vec3.ZERO) || (payload is SpellList && !payload.nonEmpty)
|
||||
return falsy.asSpellResult
|
||||
return (!args[0].isTruthy).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.logic
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.Widget
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
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 fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
return listOf(
|
||||
if (args[0].payload == Widget.NULL)
|
||||
args[1]
|
||||
else
|
||||
if (args[0].isTruthy)
|
||||
args[0]
|
||||
else
|
||||
args[1]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.logic
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.Widget
|
||||
import at.petrak.hexcasting.api.spell.ConstManaAction
|
||||
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 fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val a = args[0]
|
||||
val b = args[1]
|
||||
|
||||
return listOf(
|
||||
if (args[0].payload != Widget.NULL && args[1].payload == Widget.NULL)
|
||||
args[0]
|
||||
else if (args[0].payload == Widget.NULL && args[1].payload != Widget.NULL)
|
||||
args[1]
|
||||
if (a.isTruthy && !b.isTruthy)
|
||||
a
|
||||
else if (!a.isTruthy && b.isTruthy)
|
||||
b
|
||||
else
|
||||
LegacySpellDatum.make(Widget.NULL)
|
||||
NullIota.INSTANCE
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
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.getDouble
|
||||
import at.petrak.hexcasting.api.spell.iota.DoubleIota
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
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 fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val lhs = args.getChecked<Double>(0, argc)
|
||||
val rhs = args.getChecked<Double>(1, argc)
|
||||
if (lhs.tolerantEquals(rhs))
|
||||
return acceptsEqual.asSpellResult
|
||||
val lhs = args.getDouble(0, argc)
|
||||
val rhs = args.getDouble(1, argc)
|
||||
if (DoubleIota.tolerates(lhs, rhs))
|
||||
return acceptsEqual.asActionResult
|
||||
|
||||
return cmp.test(lhs, rhs).asSpellResult
|
||||
return cmp.test(lhs, rhs).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.logic
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.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 fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val lhs = args[0]
|
||||
val rhs = args[1]
|
||||
|
||||
return (lhs.tolerantEquals(rhs) != invert).asSpellResult
|
||||
return (Iota.tolerates(lhs, rhs) != invert).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,18 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.trig
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
|
||||
import at.petrak.hexcasting.api.utils.asTranslatedComponent
|
||||
import at.petrak.hexcasting.api.spell.getDoubleBetween
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import kotlin.math.acos
|
||||
|
||||
object OpArcCos : ConstManaOperator {
|
||||
object OpArcCos : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val value = args.getChecked<Double>(0, argc)
|
||||
if (value < -1 || value > 1)
|
||||
throw MishapInvalidIota(
|
||||
LegacySpellDatum.make(value),
|
||||
0,
|
||||
"hexcasting.mishap.invalid_value.double.between".asTranslatedComponent(-1, 1)
|
||||
)
|
||||
return acos(value).asSpellResult
|
||||
val value = args.getDoubleBetween(0, -1.0, 1.0, argc)
|
||||
return acos(value).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,18 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.trig
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
|
||||
import at.petrak.hexcasting.api.utils.asTranslatedComponent
|
||||
import at.petrak.hexcasting.api.spell.getDoubleBetween
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import kotlin.math.asin
|
||||
|
||||
object OpArcSin : ConstManaOperator {
|
||||
object OpArcSin : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val value = args.getChecked<Double>(0, argc)
|
||||
if (value < -1 || value > 1)
|
||||
throw MishapInvalidIota(
|
||||
LegacySpellDatum.make(value),
|
||||
0,
|
||||
"hexcasting.mishap.invalid_value.double.between".asTranslatedComponent(-1, 1)
|
||||
)
|
||||
return asin(value).asSpellResult
|
||||
val value = args.getDoubleBetween(0, -1.0, 1.0, OpArcCos.argc)
|
||||
return asin(value).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.trig
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.getDouble
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import kotlin.math.atan
|
||||
|
||||
object OpArcTan : ConstManaOperator {
|
||||
object OpArcTan : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val value = args.getChecked<Double>(0, argc)
|
||||
return atan(value).asSpellResult
|
||||
val value = args.getDouble(0, argc)
|
||||
return atan(value).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.trig
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.getDouble
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import kotlin.math.cos
|
||||
|
||||
object OpCos : ConstManaOperator {
|
||||
object OpCos : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val angle = args.getChecked<Double>(0, argc)
|
||||
return cos(angle).asSpellResult
|
||||
val angle = args.getDouble(0, argc)
|
||||
return cos(angle).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.trig
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.getDouble
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import kotlin.math.sin
|
||||
|
||||
object OpSin : ConstManaOperator {
|
||||
object OpSin : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val angle = args.getChecked<Double>(0, argc)
|
||||
return sin(angle).asSpellResult
|
||||
val angle = args.getDouble(0, argc)
|
||||
return sin(angle).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.math.trig
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.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 kotlin.math.cos
|
||||
import kotlin.math.tan
|
||||
|
||||
object OpTan : ConstManaOperator {
|
||||
object OpTan : ConstManaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
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)
|
||||
throw MishapDivideByZero.tan(angle)
|
||||
return tan(angle).asSpellResult
|
||||
throw MishapDivideByZero.tan(args[0] as DoubleIota)
|
||||
return tan(angle).asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.selectors
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.iota.Iota
|
||||
|
||||
object OpGetCaster : ConstManaOperator {
|
||||
object OpGetCaster : ConstManaAction {
|
||||
override val argc = 0
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
ctx.assertEntityInRange(ctx.caster)
|
||||
return ctx.caster.asSpellResult
|
||||
return ctx.caster.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.selectors
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.Operator.Companion.MAX_DISTANCE
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
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.getChecked
|
||||
import at.petrak.hexcasting.api.spell.spellListOf
|
||||
import net.minecraft.util.Mth
|
||||
import at.petrak.hexcasting.api.spell.getPositiveDouble
|
||||
import at.petrak.hexcasting.api.spell.getVec3
|
||||
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.LivingEntity
|
||||
import net.minecraft.world.entity.animal.Animal
|
||||
|
@ -18,29 +18,26 @@ import net.minecraft.world.phys.AABB
|
|||
import net.minecraft.world.phys.Vec3
|
||||
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 fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
val pos = args.getChecked<Vec3>(0, argc)
|
||||
val maybeRadius = args.getChecked<Double>(1, argc)
|
||||
val pos = args.getVec3(0, argc)
|
||||
val radius = args.getPositiveDouble(1, argc)
|
||||
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 entitiesGot = ctx.world.getEntities(
|
||||
null,
|
||||
aabb
|
||||
) {
|
||||
(checker.test(it) != negate) && ctx.isEntityInRange(it) && it.isAlive && !it.isSpectator && it.distanceToSqr(
|
||||
pos
|
||||
) <= radius * radius
|
||||
}
|
||||
.sortedBy { it.distanceToSqr(pos) }
|
||||
return spellListOf(entitiesGot)
|
||||
val entitiesGot = ctx.world.getEntities(null, aabb) {
|
||||
isReasonablySelectable(ctx, it)
|
||||
&& it.distanceToSqr(pos) <= radius * radius
|
||||
&& (checker.test(it) != negate)
|
||||
}.sortedBy { it.distanceToSqr(pos) }
|
||||
return entitiesGot.map(::EntityIota).asActionResult
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
fun isReasonablySelectable(ctx: CastingContext, e: Entity) =
|
||||
ctx.isEntityInRange(e) && e.isAlive && !e.isSpectator
|
||||
|
||||
@JvmStatic
|
||||
fun isAnimal(e: Entity): Boolean = e is Animal || e is WaterAnimal
|
||||
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.selectors
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
import at.petrak.hexcasting.api.spell.asSpellResult
|
||||
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.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.phys.AABB
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import java.util.function.Predicate
|
||||
|
||||
class OpGetEntityAt(val checker: Predicate<Entity>) : ConstManaOperator {
|
||||
class OpGetEntityAt(val checker: Predicate<Entity>) : ConstManaAction {
|
||||
override val argc = 1
|
||||
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)
|
||||
val aabb = AABB(pos.add(Vec3(-0.5, -0.5, -0.5)), pos.add(Vec3(0.5, 0.5, 0.5)))
|
||||
val entitiesGot = ctx.world.getEntities(null, aabb)
|
||||
{ checker.test(it) && ctx.isEntityInRange(it) && it.isAlive && !it.isSpectator }
|
||||
val entitiesGot = ctx.world.getEntities(null, aabb) {
|
||||
OpGetEntitiesBy.isReasonablySelectable(ctx, it) && checker.test(it)
|
||||
}.sortedBy { it.distanceToSqr(pos) }
|
||||
|
||||
val entity = entitiesGot.getOrNull(0)
|
||||
return entity.asSpellResult
|
||||
return entity.asActionResult
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import at.petrak.hexcasting.api.spell.getChecked
|
|||
import at.petrak.hexcasting.api.spell.ParticleSpray
|
||||
import at.petrak.hexcasting.api.spell.RenderedSpell
|
||||
import at.petrak.hexcasting.api.spell.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 net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpAddMotion : SpellOperator {
|
||||
object OpAddMotion : SpellAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ import at.petrak.hexcasting.api.spell.getChecked
|
|||
import at.petrak.hexcasting.api.spell.ParticleSpray
|
||||
import at.petrak.hexcasting.api.spell.RenderedSpell
|
||||
import at.petrak.hexcasting.api.spell.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.common.network.MsgBeepAck
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpBeep : SpellOperator {
|
||||
object OpBeep : SpellAction {
|
||||
override val argc = 3
|
||||
|
||||
override fun execute(
|
||||
|
|
|
@ -12,7 +12,7 @@ import net.minecraft.world.entity.Entity
|
|||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OpBlink : SpellOperator {
|
||||
object OpBlink : SpellAction {
|
||||
override val argc = 2
|
||||
override fun execute(
|
||||
args: List<Iota>,
|
||||
|
|
|
@ -8,7 +8,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
|
|||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpBreakBlock : SpellOperator {
|
||||
object OpBreakBlock : SpellAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ import at.petrak.hexcasting.api.misc.ManaConstants
|
|||
import at.petrak.hexcasting.api.spell.ParticleSpray
|
||||
import at.petrak.hexcasting.api.spell.RenderedSpell
|
||||
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.mishaps.MishapBadOffhandItem
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||
|
||||
object OpColorize : SpellOperator {
|
||||
object OpColorize : SpellAction {
|
||||
override val argc = 0
|
||||
|
||||
override fun execute(
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraft.world.item.ItemStack
|
|||
import net.minecraft.world.item.context.DirectionalPlaceContext
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
class OpConjure(val light: Boolean) : SpellOperator {
|
||||
class OpConjure(val light: Boolean) : SpellAction {
|
||||
override val argc = 1
|
||||
override fun execute(
|
||||
args: List<Iota>,
|
||||
|
|
|
@ -15,7 +15,7 @@ import net.minecraft.world.level.block.LayeredCauldronBlock
|
|||
import net.minecraft.world.level.material.Fluids
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpCreateWater : SpellOperator {
|
||||
object OpCreateWater : SpellAction {
|
||||
override val argc = 1
|
||||
override fun execute(
|
||||
args: List<Iota>,
|
||||
|
|
|
@ -17,7 +17,7 @@ import net.minecraft.world.level.material.Fluids
|
|||
import net.minecraft.world.level.material.Material
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpDestroyWater : SpellOperator {
|
||||
object OpDestroyWater : SpellAction {
|
||||
override val argc = 1
|
||||
override fun execute(
|
||||
args: List<Iota>,
|
||||
|
@ -53,7 +53,7 @@ object OpDestroyWater : SpellOperator {
|
|||
val here = todo.removeFirst()
|
||||
val distFromFocus =
|
||||
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
|
||||
val fluid = ctx.world.getFluidState(here)
|
||||
if (fluid != Fluids.EMPTY.defaultFluidState()) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.getChecked
|
|||
import at.petrak.hexcasting.api.spell.ParticleSpray
|
||||
import at.petrak.hexcasting.api.spell.RenderedSpell
|
||||
import at.petrak.hexcasting.api.spell.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.mishaps.MishapBadBlock
|
||||
import at.petrak.hexcasting.common.misc.AkashicTreeGrower
|
||||
|
@ -13,7 +13,7 @@ import net.minecraft.core.BlockPos
|
|||
import net.minecraft.tags.BlockTags
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpEdifySapling : SpellOperator {
|
||||
object OpEdifySapling : SpellAction {
|
||||
override val argc = 1
|
||||
|
||||
override fun execute(
|
||||
|
|
|
@ -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.ParticleSpray
|
||||
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.mishaps.MishapBadOffhandItem
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||
|
||||
class OpErase : SpellOperator {
|
||||
class OpErase : SpellAction {
|
||||
override val argc = 0
|
||||
|
||||
override fun execute(
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue