return new Vector(newLocX, newLocY, newLocZ);
}
@Override
public BlockFace getMovementDirection(MinecartMember<?> member, Vector movement) {
final BlockFace raildirection = this.getDirection();
final boolean isHorizontalMovement = Math.abs(movement.getX()) >= 0.0001 || Math.abs(movement.getZ()) >= 0.0001;
BlockFace direction;
if (this.isSloped()) {
// Sloped rail logic
if (isHorizontalMovement) {
// Deal with minecarts moving on straight slopes
float moveYaw = MathUtil.getLookAtYaw(movement);
float diff1 = MathUtil.getAngleDifference(moveYaw, FaceUtil.faceToYaw(raildirection));
float diff2 = MathUtil.getAngleDifference(moveYaw, FaceUtil.faceToYaw(raildirection.getOppositeFace()));
// Compare with the previous direction to sort out equality problems
if (diff1 == diff2) {
diff1 = FaceUtil.getFaceYawDifference(member.getDirectionFrom(), raildirection);
diff2 = FaceUtil.getFaceYawDifference(member.getDirectionFrom(), raildirection.getOppositeFace());
}
// Use the opposite direction if needed
if (diff1 > diff2) {
direction = raildirection.getOppositeFace();
} else {
direction = raildirection;
}
} else {
// Deal with vertically moving or standing still minecarts on slopes
if (Math.abs(movement.getY()) > 0.0001) {
// Going from vertical to a slope
if (movement.getY() > 0.0) {
direction = raildirection;
} else {
direction = raildirection.getOppositeFace();
}
} else {
// Gravity sends it down the slope at some point
direction = raildirection.getOppositeFace();
}
}
} else if (this.curved) {
// Curved rail logic
BlockFace movementDir = FaceUtil.getDirection(movement);
BlockFace[] possibleDirections = FaceUtil.getFaces(raildirection.getOppositeFace());
if (FaceUtil.isSubCardinal(movementDir)) {
direction = movementDir;
} else {
// Evaluate ingoing/outgoing faces with direction
BlockFace directionTo;
if (possibleDirections[0] == movementDir) {
// Move towards 0
directionTo = possibleDirections[0];
} else if (possibleDirections[1] == movementDir) {
// Move towards 1