2020-03-10 16:34:04 +01:00
|
|
|
package com.simibubi.create.foundation.utility;
|
|
|
|
|
2020-11-22 14:27:50 +01:00
|
|
|
import java.util.Arrays;
|
2020-12-16 17:36:22 +01:00
|
|
|
import java.util.EnumSet;
|
2020-11-22 14:27:50 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2021-11-02 06:18:30 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
2021-11-02 00:08:20 +01:00
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
import net.minecraft.core.Direction.Axis;
|
2021-02-18 19:43:22 +01:00
|
|
|
|
2020-03-10 16:34:04 +01:00
|
|
|
public class Iterate {
|
|
|
|
|
2021-04-08 19:22:11 +02:00
|
|
|
public static final boolean[] trueAndFalse = { true, false };
|
2021-12-04 08:48:55 +01:00
|
|
|
public static final boolean[] falseAndTrue = { false, true };
|
2021-04-08 19:22:11 +02:00
|
|
|
public static final int[] zeroAndOne = { 0, 1 };
|
|
|
|
public static final int[] positiveAndNegative = { 1, -1 };
|
2020-03-10 16:34:04 +01:00
|
|
|
public static final Direction[] directions = Direction.values();
|
|
|
|
public static final Direction[] horizontalDirections = getHorizontals();
|
|
|
|
public static final Axis[] axes = Axis.values();
|
2020-12-16 17:36:22 +01:00
|
|
|
public static final EnumSet<Direction.Axis> axisSet = EnumSet.allOf(Direction.Axis.class);
|
2020-03-10 16:34:04 +01:00
|
|
|
|
|
|
|
private static Direction[] getHorizontals() {
|
|
|
|
Direction[] directions = new Direction[4];
|
|
|
|
for (int i = 0; i < 4; i++)
|
2021-07-15 11:32:03 +02:00
|
|
|
directions[i] = Direction.from2DDataValue(i);
|
2020-03-10 16:34:04 +01:00
|
|
|
return directions;
|
|
|
|
}
|
2020-11-22 14:27:50 +01:00
|
|
|
|
|
|
|
public static Direction[] directionsInAxis(Axis axis) {
|
|
|
|
switch (axis) {
|
2021-04-08 19:22:11 +02:00
|
|
|
case X:
|
|
|
|
return new Direction[] { Direction.EAST, Direction.WEST };
|
|
|
|
case Y:
|
|
|
|
return new Direction[] { Direction.UP, Direction.DOWN };
|
|
|
|
default:
|
|
|
|
case Z:
|
|
|
|
return new Direction[] { Direction.SOUTH, Direction.NORTH };
|
2020-11-22 14:27:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 18:02:46 +02:00
|
|
|
public static List<BlockPos> hereAndBelow(BlockPos pos) {
|
2021-07-15 11:32:03 +02:00
|
|
|
return Arrays.asList(pos, pos.below());
|
2020-04-05 18:02:46 +02:00
|
|
|
}
|
2021-04-08 19:22:11 +02:00
|
|
|
|
2020-11-30 15:23:37 +01:00
|
|
|
public static List<BlockPos> hereBelowAndAbove(BlockPos pos) {
|
2021-07-15 11:32:03 +02:00
|
|
|
return Arrays.asList(pos, pos.below(), pos.above());
|
2020-11-30 15:23:37 +01:00
|
|
|
}
|
2023-05-09 18:23:47 +02:00
|
|
|
|
|
|
|
public static <T> T cycleValue(List<T> list, T current) {
|
|
|
|
int currentIndex = list.indexOf(current);
|
|
|
|
if (currentIndex == -1) {
|
|
|
|
throw new IllegalArgumentException("Current value not found in list");
|
|
|
|
}
|
|
|
|
int nextIndex = (currentIndex + 1) % list.size();
|
|
|
|
return list.get(nextIndex);
|
|
|
|
}
|
2020-03-10 16:34:04 +01:00
|
|
|
}
|