Skip to content

Commit

Permalink
Fix location.find.blocks tag
Browse files Browse the repository at this point in the history
These search tags are spheres, not cubes, silly
  • Loading branch information
mcmonkey4eva committed Sep 25, 2014
1 parent cf12204 commit c1f0e53
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 35 deletions.
53 changes: 28 additions & 25 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -704,16 +704,17 @@ else if (yaw < 315)
for (double x = -(radius); x <= radius; x++)
for (double y = -(radius); y <= radius; y++)
for (double z = -(radius); z <= radius; z++)
if (!materials.isEmpty()) {
for (dMaterial material : materials) {
if (material.hasData() && material.getData() != 0) {
if (material.matchesMaterialData(getBlock()
.getLocation().add(x,y,z).getBlock().getType().getNewData(getBlock()
.getLocation().add(x,y,z).getBlock().getData())))
if (Utilities.checkLocation(this, getBlock().getLocation().add(x, y, z), radius))
if (!materials.isEmpty()) {
for (dMaterial material : materials) {
if (material.hasData() && material.getData() != 0) {
if (material.matchesMaterialData(getBlock()
.getLocation().add(x,y,z).getBlock().getType().getNewData(getBlock()
.getLocation().add(x,y,z).getBlock().getData())))
found.add(new dLocation(getBlock().getLocation().add(x + 0.5, y, z + 0.5)));
}
else if (material.getMaterial() == getBlock().getLocation().add(x,y,z).getBlock().getType())
found.add(new dLocation(getBlock().getLocation().add(x + 0.5, y, z + 0.5)));
}
else if (material.getMaterial() == getBlock().getLocation().add(x,y,z).getBlock().getType())
found.add(new dLocation(getBlock().getLocation().add(x + 0.5, y, z + 0.5)));
}
} else found.add(new dLocation(getBlock().getLocation().add(x + 0.5, y, z + 0.5)));

Expand Down Expand Up @@ -749,24 +750,26 @@ else if (attribute.startsWith("surface_blocks")
for (double x = -(radius); x <= radius; x++)
for (double y = -(radius); y <= radius; y++)
for (double z = -(radius); z <= radius; z++) {
Location l = getBlock().getLocation().clone().add(x,y,z);
if (!materials.isEmpty()) {
for (dMaterial material : materials) {
if (material.matchesMaterialData(getBlock()
.getLocation().clone().add(x,y,z).getBlock().getType().getNewData(getBlock()
.getLocation().clone().add(x,y,z).getBlock().getData()))) {
if (l.clone().add(0,1,0).getBlock().getType() == Material.AIR
&& l.clone().add(0,2,0).getBlock().getType() == Material.AIR
&& l.getBlock().getType() != Material.AIR)
found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5 )));
if (Utilities.checkLocation(this, getBlock().getLocation().add(x, y, z), radius)) {
Location l = getBlock().getLocation().clone().add(x,y,z);
if (!materials.isEmpty()) {
for (dMaterial material : materials) {
if (material.matchesMaterialData(getBlock()
.getLocation().clone().add(x,y,z).getBlock().getType().getNewData(getBlock()
.getLocation().clone().add(x,y,z).getBlock().getData()))) {
if (l.clone().add(0,1,0).getBlock().getType() == Material.AIR
&& l.clone().add(0,2,0).getBlock().getType() == Material.AIR
&& l.getBlock().getType() != Material.AIR)
found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5 )));
}
}
}
}
else {
if (l.clone().add(0,1,0).getBlock().getType() == Material.AIR
&& l.clone().add(0,2,0).getBlock().getType() == Material.AIR
&& l.getBlock().getType() != Material.AIR) {
found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5 )));
else {
if (l.clone().add(0,1,0).getBlock().getType() == Material.AIR
&& l.clone().add(0,2,0).getBlock().getType() == Material.AIR
&& l.getBlock().getType() != Material.AIR) {
found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5 )));
}
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/net/aufdemrand/denizen/utilities/Utilities.java
Expand Up @@ -371,23 +371,14 @@ public static boolean checkLocation(LivingEntity entity, Location theLocation, d
* Checks entity's location against a Location (with leeway). Should be faster than
* bukkit's built in Location.distance(Location) since there's no sqrt math.
*
* Thanks chainsol :)
*
* @return true if within the specified location, false otherwise.
*/
public static boolean checkLocation(Location baseLocation, Location theLocation, double theLeeway) {

if (!baseLocation.getWorld().getName().equals(theLocation.getWorld().getName()))
return false;

if (Math.abs(baseLocation.getX() - theLocation.getX())
> theLeeway) return false;
if (Math.abs(baseLocation.getY() - theLocation.getY())
> theLeeway) return false;
if (Math.abs(baseLocation.getZ() - theLocation.getZ())
> theLeeway) return false;

return true;
return baseLocation.distanceSquared(theLocation) < theLeeway * theLeeway;
}


Expand Down

0 comments on commit c1f0e53

Please sign in to comment.