Unicopia/src/main/java/com/minelittlepony/unicopia/entity/RotatedView.java

45 lines
1 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.entity;
2021-02-23 22:49:14 +01:00
import java.util.Stack;
import net.minecraft.util.math.BlockPos;
public interface RotatedView {
2021-02-23 22:49:14 +01:00
Stack<Integer> getRotations();
2021-02-23 22:49:14 +01:00
boolean hasTransform();
2021-02-23 22:49:14 +01:00
default void pushRotation(int y) {
getRotations().add(y);
}
2021-02-23 22:49:14 +01:00
default void popRotation() {
Stack<Integer> rotations = getRotations();
synchronized (rotations) {
if (!rotations.isEmpty()) {
rotations.pop();
}
2021-02-23 22:49:14 +01:00
}
}
default BlockPos applyRotation(BlockPos pos) {
int newY = applyRotation(pos.getY());
if (newY == pos.getY()) {
return pos;
}
2021-02-23 22:49:14 +01:00
return new BlockPos(pos.getX(), newY, pos.getZ());
}
default int applyRotation(int y) {
Stack<Integer> rotations = getRotations();
synchronized (rotations) {
if (!hasTransform() || rotations.isEmpty()) {
return y;
}
return y - ((y - rotations.peek()) * 2);
}
}
}