Revert "More code quality fixes"

This reverts commit 2d6957ce
This commit is contained in:
MattBDev
2020-01-23 14:41:57 -05:00
parent 37003ec089
commit e0f6869573
115 changed files with 1688 additions and 686 deletions

View File

@ -32,22 +32,20 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.Comparator;
import javax.annotation.concurrent.Immutable;
/**
* An immutable 3-dimensional vector.
*/
@Immutable
public class BlockVector3 {
public abstract class BlockVector3 {
public static final BlockVector3 ZERO = new BlockVector3(0, 0, 0);
public static final BlockVector3 UNIT_X = new BlockVector3(1, 0, 0);
public static final BlockVector3 UNIT_Y = new BlockVector3(0, 1, 0);
public static final BlockVector3 UNIT_Z = new BlockVector3(0, 0, 1);
public static final BlockVector3 UNIT_MINUS_X = new BlockVector3(-1, 0, 0);
public static final BlockVector3 UNIT_MINUS_Y = new BlockVector3(0, -1, 0);
public static final BlockVector3 UNIT_MINUS_Z = new BlockVector3(0, 0, -1);
public static final BlockVector3 ONE = new BlockVector3(1, 1, 1);
public static final BlockVector3 ZERO = BlockVector3.at(0, 0, 0);
public static final BlockVector3 UNIT_X = BlockVector3.at(1, 0, 0);
public static final BlockVector3 UNIT_Y = BlockVector3.at(0, 1, 0);
public static final BlockVector3 UNIT_Z = BlockVector3.at(0, 0, 1);
public static final BlockVector3 UNIT_MINUS_X = BlockVector3.at(-1, 0, 0);
public static final BlockVector3 UNIT_MINUS_Y = BlockVector3.at(0, -1, 0);
public static final BlockVector3 UNIT_MINUS_Z = BlockVector3.at(0, 0, -1);
public static final BlockVector3 ONE = BlockVector3.at(1, 1, 1);
public static BlockVector3 at(double x, double y, double z) {
return at((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z));
@ -70,7 +68,7 @@ public class BlockVector3 {
break;
}
*/
return new BlockVector3(x, y, z);
return new BlockVector3Imp(x, y, z);
}
private static final int WORLD_XZ_MINMAX = 30_000_000;
@ -116,21 +114,6 @@ public class BlockVector3 {
return YzxOrderComparator.YZX_ORDER;
}
private final int x, y, z;
/**
* Construct an instance.
*
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
*/
public BlockVector3(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public MutableBlockVector3 setComponents(double x, double y, double z) {
return new MutableBlockVector3((int) x, (int) y, (int) z);
}
@ -141,35 +124,35 @@ public class BlockVector3 {
public long toLongPackedForm() {
checkLongPackable(this);
return (x & BITS_26) | ((z & BITS_26) << 26) | (((y & (long) BITS_12) << (26 + 26)));
return (getX() & BITS_26) | ((getZ() & BITS_26) << 26) | (((getY() & (long) BITS_12) << (26 + 26)));
}
public MutableBlockVector3 mutX(double x) {
return new MutableBlockVector3((int) x, y, z);
return new MutableBlockVector3((int) x, getY(), getZ());
}
public MutableBlockVector3 mutY(double y) {
return new MutableBlockVector3(x, (int) y, z);
return new MutableBlockVector3(getX(), (int) y, getZ());
}
public MutableBlockVector3 mutZ(double z) {
return new MutableBlockVector3(x, y, (int) z);
return new MutableBlockVector3(getX(), getY(), (int) z);
}
public MutableBlockVector3 mutX(int x) {
return new MutableBlockVector3(x, y, z);
return new MutableBlockVector3(x, getY(), getZ());
}
public MutableBlockVector3 mutY(int y) {
return new MutableBlockVector3(x, y, z);
return new MutableBlockVector3(getX(), y, getZ());
}
public MutableBlockVector3 mutZ(int z) {
return new MutableBlockVector3(x, y, z);
return new MutableBlockVector3(getX(), getY(), z);
}
public BlockVector3 toImmutable() {
return BlockVector3.at(x, y, z);
return BlockVector3.at(getX(), getY(), getZ());
}
/**
@ -177,9 +160,7 @@ public class BlockVector3 {
*
* @return the x coordinate
*/
public int getX() {
return x;
}
public abstract int getX();
/**
* Get the X coordinate.
@ -187,7 +168,7 @@ public class BlockVector3 {
* @return the x coordinate
*/
public int getBlockX() {
return x;
return getX();
}
/**
@ -197,7 +178,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 withX(int x) {
return BlockVector3.at(x, y, z);
return BlockVector3.at(x, getY(), getZ());
}
/**
@ -205,9 +186,7 @@ public class BlockVector3 {
*
* @return the y coordinate
*/
public int getY() {
return y;
}
public abstract int getY();
/**
* Get the Y coordinate.
@ -215,7 +194,7 @@ public class BlockVector3 {
* @return the y coordinate
*/
public int getBlockY() {
return y;
return getY();
}
/**
@ -225,7 +204,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 withY(int y) {
return BlockVector3.at(x, y, z);
return BlockVector3.at(getX(), y, getZ());
}
/**
@ -233,9 +212,7 @@ public class BlockVector3 {
*
* @return the z coordinate
*/
public int getZ() {
return z;
}
public abstract int getZ();
/**
* Get the Z coordinate.
@ -243,7 +220,7 @@ public class BlockVector3 {
* @return the z coordinate
*/
public int getBlockZ() {
return z;
return getZ();
}
/**
@ -253,7 +230,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 withZ(int z) {
return BlockVector3.at(x, y, z);
return BlockVector3.at(getX(), getY(), z);
}
/**
@ -263,7 +240,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 add(BlockVector3 other) {
return add(other.x, other.y, other.z);
return add(other.getX(), other.getY(), other.getZ());
}
/**
@ -275,7 +252,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 add(int x, int y, int z) {
return BlockVector3.at(this.x + x, this.y + y, this.z + z);
return BlockVector3.at(this.getX() + x, this.getY() + y, this.getZ() + z);
}
/**
@ -286,12 +263,12 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 add(BlockVector3... others) {
int newX = x, newY = y, newZ = z;
int newX = getX(), newY = getY(), newZ = getZ();
for (BlockVector3 other : others) {
newX += other.x;
newY += other.y;
newZ += other.z;
newX += other.getX();
newY += other.getY();
newZ += other.getZ();
}
return BlockVector3.at(newX, newY, newZ);
@ -305,7 +282,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 subtract(BlockVector3 other) {
return subtract(other.x, other.y, other.z);
return subtract(other.getX(), other.getY(), other.getZ());
}
/**
@ -318,7 +295,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 subtract(int x, int y, int z) {
return BlockVector3.at(this.x - x, this.y - y, this.z - z);
return BlockVector3.at(this.getX() - x, this.getY() - y, this.getZ() - z);
}
/**
@ -329,12 +306,12 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 subtract(BlockVector3... others) {
int newX = x, newY = y, newZ = z;
int newX = getX(), newY = getY(), newZ = getZ();
for (BlockVector3 other : others) {
newX -= other.x;
newY -= other.y;
newZ -= other.z;
newX -= other.getX();
newY -= other.getY();
newZ -= other.getZ();
}
return BlockVector3.at(newX, newY, newZ);
@ -347,7 +324,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 multiply(BlockVector3 other) {
return multiply(other.x, other.y, other.z);
return multiply(other.getX(), other.getY(), other.getZ());
}
/**
@ -359,7 +336,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 multiply(int x, int y, int z) {
return BlockVector3.at(this.x * x, this.y * y, this.z * z);
return BlockVector3.at(this.getX() * x, this.getY() * y, this.getZ() * z);
}
/**
@ -369,12 +346,12 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 multiply(BlockVector3... others) {
int newX = x, newY = y, newZ = z;
int newX = getX(), newY = getY(), newZ = getZ();
for (BlockVector3 other : others) {
newX *= other.x;
newY *= other.y;
newZ *= other.z;
newX *= other.getX();
newY *= other.getY();
newZ *= other.getZ();
}
return BlockVector3.at(newX, newY, newZ);
@ -397,7 +374,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 divide(BlockVector3 other) {
return divide(other.x, other.y, other.z);
return divide(other.getX(), other.getY(), other.getZ());
}
/**
@ -409,7 +386,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 divide(int x, int y, int z) {
return BlockVector3.at(this.x / x, this.y / y, this.z / z);
return BlockVector3.at(this.getX() / x, this.getY() / y, this.getZ() / z);
}
/**
@ -431,7 +408,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 shr(int x, int y, int z) {
return at(this.x >> x, this.y >> y, this.z >> z);
return at(this.getX() >> x, this.getY() >> y, this.getZ() >> z);
}
/**
@ -453,7 +430,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 shl(int x, int y, int z) {
return at(this.x << x, this.y << y, this.z << z);
return at(this.getX() << x, this.getY() << y, this.getZ() << z);
}
/**
@ -481,7 +458,7 @@ public class BlockVector3 {
* @return length, squared
*/
public int lengthSq() {
return x * x + y * y + z * z;
return getX() * getX() + getY() * getY() + getZ() * getZ();
}
/**
@ -501,9 +478,9 @@ public class BlockVector3 {
* @return distance
*/
public int distanceSq(BlockVector3 other) {
int dx = other.x - x;
int dy = other.y - y;
int dz = other.z - z;
int dx = other.getX() - getX();
int dy = other.getY() - getY();
int dz = other.getZ() - getZ();
return dx * dx + dy * dy + dz * dz;
}
@ -515,9 +492,9 @@ public class BlockVector3 {
*/
public BlockVector3 normalize() {
double len = length();
double x = this.x / len;
double y = this.y / len;
double z = this.z / len;
double x = this.getX() / len;
double y = this.getY() / len;
double z = this.getZ() / len;
return BlockVector3.at(x, y, z);
}
@ -528,7 +505,7 @@ public class BlockVector3 {
* @return the dot product of this and the other vector
*/
public double dot(BlockVector3 other) {
return x * other.x + y * other.y + z * other.z;
return getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ();
}
/**
@ -538,10 +515,10 @@ public class BlockVector3 {
* @return the cross product of this and the other vector
*/
public BlockVector3 cross(BlockVector3 other) {
return new BlockVector3(
y * other.z - z * other.y,
z * other.x - x * other.z,
x * other.y - y * other.x
return new BlockVector3Imp(
getY() * other.getZ() - getZ() * other.getY(),
getZ() * other.getX() - getX() * other.getZ(),
getX() * other.getY() - getY() * other.getX()
);
}
@ -553,7 +530,8 @@ public class BlockVector3 {
* @return true if the vector is contained
*/
public boolean containedWithin(BlockVector3 min, BlockVector3 max) {
return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z;
return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max
.getY() && getZ() >= min.getZ() && getZ() <= max.getZ();
}
/**
@ -565,11 +543,11 @@ public class BlockVector3 {
*/
public BlockVector3 clampY(int min, int max) {
checkArgument(min <= max, "minimum cannot be greater than maximum");
if (y < min) {
return BlockVector3.at(x, min, z);
if (getY() < min) {
return BlockVector3.at(getX(), min, getZ());
}
if (y > max) {
return BlockVector3.at(x, max, z);
if (getY() > max) {
return BlockVector3.at(getX(), max, getZ());
}
return this;
}
@ -613,7 +591,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 abs() {
return BlockVector3.at(Math.abs(x), Math.abs(y), Math.abs(z));
return BlockVector3.at(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));
}
/**
@ -629,8 +607,8 @@ public class BlockVector3 {
*/
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle);
double x = this.x - aboutX;
double z = this.z - aboutZ;
double x = this.getX() - aboutX;
double z = this.getZ() - aboutZ;
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double x2 = x * cos - z * sin;
@ -638,7 +616,7 @@ public class BlockVector3 {
return BlockVector3.at(
x2 + aboutX + translateX,
y,
getY(),
z2 + aboutZ + translateZ
);
}
@ -684,10 +662,10 @@ public class BlockVector3 {
* @return minimum
*/
public BlockVector3 getMinimum(BlockVector3 v2) {
return new BlockVector3(
Math.min(x, v2.x),
Math.min(y, v2.y),
Math.min(z, v2.z)
return new BlockVector3Imp(
Math.min(getX(), v2.getX()),
Math.min(getY(), v2.getY()),
Math.min(getZ(), v2.getZ())
);
}
@ -698,10 +676,10 @@ public class BlockVector3 {
* @return maximum
*/
public BlockVector3 getMaximum(BlockVector3 v2) {
return new BlockVector3(
Math.max(x, v2.x),
Math.max(y, v2.y),
Math.max(z, v2.z)
return new BlockVector3Imp(
Math.max(getX(), v2.getX()),
Math.max(getY(), v2.getY()),
Math.max(getZ(), v2.getZ())
);
}
@ -728,7 +706,7 @@ public class BlockVector3 {
}
public boolean setBiome(Extent orDefault, BiomeType biome) {
return orDefault.setBiome(x, y, z, biome);
return orDefault.setBiome(getX(), getY(), getZ(), biome);
}
public int getOrdinal(Extent orDefault) {
@ -748,19 +726,19 @@ public class BlockVector3 {
}
public CompoundTag getNbtData(Extent orDefault) {
return orDefault.getFullBlock(x, y, z).getNbtData();
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
}
public BlockState getOrdinalBelow(Extent orDefault) {
return orDefault.getBlock(x, y - 1, z);
return orDefault.getBlock(getX(), getY() - 1, getZ());
}
public BlockState getStateAbove(Extent orDefault) {
return orDefault.getBlock(x, y + 1, z);
return orDefault.getBlock(getX(), getY() + 1, getZ());
}
public BlockState getStateRelativeY(Extent orDefault, final int y) {
return orDefault.getBlock(x, this.y + y, z);
return orDefault.getBlock(getX(), getY() + y, getZ());
}
/**
@ -769,11 +747,11 @@ public class BlockVector3 {
* @return a new {@link BlockVector2}
*/
public BlockVector2 toBlockVector2() {
return BlockVector2.at(x, z);
return BlockVector2.at(getX(), getZ());
}
public Vector3 toVector3() {
return Vector3.at(x, y, z);
return Vector3.at(getX(), getY(), getZ());
}
@Override
@ -783,7 +761,7 @@ public class BlockVector3 {
}
BlockVector3 other = (BlockVector3) obj;
return other.x == this.x && other.y == this.y && other.z == this.z;
return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ();
}
public final boolean equals(BlockVector3 other) {
@ -793,12 +771,12 @@ public class BlockVector3 {
@Override
public int hashCode() {
return (x ^ (z << 12)) ^ (y << 24);
return (getX() ^ (getZ() << 12)) ^ (getY() << 24);
}
@Override
public String toString() {
return "(" + x + ", " + y + ", " + z + ")";
return "(" + getX() + ", " + getY() + ", " + getZ() + ")";
}
//Used by VS fork

View File

@ -0,0 +1,92 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.math;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.collect.ComparisonChain;
import com.sk89q.worldedit.math.transform.AffineTransform;
import java.util.Comparator;
/**
* An immutable 3-dimensional vector.
*/
public final class BlockVector3Imp extends BlockVector3 {
public static final BlockVector3Imp ZERO = new BlockVector3Imp(0, 0, 0);
public static final BlockVector3Imp UNIT_X = new BlockVector3Imp(1, 0, 0);
public static final BlockVector3Imp UNIT_Y = new BlockVector3Imp(0, 1, 0);
public static final BlockVector3Imp UNIT_Z = new BlockVector3Imp(0, 0, 1);
public static final BlockVector3Imp ONE = new BlockVector3Imp(1, 1, 1);
public static BlockVector3Imp at(double x, double y, double z) {
return at((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z));
}
public static BlockVector3Imp at(int x, int y, int z) {
return new BlockVector3Imp(x, y, z);
}
private final int x, y, z;
/**
* Construct an instance.
*
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
*/
protected BlockVector3Imp(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public final int getX() {
return x;
}
@Override
public final int getY() {
return y;
}
@Override
public final int getZ() {
return z;
}
@Override
public int hashCode() {
return (getX() ^ (getZ() << 12)) ^ (getY() << 24);
}
@Override
public final BlockVector3 toImmutable() {
return this;
}
@Override
public String toString() {
return "(" + getX() + ", " + getY() + ", " + getZ() + ")";
}
}

View File

@ -11,11 +11,6 @@ import java.util.Comparator;
public class DelegateBlockVector3 extends BlockVector3 {
private BlockVector3 parent;
public DelegateBlockVector3(BlockVector3 parent) {
super(parent.getX(), parent.getY(), parent.getZ());
this.parent = parent;
}
public DelegateBlockVector3 init(BlockVector3 parent) {
this.parent = parent;
return this;

View File

@ -1,7 +1,6 @@
package com.sk89q.worldedit.math;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.util.MathMan;
public class MutableBlockVector3 extends BlockVector3 {
@ -14,34 +13,27 @@ public class MutableBlockVector3 extends BlockVector3 {
}
public static MutableBlockVector3 get(int x, int y, int z) {
return FaweCache.INSTANCE.getMutableBlockVector3().get().setComponents(x, y, z);
return FaweCache.INSTANCE.getMUTABLE_BLOCKVECTOR3().get().setComponents(x, y, z);
}
public MutableBlockVector3() {
this(0, 0, 0);
}
public MutableBlockVector3() {}
public MutableBlockVector3(BlockVector3 blockVector3) {
this(blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
public MutableBlockVector3(BlockVector3 other) {
this(other.getX(), other.getY(), other.getZ());
}
public MutableBlockVector3 setComponents(BlockVector3 other) {
return setComponents(other.getBlockX(), other.getBlockY(), other.getBlockZ());
}
private int x, y, z;
private int x,y,z;
public MutableBlockVector3(int x, int y, int z) {
super(0, 0, 0);
this.x = x;
this.y = y;
this.z = z;
}
public MutableBlockVector3(double x, double y, double z) {
this(MathMan.floor(x), MathMan.floor(y), MathMan.floor(z));
}
@Override
public MutableBlockVector3 setComponents(int x, int y, int z) {
this.x = x;

View File

@ -10,11 +10,11 @@ public class MutableVector3 extends Vector3 {
}
public static MutableVector3 get(int x, int y, int z) {
return FaweCache.INSTANCE.getMutableVector3().get().setComponents(x, y, z);
return FaweCache.INSTANCE.getMUTABLE_VECTOR3().get().setComponents(x, y, z);
}
public static MutableVector3 get(double x, double y, double z) {
return FaweCache.INSTANCE.getMutableVector3().get().setComponents(x, y, z);
return FaweCache.INSTANCE.getMUTABLE_VECTOR3().get().setComponents(x, y, z);
}
public MutableVector3(double x, double y, double z) {

View File

@ -4,7 +4,6 @@ public class OffsetBlockVector3 extends DelegateBlockVector3 {
private final BlockVector3 offset;
public OffsetBlockVector3(BlockVector3 offset) {
super(offset);
this.offset = offset;
}