Skip to content

Commit

Permalink
Update Rotation utilities to fit changes made to Bukkit yaws.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Sep 15, 2013
1 parent c5caf34 commit a2c1620
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -648,7 +648,7 @@ public void target(LivingEntity target) {
: null;

((CraftCreature) entity).getHandle().
setGoalTarget(nmsTarget);
setGoalTarget(nmsTarget);

((CraftCreature) entity).getHandle().
setGoalTarget(((CraftLivingEntity) target).getHandle());
Expand Down Expand Up @@ -916,8 +916,8 @@ public String getAttribute(Attribute attribute) {
// Returns the dLocation of the entity.
// -->
if (attribute.startsWith("location")) {
return new dLocation(entity.getLocation())
.getAttribute(attribute.fulfill(1));
return new dLocation(entity.getLocation())
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down
Expand Up @@ -2259,6 +2259,7 @@ public void enchantItemEvent(EnchantItemEvent event) {
// <context.item> returns the dItem the player has clicked on.
// <context.item> returns the dInventory.
// <context.click> returns an Element with the name of the click type.
// <context.slot_type> returns an Element with the name of the slot type that was clicked.
//
// @Determine
// "CANCELLED" to stop the player from clicking.
Expand Down
35 changes: 13 additions & 22 deletions src/main/java/net/aufdemrand/denizen/utilities/entity/Rotation.java
Expand Up @@ -118,7 +118,7 @@ public static boolean isFacingLocation(Location from, Location at, float degreeL

double requiredYaw = normalizeYaw(getYaw(at.toVector().subtract(
from.toVector()).normalize()));

return (Math.abs(requiredYaw - currentYaw) < degreeLimit ||
Math.abs(requiredYaw + 360 - currentYaw) < degreeLimit ||
Math.abs(currentYaw + 360 - requiredYaw) < degreeLimit);
Expand All @@ -139,14 +139,7 @@ public static boolean isFacingLocation(Location from, Location at, float degreeL

public static boolean isFacingLocation(Entity from, Location at, float degreeLimit) {

Location location = from.getLocation();

// Important! Need to subtract 90 from player yaws
if (from instanceof Player) {
location.setYaw(location.getYaw() - 90);
}

return isFacingLocation(location, at, degreeLimit);
return isFacingLocation(from.getLocation(), at, degreeLimit);
}


Expand All @@ -164,7 +157,7 @@ public static boolean isFacingLocation(Entity from, Location at, float degreeLim

public static boolean isFacingEntity(Entity from, Entity at, float degreeLimit) {

return isFacingLocation(from, at.getLocation(), degreeLimit);
return isFacingLocation(from.getLocation(), at.getLocation(), degreeLimit);
}


Expand Down Expand Up @@ -210,15 +203,13 @@ public static float getYaw(Vector vector) {
} else if (dz < 0) {
yaw = Math.PI;
}
return (float) (-yaw * 180 / Math.PI - 90);
return (float) (-yaw * 180 / Math.PI);
}


/**
* Converts a yaw to a cardinal direction name.
*
* Thanks to sk89qs
*
* @param yaw The yaw you want to get a cardinal direction from.
*
* @return The name of the cardinal direction as a String.
Expand All @@ -228,23 +219,23 @@ public static String getCardinal(double yaw) {
yaw = normalizeYaw(yaw);
// Compare yaws, return closest direction.
if (0 <= yaw && yaw < 22.5)
return "north";
return "west";
else if (22.5 <= yaw && yaw < 67.5)
return "northeast";
return "northwest";
else if (67.5 <= yaw && yaw < 112.5)
return "east";
return "north";
else if (112.5 <= yaw && yaw < 157.5)
return "southeast";
return "northeast";
else if (157.5 <= yaw && yaw < 202.5)
return "south";
return "east";
else if (202.5 <= yaw && yaw < 247.5)
return "southwest";
return "southeast";
else if (247.5 <= yaw && yaw < 292.5)
return "west";
return "south";
else if (292.5 <= yaw && yaw < 337.5)
return "northwest";
return "southwest";
else if (337.5 <= yaw && yaw < 360.0)
return "north";
return "west";
else
return null;
}
Expand Down

0 comments on commit a2c1620

Please sign in to comment.