Move vectors to static creators, for caching

This commit is contained in:
Kenzie Togami
2018-10-19 13:13:32 -07:00
committed by IronApollo
parent a9919d130c
commit 4d6045813c
138 changed files with 670 additions and 531 deletions

View File

@ -171,7 +171,7 @@ public final class NBTUtils {
*/
public static Vector3 toVector(ListTag listTag) {
checkNotNull(listTag);
return new Vector3(listTag.asDouble(0), listTag.asDouble(1), listTag.asDouble(2));
return Vector3.at(listTag.asDouble(0), listTag.asDouble(1), listTag.asDouble(2));
}
/**

View File

@ -214,7 +214,7 @@ public class YAMLNode {
return null;
}
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
/**
@ -238,7 +238,7 @@ public class YAMLNode {
return null;
}
return new Vector2(x, z);
return Vector2.at(x, z);
}
/**
@ -570,7 +570,7 @@ public class YAMLNode {
continue;
}
list.add(new Vector3(x, y, z));
list.add(Vector3.at(x, y, z));
}
return list;
@ -600,7 +600,7 @@ public class YAMLNode {
continue;
}
list.add(new Vector2(x, z));
list.add(Vector2.at(x, z));
}
return list;
@ -630,7 +630,7 @@ public class YAMLNode {
continue;
}
list.add(new BlockVector2(x, z));
list.add(BlockVector2.at(x, z));
}
return list;

View File

@ -249,7 +249,7 @@ public class CuboidClipboard {
for (int x = 0; x < size.getBlockX(); ++x) {
for (int y = 0; y < size.getBlockY(); ++y) {
for (int z = 0; z < size.getBlockZ(); ++z) {
setBlock(x, y, z, editSession.getBlock(new BlockVector3(x, y, z).add(getOrigin())));
setBlock(x, y, z, editSession.getBlock(BlockVector3.at(x, y, z).add(getOrigin())));
}
}
}
@ -265,7 +265,7 @@ public class CuboidClipboard {
for (int x = 0; x < size.getBlockX(); ++x) {
for (int y = 0; y < size.getBlockY(); ++y) {
for (int z = 0; z < size.getBlockZ(); ++z) {
final BlockVector3 pt = new BlockVector3(x, y, z).add(getOrigin());
final BlockVector3 pt = BlockVector3.at(x, y, z).add(getOrigin());
if (region.contains(pt)) {
setBlock(x, y, z, editSession.getBlock(pt));
} else {

View File

@ -999,7 +999,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
for (int y = maxY; y >= minY; --y) {
BlockVector3 pt = new BlockVector3(x, y, z);
BlockVector3 pt = BlockVector3.at(x, y, z);
BlockState block = getBlock(pt);
if (block.getBlockType().getMaterial().isMovementBlocker()) {
return y;
@ -1246,7 +1246,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
if (extent != null) {
return this.extent.getMinimumPoint();
} else {
return new BlockVector3(-30000000, 0, -30000000);
return BlockVector3.at(-30000000, 0, -30000000);
}
}
@ -1255,7 +1255,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
if (extent != null) {
return this.extent.getMaximumPoint();
} else {
return new BlockVector3(30000000, 255, 30000000);
return BlockVector3.at(30000000, 255, 30000000);
}
}
@ -1426,10 +1426,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
checkNotNull(pattern);
checkArgument(radius >= 0, "radius >= 0");
checkArgument(depth >= 1, "depth >= 1");
if (direction.equals(new BlockVector3(0, -1, 0))) {
if (direction.equals(BlockVector3.at(0, -1, 0))) {
return fillXZ(origin, pattern, radius, depth, false);
}
final MaskIntersection mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this)));
final MaskIntersection mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this)));
// Want to replace blocks
final BlockReplace replace = new BlockReplace(EditSession.this, pattern);
@ -1477,10 +1477,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
checkNotNull(pattern);
checkArgument(radius >= 0, "radius >= 0");
checkArgument(depth >= 1, "depth >= 1");
final MaskIntersection mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))), new BoundedHeightMask(Math.max(
final MaskIntersection mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), new BoundedHeightMask(Math.max(
(origin.getBlockY() - depth) + 1, getMinimumPoint().getBlockY()), Math.min(getMaximumPoint().getBlockY(), origin.getBlockY())), Masks.negate(new ExistingBlockMask(EditSession.this)));
// MaskIntersection mask = new MaskIntersection(
// new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))),
// new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))),
// new BoundedHeightMask(
// Math.max(origin.getBlockY() - depth + 1, 0),
// Math.min(getWorld().getMaxY(), origin.getBlockY())),
@ -1559,7 +1559,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
checkNotNull(position);
checkArgument(apothem >= 1, "apothem >= 1");
final BlockVector3 adjustment = new BlockVector3(1, 1, 1).multiply(apothem - 1);
final BlockVector3 adjustment = BlockVector3.at(1, 1, 1).multiply(apothem - 1);
final Region region = new CuboidRegion(this.getWorld(), // Causes clamping of Y range
position.add(adjustment.multiply(-1)), position.add(adjustment));
final Pattern pattern = BlockTypes.AIR.getDefaultState();
@ -1742,8 +1742,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
// Vector3 center = region.getCenter();
// Region centerRegion = new CuboidRegion(
// getWorld(), // Causes clamping of Y range
// new BlockVector3(((int) center.getX()), ((int) center.getY()), ((int) center.getZ())),
// new BlockVector3(MathUtils.roundHalfUp(center.getX()),
// BlockVector3.at(((int) center.getX()), ((int) center.getY()), ((int) center.getZ())),
// BlockVector3.at(MathUtils.roundHalfUp(center.getX()),
// center.getY(), MathUtils.roundHalfUp(center.getZ())));
// return setBlocks(centerRegion, pattern);
}
@ -1892,7 +1892,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
checkNotNull(region);
checkNotNull(pattern);
final BlockReplace replace = new BlockReplace(EditSession.this, pattern);
final RegionOffset offset = new RegionOffset(new BlockVector3(0, 1, 0), replace);
final RegionOffset offset = new RegionOffset(BlockVector3.at(0, 1, 0), replace);
int minY = region.getMinimumPoint().getBlockY();
int maxY = Math.min(getMaximumPoint().getBlockY(), region.getMaximumPoint().getBlockY() + 1);
SurfaceRegionFunction surface = new SurfaceRegionFunction(this, offset, minY, maxY);
@ -1900,7 +1900,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
Operations.completeBlindly(visitor);
return this.changes = visitor.getAffected();
// BlockReplace replace = new BlockReplace(this, pattern);
// RegionOffset offset = new RegionOffset(new BlockVector3(0, 1, 0), replace);
// RegionOffset offset = new RegionOffset(BlockVector3.at(0, 1, 0), replace);
// GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), offset);
// LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
// Operations.completeLegacy(visitor);
@ -2066,7 +2066,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
new BoundedHeightMask(0, EditSession.this.getMaximumPoint().getBlockY()),
new RegionMask(
new EllipsoidRegion(null, origin,
new Vector3(radius, radius, radius))), liquidMask);
Vector3.at(radius, radius, radius))), liquidMask);
final BlockReplace replace = new BlockReplace(EditSession.this, BlockTypes.AIR.getDefaultState());
final RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1), this);
@ -2079,7 +2079,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
//
// MaskIntersection mask = new MaskIntersection(
// new BoundedHeightMask(0, getWorld().getMaxY()),
// new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))),
// new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))),
// getWorld().createLiquidMask());
//
// BlockReplace replace = new BlockReplace(this, new BlockPattern(BlockTypes.AIR.getDefaultState()));
@ -2111,7 +2111,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
// There are boundaries that the routine needs to stay in
MaskIntersection mask = new MaskIntersection(
new BoundedHeightMask(0, Math.min(origin.getBlockY(), getMaximumPoint().getBlockY())),
new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))),
new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))),
liquidMask);
BlockReplace replace = new BlockReplace(this, pattern);
@ -2528,12 +2528,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
// int ceilRadius = (int) Math.ceil(radius);
// for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
// for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
// if ((new BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) {
// if ((BlockVector3.at(x, oy, z)).distanceSq(position) > radiusSq) {
// continue;
// }
//
// for (int y = world.getMaxY(); y >= 1; --y) {
// BlockVector3 pt = new BlockVector3(x, y, z);
// BlockVector3 pt = BlockVector3.at(x, y, z);
// BlockType id = getBlock(pt).getBlockType();
//
// if (id == BlockTypes.ICE) {
@ -2601,12 +2601,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
// int ceilRadius = (int) Math.ceil(radius);
// for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
// for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
// if ((new BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) {
// if ((BlockVector3.at(x, oy, z)).distanceSq(position) > radiusSq) {
// continue;
// }
//
// for (int y = world.getMaxY(); y >= 1; --y) {
// BlockVector3 pt = new BlockVector3(x, y, z);
// BlockVector3 pt = BlockVector3.at(x, y, z);
// BlockType id = getBlock(pt).getBlockType();
//
// if (id.getMaterial().isAir()) {
@ -2693,12 +2693,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
// for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
// for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
// if ((new BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) {
// if ((BlockVector3.at(x, oy, z)).distanceSq(position) > radiusSq) {
// continue;
// }
//
// for (int y = world.getMaxY(); y >= 1; --y) {
// final BlockVector3 pt = new BlockVector3(x, y, z);
// final BlockVector3 pt = BlockVector3.at(x, y, z);
// final BlockState block = getBlock(pt);
//
// if (block.getBlockType() == BlockTypes.DIRT ||
@ -2783,11 +2783,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
switch (type.getTypeEnum()) {
case GRASS:
case DIRT:
treeType.generate(this, new BlockVector3(x, y + 1, z));
treeType.generate(this, BlockVector3.at(x, y + 1, z));
this.changes++;
break;
case SNOW:
setBlock(new BlockVector3(x, y, z), BlockTypes.AIR.getDefaultState());
setBlock(BlockVector3.at(x, y, z), BlockTypes.AIR.getDefaultState());
break;
case AIR:
case CAVE_AIR:
@ -2804,7 +2804,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
// for (int z = basePosition.getBlockZ() - size; z <= basePosition.getBlockZ()
// + size; ++z) {
// // Don't want to be in the ground
// if (!getBlock(new BlockVector3(x, basePosition.getBlockY(), z)).getBlockType().getMaterial().isAir()) {
// if (!getBlock(BlockVector3.at(x, basePosition.getBlockY(), z)).getBlockType().getMaterial().isAir()) {
// continue;
// }
// // The gods don't want a tree here
@ -2814,13 +2814,13 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
//
// for (int y = basePosition.getBlockY(); y >= basePosition.getBlockY() - 10; --y) {
// // Check if we hit the ground
// BlockType t = getBlock(new BlockVector3(x, y, z)).getBlockType();
// BlockType t = getBlock(BlockVector3.at(x, y, z)).getBlockType();
// if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) {
// treeType.generate(this, new BlockVector3(x, y + 1, z));
// treeType.generate(this, BlockVector3.at(x, y + 1, z));
// ++affected;
// break;
// } else if (t == BlockTypes.SNOW) {
// setBlock(new BlockVector3(x, y, z), BlockTypes.AIR.getDefaultState());
// setBlock(BlockVector3.at(x, y, z), BlockTypes.AIR.getDefaultState());
// } else if (!t.getMaterial().isAir()) { // Trees won't grow on this!
// break;
}
@ -2959,7 +2959,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
//TODO Optimize - avoid vector creation (math)
// final Vector3 current = mutablev.setComponents(x, y, z);
// protected BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial) {
final Vector3 current = new Vector3(x, y, z);
final Vector3 current = Vector3.at(x, y, z);
environment.setCurrentBlock(current);
final Vector3 scaled = current.subtract(zero).divide(unit);
@ -3069,22 +3069,22 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) {
this.recurseHollow(region, new BlockVector3(x, y, minZ), outside);
this.recurseHollow(region, new BlockVector3(x, y, maxZ), outside);
this.recurseHollow(region, BlockVector3.at(x, y, minZ), outside);
this.recurseHollow(region, BlockVector3.at(x, y, maxZ), outside);
}
}
for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) {
this.recurseHollow(region, new BlockVector3(minX, y, z), outside);
this.recurseHollow(region, new BlockVector3(maxX, y, z), outside);
this.recurseHollow(region, BlockVector3.at(minX, y, z), outside);
this.recurseHollow(region, BlockVector3.at(maxX, y, z), outside);
}
}
for (int z = minZ; z <= maxZ; ++z) {
for (int x = minX; x <= maxX; ++x) {
this.recurseHollow(region, new BlockVector3(x, minY, z), outside);
this.recurseHollow(region, new BlockVector3(x, maxY, z), outside);
this.recurseHollow(region, BlockVector3.at(x, minY, z), outside);
this.recurseHollow(region, BlockVector3.at(x, maxY, z), outside);
}
}
@ -3352,7 +3352,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) {
@Override
protected BaseBiome getBiome(final int x, final int z, final BaseBiome defaultBiomeType) {
final Vector2 current = new Vector2(x, z);
final Vector2 current = Vector2.at(x, z);
environment.setCurrentBlock(current.toVector3(0));
final Vector2 scaled = current.subtract(zero2D).divide(unit2D);
@ -3459,7 +3459,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
final int cz = chunk.getBlockZ();
final int bx = cx << 4;
final int bz = cz << 4;
final BlockVector3 cmin = new BlockVector3(bx, 0, bz);
final BlockVector3 cmin = BlockVector3.at(bx, 0, bz);
final BlockVector3 cmax = cmin.add(15, getMaxY(), 15);
final boolean containsBot1 = (fe == null || fe.contains(cmin.getBlockX(), cmin.getBlockY(), cmin.getBlockZ()));
final boolean containsBot2 = region.contains(cmin);
@ -3481,7 +3481,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
int zz = z + bz;
for (int y = 0; y < getMaxY() + 1; y++) {
// BlockStateHolder block = getFullBlock(mutable.setComponents(xx, y, zz));
BlockVector3 bv = new BlockVector3(xx, y, zz);
BlockVector3 bv = BlockVector3.at(xx, y, zz);
BlockStateHolder block = getFullBlock(bv);
fcs.add(mbv, block, BlockTypes.AIR.getDefaultState());
}
@ -3490,13 +3490,13 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
} else {
if (!conNextX) {
setExistingBlocks(new BlockVector3(bx + 16, 0, bz), new BlockVector3(bx + 31, getMaxY(), bz + 15));
setExistingBlocks(BlockVector3.at(bx + 16, 0, bz), BlockVector3.at(bx + 31, getMaxY(), bz + 15));
}
if (!conNextZ) {
setExistingBlocks(new BlockVector3(bx, 0, bz + 16), new BlockVector3(bx + 15, getMaxY(), bz + 31));
setExistingBlocks(BlockVector3.at(bx, 0, bz + 16), BlockVector3.at(bx + 15, getMaxY(), bz + 31));
}
if (!chunks.contains(mutable2D.setComponents(cx + 1, cz + 1)) && !conNextX && !conNextZ) {
setExistingBlocks(new BlockVector3(bx + 16, 0, bz + 16), new BlockVector3(bx + 31, getMaxY(), bz + 31));
setExistingBlocks(BlockVector3.at(bx + 16, 0, bz + 16), BlockVector3.at(bx + 31, getMaxY(), bz + 31));
}
for (int x = 0; x < 16; x++) {
int xx = x + bx;
@ -3506,7 +3506,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
mutable.mutZ(zz);
for (int y = 0; y < getMaxY() + 1; y++) {
mutable.mutY(y);
BlockVector3 mbv = new BlockVector3(xx, y, zz);
BlockVector3 mbv = BlockVector3.at(xx, y, zz);
boolean contains = (fe == null || fe.contains(xx, y, zz)) && region.contains(mbv);
if (contains) {
containsAny = true;

View File

@ -1154,7 +1154,7 @@ public class LocalSession implements TextureHolder {
if (block != null) {
// If it's null, we don't need to do anything. The old was already removed.
Map<String, Tag> tags = block.getNbtData().getValue();
cuiTemporaryBlock = new BlockVector3(
cuiTemporaryBlock = BlockVector3.at(
((IntTag) tags.get("x")).getValue(),
((IntTag) tags.get("y")).getValue(),
((IntTag) tags.get("z")).getValue()

View File

@ -29,16 +29,16 @@ import com.sk89q.worldedit.util.Direction;
*/
public enum PlayerDirection {
NORTH(new Vector3(0, 0, -1), true),
NORTH_EAST((new Vector3(1, 0, -1)).normalize(), false),
EAST(new Vector3(1, 0, 0), true),
SOUTH_EAST((new Vector3(1, 0, 1)).normalize(), false),
SOUTH(new Vector3(0, 0, 1), true),
SOUTH_WEST((new Vector3(-1, 0, 1)).normalize(), false),
WEST(new Vector3(-1, 0, 0), true),
NORTH_WEST((new Vector3(-1, 0, -1)).normalize(), false),
UP(new Vector3(0, 1, 0), true),
DOWN(new Vector3(0, -1, 0), true);
NORTH(Vector3.at(0, 0, -1), true),
NORTH_EAST((Vector3.at(1, 0, -1)).normalize(), false),
EAST(Vector3.at(1, 0, 0), true),
SOUTH_EAST((Vector3.at(1, 0, 1)).normalize(), false),
SOUTH(Vector3.at(0, 0, 1), true),
SOUTH_WEST((Vector3.at(-1, 0, 1)).normalize(), false),
WEST(Vector3.at(-1, 0, 0), true),
NORTH_WEST((Vector3.at(-1, 0, -1)).normalize(), false),
UP(Vector3.at(0, 1, 0), true),
DOWN(Vector3.at(0, -1, 0), true);
private final Vector3 dir;
private final boolean isOrthogonal;

View File

@ -78,7 +78,7 @@ public class ChunkCommands {
player.print(BBC.getPrefix() + "Chunk: " + chunkX + ", " + chunkZ);
player.print(BBC.getPrefix() + "Old format: " + folder1 + "/" + folder2 + "/" + filename);
player.print(BBC.getPrefix() + "McRegion: region/" + McRegionChunkStore.getFilename(
new BlockVector2(chunkX, chunkZ)));
BlockVector2.at(chunkX, chunkZ)));
}
@Command(

View File

@ -91,7 +91,7 @@ public class FlattenedClipboardTransform {
maximum.withZ(minimum.getZ()) };
for (int i = 0; i < corners.length; i++) {
corners[i] = transformAround.apply(new Vector3(corners[i]));
corners[i] = transformAround.apply(corners[i]);
}
MutableVector newMinimum = new MutableVector(corners[0]);
@ -109,7 +109,7 @@ public class FlattenedClipboardTransform {
newMinimum.mutY(Math.ceil(Math.floor(newMinimum.getY())));
newMinimum.mutZ(Math.ceil(Math.floor(newMinimum.getZ())));
return new CuboidRegion(new BlockVector3(newMinimum.getX(), newMinimum.getY(), newMinimum.getZ()), new BlockVector3(newMaximum.getX(), newMaximum.getY(), newMaximum.getZ()));
return new CuboidRegion(BlockVector3.at(newMinimum.getX(), newMinimum.getY(), newMinimum.getZ()), BlockVector3.at(newMaximum.getX(), newMaximum.getY(), newMaximum.getZ()));
}
/**

View File

@ -114,7 +114,7 @@ public class HistoryCommands extends MethodCommands {
RollbackOptimizedHistory rollback = new RollbackOptimizedHistory(world, uuid, Integer.parseInt(name.substring(0, name.length() - 3)));
DiskStorageHistory.DiskStorageSummary summary = rollback.summarize(RegionWrapper.GLOBAL(), false);
if (summary != null) {
rollback.setDimensions(new BlockVector3(summary.minX, 0, summary.minZ), new BlockVector3(summary.maxX, 255, summary.maxZ));
rollback.setDimensions(BlockVector3.at(summary.minX, 0, summary.minZ), BlockVector3.at(summary.maxX, 255, summary.maxZ));
rollback.setTime(historyFile.lastModified());
RollbackDatabase db = DBHandler.IMP.getDatabase(world);
db.logEdit(rollback);

View File

@ -130,7 +130,7 @@ public class MaskCommands extends MethodCommands {
max = 4
)
public Mask offset(double x, double y, double z, Mask mask) {
return new OffsetMask(mask, new BlockVector3(x, y, z));
return new OffsetMask(mask, BlockVector3.at(x, y, z));
}
@Command(
@ -390,7 +390,7 @@ public class MaskCommands extends MethodCommands {
max = 1
)
public Mask below(Mask mask) throws ExpressionException {
OffsetMask offsetMask = new OffsetMask(mask, new BlockVector3(0, 1, 0));
OffsetMask offsetMask = new OffsetMask(mask, BlockVector3.at(0, 1, 0));
return new MaskIntersection(offsetMask, Masks.negate(mask));
}
@ -402,7 +402,7 @@ public class MaskCommands extends MethodCommands {
max = 1
)
public Mask above(Mask mask) throws ExpressionException {
OffsetMask offsetMask = new OffsetMask(mask, new BlockVector3(0, -1, 0));
OffsetMask offsetMask = new OffsetMask(mask, BlockVector3.at(0, -1, 0));
return new MaskIntersection(offsetMask, Masks.negate(mask));
}

View File

@ -120,7 +120,7 @@ public class RegionCommands extends MethodCommands {
if (selection == null) {
final int cx = loc.x >> 4;
final int cz = loc.z >> 4;
selection = new CuboidRegion(new BlockVector3(cx - 8, 0, cz - 8).multiply(16), new BlockVector3(cx + 8, 0, cz + 8).multiply(16));
selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
}
int count = FaweAPI.fixLighting(loc.world, selection, FaweQueue.RelightMode.ALL);
BBC.LIGHTING_PROPOGATE_SELECTION.send(fp, count);
@ -154,7 +154,7 @@ public class RegionCommands extends MethodCommands {
if (selection == null) {
final int cx = loc.x >> 4;
final int cz = loc.z >> 4;
selection = new CuboidRegion(new BlockVector3(cx - 8, 0, cz - 8).multiply(16), new BlockVector3(cx + 8, 0, cz + 8).multiply(16));
selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
}
int count = FaweAPI.fixLighting(loc.world, selection, FaweQueue.RelightMode.NONE);
BBC.UPDATED_LIGHTING_SELECTION.send(fp, count);
@ -624,7 +624,7 @@ public class RegionCommands extends MethodCommands {
if (moveSelection) {
try {
final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
BlockVector3 shiftVector = new BlockVector3(direction.getX() * size.getX() * count, direction.getY() * size.getY() * count, direction.getZ() * size.getZ() * count);
BlockVector3 shiftVector = BlockVector3.at(direction.getX() * size.getX() * count, direction.getY() * size.getY() * count, direction.getZ() * size.getZ() * count);
region.shift(shiftVector);
session.getRegionSelector(player.getWorld()).learnChanges();

View File

@ -110,7 +110,7 @@ public class SelectionCommands {
if (args.argsLength() == 1) {
if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) {
String[] coords = args.getString(0).split(",");
pos = new BlockVector3(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2]));
pos = BlockVector3.at(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2]));
} else {
BBC.SELECTOR_INVALID_COORDINATES.send(player, args.getString(0));
return;
@ -141,7 +141,7 @@ public class SelectionCommands {
if (args.argsLength() == 1) {
if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) {
String[] coords = args.getString(0).split(",");
pos = new BlockVector3(Integer.parseInt(coords[0]),
pos = BlockVector3.at(Integer.parseInt(coords[0]),
Integer.parseInt(coords[1]),
Integer.parseInt(coords[2]));
} else {
@ -237,8 +237,8 @@ public class SelectionCommands {
final BlockVector2 min2D = ChunkStore.toChunk(region.getMinimumPoint());
final BlockVector2 max2D = ChunkStore.toChunk(region.getMaximumPoint());
min = new BlockVector3(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
max = new BlockVector3(max2D.getBlockX() * 16 + 15, world.getMaxY(), max2D.getBlockZ() * 16 + 15);
min = BlockVector3.at(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
max = BlockVector3.at(max2D.getBlockX() * 16 + 15, world.getMaxY(), max2D.getBlockZ() * 16 + 15);
BBC.SELECTION_CHUNKS.send(player, min2D.getBlockX() + ", " + min2D.getBlockZ(), max2D.getBlockX() + ", " + max2D.getBlockZ());
} else {
@ -251,14 +251,14 @@ public class SelectionCommands {
}
int x = Integer.parseInt(coords[0]);
int z = Integer.parseInt(coords[1]);
BlockVector2 pos = new BlockVector2(x, z);
BlockVector2 pos = BlockVector2.at(x, z);
min2D = (args.hasFlag('c')) ? pos : ChunkStore.toChunk(pos.toBlockVector3());
} else {
// use player loc
min2D = ChunkStore.toChunk(player.getBlockIn().toVector().toBlockPoint());
}
min = new BlockVector3(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
min = BlockVector3.at(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
max = min.add(15, world.getMaxY(), 15);
BBC.SELECTION_CHUNK.send(player, min2D.getBlockX() + ", " + min2D.getBlockZ());
@ -328,8 +328,8 @@ public class SelectionCommands {
try {
int oldSize = region.getArea();
region.expand(
new BlockVector3(0, (player.getWorld().getMaxY() + 1), 0),
new BlockVector3(0, -(player.getWorld().getMaxY() + 1), 0));
BlockVector3.at(0, (player.getWorld().getMaxY() + 1), 0),
BlockVector3.at(0, -(player.getWorld().getMaxY() + 1), 0));
session.getRegionSelector(player.getWorld()).learnChanges();
int newSize = region.getArea();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
@ -567,15 +567,15 @@ public class SelectionCommands {
int change = args.getInteger(0);
if (!args.hasFlag('h')) {
changes.add((new BlockVector3(0, 1, 0)).multiply(change));
changes.add((new BlockVector3(0, -1, 0)).multiply(change));
changes.add((BlockVector3.at(0, 1, 0)).multiply(change));
changes.add((BlockVector3.at(0, -1, 0)).multiply(change));
}
if (!args.hasFlag('v')) {
changes.add((new BlockVector3(1, 0, 0)).multiply(change));
changes.add((new BlockVector3(-1, 0, 0)).multiply(change));
changes.add((new BlockVector3(0, 0, 1)).multiply(change));
changes.add((new BlockVector3(0, 0, -1)).multiply(change));
changes.add((BlockVector3.at(1, 0, 0)).multiply(change));
changes.add((BlockVector3.at(-1, 0, 0)).multiply(change));
changes.add((BlockVector3.at(0, 0, 1)).multiply(change));
changes.add((BlockVector3.at(0, 0, -1)).multiply(change));
}
return changes.toArray(new BlockVector3[0]);

View File

@ -204,7 +204,7 @@ public class DefaultMaskParser extends FaweParser<Mask> {
// } else {
// submask = new ExistingBlockMask(extent);
// }
// OffsetMask offsetMask = new OffsetMask(submask, new BlockVector3(0, firstChar == '>' ? -1 : 1, 0));
// OffsetMask offsetMask = new OffsetMask(submask, BlockVector3.at(0, firstChar == '>' ? -1 : 1, 0));
// return new MaskIntersection(offsetMask, Masks.negate(submask));
//
// case '$':
@ -217,7 +217,7 @@ public class DefaultMaskParser extends FaweParser<Mask> {
// BaseBiome biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry);
// if (biome == null) {
// throw new InputParseException("Unknown biome '" + biomeName + '\'');
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
}
}
//<<<<<<< HEAD

View File

@ -115,7 +115,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
byte free = 0;
while (y <= world.getMaximumPoint().getBlockY() + 2) {
if (!world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) {
if (!world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) {
++free;
} else {
free = 0;
@ -123,10 +123,10 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (free == 2) {
if (y - 1 != origY) {
final BlockVector3 pos = new BlockVector3(x, y - 2, z);
final BlockVector3 pos = BlockVector3.at(x, y - 2, z);
final BlockStateHolder state = world.getBlock(pos);
setPosition(new Vector3(x + 0.5, y - 2 + BlockType.centralTopLimit(state), z + 0.5));
// setPosition(new Vector3(x + 0.5, y - 2 + 1, z + 0.5));
setPosition(Vector3.at(x + 0.5, y - 2 + BlockType.centralTopLimit(state), z + 0.5));
// setPosition(Vector3.at(x + 0.5, y - 2 + 1, z + 0.5));
}
return;
@ -144,10 +144,10 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
int z = searchPos.getBlockZ();
while (y >= 0) {
final BlockVector3 pos = new BlockVector3(x, y, z);
final BlockVector3 pos = BlockVector3.at(x, y, z);
final BlockState id = world.getBlock(pos);
if (id.getBlockType().getMaterial().isMovementBlocker()) {
setPosition(new Vector3(x + 0.5, y + + BlockType.centralTopLimit(id), z + 0.5));
setPosition(Vector3.at(x + 0.5, y + + BlockType.centralTopLimit(id), z + 0.5));
return;
}
@ -171,7 +171,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
int maxY = world.getMaxY();
if (y >= maxY) return false;
BlockMaterial initialMaterial = world.getBlockType(new BlockVector3(x, y, z)).getMaterial();
BlockMaterial initialMaterial = world.getBlockType(BlockVector3.at(x, y, z)).getMaterial();
boolean lastState = initialMaterial.isMovementBlocker() && initialMaterial.isFullCube();
@ -181,7 +181,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
for (int level = y + 1; level <= maxY + 2; level++) {
BlockState state;
if (level >= maxY) state = BlockTypes.VOID_AIR.getDefaultState();
else state = world.getBlock(new BlockVector3(x, level, z));
else state = world.getBlock(BlockVector3.at(x, level, z));
BlockTypes type = state.getBlockType();
BlockMaterial material = type.getMaterial();
@ -196,7 +196,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
double bottomLimit = BlockType.centralBottomLimit(state);
double space = level + bottomLimit - freeStart;
if (space >= height) {
setPosition(new Vector3(x + 0.5, freeStart, z + 0.5));
setPosition(Vector3.at(x + 0.5, freeStart, z + 0.5));
return true;
}
// Not enough room, reset the free position
@ -220,7 +220,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final int z = pos.getBlockZ();
final Extent world = pos.getExtent();
BlockMaterial initialMaterial = world.getBlockType(new BlockVector3(x, y, z)).getMaterial();
BlockMaterial initialMaterial = world.getBlockType(BlockVector3.at(x, y, z)).getMaterial();
boolean lastState = initialMaterial.isMovementBlocker() && initialMaterial.isFullCube();
@ -233,7 +233,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
for (int level = y + 1; level > 0; level--) {
BlockState state;
if (level >= maxY) state = BlockTypes.VOID_AIR.getDefaultState();
else state = world.getBlock(new BlockVector3(x, level, z));
else state = world.getBlock(BlockVector3.at(x, level, z));
BlockTypes type = state.getBlockType();
BlockMaterial material = type.getMaterial();
@ -249,7 +249,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
double freeStart = level + topLimit;
double space = freeEnd - freeStart;
if (space >= height) {
setPosition(new Vector3(x + 0.5, freeStart, z + 0.5));
setPosition(Vector3.at(x + 0.5, freeStart, z + 0.5));
return true;
}
// Not enough room, reset the free position
@ -280,13 +280,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
Extent world = getLocation().getExtent();
// No free space above
if (!world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isAir()) {
if (!world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isAir()) {
return false;
}
while (y <= world.getMaximumPoint().getY()) {
// Found a ceiling!
if (world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) {
if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) {
int platformY = Math.max(initialY, y - 3 - clearance);
floatAt(x, platformY + 1, z, alwaysGlass);
return true;
@ -314,7 +314,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final Extent world = getLocation().getExtent();
while (y <= world.getMaximumPoint().getY() + 2) {
if (world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) {
if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) {
break; // Hit something
} else if (y > maxY + 1) {
break;
@ -332,14 +332,14 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
try {
BlockVector3 spot = new BlockVector3(x, y - 1, z);
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState());
}
}catch (WorldEditException e) {
e.printStackTrace();
}
setPosition(new Vector3(x + 0.5, y, z + 0.5));
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
}
@Override

View File

@ -129,7 +129,7 @@ public class AbstractDelegateExtent implements LightingExtent {
// mutable.mutX(x);
// mutable.mutY(y);
// mutable.mutZ(z);
return extent.getLazyBlock(new BlockVector3(x, y, z));
return extent.getLazyBlock(BlockVector3.at(x, y, z));
}
@Override
@ -142,7 +142,7 @@ public class AbstractDelegateExtent implements LightingExtent {
// mutable.mutX(x);
// mutable.mutY(y);
// mutable.mutZ(z);
return setBlock(new BlockVector3(x, y, z), block);
return setBlock(BlockVector3.at(x, y, z), block);
}
public BlockState getBlock(BlockVector3 position) {

View File

@ -127,15 +127,15 @@ public interface Extent extends InputExtent, OutputExtent {
}
default BlockState getLazyBlock(int x, int y, int z) {
return getLazyBlock(new BlockVector3(x, y, z));
return getLazyBlock(BlockVector3.at(x, y, z));
}
default boolean setBlock(int x, int y, int z, BlockStateHolder state) throws WorldEditException {
return setBlock(new BlockVector3(x, y, z), state);
return setBlock(BlockVector3.at(x, y, z), state);
}
default boolean setBiome(int x, int y, int z, BaseBiome biome) {
return setBiome(new BlockVector2(x, z), biome);
return setBiome(BlockVector2.at(x, z), biome);
}
default int getHighestTerrainBlock(final int x, final int z, int minY, int maxY) {

View File

@ -84,7 +84,7 @@ public class MaskingExtent extends AbstractDelegateExtent {
@Override
public boolean setBiome(int x, int y, int z, BaseBiome biome) {
return mask.test(new BlockVector3(x, y, z)) && super.setBiome(x, y, z, biome);
return mask.test(BlockVector3.at(x, y, z)) && super.setBiome(x, y, z, biome);
}

View File

@ -52,7 +52,7 @@ import java.util.List;
*/
public class NullExtent implements Extent {
private final BlockVector3 nullPoint = new BlockVector3(0, 0, 0);
private final BlockVector3 nullPoint = BlockVector3.at(0, 0, 0);
public static final NullExtent INSTANCE = new NullExtent();

View File

@ -31,7 +31,6 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.AbstractRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.extent.cache;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.block.BlockState;
/**

View File

@ -312,11 +312,11 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public int getOpacity(int x, int y, int z) {
return getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().getLightOpacity();
return getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().getLightOpacity();
}
@Override
public int getBrightness(int x, int y, int z) {
return getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().getLightValue();
return getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().getLightValue();
}
}

View File

@ -117,12 +117,12 @@ public class MCEditSchematicReader extends NBTSchematicReader {
int originX = requireTag(schematic, "WEOriginX", IntTag.class).getValue();
int originY = requireTag(schematic, "WEOriginY", IntTag.class).getValue();
int originZ = requireTag(schematic, "WEOriginZ", IntTag.class).getValue();
BlockVector3 min = new BlockVector3(originX, originY, originZ);
BlockVector3 min = BlockVector3.at(originX, originY, originZ);
int offsetX = requireTag(schematic, "WEOffsetX", IntTag.class).getValue();
int offsetY = requireTag(schematic, "WEOffsetY", IntTag.class).getValue();
int offsetZ = requireTag(schematic, "WEOffsetZ", IntTag.class).getValue();
BlockVector3 offset = new BlockVector3(offsetX, offsetY, offsetZ);
BlockVector3 offset = BlockVector3.at(offsetX, offsetY, offsetZ);
origin = min.subtract(offset);
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
@ -206,7 +206,7 @@ public class MCEditSchematicReader extends NBTSchematicReader {
}
}
BlockVector3 vec = new BlockVector3(x, y, z);
BlockVector3 vec = BlockVector3.at(x, y, z);
tileEntitiesMap.put(vec, values);
}
@ -220,7 +220,7 @@ public class MCEditSchematicReader extends NBTSchematicReader {
for (int y = 0; y < height; ++y) {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;
BlockVector3 pt = new BlockVector3(x, y, z);
BlockVector3 pt = BlockVector3.at(x, y, z);
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]);
try {

View File

@ -122,14 +122,28 @@ public class SpongeSchematicReader extends NBTSchematicReader {
private FaweClipboard setupClipboard(int size, UUID uuid) {
if (fc != null) {
if (fc.getDimensions().getX() == 0) {
fc.setDimensions(new BlockVector3(size, 1, 1));
fc.setDimensions(BlockVector3.at(size, 1, 1));
}
return fc;
}
//<<<<<<< HEAD
if (Settings.IMP.CLIPBOARD.USE_DISK) {
return fc = new DiskOptimizedClipboard(size, 1, 1, uuid);
} else if (Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL == 0) {
return fc = new CPUOptimizedClipboard(size, 1, 1);
//=======
//
// BlockVector3 min = BlockVector3.at(offsetParts[0], offsetParts[1], offsetParts[2]);
//
// if (metadata.containsKey("WEOffsetX")) {
// // We appear to have WorldEdit Metadata
// int offsetX = requireTag(metadata, "WEOffsetX", IntTag.class).getValue();
// int offsetY = requireTag(metadata, "WEOffsetY", IntTag.class).getValue();
// int offsetZ = requireTag(metadata, "WEOffsetZ", IntTag.class).getValue();
// BlockVector3 offset = BlockVector3.at(offsetX, offsetY, offsetZ);
// origin = min.subtract(offset);
// region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
} else {
return fc = new MemoryOptimizedClipboard(size, 1, 1);
}
@ -310,7 +324,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
private Clipboard readVersion1(UUID uuid) throws IOException {
width = height = length = offsetX = offsetY = offsetZ = Integer.MIN_VALUE;
final BlockArrayClipboard clipboard = new BlockArrayClipboard(new CuboidRegion(new BlockVector3(0, 0, 0), new BlockVector3(0, 0, 0)), fc);
final BlockArrayClipboard clipboard = new BlockArrayClipboard(new CuboidRegion(BlockVector3.at(0, 0, 0), BlockVector3.at(0, 0, 0)), fc);
FastByteArrayOutputStream blocksOut = new FastByteArrayOutputStream();
FastByteArrayOutputStream biomesOut = new FastByteArrayOutputStream();
@ -318,7 +332,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
streamer.addReader("Schematic.Width", (BiConsumer<Integer, Short>) (i, v) -> width = v);
streamer.addReader("Schematic.Height", (BiConsumer<Integer, Short>) (i, v) -> height = v);
streamer.addReader("Schematic.Length", (BiConsumer<Integer, Short>) (i, v) -> length = v);
streamer.addReader("Schematic.Offset", (BiConsumer<Integer, int[]>) (i, v) -> min = new BlockVector3(v[0], v[1], v[2]));
streamer.addReader("Schematic.Offset", (BiConsumer<Integer, int[]>) (i, v) -> min = BlockVector3.at(v[0], v[1], v[2]));
streamer.addReader("Schematic.Metadata.WEOffsetX", (BiConsumer<Integer, Integer>) (i, v) -> offsetX = v);
streamer.addReader("Schematic.Metadata.WEOffsetY", (BiConsumer<Integer, Integer>) (i, v) -> offsetY = v);
streamer.addReader("Schematic.Metadata.WEOffsetZ", (BiConsumer<Integer, Integer>) (i, v) -> offsetZ = v);
@ -329,6 +343,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
int index = ((IntTag) entry.getValue()).getValue();
palette[index] = (char) state.getOrdinal();
}
//<<<<<<< HEAD
});
streamer.addReader("Schematic.BlockData.#", new NBTStreamer.LazyReader() {
@Override
@ -338,6 +353,23 @@ public class SpongeSchematicReader extends NBTSchematicReader {
} catch (IOException e) {
e.printStackTrace();
}
//=======
// palette.put(id, state);
// }
//
// byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue();
//
// Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
// try {
// List<Map<String, Tag>> tileEntityTags = requireTag(schematic, "TileEntities", ListTag.class).getValue().stream()
// .map(tag -> (CompoundTag) tag)
// .map(CompoundTag::getValue)
// .collect(Collectors.toList());
//
// for (Map<String, Tag> tileEntity : tileEntityTags) {
// int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
// tileEntitiesMap.put(BlockVector3.at(pos[0], pos[1], pos[2]), tileEntity);
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
}
});
streamer.addReader("Schematic.Biomes.#", new NBTStreamer.LazyReader() {
@ -362,6 +394,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
int z = pos[2];
fc.setTile(x, y, z, value);
}
//<<<<<<< HEAD
});
streamer.addReader("Schematic.Entities.#", new BiConsumer<Integer, CompoundTag>() {
@Override
@ -390,7 +423,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
BlockVector3 origin = min;
CuboidRegion region;
if (offsetX != Integer.MIN_VALUE && offsetY != Integer.MIN_VALUE && offsetZ != Integer.MIN_VALUE) {
origin = origin.subtract(new BlockVector3(offsetX, offsetY, offsetZ));
origin = origin.subtract(BlockVector3.at(offsetX, offsetY, offsetZ));
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
} else {
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
@ -402,6 +435,21 @@ public class SpongeSchematicReader extends NBTSchematicReader {
for (int index = 0; index < volume; index++) {
BlockState state = BlockTypes.states[palette[fis.read()]];
fc.setBlock(index, state);
//=======
// // index = (y * length + z) * width + x
// int y = index / (width * length);
// int z = (index % (width * length)) / width;
// int x = (index % (width * length)) % width;
// BlockState state = palette.get(value);
// BlockVector3 pt = BlockVector3.at(x, y, z);
// try {
// if (tileEntitiesMap.containsKey(pt)) {
// Map<String, Tag> values = Maps.newHashMap(tileEntitiesMap.get(pt));
// for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) {
// if (handler.isAffectedBlock(state)) {
// handler.updateNBT(state, values);
// }
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
}
} else {
for (int index = 0; index < volume; index++) {
@ -419,7 +467,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
}
}
}
fc.setDimensions(new BlockVector3(width, height, length));
fc.setDimensions(BlockVector3.at(width, height, length));
clipboard.init(region, fc);
clipboard.setOrigin(origin);
return clipboard;

View File

@ -178,13 +178,13 @@ public class SpongeSchematicWriter implements ClipboardWriter {
// int z0 = min.getBlockZ() + z;
// for (int x = 0; x < width; x++) {
// int x0 = min.getBlockX() + x;
// BlockVector3 point = new BlockVector3(x0, y0, z0);
// BlockVector3 point = BlockVector3.at(x0, y0, z0);
// BaseBlock block = clipboard.getFullBlock(point);
// if (block.getNbtData() != null) {
// Map<String, Tag> values = new HashMap<>();
// for (Map.Entry<String, Tag> entry : block.getNbtData().getValue().entrySet()) {
// values.put(entry.getKey(), entry.getValue());
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
}
int ordinal = block.getOrdinal();
char value = palette[ordinal];

View File

@ -77,7 +77,7 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent {
if (!enabled) {
return getExtent().setBlock(location, block);
}
BlockVector2 chunkPos = new BlockVector2(location.getBlockX() >> 4, location.getBlockZ() >> 4);
BlockVector2 chunkPos = BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4);
batches.computeIfAbsent(chunkPos, k -> new LocatedBlockList()).add(location, block);
return true;
}

View File

@ -89,7 +89,7 @@ public class FastModeExtent extends AbstractDelegateExtent {
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
if (enabled) {
dirtyChunks.add(new BlockVector2(location.getBlockX() >> 4, location.getBlockZ() >> 4));
dirtyChunks.add(BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4));
return world.setBlock(location, block, false);
} else {
return world.setBlock(location, block, true);

View File

@ -93,7 +93,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent {
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
if (toolUse && block.getBlockType().getMaterial().isAir()) {
world.simulateBlockMine(new BlockVector3(x, y, z));
world.simulateBlockMine(BlockVector3.at(x, y, z));
return true;
} else {
return super.setBlock(x, y, z, block);

View File

@ -163,12 +163,16 @@ public class ExtentEntityCopy implements EntityFunction {
boolean hasFacing = tag.containsKey("Facing");
if (hasTilePosition) {
<<<<<<< HEAD
//<<<<<<< HEAD
changed = true;
// Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
// Vector newTilePosition = transform.apply(tilePosition.subtract(from)).add(to);
//=======
Vector3 tilePosition = new Vector3(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
=======
Vector3 tilePosition = Vector3.at(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
BlockVector3 newTilePosition = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint();
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner

View File

@ -43,14 +43,14 @@ public class BackwardsExtentBlockCopy implements Operation {
}
private CuboidRegion transform(Transform transform, Region region) {
BlockVector3 min = new BlockVector3(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
BlockVector3 max = new BlockVector3(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
BlockVector3 min = BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
BlockVector3 max = BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
BlockVector3 pos1 = region.getMinimumPoint();
BlockVector3 pos2 = region.getMaximumPoint();
for (int x : new int[] { pos1.getBlockX(), pos2.getBlockX() }) {
for (int y : new int[] { pos1.getBlockY(), pos2.getBlockY() }) {
for (int z : new int[] { pos1.getBlockZ(), pos2.getBlockZ() }) {
BlockVector3 pt = transform(transform, new BlockVector3(x, y, z));
BlockVector3 pt = transform(transform, BlockVector3.at(x, y, z));
min = min.getMinimum(pt);
max = max.getMaximum(pt);
}
@ -68,7 +68,7 @@ public class BackwardsExtentBlockCopy implements Operation {
// tmp.mutY((tmp.getBlockY() + origin.getBlockY()));
// tmp.mutZ((tmp.getBlockZ() + origin.getBlockZ()));
// return tmp;
return transform.apply(new Vector3(pt.getBlockX() - origin.getBlockX(), pt.getBlockY() - origin.getBlockY(), pt.getBlockZ() - origin.getBlockZ())).toBlockPoint().add(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
return transform.apply(Vector3.at(pt.getBlockX() - origin.getBlockX(), pt.getBlockY() - origin.getBlockY(), pt.getBlockZ() - origin.getBlockZ())).toBlockPoint().add(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
}
@Override

View File

@ -48,7 +48,6 @@ import com.sk89q.worldedit.function.visitor.IntersectRegionFunction;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.Identity;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.Region;
@ -322,7 +321,7 @@ public class ForwardExtentCopy implements Operation {
int z = translation.getBlockZ();
maskFunc = position -> {
BlockVector3 bv = new BlockVector3(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z);
BlockVector3 bv = BlockVector3.at(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z);
if (region.contains(bv)) {
return sourceFunction.apply(bv);
}
@ -330,7 +329,7 @@ public class ForwardExtentCopy implements Operation {
};
copySrcFunc = position -> {
BlockVector3 bv = new BlockVector3(position.getBlockX() - x, position.getBlockY() - y, position.getBlockZ() - z);
BlockVector3 bv = BlockVector3.at(position.getBlockX() - x, position.getBlockY() - y, position.getBlockZ() - z);
if (!region.contains(bv)) {
return sourceFunction.apply(position);
}

View File

@ -45,7 +45,7 @@ public class ClipboardPattern extends AbstractPattern {
if (xp < 0) xp += sx;
if (yp < 0) yp += sy;
if (zp < 0) zp += sz;
return clipboard.getBlock(new BlockVector3(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
return clipboard.getBlock(BlockVector3.at(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
//=======
// public BlockStateHolder apply(BlockVector3 position) {
// int xp = Math.abs(position.getBlockX()) % size.getBlockX();

View File

@ -46,7 +46,7 @@ public interface Pattern extends com.sk89q.worldedit.patterns.Pattern{
@Override
default BaseBlock next(int x, int y, int z) {
return new BaseBlock(apply(new BlockVector3(x, y, z)));
return new BaseBlock(apply(BlockVector3.at(x, y, z)));
}
/**

View File

@ -93,10 +93,6 @@ public class RepeatingExtentPattern extends AbstractPattern {
int x = base.getBlockX() % size.getBlockX();
int y = base.getBlockY() % size.getBlockY();
int z = base.getBlockZ() % size.getBlockZ();
//<<<<<<< HEAD
// return extent.getBlock(new Vector(x, y, z));
//=======
return extent.getFullBlock(new BlockVector3(x, y, z));
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
return extent.getFullBlock(BlockVector3.at(x, y, z));
}
}

View File

@ -44,18 +44,18 @@ public abstract class BreadthFirstSearch implements Operation {
public static final BlockVector3[] DIAGONAL_DIRECTIONS;
static {
DEFAULT_DIRECTIONS[0] = (new BlockVector3(0, -1, 0));
DEFAULT_DIRECTIONS[1] = (new BlockVector3(0, 1, 0));
DEFAULT_DIRECTIONS[2] = (new BlockVector3(-1, 0, 0));
DEFAULT_DIRECTIONS[3] = (new BlockVector3(1, 0, 0));
DEFAULT_DIRECTIONS[4] = (new BlockVector3(0, 0, -1));
DEFAULT_DIRECTIONS[5] = (new BlockVector3(0, 0, 1));
DEFAULT_DIRECTIONS[0] = (BlockVector3.at(0, -1, 0));
DEFAULT_DIRECTIONS[1] = (BlockVector3.at(0, 1, 0));
DEFAULT_DIRECTIONS[2] = (BlockVector3.at(-1, 0, 0));
DEFAULT_DIRECTIONS[3] = (BlockVector3.at(1, 0, 0));
DEFAULT_DIRECTIONS[4] = (BlockVector3.at(0, 0, -1));
DEFAULT_DIRECTIONS[5] = (BlockVector3.at(0, 0, 1));
List<BlockVector3> list = new ArrayList<>();
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
if (x != 0 || y != 0 || z != 0) {
BlockVector3 pos = new BlockVector3(x, y, z);
BlockVector3 pos = BlockVector3.at(x, y, z);
if (!list.contains(pos)) {
list.add(pos);
}
@ -100,10 +100,6 @@ public abstract class BreadthFirstSearch implements Operation {
this.maxDepth = maxDepth;
}
public Collection<BlockVector3> getDirections() {
return this.directions;
}
public void setDirections(List<BlockVector3> directions) {
this.directions = directions;
}
@ -116,6 +112,44 @@ public abstract class BreadthFirstSearch implements Operation {
}
return array;
}
/**
* Get the list of directions will be visited.
*
* <p>Directions are {@link BlockVector3}s that determine
* what adjacent points area available. Vectors should not be
* unit vectors. An example of a valid direction is
* {@code BlockVector3.at(1, 0, 1)}.</p>
*
* <p>The list of directions can be cleared.</p>
*
* @return the list of directions
*/
protected Collection<BlockVector3> getDirections() {
return directions;
}
/**
* Add the directions along the axes as directions to visit.
*/
protected void addAxes() {
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.at(0, 1, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, 0, 1));
}
/**
* Add the diagonal directions as directions to visit.
*/
protected void addDiagonal() {
directions.add(BlockVector3.at(1, 0, 1));
directions.add(BlockVector3.at(-1, 0, -1));
directions.add(BlockVector3.at(1, 0, -1));
directions.add(BlockVector3.at(-1, 0, 1));
}
public void visit(final BlockVector3 pos) {
if (!isVisited(pos)) {
@ -223,7 +257,7 @@ public abstract class BreadthFirstSearch implements Operation {
int x = from.getBlockX() + direction.x;
int z = from.getBlockZ() + direction.z;
if (!visited.contains(x, y, z)) {
if (isVisitable(from, new BlockVector3(x, y, z))) {
if (isVisitable(from, BlockVector3.at(x, y, z))) {
j++;
visited.add(x, y, z);
tempQueue.add(x, y, z);

View File

@ -53,12 +53,12 @@ public class DirectionalVisitor extends RecursiveVisitor {
this.dirVec = direction;
final Collection<BlockVector3> directions = this.getDirections();
directions.clear();
directions.add(new BlockVector3(1, 0, 0));
directions.add(new BlockVector3(-1, 0, 0));
directions.add(new BlockVector3(0, 0, 1));
directions.add(new BlockVector3(0, 0, -1));
directions.add(new BlockVector3(0, -1, 0));
directions.add(new BlockVector3(0, 1, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.at(0, 1, 0));
}
@Override

View File

@ -62,11 +62,11 @@ public class DownwardVisitor extends RecursiveVisitor {
Collection<BlockVector3> directions = getDirections();
directions.clear();
directions.add(new BlockVector3(1, 0, 0));
directions.add(new BlockVector3(-1, 0, 0));
directions.add(new BlockVector3(0, 0, 1));
directions.add(new BlockVector3(0, 0, -1));
directions.add(new BlockVector3(0, -1, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
}
@Override

View File

@ -48,11 +48,11 @@ public class NonRisingVisitor extends RecursiveVisitor {
super(mask, function, depth, hasFaweQueue);
Collection<BlockVector3> directions = getDirections();
directions.clear();
directions.add(new BlockVector3(1, 0, 0));
directions.add(new BlockVector3(-1, 0, 0));
directions.add(new BlockVector3(0, 0, 1));
directions.add(new BlockVector3(0, 0, -1));
directions.add(new BlockVector3(0, -1, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
}

View File

@ -397,7 +397,7 @@ public final class Functions {
} catch (IllegalArgumentException e) {
throw new EvaluationException(0, "Perlin noise error: " + e.getMessage());
}
return perlin.noise(new Vector3(x.getValue(), y.getValue(), z.getValue()));
return perlin.noise(Vector3.at(x.getValue(), y.getValue(), z.getValue()));
}
private static final ThreadLocal<VoronoiNoise> localVoronoi = ThreadLocal.withInitial(VoronoiNoise::new);
@ -410,7 +410,7 @@ public final class Functions {
} catch (IllegalArgumentException e) {
throw new EvaluationException(0, "Voronoi error: " + e.getMessage());
}
return voronoi.noise(new Vector3(x.getValue(), y.getValue(), z.getValue()));
return voronoi.noise(Vector3.at(x.getValue(), y.getValue(), z.getValue()));
}
private static final ThreadLocal<RidgedMultiFractalNoise> localRidgedMulti = ThreadLocal.withInitial(RidgedMultiFractalNoise::new);
@ -424,7 +424,7 @@ public final class Functions {
} catch (IllegalArgumentException e) {
throw new EvaluationException(0, "Ridged multi error: " + e.getMessage());
}
return ridgedMulti.noise(new Vector3(x.getValue(), y.getValue(), z.getValue()));
return ridgedMulti.noise(Vector3.at(x.getValue(), y.getValue(), z.getValue()));
}
private static double queryInternal(RValue type, RValue data, double typeId, double dataValue) throws EvaluationException {

View File

@ -55,6 +55,26 @@ public class BlockVector2 {
.result();
};
public static BlockVector2 at(double x, double z) {
return at((int) Math.floor(x), (int) Math.floor(z));
}
public static BlockVector2 at(int x, int z) {
switch (x) {
case 0:
if (z == 0) {
return ZERO;
}
break;
case 1:
if (z == 1) {
return ONE;
}
break;
}
return new BlockVector2(x, z);
}
private final int x, z;
/**
@ -63,17 +83,7 @@ public class BlockVector2 {
* @param x the X coordinate
* @param z the Z coordinate
*/
public BlockVector2(double x, double z) {
this((int) Math.floor(x), (int) Math.floor(z));
}
/**
* Construct an instance.
*
* @param x the X coordinate
* @param z the Z coordinate
*/
public BlockVector2(int x, int z) {
private BlockVector2(int x, int z) {
this.x = x;
this.z = z;
}
@ -103,7 +113,7 @@ public class BlockVector2 {
* @return a new vector
*/
public BlockVector2 withX(int x) {
return new BlockVector2(x, z);
return BlockVector2.at(x, z);
}
/**
@ -131,7 +141,7 @@ public class BlockVector2 {
* @return a new vector
*/
public BlockVector2 withZ(int z) {
return new BlockVector2(x, z);
return BlockVector2.at(x, z);
}
/**
@ -152,7 +162,7 @@ public class BlockVector2 {
* @return a new vector
*/
public BlockVector2 add(int x, int z) {
return new BlockVector2(this.x + x, this.z + z);
return BlockVector2.at(this.x + x, this.z + z);
}
/**
@ -170,7 +180,7 @@ public class BlockVector2 {
newZ += other.z;
}
return new BlockVector2(newX, newZ);
return BlockVector2.at(newX, newZ);
}
/**
@ -193,7 +203,7 @@ public class BlockVector2 {
* @return a new vector
*/
public BlockVector2 subtract(int x, int z) {
return new BlockVector2(this.x - x, this.z - z);
return BlockVector2.at(this.x - x, this.z - z);
}
/**
@ -211,7 +221,7 @@ public class BlockVector2 {
newZ -= other.z;
}
return new BlockVector2(newX, newZ);
return BlockVector2.at(newX, newZ);
}
/**
@ -232,7 +242,7 @@ public class BlockVector2 {
* @return a new vector
*/
public BlockVector2 multiply(int x, int z) {
return new BlockVector2(this.x * x, this.z * z);
return BlockVector2.at(this.x * x, this.z * z);
}
/**
@ -249,7 +259,7 @@ public class BlockVector2 {
newZ *= other.z;
}
return new BlockVector2(newX, newZ);
return BlockVector2.at(newX, newZ);
}
/**
@ -280,7 +290,7 @@ public class BlockVector2 {
* @return a new vector
*/
public BlockVector2 divide(int x, int z) {
return new BlockVector2(this.x / x, this.z / z);
return BlockVector2.at(this.x / x, this.z / z);
}
/**
@ -343,7 +353,7 @@ public class BlockVector2 {
double len = length();
double x = this.x / len;
double z = this.z / len;
return new BlockVector2(x, z);
return BlockVector2.at(x, z);
}
/**
@ -407,7 +417,7 @@ public class BlockVector2 {
* @return a new vector
*/
public BlockVector2 abs() {
return new BlockVector2(Math.abs(x), Math.abs(z));
return BlockVector2.at(Math.abs(x), Math.abs(z));
}
/**
@ -429,7 +439,7 @@ public class BlockVector2 {
double sin = Math.sin(angle);
double x2 = x * cos - z * sin;
double z2 = x * sin + z * cos;
return new BlockVector2(
return BlockVector2.at(
x2 + aboutX + translateX,
z2 + aboutZ + translateZ);
}
@ -461,7 +471,7 @@ public class BlockVector2 {
}
public Vector2 toVector2() {
return new Vector2(x, z);
return Vector2.at(x, z);
}
/**
@ -480,7 +490,7 @@ public class BlockVector2 {
* @return a new vector
*/
public Vector3 toVector3(double y) {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
/**
@ -499,7 +509,7 @@ public class BlockVector2 {
* @return a new vector
*/
public BlockVector3 toBlockVector3(int y) {
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
@Override

View File

@ -37,6 +37,28 @@ public class BlockVector3 {
public static final BlockVector3 UNIT_Z = new BlockVector3(0, 0, 1);
public static final BlockVector3 ONE = new BlockVector3(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));
}
public static BlockVector3 at(int x, int y, int z) {
// switch for efficiency on typical cases
// in MC y is rarely 0/1 on selections
switch (y) {
case 0:
if (x == 0 && z == 0) {
return ZERO;
}
break;
case 1:
if (x == 1 && z == 1) {
return ONE;
}
break;
}
return new BlockVector3(x, y, z);
}
// thread-safe initialization idiom
private static final class YzxOrderComparator {
private static final Comparator<BlockVector3> YZX_ORDER = (a, b) -> {
@ -67,18 +89,7 @@ public class BlockVector3 {
* @param y the Y coordinate
* @param z the Z coordinate
*/
public BlockVector3(double x, double y, double z) {
this((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(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) {
private BlockVector3(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
@ -109,7 +120,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 withX(int x) {
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
/**
@ -137,7 +148,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 withY(int y) {
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
/**
@ -165,7 +176,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 withZ(int z) {
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
/**
@ -187,7 +198,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 add(int x, int y, int z) {
return new BlockVector3(this.x + x, this.y + y, this.z + z);
return BlockVector3.at(this.x + x, this.y + y, this.z + z);
}
/**
@ -206,7 +217,7 @@ public class BlockVector3 {
newZ += other.z;
}
return new BlockVector3(newX, newY, newZ);
return BlockVector3.at(newX, newY, newZ);
}
/**
@ -230,7 +241,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 subtract(int x, int y, int z) {
return new BlockVector3(this.x - x, this.y - y, this.z - z);
return BlockVector3.at(this.x - x, this.y - y, this.z - z);
}
/**
@ -249,7 +260,7 @@ public class BlockVector3 {
newZ -= other.z;
}
return new BlockVector3(newX, newY, newZ);
return BlockVector3.at(newX, newY, newZ);
}
/**
@ -271,7 +282,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 multiply(int x, int y, int z) {
return new BlockVector3(this.x * x, this.y * y, this.z * z);
return BlockVector3.at(this.x * x, this.y * y, this.z * z);
}
/**
@ -289,7 +300,7 @@ public class BlockVector3 {
newZ *= other.z;
}
return new BlockVector3(newX, newY, newZ);
return BlockVector3.at(newX, newY, newZ);
}
/**
@ -321,7 +332,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 divide(int x, int y, int z) {
return new BlockVector3(this.x / x, this.y / y, this.z / z);
return BlockVector3.at(this.x / x, this.y / y, this.z / z);
}
/**
@ -386,7 +397,7 @@ public class BlockVector3 {
double x = this.x / len;
double y = this.y / len;
double z = this.z / len;
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
/**
@ -434,10 +445,10 @@ public class BlockVector3 {
public BlockVector3 clampY(int min, int max) {
checkArgument(min <= max, "minimum cannot be greater than maximum");
if (y < min) {
return new BlockVector3(x, min, z);
return BlockVector3.at(x, min, z);
}
if (y > max) {
return new BlockVector3(x, max, z);
return BlockVector3.at(x, max, z);
}
return this;
}
@ -481,7 +492,7 @@ public class BlockVector3 {
* @return a new vector
*/
public BlockVector3 abs() {
return new BlockVector3(Math.abs(x), Math.abs(y), Math.abs(z));
return BlockVector3.at(Math.abs(x), Math.abs(y), Math.abs(z));
}
/**
@ -504,7 +515,7 @@ public class BlockVector3 {
double x2 = x * cos - z * sin;
double z2 = x * sin + z * cos;
return new BlockVector3(
return BlockVector3.at(
x2 + aboutX + translateX,
y,
z2 + aboutZ + translateZ
@ -579,11 +590,11 @@ public class BlockVector3 {
* @return a new {@link BlockVector2}
*/
public BlockVector2 toBlockVector2() {
return new BlockVector2(x, z);
return BlockVector2.at(x, z);
}
public Vector3 toVector3() {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
@Override

View File

@ -126,7 +126,7 @@ public final class MathUtils {
* @return midpoint Vector3
*/
public static Vector3 midpoint(Vector3 v1, Vector3 v2) {
return new Vector3(
return Vector3.at(
(v1.getX() + v2.getX()) / 2,
(v1.getY() + v2.getY()) / 2,
(v1.getZ() + v2.getZ()) / 2
@ -141,7 +141,7 @@ public final class MathUtils {
* @return midpoint BlockVector3
*/
public static BlockVector3 midpoint(BlockVector3 v1, BlockVector3 v2) {
return new BlockVector3(
return BlockVector3.at(
(v1.getBlockX() + v2.getBlockX()) / 2,
(v1.getBlockY() + v2.getBlockY()) / 2,
(v1.getBlockZ() + v2.getBlockZ()) / 2

View File

@ -580,15 +580,15 @@ public class MutableBlockVector implements Serializable {
* @return a new {@link BlockVector2}
*/
public BlockVector2 toBlockVector2() {
return new BlockVector2(x, z);
return BlockVector2.at(x, z);
}
public Vector3 toVector3() {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
public BlockVector3 toBlockVector3() {
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
@Override

View File

@ -453,7 +453,7 @@ public final class MutableBlockVector2D implements Serializable {
* @return a new vector
*/
public Vector2 toVector2() {
return new Vector2(x, z);
return Vector2.at(x, z);
}
/**
@ -472,7 +472,7 @@ public final class MutableBlockVector2D implements Serializable {
* @return a new vector
*/
public Vector3 toVector3(double y) {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
/**
@ -491,7 +491,7 @@ public final class MutableBlockVector2D implements Serializable {
* @return a new vector
*/
public BlockVector3 toBlockVector3(int y) {
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
/**
@ -500,7 +500,7 @@ public final class MutableBlockVector2D implements Serializable {
* @return a new vector
*/
public BlockVector2 toBlockVector2() {
return new BlockVector2(x, z);
return BlockVector2.at(x, z);
}
@Override

View File

@ -338,7 +338,7 @@ public class MutableVector implements Serializable {
* @return the cross product of this and the other vector
*/
public Vector3 cross(MutableVector other) {
return new Vector3(
return Vector3.at(
y * other.z - z * other.y,
z * other.x - x * other.z,
x * other.y - y * other.x
@ -518,7 +518,7 @@ public class MutableVector implements Serializable {
* @return a new {@code BlockVector}
*/
public static BlockVector3 toBlockPoint(double x, double y, double z) {
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
/**
@ -536,11 +536,11 @@ public class MutableVector implements Serializable {
* @return a new {@link Vector2}
*/
public Vector2 toVector2() {
return new Vector2(x, z);
return Vector2.at(x, z);
}
public Vector3 toVector3() {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
@Override

View File

@ -25,12 +25,29 @@ import com.sk89q.worldedit.math.transform.AffineTransform;
* An immutable 2-dimensional vector.
*/
public final class Vector2 {
public static final Vector2 ZERO = new Vector2(0, 0);
public static final Vector2 UNIT_X = new Vector2(1, 0);
public static final Vector2 UNIT_Z = new Vector2(0, 1);
public static final Vector2 ONE = new Vector2(1, 1);
public static Vector2 at(double x, double z) {
int xTrunc = (int) x;
switch (xTrunc) {
case 0:
if (x == 0 && z == 0) {
return ZERO;
}
break;
case 1:
if (x == 1 && z == 1) {
return ONE;
}
break;
}
return new Vector2(x, z);
}
private final double x, z;
/**
@ -39,21 +56,11 @@ public final class Vector2 {
* @param x the X coordinate
* @param z the Z coordinate
*/
public Vector2(double x, double z) {
private Vector2(double x, double z) {
this.x = x;
this.z = z;
}
/**
* Copy another vector.
*
* @param other the other vector
*/
public Vector2(Vector2 other) {
this.x = other.x;
this.z = other.z;
}
/**
* Get the X coordinate.
*
@ -70,7 +77,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 withX(double x) {
return new Vector2(x, z);
return Vector2.at(x, z);
}
/**
@ -89,7 +96,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 withZ(double z) {
return new Vector2(x, z);
return Vector2.at(x, z);
}
/**
@ -110,7 +117,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 add(double x, double z) {
return new Vector2(this.x + x, this.z + z);
return Vector2.at(this.x + x, this.z + z);
}
/**
@ -128,7 +135,7 @@ public final class Vector2 {
newZ += other.z;
}
return new Vector2(newX, newZ);
return Vector2.at(newX, newZ);
}
/**
@ -151,7 +158,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 subtract(double x, double z) {
return new Vector2(this.x - x, this.z - z);
return Vector2.at(this.x - x, this.z - z);
}
/**
@ -169,7 +176,7 @@ public final class Vector2 {
newZ -= other.z;
}
return new Vector2(newX, newZ);
return Vector2.at(newX, newZ);
}
/**
@ -190,7 +197,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 multiply(double x, double z) {
return new Vector2(this.x * x, this.z * z);
return Vector2.at(this.x * x, this.z * z);
}
/**
@ -207,7 +214,7 @@ public final class Vector2 {
newZ *= other.z;
}
return new Vector2(newX, newZ);
return Vector2.at(newX, newZ);
}
/**
@ -238,7 +245,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 divide(double x, double z) {
return new Vector2(this.x / x, this.z / z);
return Vector2.at(this.x / x, this.z / z);
}
/**
@ -329,7 +336,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 floor() {
return new Vector2(Math.floor(x), Math.floor(z));
return Vector2.at(Math.floor(x), Math.floor(z));
}
/**
@ -338,7 +345,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 ceil() {
return new Vector2(Math.ceil(x), Math.ceil(z));
return Vector2.at(Math.ceil(x), Math.ceil(z));
}
/**
@ -349,7 +356,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 round() {
return new Vector2(Math.floor(x + 0.5), Math.floor(z + 0.5));
return Vector2.at(Math.floor(x + 0.5), Math.floor(z + 0.5));
}
/**
@ -359,7 +366,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector2 abs() {
return new Vector2(Math.abs(x), Math.abs(z));
return Vector2.at(Math.abs(x), Math.abs(z));
}
/**
@ -413,7 +420,7 @@ public final class Vector2 {
}
public static BlockVector2 toBlockPoint(double x, double z) {
return new BlockVector2(x, z);
return BlockVector2.at(x, z);
}
/**
@ -441,7 +448,7 @@ public final class Vector2 {
* @return a new vector
*/
public Vector3 toVector3(double y) {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
@Override

View File

@ -37,6 +37,25 @@ public class Vector3 {
public static final Vector3 UNIT_Z = new Vector3(0, 0, 1);
public static final Vector3 ONE = new Vector3(1, 1, 1);
public static Vector3 at(double x, double y, double z) {
// switch for efficiency on typical cases
// in MC y is rarely 0/1 on selections
int yTrunc = (int) y;
switch (yTrunc) {
case 0:
if (x == 0 && y == 0 && z == 0) {
return ZERO;
}
break;
case 1:
if (x == 1 && y == 1 && z == 1) {
return ONE;
}
break;
}
return new Vector3(x, y, z);
}
// thread-safe initialization idiom
private static final class YzxOrderComparator {
private static final Comparator<Vector3> YZX_ORDER = (a, b) -> {
@ -67,23 +86,12 @@ public class Vector3 {
* @param y the Y coordinate
* @param z the Z coordinate
*/
public Vector3(double x, double y, double z) {
private Vector3(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* Copy another vector.
*
* @param other another vector to make a copy of
*/
public Vector3(Vector3 other) {
this.x = other.x;
this.y = other.y;
this.z = other.z;
}
/**
* Get the X coordinate.
*
@ -100,7 +108,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 withX(double x) {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
/**
@ -119,7 +127,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 withY(double y) {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
/**
@ -138,7 +146,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 withZ(double z) {
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
/**
@ -160,7 +168,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 add(double x, double y, double z) {
return new Vector3(this.x + x, this.y + y, this.z + z);
return Vector3.at(this.x + x, this.y + y, this.z + z);
}
/**
@ -179,7 +187,7 @@ public class Vector3 {
newZ += other.z;
}
return new Vector3(newX, newY, newZ);
return Vector3.at(newX, newY, newZ);
}
/**
@ -203,7 +211,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 subtract(double x, double y, double z) {
return new Vector3(this.x - x, this.y - y, this.z - z);
return Vector3.at(this.x - x, this.y - y, this.z - z);
}
/**
@ -222,7 +230,7 @@ public class Vector3 {
newZ -= other.z;
}
return new Vector3(newX, newY, newZ);
return Vector3.at(newX, newY, newZ);
}
/**
@ -244,7 +252,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 multiply(double x, double y, double z) {
return new Vector3(this.x * x, this.y * y, this.z * z);
return Vector3.at(this.x * x, this.y * y, this.z * z);
}
/**
@ -262,7 +270,7 @@ public class Vector3 {
newZ *= other.z;
}
return new Vector3(newX, newY, newZ);
return Vector3.at(newX, newY, newZ);
}
/**
@ -294,7 +302,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 divide(double x, double y, double z) {
return new Vector3(this.x / x, this.y / y, this.z / z);
return Vector3.at(this.x / x, this.y / y, this.z / z);
}
/**
@ -403,10 +411,10 @@ public class Vector3 {
public Vector3 clampY(int min, int max) {
checkArgument(min <= max, "minimum cannot be greater than maximum");
if (y < min) {
return new Vector3(x, min, z);
return Vector3.at(x, min, z);
}
if (y > max) {
return new Vector3(x, max, z);
return Vector3.at(x, max, z);
}
return this;
}
@ -417,7 +425,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 floor() {
return new Vector3(Math.floor(x), Math.floor(y), Math.floor(z));
return Vector3.at(Math.floor(x), Math.floor(y), Math.floor(z));
}
/**
@ -426,7 +434,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 ceil() {
return new Vector3(Math.ceil(x), Math.ceil(y), Math.ceil(z));
return Vector3.at(Math.ceil(x), Math.ceil(y), Math.ceil(z));
}
/**
@ -437,7 +445,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 round() {
return new Vector3(Math.floor(x + 0.5), Math.floor(y + 0.5), Math.floor(z + 0.5));
return Vector3.at(Math.floor(x + 0.5), Math.floor(y + 0.5), Math.floor(z + 0.5));
}
/**
@ -447,7 +455,7 @@ public class Vector3 {
* @return a new vector
*/
public Vector3 abs() {
return new Vector3(Math.abs(x), Math.abs(y), Math.abs(z));
return Vector3.at(Math.abs(x), Math.abs(y), Math.abs(z));
}
/**
@ -548,7 +556,7 @@ public class Vector3 {
* @return a new {@code BlockVector}
*/
public static BlockVector3 toBlockPoint(double x, double y, double z) {
return new BlockVector3(x, y, z);
return BlockVector3.at(x, y, z);
}
/**
@ -566,7 +574,7 @@ public class Vector3 {
* @return a new {@link Vector2}
*/
public Vector2 toVector2() {
return new Vector2(x, z);
return Vector2.at(x, z);
}
@Override

View File

@ -200,19 +200,20 @@ public class HeightMap {
} else {
existing = PropertyGroup.LEVEL.set(existing, 15);
session.setBlock(xr, newBlock, zr, existing);
//=======
// BlockState existing = session.getBlock(new BlockVector3(xr, curHeight, zr));
// BlockState existing = session.getBlock(BlockVector3.at(xr, curHeight, zr));
//
// // Skip water/lava
// if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) {
// session.setBlock(new BlockVector3(xr, newHeight, zr), existing);
// session.setBlock(BlockVector3.at(xr, newHeight, zr), existing);
// ++blocksChanged;
//
// // Grow -- start from 1 below top replacing airblocks
// for (int y = newHeight - 1 - originY; y >= 0; --y) {
// int copyFrom = (int) (y * scale);
// session.setBlock(new BlockVector3(xr, originY + y, zr), session.getBlock(new BlockVector3(xr, originY + copyFrom, zr)));
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// session.setBlock(BlockVector3.at(xr, originY + y, zr), session.getBlock(BlockVector3.at(xr, originY + copyFrom, zr)));
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
++blocksChanged;
}
}
@ -225,8 +226,8 @@ public class HeightMap {
// // Shrink -- start from bottom
// for (int y = 0; y < newHeight - originY; ++y) {
// int copyFrom = (int) (y * scale);
// session.setBlock(new BlockVector3(xr, originY + y, zr), session.getBlock(new BlockVector3(xr, originY + copyFrom, zr)));
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// session.setBlock(BlockVector3.at(xr, originY + y, zr), session.getBlock(BlockVector3.at(xr, originY + copyFrom, zr)));
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
++blocksChanged;
}
// Set the top block of the column to be the same type
@ -294,12 +295,12 @@ public class HeightMap {
} else if (curHeight > newHeight) {
// Set the top block of the column to be the same type
// (this could otherwise go wrong with rounding)
session.setBlock(xr, newHeight, zr, session.getBlock(xr, curHeight, zr));
session.setBlock(BlockVector3.at(xr, newHeight, zr), session.getBlock(BlockVector3.at(xr, curHeight, zr)));
++blocksChanged;
// Fill rest with air
for (int y = newHeight + 1; y <= curHeight; ++y) {
session.setBlock(xr, y, zr, fillerAir);
session.setBlock(BlockVector3.at(xr, y, zr), fillerAir);
++blocksChanged;
}
}

View File

@ -53,7 +53,7 @@ public final class Polygons {
final List<BlockVector2> points = new ArrayList<>(nPoints);
for (int i = 0; i < nPoints; ++i) {
double angle = i * (2.0 * Math.PI) / nPoints;
final Vector2 pos = new Vector2(Math.cos(angle), Math.sin(angle));
final Vector2 pos = Vector2.at(Math.cos(angle), Math.sin(angle));
final BlockVector2 blockVector2D = pos.multiply(radius).toBlockPoint().add(center);
points.add(blockVector2D);
}

View File

@ -38,7 +38,7 @@ public class Node {
private double continuity;
public Node() {
this(new Vector3(0, 0, 0));
this(Vector3.at(0, 0, 0));
}
public Node(Node other) {

View File

@ -292,7 +292,7 @@ public class AffineTransform implements Transform, Serializable {
@Override
public Vector3 apply(Vector3 vector) {
return new Vector3(
return Vector3.at(
vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03,
vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13,
vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23);

View File

@ -22,7 +22,7 @@ public class RoundedTransform implements Transform{
// mutable.mutX((int) Math.floor(val.getX() + 0.5));
// mutable.mutY((int) Math.floor(val.getY() + 0.5));
// mutable.mutZ((int) Math.floor(val.getZ() + 0.5));
return new Vector3(Math.floor(val.getX() + 0.5), Math.floor(val.getY() + 0.5), Math.floor(val.getY() + 0.5));
return Vector3.at(Math.floor(val.getX() + 0.5), Math.floor(val.getY() + 0.5), Math.floor(val.getY() + 0.5));
}
@Override

View File

@ -88,10 +88,10 @@ public abstract class AbstractRegion implements Region {
final List<BlockVector2> points = new ArrayList<>(4);
points.add(new BlockVector2(min.getX(), min.getZ()));
points.add(new BlockVector2(min.getX(), max.getZ()));
points.add(new BlockVector2(max.getX(), max.getZ()));
points.add(new BlockVector2(max.getX(), min.getZ()));
points.add(BlockVector2.at(min.getX(), min.getZ()));
points.add(BlockVector2.at(min.getX(), max.getZ()));
points.add(BlockVector2.at(max.getX(), max.getZ()));
points.add(BlockVector2.at(max.getX(), min.getZ()));
return points;
}
@ -166,11 +166,11 @@ public abstract class AbstractRegion implements Region {
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
if (!contains(new BlockVector3(x, minY, z))) {
if (!contains(BlockVector3.at(x, minY, z))) {
continue;
}
chunks.add(new BlockVector2(
chunks.add(BlockVector2.at(
x >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS
));
@ -190,11 +190,11 @@ public abstract class AbstractRegion implements Region {
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
if (!contains(new BlockVector3(x, y, z))) {
if (!contains(BlockVector3.at(x, y, z))) {
continue;
}
chunks.add(new BlockVector3(
chunks.add(BlockVector3.at(
x >> ChunkStore.CHUNK_SHIFTS,
y >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS

View File

@ -349,10 +349,17 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
};
}
//<<<<<<< HEAD
@Override
public int size() {
return size;
}
//=======
// for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
// for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
// chunks.add(BlockVector2.at(x, z));
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
@Override
public boolean contains(Object o) {
@ -381,7 +388,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
for (int y = min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y <= max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; ++y) {
chunks.add(new BlockVector3(x, y, z));
chunks.add(BlockVector3.at(x, y, z));
}
}
}
@ -463,6 +470,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public BlockVector3 next() {
//<<<<<<< HEAD
mutable.mutX(x);
mutable.mutY(y);
mutable.mutZ(z);
@ -498,6 +506,16 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
} else {
x = cbx;
z = cbz;
//=======
// if (!hasNext()) throw new NoSuchElementException();
// BlockVector3 answer = BlockVector3.at(nextX, nextY, nextZ);
// if (++nextX > max.getBlockX()) {
// nextX = min.getBlockX();
// if (++nextY > max.getBlockY()) {
// nextY = min.getBlockY();
// if (++nextZ > max.getBlockZ()) {
// nextX = Integer.MIN_VALUE;
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
}
} else {
x = cbx;
@ -525,10 +543,16 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
//<<<<<<< HEAD
public BlockVector3 next() {
mutable.mutX(nextX);
mutable.mutY(nextY);
mutable.mutZ(nextZ);
//=======
// public BlockVector2 next() {
// if (!hasNext()) throw new NoSuchElementException();
// BlockVector2 answer = BlockVector2.at(nextX, nextZ);
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
if (++nextX > max.getBlockX()) {
nextX = min.getBlockX();
if (++nextZ > max.getBlockZ()) {
@ -575,7 +599,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
public BlockVector2 next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
// BlockVector2 answer = mutable.setComponents(nextX, nextZ);
BlockVector2 answer = new BlockVector2(nextX, nextZ);
BlockVector2 answer = BlockVector2.at(nextX, nextZ);
if (++nextX > max.getBlockX()) {
nextX = min.getBlockX();
if (++nextZ > max.getBlockZ()) {

View File

@ -268,7 +268,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
public void contract(BlockVector3... changes) throws RegionOperationException {
center = center.subtract(calculateDiff2D(changes));
Vector2 newRadius = radius.subtract(calculateChanges2D(changes).toVector2());
radius = new Vector2(1.5, 1.5).getMaximum(newRadius);
radius = Vector2.at(1.5, 1.5).getMaximum(newRadius);
this.radiusInverse = Vector2.ONE.divide(radius);
for (BlockVector3 change : changes) {
int height = maxY - minY;
@ -377,7 +377,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
public static CylinderRegion createRadius(Extent extent, BlockVector3 center, double radius) {
checkNotNull(extent);
checkNotNull(center);
Vector2 radiusVec = new Vector2(radius, radius);
Vector2 radiusVec = Vector2.at(radius, radius);
int minY = extent.getMinimumPoint().getBlockY();
int maxY = extent.getMaximumPoint().getBlockY();
return new CylinderRegion(center, radiusVec, minY, maxY);

View File

@ -136,7 +136,7 @@ public class EllipsoidRegion extends AbstractRegion {
public void contract(BlockVector3... changes) throws RegionOperationException {
center = center.subtract(calculateDiff(changes));
Vector3 newRadius = radius.subtract(calculateChanges(changes).toVector3());
setRadius(new Vector3(1.5, 1.5, 1.5).getMaximum(newRadius));
setRadius(Vector3.at(1.5, 1.5, 1.5).getMaximum(newRadius));
}
@Override
@ -199,11 +199,11 @@ public class EllipsoidRegion extends AbstractRegion {
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
if (!contains(new BlockVector3(x, centerY, z))) {
if (!contains(BlockVector3.at(x, centerY, z))) {
continue;
}
chunks.add(new BlockVector2(
chunks.add(BlockVector2.at(
x >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS
));

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector2;
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
import com.sk89q.worldedit.world.World;
@ -131,8 +130,8 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
minY = Math.min(Math.max(0, minY), world == null ? 255 : world.getMaxY());
maxY = Math.min(Math.max(0, maxY), world == null ? 255 : world.getMaxY());
min = new BlockVector2(minX, minZ);
max = new BlockVector2(maxX, maxZ);
min = BlockVector2.at(minX, minZ);
max = BlockVector2.at(maxX, maxZ);
}
/**
@ -151,7 +150,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
* @param position the position
*/
public void addPoint(BlockVector3 position) {
points.add(new BlockVector2(position.getBlockX(), position.getBlockZ()));
points.add(BlockVector2.at(position.getBlockX(), position.getBlockZ()));
recalculate();
}
@ -267,7 +266,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
for (int i = 0; i < points.size(); ++i) {
BlockVector2 point = points.get(i);
points.set(i, new BlockVector2(point.getX() + changeX, point.getZ() + changeZ));
points.set(i, BlockVector2.at(point.getX() + changeX, point.getZ() + changeZ));
}
minY += changeY;

View File

@ -34,7 +34,7 @@ public class CylinderRegionFactory implements RegionFactory {
@Override
public Region createCenteredAt(BlockVector3 position, double size) {
return new CylinderRegion(position, new Vector2(size, size), position.getBlockY() - (int) (height / 2), position.getBlockY() + (int) (height / 2));
return new CylinderRegion(position, Vector2.at(size, size), position.getBlockY() - (int) (height / 2), position.getBlockY() + (int) (height / 2));
}
}

View File

@ -28,7 +28,7 @@ public class SphereRegionFactory implements RegionFactory {
@Override
public Region createCenteredAt(BlockVector3 position, double size) {
return new EllipsoidRegion(position, new Vector3(size, size, size));
return new EllipsoidRegion(position, Vector3.at(size, size, size));
}
}

View File

@ -68,7 +68,7 @@ public class FlatRegion3DIterator implements Iterator<BlockVector3> {
throw new NoSuchElementException();
}
BlockVector3 current = new BlockVector3(next2D.getBlockX(), nextY, next2D.getBlockZ());
BlockVector3 current = BlockVector3.at(next2D.getBlockX(), nextY, next2D.getBlockZ());
if (nextY < maxY) {
nextY++;
} else if (flatIterator.hasNext()) {

View File

@ -67,7 +67,7 @@ public class FlatRegionIterator implements Iterator<BlockVector2> {
}
private void forward() {
while (hasNext() && !region.contains(nextX, y, nextZ)) {
while (hasNext() && !region.contains(BlockVector3.at(nextX, y, nextZ))) {
forwardOne();
}
}
@ -78,7 +78,7 @@ public class FlatRegionIterator implements Iterator<BlockVector2> {
throw new NoSuchElementException();
}
BlockVector2 answer = new BlockVector2(nextX, nextZ);
BlockVector2 answer = BlockVector2.at(nextX, nextZ);
forwardOne();
forward();

View File

@ -63,7 +63,7 @@ public class RegionIterator implements Iterator<BlockVector3> {
}
private void forward() {
while (hasNext() && !region.contains(new BlockVector3(nextX, nextY, nextZ))) {
while (hasNext() && !region.contains(BlockVector3.at(nextX, nextY, nextZ))) {
forwardOne();
}
}
@ -72,7 +72,7 @@ public class RegionIterator implements Iterator<BlockVector3> {
public BlockVector3 next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
BlockVector3 answer = new BlockVector3(nextX, nextY, nextZ);
BlockVector3 answer = BlockVector3.at(nextX, nextY, nextZ);
forwardOne();
forward();

View File

@ -115,8 +115,8 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
final BlockVector3 o1 = position1;
final BlockVector3 o2 = position2;
position1 = new BlockVector3(x1, y1, z1);
position2 = new BlockVector3(x2, y2, z2);
position1 = BlockVector3.at(x1, y1, z1);
position2 = BlockVector3.at(x2, y2, z2);
region.setPos1(position1);
region.setPos2(position2);

View File

@ -116,7 +116,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
checkNotNull(points);
final BlockVector2 pos2D = points.get(0);
pos1 = new BlockVector3(pos2D.getX(), minY, pos2D.getZ());
pos1 = BlockVector3.at(pos2D.getX(), minY, pos2D.getZ());
region = new Polygonal2DRegion(world, points, minY, maxY);
}
@ -222,7 +222,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
@Override
public void learnChanges() {
BlockVector2 pt = region.getPoints().get(0);
pos1 = new BlockVector3(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ());
pos1 = BlockVector3.at(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ());
}
@Override

View File

@ -59,7 +59,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
super(oldSelector);
final Vector3 radius = region.getRadius();
final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ());
region.setRadius(new Vector3(radiusScalar, radiusScalar, radiusScalar));
region.setRadius(Vector3.at(radiusScalar, radiusScalar, radiusScalar));
}
/**
@ -70,7 +70,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
* @param radius the radius
*/
public SphereRegionSelector(@Nullable World world, BlockVector3 center, int radius) {
super(world, center, new Vector3(radius, radius, radius));
super(world, center, Vector3.at(radius, radius, radius));
}
@Override
@ -80,7 +80,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
}
final double radiusScalar = Math.ceil(position.toVector3().distance(region.getCenter()));
region.setRadius(new Vector3(radiusScalar, radiusScalar, radiusScalar));
region.setRadius(Vector3.at(radiusScalar, radiusScalar, radiusScalar));
return true;
}

View File

@ -37,7 +37,7 @@ public class RegionShape extends ArbitraryShape {
@Override
protected BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial) {
if (!this.extent.contains(new BlockVector3(x, y, z))) {
if (!this.extent.contains(BlockVector3.at(x, y, z))) {
return null;
}

View File

@ -44,7 +44,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
public BlockVector3 toWorld(double x, double y, double z) {
// unscale, unoffset, round-nearest
return new Vector3(x, y, z).multiply(unit).add(zero2).toBlockPoint();
return Vector3.at(x, y, z).multiply(unit).add(zero2).toBlockPoint();
}
public Vector3 toWorldRel(double x, double y, double z) {

View File

@ -30,27 +30,27 @@ import java.util.HashMap;
*/
public enum Direction {
NORTH(new Vector3(0, 0, -1), Flag.CARDINAL, 3, 1),
EAST(new Vector3(1, 0, 0), Flag.CARDINAL, 0, 2),
SOUTH(new Vector3(0, 0, 1), Flag.CARDINAL, 1, 3),
WEST(new Vector3(-1, 0, 0), Flag.CARDINAL, 2, 0),
NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1),
EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2),
SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL, 1, 3),
WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL, 2, 0),
UP(new Vector3(0, 1, 0), Flag.UPRIGHT, -1, -1),
DOWN(new Vector3(0, -1, 0), Flag.UPRIGHT, -1, -1),
UP(Vector3.at(0, 1, 0), Flag.UPRIGHT, -1, -1),
DOWN(Vector3.at(0, -1, 0), Flag.UPRIGHT, -1, -1),
NORTHEAST(new Vector3(1, 0, -1), Flag.ORDINAL, 7, 8),
NORTHWEST(new Vector3(-1, 0, -1), Flag.ORDINAL, 9, 6),
SOUTHEAST(new Vector3(1, 0, 1), Flag.ORDINAL, 6, 9),
SOUTHWEST(new Vector3(-1, 0, 1), Flag.ORDINAL, 8, 7),
NORTHEAST(Vector3.at(1, 0, -1), Flag.ORDINAL, 7, 8),
NORTHWEST(Vector3.at(-1, 0, -1), Flag.ORDINAL, 9, 6),
SOUTHEAST(Vector3.at(1, 0, 1), Flag.ORDINAL, 6, 9),
SOUTHWEST(Vector3.at(-1, 0, 1), Flag.ORDINAL, 8, 7),
WEST_NORTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6),
WEST_SOUTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7),
NORTH_NORTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6),
NORTH_NORTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8),
EAST_NORTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8),
EAST_SOUTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9),
SOUTH_SOUTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9),
SOUTH_SOUTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7);
WEST_NORTHWEST(Vector3.at(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6),
WEST_SOUTHWEST(Vector3.at(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7),
NORTH_NORTHWEST(Vector3.at(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6),
NORTH_NORTHEAST(Vector3.at(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8),
EAST_NORTHEAST(Vector3.at(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8),
EAST_SOUTHEAST(Vector3.at(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9),
SOUTH_SOUTHEAST(Vector3.at(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9),
SOUTH_SOUTHWEST(Vector3.at(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7);
private final Vector3 direction;
private final BlockVector3 blockVector;
@ -70,7 +70,7 @@ public enum Direction {
private Direction(Vector3 vector, int flags, int left, int right) {
this.direction = vector.normalize();
this.blockVector = new BlockVector3(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
this.blockVector = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
this.flags = flags;
this.left = left;
this.right = right;

View File

@ -61,7 +61,7 @@ public class Location{
* @param z the Z coordinate
*/
public Location(Extent extent, double x, double y, double z) {
this(extent, new Vector3(x, y, z), Vector3.ZERO);
this(extent, Vector3.at(x, y, z), Vector3.ZERO);
}
/**
@ -86,7 +86,7 @@ public class Location{
* @param direction the direction vector
*/
public Location(Extent extent, double x, double y, double z, Vector3 direction) {
this(extent, new Vector3(x, y, z), direction);
this(extent, Vector3.at(x, y, z), direction);
}
/**
@ -101,7 +101,7 @@ public class Location{
* @param pitch the pitch, in degrees
*/
public Location(Extent extent, double x, double y, double z, float yaw, float pitch) {
this(extent, new Vector3(x, y, z), yaw, pitch);
this(extent, Vector3.at(x, y, z), yaw, pitch);
}
/**
@ -212,7 +212,7 @@ public class Location{
double yaw = Math.toRadians(this.getYaw());
double pitch = Math.toRadians(this.getPitch());
double xz = Math.cos(pitch);
return new Vector3(
return Vector3.at(
-xz * Math.sin(yaw),
-Math.sin(pitch),
xz * Math.cos(yaw));

View File

@ -83,7 +83,7 @@ public class TargetBlock {
double h = (checkDistance * Math.cos(Math.toRadians(yRotation)));
offset = new Vector3((h * Math.cos(Math.toRadians(xRotation))),
offset = Vector3.at((h * Math.cos(Math.toRadians(xRotation))),
(checkDistance * Math.sin(Math.toRadians(yRotation))),
(h * Math.sin(Math.toRadians(xRotation))));

View File

@ -44,6 +44,6 @@ public class VectorAdapter implements JsonDeserializer<Vector3> {
double y = jsonArray.get(1).getAsDouble();
double z = jsonArray.get(2).getAsDouble();
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
}

View File

@ -120,12 +120,12 @@ public abstract class AbstractWorld implements World {
@Override
public BlockVector3 getMinimumPoint() {
return new BlockVector3(-30000000, 0, -30000000);
return BlockVector3.at(-30000000, 0, -30000000);
}
@Override
public BlockVector3 getMaximumPoint() {
return new BlockVector3(30000000, 255, 30000000);
return BlockVector3.at(30000000, 255, 30000000);
}
@Override

View File

@ -108,12 +108,12 @@ public interface SimpleWorld extends World {
@Override
default BlockVector3 getMinimumPoint() {
return new BlockVector3(-30000000, 0, -30000000);
return BlockVector3.at(-30000000, 0, -30000000);
}
@Override
default BlockVector3 getMaximumPoint() {
return new BlockVector3(30000000, 255, 30000000);
return BlockVector3.at(30000000, 255, 30000000);
}
@Override

View File

@ -224,7 +224,7 @@ public class AnvilChunk implements Chunk {
values.put(entry.getKey(), entry.getValue());
}
BlockVector3 vec = new BlockVector3(x, y, z);
BlockVector3 vec = BlockVector3.at(x, y, z);
tileEntities.put(vec, values);
}
}

View File

@ -201,7 +201,7 @@ public class AnvilChunk13 implements Chunk {
values.put(entry.getKey(), entry.getValue());
}
BlockVector3 vec = new BlockVector3(x, y, z);
BlockVector3 vec = BlockVector3.at(x, y, z);
tileEntities.put(vec, values);
}
}

View File

@ -127,7 +127,7 @@ public class OldChunk implements Chunk {
values.put(entry.getKey(), entry.getValue());
}
BlockVector3 vec = new BlockVector3(x, y, z);
BlockVector3 vec = BlockVector3.at(x, y, z);
tileEntities.put(vec, values);
}
}

View File

@ -79,7 +79,7 @@ public class SnapshotRestore {
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
BlockVector3 pos = new BlockVector3(x, y, z);
BlockVector3 pos = BlockVector3.at(x, y, z);
checkAndAddBlock(pos);
}
}

View File

@ -57,7 +57,7 @@ public abstract class ChunkStore implements Closeable {
* @return chunk coordinates
*/
public static BlockVector2 toChunk(BlockVector3 position) {
return new BlockVector2(position.getX() >> CHUNK_SHIFTS, position.getZ() >> CHUNK_SHIFTS);
return BlockVector2.at(position.getX() >> CHUNK_SHIFTS, position.getZ() >> CHUNK_SHIFTS);
}
/**