Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- ListIota now uses the asymptotically-efficient TreeList internally ([#1032](https://github.com/FallingColors/HexMod/pull/1032)) @s5bug
- 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
- 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import at.petrak.hexcasting.api.casting.iota.Iota
object OpAppend : ConstMediaAction {
override val argc = 2
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val list = args.getList(0, argc).toMutableList()
val list = args.getList(0, argc)
val datum = args[1]
list.add(datum)
return list.asActionResult
return list.appended(datum).asActionResult
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import at.petrak.hexcasting.api.casting.iota.Iota
object OpConcat : ConstMediaAction {
override val argc = 2
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val lhs = args.getList(0, argc).toMutableList()
val lhs = args.getList(0, argc)
val rhs = args.getList(1, argc)
lhs.addAll(rhs)
return lhs.asActionResult
return lhs.appendedAll(rhs).asActionResult
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlin.math.roundToInt
object OpIndex : ConstMediaAction {
override val argc = 2
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val list = args.getList(0, argc).toMutableList()
val list = args.getList(0, argc)
val index = args.getDouble(1, argc)
val x = list.getOrElse(index.roundToInt()) { NullIota() }
return listOf(x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object OpIndexOf : ConstMediaAction {
get() = 2

override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val list = args.getList(0, argc).toMutableList()
val list = args.getList(0, argc)
val value = args[1]
return list.indexOfFirst { Iota.tolerates(value, it) }.asActionResult
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import at.petrak.hexcasting.api.casting.iota.Iota
object OpListSize : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
return args.getList(0, argc).toList().size.asActionResult // mmm one-liner
return args.getList(0, argc).size.asActionResult // mmm one-liner
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ object OpRemove : ConstMediaAction {
get() = 2

override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val list = args.getList(0, argc).toMutableList()
val list = args.getList(0, argc)
val index = args.getInt(1, argc)
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import at.petrak.hexcasting.api.casting.iota.Iota
object OpReverski : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
return args.getList(0, argc).toList().asReversed().asActionResult // okay kotlin kinda pogged for this
return args.getList(0, argc).reversed().asActionResult
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlin.math.min
object OpSlice : ConstMediaAction {
override val argc = 3
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val list = args.getList(0, argc).toList()
val list = args.getList(0, argc)
val index1 = args.getPositiveIntUnderInclusive(1, list.size, argc)
val index2 = args.getPositiveIntUnderInclusive(2, list.size, argc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ object OpSplat : ConstMediaAction {
get() = 1

override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> =
args.getList(0, argc).toList()
args.getList(0, argc)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class OpMakePackagedSpell(val isValid: Predicate<ItemStack>, 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object ListArithmetic : Arithmetic {
UNAPPEND -> OperatorUnappend
ADD -> make2 { list0, list1 -> list0 + list1 }
ABS -> OperatorUnary(all(IotaPredicate.ofType(LIST))) { iota: Iota -> DoubleIota(downcast(iota, LIST).list.size.toDouble()) }
REV -> OperatorUnary(all(IotaPredicate.ofType(LIST))) { iota: Iota -> ListIota(downcast(iota, LIST).list.toList().asReversed()) }
REV -> OperatorUnary(all(IotaPredicate.ofType(LIST))) { iota: Iota -> ListIota(downcast(iota, LIST).list.reversed()) }
INDEX_OF -> OperatorIndexOf
REMOVE -> OperatorRemove
REPLACE -> OperatorReplace
Expand All @@ -58,6 +58,6 @@ object ListArithmetic : Arithmetic {

private fun make2(op: BinaryOperator<List<Iota>>): OperatorBinary = OperatorBinary(all(IotaPredicate.ofType(LIST)))
{ i: Iota, j: Iota -> ListIota(
op.apply(downcast(i, LIST).list.toList(), downcast(j, LIST).list.toList())
op.apply(downcast(i, LIST).list, downcast(j, LIST).list)
) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ object ListSetArithmetic : Arithmetic {

private fun make2(op: BinaryOperator<List<Iota>>): OperatorBinary = OperatorBinary(all(IotaPredicate.ofType(LIST)))
{ i: Iota, j: Iota -> ListIota(
op.apply(downcast(i, LIST).list.toList(), downcast(j, LIST).list.toList())
op.apply(downcast(i, LIST).list, downcast(j, LIST).list)
) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.LIST
object OperatorAppend : OperatorBasic(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST), IotaPredicate.TRUE)) {
override fun apply(iotas: Iterable<Iota>, env: CastingEnvironment): Iterable<Iota> {
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlin.math.roundToInt
object OperatorIndex : OperatorBasic(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST), IotaPredicate.ofType(DOUBLE))) {
override fun apply(iotas: Iterable<Iota>, env: CastingEnvironment): Iterable<Iota> {
val it = iotas.iterator()
val list = downcast(it.next(), LIST).list.toMutableList()
val list = downcast(it.next(), LIST).list
val index = downcast(it.next(), DOUBLE).double
val x = list.getOrElse(index.roundToInt()) { NullIota() }
return listOf(x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.LIST
object OperatorIndexOf : OperatorBasic(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST), IotaPredicate.TRUE)) {
override fun apply(iotas: Iterable<Iota>, env: CastingEnvironment): Iterable<Iota> {
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.LIST
object OperatorRemove : OperatorBasic(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST), IotaPredicate.ofType(DOUBLE))) {
override fun apply(iotas: Iterable<Iota>, env: CastingEnvironment): Iterable<Iota> {
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import kotlin.math.min
object OperatorSlice : OperatorBasic(3, IotaMultiPredicate.triple(IotaPredicate.ofType(LIST), IotaPredicate.ofType(DOUBLE), IotaPredicate.ofType(DOUBLE))) {
override fun apply(iotas: Iterable<Iota>, env: CastingEnvironment): Iterable<Iota> {
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<Iota>().asActionResult
return list.subList(min(index0, index1), max(index0, index1)).asActionResult
return list.slice(min(index0, index1), max(index0, index1)).asActionResult
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.LIST
object OperatorUnappend : OperatorBasic(1, IotaMultiPredicate.all(IotaPredicate.ofType(LIST))) {
override fun apply(iotas: Iterable<Iota>, env: CastingEnvironment): Iterable<Iota> {
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)
val last = if(list.isEmpty()) NullIota() else list.last()
return listOf(ListIota(list.init()), last)
}
}
Loading