add negative behaviour to OpFisherman and OpFishermanButItCopies, moves/copies from the top of the stack to |x| elements deep.

This commit is contained in:
Talia-12 2023-04-21 17:04:14 +10:00
parent 0ff0c7904b
commit 178bf2dbcd
4 changed files with 23 additions and 11 deletions

View file

@ -232,7 +232,7 @@ fun List<Iota>.getIntBetween(idx: Int, min: Int, max: Int, argc: Int = 0): Int {
return rounded
}
}
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "double.between", min, max)
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.between", min, max)
}
fun List<Iota>.getBlockPos(idx: Int, argc: Int = 0): BlockPos {

View file

@ -24,20 +24,26 @@ object OpFisherman : Action {
val depth = let {
val x = stack.last()
stack.removeLast()
val maxIdx = stack.size - 1
if (x is DoubleIota) {
val double = x.double
val rounded = double.roundToInt()
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded in 1..maxIdx) {
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded in -maxIdx..maxIdx) {
return@let rounded
}
}
throw MishapInvalidIota.of(x, 0, "double.between", 1, maxIdx)
throw MishapInvalidIota.of(x, 0, "int.between", -maxIdx, maxIdx)
}
if (depth >= 0) {
val fish = stack.removeAt(stack.size - 1 - depth)
stack.add(fish)
} else {
val lure = stack.removeLast()
stack.add(stack.size + depth, lure)
}
stack.removeLast()
val fish = stack.removeAt(stack.size - depth)
stack.add(fish)
return OperationResult(stack, userData, listOf(), continuation)
}

View file

@ -4,7 +4,7 @@ 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.SpellContinuation
import at.petrak.hexcasting.api.casting.getPositiveIntUnderInclusive
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
@ -19,10 +19,16 @@ object OpFishermanButItCopies : Action {
if (stack.size < 2)
throw MishapNotEnoughArgs(2, stack.size)
val depth = stack.getPositiveIntUnderInclusive(stack.lastIndex, stack.size - 2)
val depth = stack.getIntBetween(stack.lastIndex, -(stack.size - 2), stack.size - 2)
stack.removeLast()
val fish = stack.get(stack.size - 1 - depth)
stack.add(fish)
if (depth >= 0) {
val fish = stack[stack.size - 1 - depth]
stack.add(fish)
} else {
val lure = stack.last()
stack.add(stack.size - 1 + depth, lure)
}
return OperationResult(stack, userData, listOf(), continuation)
}

View file

@ -992,7 +992,7 @@
"hexcasting.page.stackmanip.2dup": "Copy the top two iotas of the stack. [0, 1] becomes [0, 1, 0, 1].",
"hexcasting.page.stackmanip.stack_len": "Pushes the size of the stack as a number to the top of the stack. (For example, a stack of [0, 1] will become [0, 1, 2].)",
"hexcasting.page.stackmanip.duplicate_n": "Removes the number at the top of the stack, then copies the top iota of the stack that number of times. (A count of 2 results in two of the iota on the stack, not three.)",
"hexcasting.page.stackmanip.fisherman": "Grabs the element in the stack indexed by the number and brings it to the top.",
"hexcasting.page.stackmanip.fisherman": "Grabs the element in the stack indexed by the number and brings it to the top. If the number is negative, instead moves the top element of the stack down that many elements.",
"hexcasting.page.stackmanip.fisherman/copy": "Like $(action)Fisherman's Gambit/$, but instead of moving the iota, copies it.",
"hexcasting.page.stackmanip.mask.1": "An infinite family of actions that keep or remove elements at the top of the stack based on the sequence of dips and lines.",
"hexcasting.page.stackmanip.mask.2": "Assuming that I draw a Bookkeeper's Gambit pattern left-to-right, the number of iotas the action will require is determined by the horizontal distance covered by the pattern. From deepest in the stack to shallowest, a flat line will keep the iota, whereas a triangle dipping down will remove it.$(br2)If my stack contains $(italic)0, 1, 2/$ from deepest to shallowest, drawing the first pattern opposite will give me $(italic)1/$, the second will give me $(italic)0/$, and the third will give me $(italic)0, 2/$ (the 0 at the bottom is left untouched).",