diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be5e139f..80658710f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - SpellList has been removed ([#1032](https://github.com/FallingColors/HexMod/pull/1032)) @s5bug - Casting Image and Casting Frames now store iotas in a TreeList ([#1033](https://github.com/FallingColors/HexMod/pull/1033)) @s5bug - Changed resource registration to use the IXplatRegister system ([#1212](https://github.com/FallingColors/HexMod/pull/1212)) @Olfi01 +- Operations and actions now accept the old stack and produce the new stack through a TreeList ([#1038](https://github.com/FallingColors/HexMod/pull/1038)) @s5bug ## `0.11.3` - 2025-11-22 diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/lists/OpSplat.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/lists/OpSplat.kt index f35f0d8ac..cf46c476c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/lists/OpSplat.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/lists/OpSplat.kt @@ -10,5 +10,5 @@ object OpSplat : ConstMediaAction { get() = 1 override fun execute(args: List, env: CastingEnvironment): List = - args.getList(0, argc).toList() + args.getList(0, argc) } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpMakePackagedSpell.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpMakePackagedSpell.kt index b1af0cbf4..b574726a8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpMakePackagedSpell.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpMakePackagedSpell.kt @@ -31,7 +31,7 @@ class OpMakePackagedSpell(val isValid: Predicate, val expectedTypeDes env: CastingEnvironment ): SpellAction.Result { val entity = args.getItemEntity(env.world, 0, argc) - val patterns = args.getList(1, argc).toList() + val patterns = args.getList(1, argc) val (handStack) = env.getHeldItemToOperateOn { val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(it) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListArithmetic.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListArithmetic.kt index 38ae7dfa2..b4f852fb1 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListArithmetic.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListArithmetic.kt @@ -46,7 +46,7 @@ object ListArithmetic : Arithmetic { UNAPPEND -> OperatorUnappend ADD -> make2 { list0, list1 -> list0 + list1 } ABS -> OperatorUnary(all(IotaPredicate.ofType(LIST.get()))) { iota: Iota -> DoubleIota(downcast(iota, LIST.get()).list.size.toDouble()) } - REV -> OperatorUnary(all(IotaPredicate.ofType(LIST.get()))) { iota: Iota -> ListIota(downcast(iota, LIST.get()).list.toList().asReversed()) } + REV -> OperatorUnary(all(IotaPredicate.ofType(LIST.get()))) { iota: Iota -> ListIota(downcast(iota, LIST.get()).list.reversed()) } INDEX_OF -> OperatorIndexOf REMOVE -> OperatorRemove REPLACE -> OperatorReplace @@ -58,6 +58,6 @@ object ListArithmetic : Arithmetic { private fun make2(op: BinaryOperator>): OperatorBinary = OperatorBinary(all(IotaPredicate.ofType(LIST.get()))) { i: Iota, j: Iota -> ListIota( - op.apply(downcast(i, LIST.get()).list.toList(), downcast(j, LIST.get()).list.toList()) + op.apply(downcast(i, LIST.get()).list, downcast(j, LIST.get()).list) ) } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListSetArithmetic.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListSetArithmetic.kt index f20b1659a..4c1481e1e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListSetArithmetic.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListSetArithmetic.kt @@ -38,6 +38,6 @@ object ListSetArithmetic : Arithmetic { private fun make2(op: BinaryOperator>): OperatorBinary = OperatorBinary(all(IotaPredicate.ofType(LIST.get()))) { i: Iota, j: Iota -> ListIota( - op.apply(downcast(i, LIST.get()).list.toList(), downcast(j, LIST.get()).list.toList()) + op.apply(downcast(i, LIST.get()).list, downcast(j, LIST.get()).list) ) } } \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorAppend.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorAppend.kt index dae4257ff..85288f897 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorAppend.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorAppend.kt @@ -12,8 +12,7 @@ import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.LIST object OperatorAppend : OperatorBasic(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST.get()), IotaPredicate.TRUE)) { override fun apply(iotas: Iterable, env: CastingEnvironment): Iterable { val it = iotas.iterator().withIndex() - val list = it.nextList(arity).toMutableList() - list.add(it.next().value) - return list.asActionResult + val list = it.nextList(arity) + return list.appended(it.next().value).asActionResult } } \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndex.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndex.kt index a3c378b9c..88bb27de7 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndex.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndex.kt @@ -13,7 +13,7 @@ import kotlin.math.roundToInt object OperatorIndex : OperatorBasic(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST.get()), IotaPredicate.ofType(DOUBLE.get()))) { override fun apply(iotas: Iterable, env: CastingEnvironment): Iterable { val it = iotas.iterator() - val list = downcast(it.next(), LIST.get()).list.toMutableList() + val list = downcast(it.next(), LIST.get()).list val index = downcast(it.next(), DOUBLE.get()).double val x = list.getOrElse(index.roundToInt()) { NullIota() } return listOf(x) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndexOf.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndexOf.kt index 3f797ad49..18510e051 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndexOf.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndexOf.kt @@ -12,7 +12,7 @@ import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.LIST object OperatorIndexOf : OperatorBasic(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST.get()), IotaPredicate.TRUE)) { override fun apply(iotas: Iterable, env: CastingEnvironment): Iterable { val it = iotas.iterator().withIndex() - val list = it.nextList(arity).toList() + val list = it.nextList(arity) val toFind = it.next().value return list.indexOfFirst { Iota.tolerates(toFind, it) }.asActionResult } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorRemove.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorRemove.kt index df7902db6..8e24a32f2 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorRemove.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorRemove.kt @@ -14,11 +14,11 @@ import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.LIST object OperatorRemove : OperatorBasic(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST.get()), IotaPredicate.ofType(DOUBLE.get()))) { override fun apply(iotas: Iterable, env: CastingEnvironment): Iterable { val it = iotas.iterator().withIndex() - val list = it.nextList(arity).toMutableList() + val list = it.nextList(arity) val index = it.nextInt(arity) if (index < 0 || index >= list.size) return list.asActionResult - list.removeAt(index) - return list.asActionResult + + return list.take(index).appendedAll(list.drop(index + 1)).asActionResult } } \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorSlice.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorSlice.kt index 6e687906f..caa3a1e9d 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorSlice.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorSlice.kt @@ -16,12 +16,12 @@ import kotlin.math.min object OperatorSlice : OperatorBasic(3, IotaMultiPredicate.triple(IotaPredicate.ofType(LIST.get()), IotaPredicate.ofType(DOUBLE.get()), IotaPredicate.ofType(DOUBLE.get()))) { override fun apply(iotas: Iterable, env: CastingEnvironment): Iterable { val it = iotas.iterator().withIndex() - val list = it.nextList(arity).toList() + val list = it.nextList(arity) val index0 = it.nextPositiveIntUnderInclusive(list.size, arity) val index1 = it.nextPositiveIntUnderInclusive(list.size, arity) if (index0 == index1) return emptyList().asActionResult - return list.subList(min(index0, index1), max(index0, index1)).asActionResult + return list.slice(min(index0, index1), max(index0, index1)).asActionResult } } \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorUnappend.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorUnappend.kt index ba4b8f407..b1215d98c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorUnappend.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorUnappend.kt @@ -13,8 +13,9 @@ import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.LIST object OperatorUnappend : OperatorBasic(1, IotaMultiPredicate.all(IotaPredicate.ofType(LIST.get()))) { override fun apply(iotas: Iterable, env: CastingEnvironment): Iterable { val it = iotas.iterator().withIndex() - val list = it.nextList(arity).toMutableList() - val last = list.removeLastOrNull() ?: NullIota() - return listOf(ListIota(list), last) + val list = it.nextList(arity) + if (!list.isEmpty()) + return listOf(ListIota(list.init()), list.last()) + return listOf(ListIota(list), NullIota()) } } \ No newline at end of file