package net.mcft.copy.betterstorage.utils;

import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.ForgeDirection;

public class DirectionUtils {
	
	/** Gets the ForgeDirection from the direction an entity is facing. */
	public static ForgeDirection getOrientation(Entity entity) {
		int dir = MathHelper.floor_double(entity.rotationYaw * 4.0 / 360.0 + 0.5) & 3;
		switch (dir) {
			case 1: return ForgeDirection.WEST;
			case 2: return ForgeDirection.NORTH;
			case 3: return ForgeDirection.EAST;
			default: return ForgeDirection.SOUTH;
		}
	}
	
	/** Gets the direction from a ForgeDirection in degrees. */
	public static int getRotation(ForgeDirection dir) {
		if (dir == ForgeDirection.WEST) return 90;
		else if (dir == ForgeDirection.NORTH) return 180;
		else if (dir == ForgeDirection.EAST) return 270;
		else return 0;
	}
	
	/** Returns the difference between the two angles in degrees (-180 to 180). */
	public static double angleDifference(double angle1, double angle2) {
		return (angle2 - angle1 + 180) % 360 - 180;
	}
	
	/** Returns the ForgeDirection from a vanilla side value. */
	public static ForgeDirection getDirectionFromSide(int side) {
		switch (side) {
			case 0: return ForgeDirection.DOWN;
			case 1: return ForgeDirection.UP;
			case 2: return ForgeDirection.NORTH;
			case 3: return ForgeDirection.SOUTH;
			case 4: return ForgeDirection.WEST;
			case 5: return ForgeDirection.EAST;
			default: return ForgeDirection.UNKNOWN;
		}
	}
	
}

@@ -881,209 +881,8 @@
 %7D%0A%09%0A
-%09/** Returns the difference between the two angles in degrees (-180 to 180). */%0A%09public static double angleDifference(double angle1, double angle2) %7B%0A%09%09return (angle2 - angle1 + 180) %25 360 - 180;%0A%09%7D%0A%09%0A
 %09/**
@@ -935,24 +935,24 @@
 e value. */%0A
+
 %09public stat
@@ -1297,16 +1297,16 @@
 NKNOWN;%0A
-
 %09%09%7D%0A%09%7D%0A%09
@@ -1306,10 +1306,674 @@
 %09%7D%0A%09%7D%0A%09%0A
+%09/** Returns the difference between the two angles in degrees (-180 to 180). */%0A%09public static double angleDifference(double angle1, double angle2) %7B%0A%09%09angle1 = (angle1 + 360) %25 360;%0A%09%09angle2 = (angle2 + 360) %25 360;%0A%09%09return (angle2 - angle1 + 180) %25 360 - 180;%0A%09%7D%0A%09%0A%09/** Returns the angle between two points on a plane (-180 to 180). */%0A%09public static double angleBetween(double x1, double y1, double x2, double y2) %7B%0A%09%09return Math.toDegrees(Math.atan2(y2 - y1, x2 - x1));%0A%09%7D%0A%09%0A%09/** Returns the angle between two entities (-180 to 180). */%0A%09public static double angleBetween(Entity e1, Entity e2) %7B%0A%09%09return angleBetween(e1.posX, e1.posZ, e2.posX, e2.posZ);%0A%09%7D%0A%09%0A
 %7D%0A

Fix angleDifference not working with any angle