Fix some coordinate errors

- Fixes WorldGuard weirdness
 - Fixes #860
This commit is contained in:
dordsor21
2021-01-18 15:37:14 +00:00
parent 798b4cdd4e
commit c218743fa8
4 changed files with 33 additions and 14 deletions

View File

@ -83,16 +83,31 @@ public abstract class Vector3 {
return YzxOrderComparator.YZX_ORDER;
}
/**
* Gets the x coordinate rounded, accounting for negative coordinates
*
* @return the x coordinate
*/
public int getBlockX() {
return (int) MathUtils.roundHalfUp(getX());
return MathMan.roundInt(getX());
}
/**
* Gets the y coordinate rounded, accounting for negative coordinates
*
* @return the y coordinate
*/
public int getBlockY() {
return (int) MathUtils.roundHalfUp(getY());
return MathMan.roundInt(getY());
}
/**
* Gets the z coordinate rounded, accounting for negative coordinates
*
* @return the z coordinate
*/
public int getBlockZ() {
return (int) MathUtils.roundHalfUp(getZ());
return MathMan.roundInt(getZ());
}
public MutableVector3 setComponents(Vector3 other) {
@ -487,6 +502,15 @@ public abstract class Vector3 {
return Vector3.at(Math.floor(getX() + 0.5), Math.floor(getY() + 0.5), Math.floor(getZ() + 0.5));
}
/**
* Rounds all components using {@link MathUtils#roundHalfUp(double)}
*
* @return a new vector
*/
public Vector3 roundHalfUp() {
return Vector3.at(MathUtils.roundHalfUp(getX()), MathUtils.roundHalfUp(getY()), MathUtils.roundHalfUp(getZ()));
}
/**
* Returns a vector with the absolute values of the components of
* this vector.
@ -595,8 +619,7 @@ public abstract class Vector3 {
* @return a new {@code BlockVector}
*/
public static BlockVector3 toBlockPoint(double x, double y, double z) {
return BlockVector3.at(MathUtils.roundHalfUp(x), MathUtils.roundHalfUp(y), MathUtils.roundHalfUp(z));
//return BlockVector3.at(x, y, z);
return BlockVector3.at(x, y, z);
}
/**

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.util;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -80,8 +79,7 @@ public enum Direction {
}
Direction(Vector3 vector, int flags, int left, int right) {
this.blockPoint = BlockVector3.at(MathMan.roundInt(Math.signum(vector.getX())),
MathMan.roundInt(Math.signum(vector.getY())), MathMan.roundInt(Math.signum(vector.getZ())));
this.blockPoint = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
this.direction = vector.normalize();
this.flags = flags;
this.left = left;