Skip to content

Commit

Permalink
Improve Rotation.mapTrace
Browse files Browse the repository at this point in the history
Semi-accurately return the location on the map targetted
  • Loading branch information
mcmonkey4eva committed Dec 13, 2014
1 parent b4dc113 commit 122ec85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -1394,9 +1394,10 @@ else if (attribute.startsWith("equipment")) {
// TODO: meta
if (attribute.startsWith("map_trace")) {
Location location = Rotation.mapTrace(getLivingEntity(), 200);
if (location != null)
if (location != null) {
// TODO: make this return the point (between 0,0 and 128,128) on the map
return new dLocation(null, location.getX(), location.getY()).getAttribute(attribute.fulfill(1));
return new dLocation(location).getAttribute(attribute.fulfill(1));
}
}

// <--[tag]
Expand Down
Expand Up @@ -168,6 +168,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
radius.debug() +
data.debug() +
qty.debug() +
offset.debug() +
(effect != null ? "" : offset.debug()));

for (dLocation location: locations) {
Expand Down
Expand Up @@ -98,6 +98,7 @@ public static Location mapTrace(LivingEntity from, double range) {
Vector endVec = startVec.clone().add(new Vector(nx, -ny, nz).multiply(range));
MovingObjectPosition l = rayTrace(start.getWorld(), startVec, endVec);
if (l == null || l.pos == null) return null;
Vector finalVec = new Vector(l.pos.a, l.pos.b, l.pos.c);
double yaw = start.getYaw();
double angleX = -1;
double angleY = 0;
Expand All @@ -115,9 +116,9 @@ public static Location mapTrace(LivingEntity from, double range) {
angleX = -yaw+90;
break;
}
if (angleX < 0 || angleY < 0) return null;
// TODO: calculate and return the actual location of the map (should be distance between original start/end minus 0.072)
Vector hit = startVec.normalize().multiply((0.072/angleX)*(180-angleX));
// wallPosition - ((end - start).normalize() * 0.072)
// TODO: Increase accuracy using trigonometry (forward.norm*length is imperfect)
Vector hit = finalVec.clone().subtract((endVec.clone().subtract(startVec)).normalize().multiply(0.072));
return new Location(start.getWorld(), hit.getX(), hit.getY(), hit.getZ());
}

Expand Down

0 comments on commit 122ec85

Please sign in to comment.