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