Skip to content

Commit

Permalink
location.precise_impact_normal
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 2, 2015
1 parent d37e7ff commit f3b9354
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -641,6 +641,27 @@ else if (type == Material.TRAP_DOOR
// DIRECTION ATTRIBUTES
/////////////////

// <--[tag]
// @attribute <l@location.precise_impact_normal[<range>]>
// @returns dLocation
// @description
// Returns the exact impact normal at the location this location is pointing at.
// Optionally, specify a maximum range to find the location from.
// -->
if (attribute.startsWith("precise_impact_normal")) {
int range = attribute.getIntContext(1);
if (range < 1) range = 200;
double xzLen = Math.cos((getPitch() % 360) * (Math.PI / 180));
double nx = xzLen * Math.sin(-getYaw() * (Math.PI / 180));
double ny = Math.sin(getPitch() * (Math.PI / 180));
double nz = xzLen * Math.cos(getYaw() * (Math.PI / 180));
Location location = Rotation.getImpactNormal(this, new org.bukkit.util.Vector(nx, -ny, nz), range);
if (location != null)
return new dLocation(location).getAttribute(attribute.fulfill(1));
else
return null;
}

// <--[tag]
// @attribute <l@location.precise_cursor_on[<range>]>
// @returns dLocation
Expand Down
Expand Up @@ -143,6 +143,15 @@ public static Location rayTrace(Location start, Vector direction, double range)
return null;
}

public static Location getImpactNormal(Location start, Vector direction, double range) {
Vector startVec = start.toVector();
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
if (l != null && l.direction != null) {
return new Location(start.getWorld(), l.direction.getAdjacentX(), l.direction.getAdjacentY(), l.direction.getAdjacentZ());
}
return null;
}

/**
* Gets the precise location a LivingEntity is looking at.
*
Expand Down

0 comments on commit f3b9354

Please sign in to comment.