it compiles! now to bang on things until they break
This commit is contained in:
parent
17439c48bf
commit
92860e463d
18 changed files with 116 additions and 167 deletions
|
@ -2,9 +2,9 @@ package at.petrak.hexcasting.api.casting.castables
|
|||
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import java.text.DecimalFormat
|
||||
|
||||
|
@ -23,18 +23,19 @@ import java.text.DecimalFormat
|
|||
*/
|
||||
interface Action {
|
||||
/**
|
||||
* Operate on the stack. Return the new stack and any side effects of the cast.
|
||||
* Functionally update the image. Return the image and any side effects.
|
||||
*
|
||||
* Although this is passed a [MutableList], this is only for the convenience of implementors.
|
||||
* It is a clone of the stack and modifying it does nothing. You must return the new stack
|
||||
* with the [OperationResult]. Similar with the `userData`.
|
||||
* This is a <i>very</i> low-level function -- the implementor is responsible for a lot. For example,
|
||||
* remember to increment the op count, sil vous plait.
|
||||
*
|
||||
* A particle effect at the cast site and various messages and advancements are done automagically.
|
||||
*
|
||||
* The userdata tag is copied for you, so you don't need to worry about mutation messing up things
|
||||
* behind the scenes.
|
||||
*/
|
||||
fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
image: CastingImage,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ package at.petrak.hexcasting.api.casting.castables
|
|||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
/**
|
||||
* A SimpleOperator that always costs the same amount of media.
|
||||
|
@ -23,12 +23,9 @@ interface ConstMediaAction : Action {
|
|||
return CostMediaActionResult(stack)
|
||||
}
|
||||
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
if (this.argc > stack.size)
|
||||
throw MishapNotEnoughArgs(this.argc, stack.size)
|
||||
val args = stack.takeLast(this.argc)
|
||||
|
@ -38,7 +35,8 @@ interface ConstMediaAction : Action {
|
|||
|
||||
val sideEffects = mutableListOf<OperatorSideEffect>(OperatorSideEffect.ConsumeMedia(this.mediaCost))
|
||||
|
||||
return OperationResult(stack, userData, sideEffects, continuation, result.opCount)
|
||||
val image2 = image.copy(stack = stack, opsConsumed = image.opsConsumed + result.opCount)
|
||||
return OperationResult(image2, sideEffects, continuation)
|
||||
}
|
||||
|
||||
data class CostMediaActionResult(val resultStack: List<Iota>, val opCount: Long = 1)
|
||||
|
|
|
@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.RenderedSpell
|
|||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
|
@ -28,17 +29,17 @@ interface SpellAction : Action {
|
|||
return this.execute(args, ctx)
|
||||
}
|
||||
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
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()
|
||||
val result = this.executeWithUserdata(args, env, userData)
|
||||
|
||||
// execute!
|
||||
val userDataMut = image.userData.copy()
|
||||
val result = this.executeWithUserdata(args, env, userDataMut)
|
||||
|
||||
val sideEffects = mutableListOf<OperatorSideEffect>()
|
||||
|
||||
|
@ -56,7 +57,9 @@ interface SpellAction : Action {
|
|||
for (spray in result.particles)
|
||||
sideEffects.add(OperatorSideEffect.Particles(spray))
|
||||
|
||||
return OperationResult(stack, userData, sideEffects, continuation, result.opCount)
|
||||
val image2 = image.copy(stack = stack, opsConsumed = image.opsConsumed + result.opCount, userData = userDataMut)
|
||||
|
||||
return OperationResult(image2, sideEffects, continuation)
|
||||
}
|
||||
|
||||
data class Result(val effect: RenderedSpell, val cost: Int, val particles: List<ParticleSpray>, val opCount: Long = 1)
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package at.petrak.hexcasting.api.casting.eval
|
||||
|
||||
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
/**
|
||||
* What happens when an operator is through?
|
||||
*/
|
||||
data class OperationResult(
|
||||
val newStack: List<Iota>,
|
||||
val newUserdata: CompoundTag,
|
||||
val newImage: CastingImage,
|
||||
val sideEffects: List<OperatorSideEffect>,
|
||||
val newContinuation: SpellContinuation,
|
||||
val opsUsed: Long,
|
||||
)
|
||||
|
|
|
@ -12,7 +12,7 @@ import net.minecraft.world.entity.Entity
|
|||
/**
|
||||
* The state of a casting VM, containing the stack and all
|
||||
*/
|
||||
data class CastingImage private constructor(
|
||||
data class CastingImage constructor(
|
||||
val stack: List<Iota>,
|
||||
|
||||
val parenCount: Int,
|
||||
|
|
|
@ -29,7 +29,6 @@ import net.minecraft.server.level.ServerLevel;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -95,32 +94,23 @@ public class PatternIota extends Iota {
|
|||
throw new MishapInvalidPattern();
|
||||
} else throw new IllegalStateException();
|
||||
|
||||
// do the actual calculation!!
|
||||
var result = action.operate(
|
||||
vm.getEnv(),
|
||||
new ArrayList<>(vm.getImage().getStack()),
|
||||
vm.getImage().getUserData().copy(),
|
||||
vm.getImage(),
|
||||
continuation
|
||||
);
|
||||
var opsUsed = result.getOpsUsed();
|
||||
if (vm.getImage().getOpsConsumed() + opsUsed > HexConfig.server().maxOpCount()) {
|
||||
if (result.getNewImage().getOpsConsumed() > HexConfig.server().maxOpCount()) {
|
||||
throw new MishapEvalTooMuch();
|
||||
}
|
||||
|
||||
var cont2 = result.getNewContinuation();
|
||||
var stack2 = result.getNewStack();
|
||||
var userData2 = result.getNewUserdata();
|
||||
// TODO parens also break prescience
|
||||
var sideEffects = result.getSideEffects();
|
||||
|
||||
var extantImage = vm.getImage();
|
||||
var updatedImage = extantImage.copy(stack2,
|
||||
extantImage.getParenCount(), extantImage.getParenthesized(), extantImage.getEscapeNext(),
|
||||
extantImage.getOpsConsumed() + opsUsed,
|
||||
userData2);
|
||||
|
||||
return new CastResult(
|
||||
cont2,
|
||||
updatedImage,
|
||||
result.getNewImage(),
|
||||
sideEffects,
|
||||
ResolvedPatternType.EVALUATED,
|
||||
vm.getEnv().getSoundType()
|
||||
|
|
|
@ -4,26 +4,22 @@ import at.petrak.hexcasting.api.casting.SpellList
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.FrameEvaluate
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.FrameFinishEval
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.evaluatable
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.iota.PatternIota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
object OpEval : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
val datum = stack.removeLastOrNull() ?: throw MishapNotEnoughArgs(1, 0)
|
||||
val instrs = evaluatable(datum, 0)
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
val iota = stack.removeLastOrNull() ?: throw MishapNotEnoughArgs(1, 0)
|
||||
// TODO: use the new iota eval stuff
|
||||
val instrs = evaluatable(iota, 0)
|
||||
|
||||
|
||||
// if not installed already...
|
||||
// also, never make a break boundary when evaluating just one pattern
|
||||
val newCont =
|
||||
if (instrs.left().isPresent || (continuation is SpellContinuation.NotDone && continuation.frame is FrameFinishEval)) {
|
||||
|
@ -34,6 +30,8 @@ object OpEval : Action {
|
|||
|
||||
val instrsList = instrs.map({ SpellList.LList(0, listOf(PatternIota(it))) }, { it })
|
||||
val frame = FrameEvaluate(instrsList, true)
|
||||
return OperationResult(stack, userData, listOf(), newCont.pushFrame(frame), 1)
|
||||
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), newCont.pushFrame(frame))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,20 +3,16 @@ package at.petrak.hexcasting.common.casting.operators.eval
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.FrameForEach
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.getList
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
object OpForEach : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
if (stack.size < 2)
|
||||
throw MishapNotEnoughArgs(2, stack.size)
|
||||
|
||||
|
@ -26,13 +22,8 @@ object OpForEach : Action {
|
|||
stack.removeLastOrNull()
|
||||
|
||||
val frame = FrameForEach(datums, instrs, null, mutableListOf())
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
|
||||
return OperationResult(
|
||||
stack,
|
||||
userData,
|
||||
listOf(),
|
||||
continuation.pushFrame(frame),
|
||||
1
|
||||
)
|
||||
return OperationResult(image2, listOf(), continuation.pushFrame(frame))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,13 @@ package at.petrak.hexcasting.common.casting.operators.eval
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
object OpHalt : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
var newStack = stack.toList()
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
var newStack = image.stack.toList()
|
||||
|
||||
var done = false
|
||||
var newCont = continuation
|
||||
while (!done && newCont is SpellContinuation.NotDone) {
|
||||
|
@ -30,6 +25,7 @@ object OpHalt : Action {
|
|||
newStack = listOf()
|
||||
}
|
||||
|
||||
return OperationResult(newStack, userData, listOf(), newCont, 1)
|
||||
val image2 = image.withUsedOp().copy(stack = newStack)
|
||||
return OperationResult(image2, listOf(), newCont)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,18 @@ package at.petrak.hexcasting.common.casting.operators.eval
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import at.petrak.hexcasting.api.casting.iota.DoubleIota
|
||||
import at.petrak.hexcasting.api.mod.HexConfig
|
||||
|
||||
object OpThanos : Action {
|
||||
override fun operate(env: CastingEnvironment, stack: MutableList<Iota>, userData: CompoundTag, continuation: SpellContinuation): OperationResult {
|
||||
throw NotImplementedError()
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val opsLeft = HexConfig.server().maxOpCount() - image.opsConsumed
|
||||
val stack = image.stack.toMutableList()
|
||||
stack.add(DoubleIota(opsLeft.toDouble()))
|
||||
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), continuation)
|
||||
}
|
||||
}
|
|
@ -4,19 +4,16 @@ import at.petrak.hexcasting.api.casting.asActionResult
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.getPositiveIntUnderInclusive
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
object OpLastNToList : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
if (stack.isEmpty())
|
||||
throw MishapNotEnoughArgs(1, 0)
|
||||
val yoinkCount = stack.takeLast(1).getPositiveIntUnderInclusive(0, stack.size - 1)
|
||||
|
@ -28,6 +25,7 @@ object OpLastNToList : Action {
|
|||
}
|
||||
stack.addAll(output.asActionResult)
|
||||
|
||||
return OperationResult(stack, userData, listOf(), continuation, 1)
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), continuation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,25 +4,24 @@ import at.petrak.hexcasting.api.HexAPI
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.iota.IotaType
|
||||
import at.petrak.hexcasting.api.casting.iota.NullIota
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
object OpPeekLocal : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
val rm = if (userData.contains(HexAPI.RAVENMIND_USERDATA)) {
|
||||
IotaType.deserialize(userData.getCompound(HexAPI.RAVENMIND_USERDATA), env.world)
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
val rm = if (image.userData.contains(HexAPI.RAVENMIND_USERDATA)) {
|
||||
IotaType.deserialize(image.userData.getCompound(HexAPI.RAVENMIND_USERDATA), env.world)
|
||||
} else {
|
||||
NullIota()
|
||||
}
|
||||
stack.add(rm)
|
||||
return OperationResult(stack, userData, listOf(), continuation, 1)
|
||||
|
||||
// does not mutate userdata
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), continuation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,24 +4,21 @@ import at.petrak.hexcasting.api.HexAPI
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
object OpPushLocal : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
if (stack.isEmpty())
|
||||
throw MishapNotEnoughArgs(1, 0)
|
||||
|
||||
val newLocal = stack.removeLast()
|
||||
userData.put(HexAPI.RAVENMIND_USERDATA, newLocal.serialize())
|
||||
image.userData.put(HexAPI.RAVENMIND_USERDATA, newLocal.serialize())
|
||||
|
||||
return OperationResult(stack, userData, listOf(), continuation, 1)
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), continuation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,33 +5,28 @@ import at.petrak.hexcasting.api.casting.castables.Action
|
|||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
// TODO should this dump the whole stack
|
||||
object OpPrint : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
if (stack.isEmpty()) {
|
||||
throw MishapNotEnoughArgs(1, 0)
|
||||
}
|
||||
val datum = stack[stack.lastIndex]
|
||||
|
||||
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(
|
||||
stack,
|
||||
userData,
|
||||
image2,
|
||||
listOf(
|
||||
OperatorSideEffect.AttemptSpell(Spell(datum), hasCastingSound = false, awardStat = false)
|
||||
),
|
||||
continuation,
|
||||
1,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,21 +3,17 @@ package at.petrak.hexcasting.common.casting.operators.stack
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.getPositiveInt
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
// "lehmer code"
|
||||
object OpAlwinfyHasAscendedToABeingOfPureMath : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
if (stack.isEmpty())
|
||||
throw MishapNotEnoughArgs(1, 0)
|
||||
|
||||
|
@ -45,13 +41,8 @@ object OpAlwinfyHasAscendedToABeingOfPureMath : Action {
|
|||
editTarget = editTarget.subList(1, editTarget.size)
|
||||
}
|
||||
|
||||
return OperationResult(
|
||||
stack,
|
||||
userData,
|
||||
listOf(),
|
||||
continuation,
|
||||
1
|
||||
)
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), continuation)
|
||||
}
|
||||
|
||||
private class FactorialIter : Iterator<Int> {
|
||||
|
|
|
@ -3,22 +3,18 @@ package at.petrak.hexcasting.common.casting.operators.stack
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.DoubleIota
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidIota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OpFisherman : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
if (stack.size < 2)
|
||||
throw MishapNotEnoughArgs(2, stack.size)
|
||||
|
||||
|
@ -44,7 +40,7 @@ object OpFisherman : Action {
|
|||
stack.add(stack.size + depth, lure)
|
||||
}
|
||||
|
||||
|
||||
return OperationResult(stack, userData, listOf(), continuation, 1)
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), continuation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,19 +3,15 @@ package at.petrak.hexcasting.common.casting.operators.stack
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.getIntBetween
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
object OpFishermanButItCopies : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
|
||||
if (stack.size < 2)
|
||||
throw MishapNotEnoughArgs(2, stack.size)
|
||||
|
||||
|
@ -30,6 +26,7 @@ object OpFishermanButItCopies : Action {
|
|||
stack.add(stack.size - 1 + depth, lure)
|
||||
}
|
||||
|
||||
return OperationResult(stack, userData, listOf(), continuation, 1)
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), continuation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,19 +3,15 @@ package at.petrak.hexcasting.common.casting.operators.stack
|
|||
import at.petrak.hexcasting.api.casting.castables.Action
|
||||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
||||
import at.petrak.hexcasting.api.casting.eval.OperationResult
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
|
||||
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
|
||||
import at.petrak.hexcasting.api.casting.iota.DoubleIota
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
||||
object OpStackSize : Action {
|
||||
override fun operate(
|
||||
env: CastingEnvironment,
|
||||
stack: MutableList<Iota>,
|
||||
userData: CompoundTag,
|
||||
continuation: SpellContinuation
|
||||
): OperationResult {
|
||||
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
|
||||
val stack = image.stack.toMutableList()
|
||||
stack.add(DoubleIota(stack.size.toDouble()))
|
||||
return OperationResult(stack, userData, listOf(), continuation, 1)
|
||||
val image2 = image.withUsedOp().copy(stack = stack)
|
||||
return OperationResult(image2, listOf(), continuation)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue