summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-07-23 02:06:13 +0200
committersnowleo <schneeleo@gmail.com>2011-07-23 02:06:13 +0200
commit9b0b37ee818c64487bafc02dcc104ae8cff7d5e2 (patch)
tree442484a126ddd2c561edae947e73a96d45bd4ba9
parentd7c10d19758ceecb234379d643df2c6f19a5f0b6 (diff)
downloadEssentials-9b0b37ee818c64487bafc02dcc104ae8cff7d5e2.tar
Essentials-9b0b37ee818c64487bafc02dcc104ae8cff7d5e2.tar.gz
Essentials-9b0b37ee818c64487bafc02dcc104ae8cff7d5e2.tar.lz
Essentials-9b0b37ee818c64487bafc02dcc104ae8cff7d5e2.tar.xz
Essentials-9b0b37ee818c64487bafc02dcc104ae8cff7d5e2.zip
Fix Util.getSafeDestination() to use int instead of double.
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java44
1 files changed, 22 insertions, 22 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index 97f051db4..6e772a252 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -216,21 +216,21 @@ public class Util
return c.getTimeInMillis();
}
- public static Location getSafeDestination(Location loc) throws Exception
+ public static Location getSafeDestination(final Location loc) throws Exception
{
if (loc == null || loc.getWorld() == null)
{
throw new Exception(Util.i18n("destinationNotSet"));
}
- World world = loc.getWorld();
- double x = Math.floor(loc.getX()) + 0.5;
- double y = Math.floor(loc.getY());
- double z = Math.floor(loc.getZ()) + 0.5;
+ final World world = loc.getWorld();
+ int x = loc.getBlockX();
+ int y = loc.getBlockY();
+ int z = loc.getBlockZ();
while (isBlockAboveAir(world, x, y, z))
{
- y -= 1.0D;
- if (y < 0.0D)
+ y -= 1;
+ if (y < 0)
{
throw new Exception(Util.i18n("holeInFloor"));
}
@@ -238,33 +238,33 @@ public class Util
while (isBlockUnsafe(world, x, y, z))
{
- y += 1.0D;
- if (y >= 110.0D)
+ y += 1;
+ if (y >= 127)
{
- x += 1.0D;
+ x += 1;
break;
}
}
while (isBlockUnsafe(world, x, y, z))
{
- y -= 1.0D;
- if (y <= 1.0D)
+ y -= 1;
+ if (y <= 1)
{
- y = 110.0D;
- x += 1.0D;
+ y = 127;
+ x += 1;
}
}
- return new Location(world, x, y, z, loc.getYaw(), loc.getPitch());
+ return new Location(world, x + 0.5D, y, z + 0.5D, loc.getYaw(), loc.getPitch());
}
- private static boolean isBlockAboveAir(World world, double x, double y, double z)
+ private static boolean isBlockAboveAir(final World world, final int x, final int y, final int z)
{
- return world.getBlockAt((int)Math.floor(x), (int)Math.floor(y - 1.0D), (int)Math.floor(z)).getType() == Material.AIR;
+ return world.getBlockAt(x, y - 1, z).getType() == Material.AIR;
}
- public static boolean isBlockUnsafe(World world, double x, double y, double z)
+ public static boolean isBlockUnsafe(final World world, final int x, final int y, final int z)
{
- Block below = world.getBlockAt((int)Math.floor(x), (int)Math.floor(y - 1.0D), (int)Math.floor(z));
+ final Block below = world.getBlockAt(x, y - 1, z);
if (below.getType() == Material.LAVA || below.getType() == Material.STATIONARY_LAVA)
{
return true;
@@ -275,8 +275,8 @@ public class Util
return true;
}
- if ((world.getBlockAt((int)Math.floor(x), (int)Math.floor(y), (int)Math.floor(z)).getType() != Material.AIR)
- || (world.getBlockAt((int)Math.floor(x), (int)Math.floor(y + 1.0D), (int)Math.floor(z)).getType() != Material.AIR))
+ if ((world.getBlockAt(x, y, z).getType() != Material.AIR)
+ || (world.getBlockAt(x, y + 1, z).getType() != Material.AIR))
{
return true;
}
@@ -294,7 +294,7 @@ public class Util
return str;
}
- public static double roundDouble(double d)
+ public static double roundDouble(final double d)
{
return Math.round(d * 100.0) / 100.0;
}