2021-02-23 17:08:50 +01:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
|
|
|
|
2021-02-23 22:49:14 +01:00
|
|
|
import java.util.Stack;
|
|
|
|
|
2021-02-23 17:08:50 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
|
|
|
public interface RotatedView {
|
|
|
|
|
2021-02-23 22:49:14 +01:00
|
|
|
Stack<Integer> getRotations();
|
2021-02-23 17:08:50 +01:00
|
|
|
|
2021-02-23 22:49:14 +01:00
|
|
|
boolean hasTransform();
|
2021-02-23 17:08:50 +01:00
|
|
|
|
2021-02-23 22:49:14 +01:00
|
|
|
default void pushRotation(int y) {
|
|
|
|
getRotations().add(y);
|
|
|
|
}
|
2021-02-23 17:08:50 +01:00
|
|
|
|
2021-02-23 22:49:14 +01:00
|
|
|
default void popRotation() {
|
2021-02-27 16:47:54 +01:00
|
|
|
Stack<Integer> rotations = getRotations();
|
|
|
|
synchronized (rotations) {
|
|
|
|
if (!rotations.isEmpty()) {
|
|
|
|
rotations.pop();
|
|
|
|
}
|
2021-02-23 22:49:14 +01:00
|
|
|
}
|
2021-02-23 17:08:50 +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());
|
2021-02-23 17:08:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
default int applyRotation(int y) {
|
2021-02-27 16:47:54 +01:00
|
|
|
Stack<Integer> rotations = getRotations();
|
|
|
|
synchronized (rotations) {
|
|
|
|
if (!hasTransform() || rotations.isEmpty()) {
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
return y - ((y - rotations.peek()) * 2);
|
2021-02-23 17:08:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|