Paste #12034: Untitled Paste

Date: 2014/12/12 19:43:08 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


public static Location mapTrace(LivingEntity from, double range) {
        Location start = from.getEyeLocation();
        Vector startVec = start.toVector();
        double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180));
        double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI/180));
        double ny = Math.sin(start.getPitch() * (Math.PI / 180));
        double nz = xzLen * Math.cos(start.getYaw() * (Math.PI/180));
        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;
        double yaw = start.getYaw();
        double angleX = -1;
        double angleY = 0;
        switch (l.direction) {
            case NORTH:
                angleX = -yaw;
                break;
            case SOUTH:
                angleX = -yaw+180;
                break;
            case EAST:
                angleX = -yaw-90;
                break;
            case WEST:
                angleX = -yaw+90;
                break;
        }
        if (angleX < 0 || angleY < 0) return null;
        Vector hit = startVec.normalize().multiply((0.072/angleX)*(180-angleX));
        return new Location(start.getWorld(), hit.getX(), hit.getY(), hit.getZ());
    }