diff --git a/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java b/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java index 081250f8..61754a21 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java +++ b/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java @@ -291,7 +291,7 @@ public class RegisterPatterns { OpSingleton.INSTANCE); PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqaeaae", HexDir.NORTH_EAST), prefix("empty_list"), OpEmptyList.INSTANCE); - PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqaedae", HexDir.EAST), prefix("reverse_list"), + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqaede", HexDir.EAST), prefix("reverse_list"), OpReverski.INSTANCE); } catch (PatternRegistry.RegisterPatternException exn) { diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpLastNToList.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpLastNToList.kt new file mode 100644 index 00000000..7d0f7ba0 --- /dev/null +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/lists/OpLastNToList.kt @@ -0,0 +1,36 @@ +package at.petrak.hexcasting.common.casting.operators.lists + +import at.petrak.hexcasting.api.OperationResult +import at.petrak.hexcasting.api.Operator +import at.petrak.hexcasting.api.Operator.Companion.getChecked +import at.petrak.hexcasting.api.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.SpellDatum +import at.petrak.hexcasting.common.casting.CastException +import at.petrak.hexcasting.common.casting.CastingContext +import at.petrak.hexcasting.common.casting.OperatorSideEffect + +object OpLastNToList : Operator { + val manaCost: Int + get() = 0 + + override fun operate(stack: MutableList>, ctx: CastingContext): OperationResult { + if (stack.isEmpty()) + throw CastException(CastException.Reason.NOT_ENOUGH_ARGS, 1, stack.size) + val arg = stack.takeLast(1).getChecked(0) + stack.removeLast() + if (arg < 0) { + throw CastException(CastException.Reason.INVALID_VALUE, "integer greater than 0", arg) + } + val output = emptyList>() + output.toMutableList().addAll(stack.takeLast(arg.toInt())) + val endSize = stack.size - output.toList().size + while (stack.size != endSize) { + stack.removeLast() + } + stack.add(spellListOf(output)) + + val sideEffects = mutableListOf(OperatorSideEffect.ConsumeMana(this.manaCost)) + + return OperationResult(stack, sideEffects) + } +} \ No newline at end of file