From 2f71a32f64af34f8c2ab99d3ea1b4fe70718540d Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 8 Jan 2011 10:52:48 -0800 Subject: [PATCH] Fixed inaccuracy with LocalPlayer.getBlockIn() and LocalPlayer.getBlockOn(). --- src/com/sk89q/worldedit/LocalPlayer.java | 7 +++++-- src/com/sk89q/worldedit/WorldVector.java | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/com/sk89q/worldedit/LocalPlayer.java b/src/com/sk89q/worldedit/LocalPlayer.java index 621cad592..d776c43a4 100644 --- a/src/com/sk89q/worldedit/LocalPlayer.java +++ b/src/com/sk89q/worldedit/LocalPlayer.java @@ -276,7 +276,9 @@ public abstract class LocalPlayer { * @return point */ public WorldVector getBlockIn() { - return getPosition(); + WorldVector pos = getPosition(); + return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(), + pos.getY(), pos.getZ()); } /** @@ -286,7 +288,8 @@ public abstract class LocalPlayer { */ public WorldVector getBlockOn() { WorldVector pos = getPosition(); - return new WorldVector(pos.getWorld(), pos.subtract(0, 1, 0)); + return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(), + pos.getY() - 1, pos.getZ()); } /** diff --git a/src/com/sk89q/worldedit/WorldVector.java b/src/com/sk89q/worldedit/WorldVector.java index 469cba030..63130441a 100644 --- a/src/com/sk89q/worldedit/WorldVector.java +++ b/src/com/sk89q/worldedit/WorldVector.java @@ -93,6 +93,21 @@ public class WorldVector extends Vector { return world; } + /** + * Get a block point from a point. + * + * @param x + * @param y + * @param z + * @return point + */ + public static WorldVector toBlockPoint(LocalWorld world, double x, double y, + double z) { + return new WorldVector(world, (int)Math.floor(x), + (int)Math.floor(y), + (int)Math.floor(z)); + } + /** * Gets a BlockVector version. *