diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/OperatorUtils.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt similarity index 100% rename from Common/src/main/java/at/petrak/hexcasting/api/casting/OperatorUtils.kt rename to Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/Arithmetic.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/Arithmetic.java index 7e2ee6d5..8e36ee6e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/Arithmetic.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/Arithmetic.java @@ -26,8 +26,12 @@ public interface Arithmetic { // Lists HexPattern INDEX = HexPattern.fromAngles("deeed", HexDir.NORTH_WEST); HexPattern SLICE = HexPattern.fromAngles("qaeaqwded", HexDir.NORTH_WEST); + HexPattern APPEND = HexPattern.fromAngles("edqde", HexDir.SOUTH_WEST); + HexPattern UNAPPEND = HexPattern.fromAngles("qaeaq", HexDir.NORTH_WEST); HexPattern REV = HexPattern.fromAngles("qqqaede", HexDir.EAST); HexPattern INDEX_OF = HexPattern.fromAngles("dedqde", HexDir.EAST); HexPattern REMOVE = HexPattern.fromAngles("edqdewaqa", HexDir.SOUTH_WEST); HexPattern REPLACE = HexPattern.fromAngles("wqaeaqw", HexDir.NORTH_WEST); + HexPattern CONS = HexPattern.fromAngles("ddewedd", HexDir.SOUTH_EAST); + HexPattern UNCONS = HexPattern.fromAngles("aaqwqaa", HexDir.SOUTH_WEST); } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/ListArithmetic.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/ListArithmetic.java deleted file mode 100644 index 0d9549b2..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/ListArithmetic.java +++ /dev/null @@ -1,37 +0,0 @@ -package at.petrak.hexcasting.api.casting.arithmetic.impls; - -import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic; -import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator; -import at.petrak.hexcasting.api.casting.math.HexPattern; - -import java.util.List; - -public enum ListArithmetic implements Arithmetic { - INSTANCE; - - public static final List OPS = List.of( - INDEX, - SLICE, - ADD, - ABS, - REV, - INDEX_OF, - REMOVE, - REPLACE - ); - - @Override - public String arithName() { - return null; - } - - @Override - public Iterable opTypes() { - return null; - } - - @Override - public Operator getOperator(HexPattern pattern) { - return null; - } -} diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/Operator.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/Operator.java index 0be915f0..6fcbaae8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/Operator.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/Operator.java @@ -1,6 +1,6 @@ package at.petrak.hexcasting.api.casting.arithmetic.operator; -import at.petrak.hexcasting.api.casting.arithmetic.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; import at.petrak.hexcasting.api.casting.iota.Iota; import at.petrak.hexcasting.api.casting.iota.IotaType; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorBinary.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorBinary.java index af7aff8e..975924d7 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorBinary.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorBinary.java @@ -1,7 +1,7 @@ package at.petrak.hexcasting.api.casting.arithmetic.operator; -import at.petrak.hexcasting.api.casting.arithmetic.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; import at.petrak.hexcasting.api.casting.iota.Iota; import java.util.List; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorUnary.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorUnary.java index 8ea1fa2a..5fc8cd61 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorUnary.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorUnary.java @@ -1,7 +1,7 @@ package at.petrak.hexcasting.api.casting.arithmetic.operator; -import at.petrak.hexcasting.api.casting.arithmetic.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; import at.petrak.hexcasting.api.casting.iota.Iota; import java.util.List; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/IotaMultiPredicate.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/predicates/IotaMultiPredicate.java similarity index 61% rename from Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/IotaMultiPredicate.java rename to Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/predicates/IotaMultiPredicate.java index 8f9ea2dc..3ec5b5ea 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/IotaMultiPredicate.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/predicates/IotaMultiPredicate.java @@ -1,4 +1,4 @@ -package at.petrak.hexcasting.api.casting.arithmetic; +package at.petrak.hexcasting.api.casting.arithmetic.predicates; import at.petrak.hexcasting.api.casting.iota.Iota; @@ -9,19 +9,29 @@ public interface IotaMultiPredicate { static IotaMultiPredicate all(IotaPredicate child) { return new All(child); } - static IotaMultiPredicate bofa(IotaPredicate first, IotaPredicate second) { - return new Any(first, second); + static IotaMultiPredicate pair(IotaPredicate first, IotaPredicate second) { + return new Pair(first, second); + } + static IotaMultiPredicate triple(IotaPredicate first, IotaPredicate second, IotaPredicate third) { + return new Triple(first, second, third); } static IotaMultiPredicate any(IotaPredicate needs, IotaPredicate fallback) { return new Any(needs, fallback); } - record Bofa(IotaPredicate first, IotaPredicate second) implements IotaMultiPredicate { + record Pair(IotaPredicate first, IotaPredicate second) implements IotaMultiPredicate { @Override public boolean test(Iterable iotas) { var it = iotas.iterator(); return it.hasNext() && first.test(it.next()) && it.hasNext() && second.test(it.next()) && !it.hasNext(); } } + record Triple(IotaPredicate first, IotaPredicate second, IotaPredicate third) implements IotaMultiPredicate { + @Override + public boolean test(Iterable iotas) { + var it = iotas.iterator(); + return it.hasNext() && first.test(it.next()) && it.hasNext() && second.test(it.next()) && it.hasNext() && third.test(it.next()) && !it.hasNext(); + } + } record Any(IotaPredicate needs, IotaPredicate fallback) implements IotaMultiPredicate { @Override public boolean test(Iterable iotas) { diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/IotaPredicate.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/predicates/IotaPredicate.java similarity index 87% rename from Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/IotaPredicate.java rename to Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/predicates/IotaPredicate.java index 635869f9..b91d2265 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/IotaPredicate.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/predicates/IotaPredicate.java @@ -1,4 +1,4 @@ -package at.petrak.hexcasting.api.casting.arithmetic; +package at.petrak.hexcasting.api.casting.arithmetic.predicates; import at.petrak.hexcasting.api.casting.iota.Iota; import at.petrak.hexcasting.api.casting.iota.IotaType; @@ -28,4 +28,6 @@ public interface IotaPredicate { return iota.getType().equals(this.type); } } + + IotaPredicate TRUE = iota -> true; } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/DoubleArithmetic.java b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/DoubleArithmetic.java similarity index 91% rename from Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/DoubleArithmetic.java rename to Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/DoubleArithmetic.java index 47fe2654..34e4bbfe 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/DoubleArithmetic.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/DoubleArithmetic.java @@ -1,8 +1,8 @@ -package at.petrak.hexcasting.api.casting.arithmetic.impls; +package at.petrak.hexcasting.common.casting.arithmetic; import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic; -import at.petrak.hexcasting.api.casting.arithmetic.IotaMultiPredicate; -import at.petrak.hexcasting.api.casting.arithmetic.IotaPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate; import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator; import at.petrak.hexcasting.api.casting.arithmetic.operator.OperatorBinary; import at.petrak.hexcasting.api.casting.arithmetic.operator.OperatorUnary; diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListArithmetic.java b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListArithmetic.java new file mode 100644 index 00000000..1e1847f0 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/ListArithmetic.java @@ -0,0 +1,75 @@ +package at.petrak.hexcasting.common.casting.arithmetic; + +import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator; +import at.petrak.hexcasting.api.casting.iota.DoubleIota; +import at.petrak.hexcasting.api.casting.iota.ListIota; +import at.petrak.hexcasting.common.casting.arithmetic.operator.list.*; +import at.petrak.hexcasting.api.casting.arithmetic.operator.OperatorUnary; +import at.petrak.hexcasting.api.casting.math.HexPattern; + +import java.util.List; + +import static at.petrak.hexcasting.api.casting.arithmetic.operator.Operator.downcast; +import static at.petrak.hexcasting.common.lib.hex.HexIotaTypes.*; + +public enum ListArithmetic implements Arithmetic { + INSTANCE; + + public static final List OPS = List.of( + INDEX, + SLICE, + APPEND, + UNAPPEND, + ADD, + ABS, + REV, + INDEX_OF, + REMOVE, + REPLACE, + CONS, + UNCONS + ); + + @Override + public String arithName() { + return "list_ops"; + } + + @Override + public Iterable opTypes() { + return OPS; + } + + @Override + public Operator getOperator(HexPattern pattern) { + if (pattern.equals(INDEX)) { + return OperatorIndex.INSTANCE; + } else if (pattern.equals(SLICE)) { + return OperatorSlice.INSTANCE; + } else if (pattern.equals(APPEND)) { + return OperatorAppend.INSTANCE; + } else if (pattern.equals(UNAPPEND)) { + return OperatorUnappend.INSTANCE; + } else if (pattern.equals(ADD)) { + return OperatorConcat.INSTANCE; + } else if (pattern.equals(ABS)) { + return new OperatorUnary(IotaMultiPredicate.any(IotaPredicate.ofType(LIST), IotaPredicate.ofType(LIST)), iota -> new DoubleIota(downcast(iota, LIST).getList().size())); + } else if (pattern.equals(REV)) { + return new OperatorUnary(IotaMultiPredicate.any(IotaPredicate.ofType(LIST), IotaPredicate.ofType(LIST)), iota -> new ListIota(downcast(iota, LIST).getList())); + } else if (pattern.equals(INDEX_OF)) { + return new OperatorUnary(IotaMultiPredicate.any(IotaPredicate.ofType(LIST), IotaPredicate.ofType(LIST)), iota -> iota); + } else if (pattern.equals(REMOVE)) { + return new OperatorUnary(IotaMultiPredicate.any(IotaPredicate.ofType(LIST), IotaPredicate.ofType(LIST)), iota -> iota); + } else if (pattern.equals(REPLACE)) { + return new OperatorUnary(IotaMultiPredicate.any(IotaPredicate.ofType(LIST), IotaPredicate.ofType(LIST)), iota -> iota); + } else if (pattern.equals(CONS)) { + return new OperatorUnary(IotaMultiPredicate.any(IotaPredicate.ofType(LIST), IotaPredicate.ofType(LIST)), iota -> iota); + } else if (pattern.equals(UNCONS)) { + return new OperatorUnary(IotaMultiPredicate.any(IotaPredicate.ofType(LIST), IotaPredicate.ofType(LIST)), iota -> iota); + } + return null; + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/Vec3Arithmetic.java b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/Vec3Arithmetic.java similarity index 84% rename from Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/Vec3Arithmetic.java rename to Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/Vec3Arithmetic.java index 1fbd0275..e125a869 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/impls/Vec3Arithmetic.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/Vec3Arithmetic.java @@ -1,12 +1,15 @@ -package at.petrak.hexcasting.api.casting.arithmetic.impls; +package at.petrak.hexcasting.common.casting.arithmetic; import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic; -import at.petrak.hexcasting.api.casting.arithmetic.IotaMultiPredicate; -import at.petrak.hexcasting.api.casting.arithmetic.IotaPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate; import at.petrak.hexcasting.api.casting.arithmetic.operator.*; import at.petrak.hexcasting.api.casting.iota.DoubleIota; import at.petrak.hexcasting.api.casting.iota.Vec3Iota; import at.petrak.hexcasting.api.casting.math.HexPattern; +import at.petrak.hexcasting.common.casting.arithmetic.operator.vec.OperatorPack; +import at.petrak.hexcasting.common.casting.arithmetic.operator.vec.OperatorUnpack; +import at.petrak.hexcasting.common.casting.arithmetic.operator.vec.OperatorVec3Delegating; import net.minecraft.world.phys.Vec3; import java.util.ArrayList; diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/OperatorUtils.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/OperatorUtils.kt new file mode 100644 index 00000000..89798afa --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/OperatorUtils.kt @@ -0,0 +1,30 @@ +package at.petrak.hexcasting.common.casting.arithmetic.operator + +import at.petrak.hexcasting.api.casting.SpellList +import at.petrak.hexcasting.api.casting.iota.DoubleIota +import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.api.casting.iota.ListIota +import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidIota +import kotlin.math.abs +import kotlin.math.roundToInt + +fun Iterator>.nextList(argc: Int = 0): SpellList { + val (idx, x) = this.next() + if (x is ListIota) { + return x.list + } else { + throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "list") + } +} + +fun Iterator>.nextPositiveIntUnderInclusive(max: Int, argc: Int = 0): Int { + val (idx, x) = this.next() + if (x is DoubleIota) { + val double = x.double + val rounded = double.roundToInt() + if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded in 0..max) { + return rounded + } + } + throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive.less.equal", max) +} \ 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 new file mode 100644 index 00000000..2cb59ab4 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorAppend.kt @@ -0,0 +1,18 @@ +package at.petrak.hexcasting.common.casting.arithmetic.operator.list + +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate +import at.petrak.hexcasting.api.casting.asActionResult +import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.common.casting.arithmetic.operator.nextList +import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.* + +object OperatorAppend : Operator(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST), IotaPredicate.TRUE)) { + override fun apply(iotas: Iterable): Iterable { + val it = iotas.iterator().withIndex() + val list = it.nextList(arity).toMutableList() + list.add(it.next().value) + return list.asActionResult + } +} \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorConcat.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorConcat.kt new file mode 100644 index 00000000..f1168eb1 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorConcat.kt @@ -0,0 +1,19 @@ +package at.petrak.hexcasting.common.casting.arithmetic.operator.list + +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate +import at.petrak.hexcasting.api.casting.asActionResult +import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.common.casting.arithmetic.operator.nextList +import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.* + +object OperatorConcat : Operator(2, IotaMultiPredicate.all(IotaPredicate.ofType(LIST))) { + override fun apply(iotas: Iterable): Iterable { + val it = iotas.iterator().withIndex() + val lhs = it.nextList(arity).toMutableList() + val rhs = it.nextList(arity) + lhs.addAll(rhs) + return lhs.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 new file mode 100644 index 00000000..6d696c5c --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorIndex.kt @@ -0,0 +1,19 @@ +package at.petrak.hexcasting.common.casting.arithmetic.operator.list + +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator +import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.api.casting.iota.NullIota +import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.* +import kotlin.math.roundToInt + +object OperatorIndex : Operator(2, IotaMultiPredicate.pair(IotaPredicate.ofType(LIST), IotaPredicate.ofType(DOUBLE))) { + override fun apply(iotas: Iterable): Iterable { + val it = iotas.iterator() + val list = downcast(it.next(), LIST).list.toMutableList() + val index = downcast(it.next(), DOUBLE).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/OperatorSlice.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorSlice.kt new file mode 100644 index 00000000..092a1123 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorSlice.kt @@ -0,0 +1,25 @@ +package at.petrak.hexcasting.common.casting.arithmetic.operator.list + +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator +import at.petrak.hexcasting.api.casting.asActionResult +import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.common.casting.arithmetic.operator.nextList +import at.petrak.hexcasting.common.casting.arithmetic.operator.nextPositiveIntUnderInclusive +import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.* +import kotlin.math.max +import kotlin.math.min + +object OperatorSlice : Operator(3, IotaMultiPredicate.triple(IotaPredicate.ofType(LIST), IotaPredicate.ofType(DOUBLE), IotaPredicate.ofType(DOUBLE))) { + override fun apply(iotas: Iterable): Iterable { + val it = iotas.iterator().withIndex() + val list = it.nextList(arity).toList() + 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 + } +} \ 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 new file mode 100644 index 00000000..0721f18d --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/list/OperatorUnappend.kt @@ -0,0 +1,19 @@ +package at.petrak.hexcasting.common.casting.arithmetic.operator.list + +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate +import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.api.casting.iota.ListIota +import at.petrak.hexcasting.api.casting.iota.NullIota +import at.petrak.hexcasting.common.casting.arithmetic.operator.nextList +import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.* + +object OperatorUnappend : Operator(1, IotaMultiPredicate.all(IotaPredicate.ofType(LIST))) { + override fun apply(iotas: Iterable): Iterable { + val it = iotas.iterator().withIndex() + val list = it.nextList(arity).toMutableList() + val last = list.removeLastOrNull() ?: NullIota() + return listOf(ListIota(list), last) + } +} \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorPack.java b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorPack.java similarity index 71% rename from Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorPack.java rename to Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorPack.java index 4e558c7b..e4f6b218 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorPack.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorPack.java @@ -1,8 +1,9 @@ -package at.petrak.hexcasting.api.casting.arithmetic.operator; +package at.petrak.hexcasting.common.casting.arithmetic.operator.vec; -import at.petrak.hexcasting.api.casting.arithmetic.IotaMultiPredicate; -import at.petrak.hexcasting.api.casting.arithmetic.IotaPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator; import at.petrak.hexcasting.api.casting.iota.Iota; import at.petrak.hexcasting.api.casting.iota.Vec3Iota; import at.petrak.hexcasting.common.lib.hex.HexIotaTypes; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorUnpack.java b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorUnpack.java similarity index 70% rename from Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorUnpack.java rename to Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorUnpack.java index b1faf7f0..93a977b1 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorUnpack.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorUnpack.java @@ -1,8 +1,9 @@ -package at.petrak.hexcasting.api.casting.arithmetic.operator; +package at.petrak.hexcasting.common.casting.arithmetic.operator.vec; -import at.petrak.hexcasting.api.casting.arithmetic.IotaMultiPredicate; -import at.petrak.hexcasting.api.casting.arithmetic.IotaPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator; import at.petrak.hexcasting.api.casting.iota.DoubleIota; import at.petrak.hexcasting.api.casting.iota.Iota; import at.petrak.hexcasting.common.lib.hex.HexIotaTypes; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorVec3Delegating.java b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorVec3Delegating.java similarity index 84% rename from Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorVec3Delegating.java rename to Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorVec3Delegating.java index 511f05e2..8d135f83 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/arithmetic/operator/OperatorVec3Delegating.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/arithmetic/operator/vec/OperatorVec3Delegating.java @@ -1,10 +1,11 @@ -package at.petrak.hexcasting.api.casting.arithmetic.operator; +package at.petrak.hexcasting.common.casting.arithmetic.operator.vec; -import at.petrak.hexcasting.api.casting.arithmetic.IotaMultiPredicate; -import at.petrak.hexcasting.api.casting.arithmetic.IotaPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate; +import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate; import at.petrak.hexcasting.api.casting.arithmetic.IterPair; import at.petrak.hexcasting.api.casting.arithmetic.TripleIterable; -import at.petrak.hexcasting.api.casting.arithmetic.impls.DoubleArithmetic; +import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator; +import at.petrak.hexcasting.common.casting.arithmetic.DoubleArithmetic; import at.petrak.hexcasting.api.casting.iota.DoubleIota; import at.petrak.hexcasting.api.casting.iota.Iota; import at.petrak.hexcasting.api.casting.iota.Vec3Iota; diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexArithmetics.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexArithmetics.java index ab837c77..6b559a09 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexArithmetics.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexArithmetics.java @@ -1,11 +1,12 @@ package at.petrak.hexcasting.common.lib.hex; import at.petrak.hexcasting.api.casting.arithmetic.engine.ArithmeticEngine; -import at.petrak.hexcasting.api.casting.arithmetic.impls.DoubleArithmetic; -import at.petrak.hexcasting.api.casting.arithmetic.impls.Vec3Arithmetic; +import at.petrak.hexcasting.common.casting.arithmetic.DoubleArithmetic; +import at.petrak.hexcasting.common.casting.arithmetic.ListArithmetic; +import at.petrak.hexcasting.common.casting.arithmetic.Vec3Arithmetic; import java.util.List; public class HexArithmetics { - public static ArithmeticEngine ENGINE = new ArithmeticEngine(List.of(DoubleArithmetic.INSTANCE, Vec3Arithmetic.INSTANCE)); + public static ArithmeticEngine ENGINE = new ArithmeticEngine(List.of(DoubleArithmetic.INSTANCE, Vec3Arithmetic.INSTANCE, ListArithmetic.INSTANCE)); }