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

39 lines
835 B
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() {
if (!getRotations().isEmpty()) {
getRotations().pop();
}
}
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) {
2021-02-23 22:49:14 +01:00
if (!hasTransform() || getRotations().isEmpty()) {
return y;
}
2021-02-23 22:49:14 +01:00
return y - ((y - getRotations().peek()) * 2);
}
}