Move vectors to static creators, for caching

This commit is contained in:
Kenzie Togami 2018-10-19 13:13:32 -07:00
parent 399e0ad5fa
commit 2c8b2fe089
No known key found for this signature in database
GPG Key ID: 5D200B325E157A81
69 changed files with 366 additions and 334 deletions

View File

@ -240,7 +240,7 @@ public class BukkitAdapter {
*/
public static Vector3 asVector(org.bukkit.Location location) {
checkNotNull(location);
return new Vector3(location.getX(), location.getY(), location.getZ());
return Vector3.at(location.getX(), location.getY(), location.getZ());
}
/**
@ -251,7 +251,7 @@ public class BukkitAdapter {
*/
public static BlockVector3 asBlockVector(org.bukkit.Location location) {
checkNotNull(location);
return new BlockVector3(location.getX(), location.getY(), location.getZ());
return BlockVector3.at(location.getX(), location.getY(), location.getZ());
}
/**

View File

@ -175,7 +175,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
return;
}
setPosition(new Vector3(x + 0.5, y, z + 0.5));
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
player.setFlying(true);
}

View File

@ -169,7 +169,7 @@ public class BukkitWorld extends AbstractWorld {
BlockStateHolder[] history = new BlockStateHolder[16 * 16 * (getMaxY() + 1)];
for (BlockVector2 chunk : region.getChunks()) {
BlockVector3 min = new BlockVector3(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
BlockVector3 min = BlockVector3.at(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
// First save all the blocks inside
for (int x = 0; x < 16; ++x) {

View File

@ -40,7 +40,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public boolean setBlockData(int x, int y, int z, BlockData blockData) {
try {
editSession.setBlock(new BlockVector3(x, y, z), BukkitAdapter.adapt(blockData));
editSession.setBlock(BlockVector3.at(x, y, z), BukkitAdapter.adapt(blockData));
} catch (MaxChangedBlocksException e) {
return false;
}
@ -49,7 +49,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public BlockData getBlockData(int x, int y, int z) {
return BukkitAdapter.adapt(editSession.getBlock(new BlockVector3(x, y, z)));
return BukkitAdapter.adapt(editSession.getBlock(BlockVector3.at(x, y, z)));
}
@Override
@ -59,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isAir();
return editSession.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isAir();
}
}

View File

@ -169,7 +169,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

@ -215,7 +215,7 @@ public class YAMLNode {
return null;
}
return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}
/**
@ -239,7 +239,7 @@ public class YAMLNode {
return null;
}
return new Vector2(x, z);
return Vector2.at(x, z);
}
/**
@ -571,7 +571,7 @@ public class YAMLNode {
continue;
}
list.add(new Vector3(x, y, z));
list.add(Vector3.at(x, y, z));
}
return list;
@ -601,7 +601,7 @@ public class YAMLNode {
continue;
}
list.add(new Vector2(x, z));
list.add(Vector2.at(x, z));
}
return list;
@ -631,7 +631,7 @@ public class YAMLNode {
continue;
}
list.add(new BlockVector2(x, z));
list.add(BlockVector2.at(x, z));
}
return list;

View File

@ -482,7 +482,7 @@ public class EditSession implements Extent, AutoCloseable {
*/
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;
@ -713,7 +713,7 @@ public class EditSession implements Extent, AutoCloseable {
checkArgument(depth >= 1, "depth >= 1");
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())),
@ -904,8 +904,8 @@ public class EditSession implements Extent, AutoCloseable {
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);
}
@ -1055,7 +1055,7 @@ public class EditSession implements Extent, AutoCloseable {
checkNotNull(pattern);
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);
@ -1180,7 +1180,7 @@ public class EditSession implements Extent, AutoCloseable {
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()));
@ -1220,7 +1220,7 @@ public class EditSession implements Extent, AutoCloseable {
// There are boundaries that the routine needs to stay in
MaskIntersection mask = new MaskIntersection(
new BoundedHeightMask(0, Math.min(origin.getBlockY(), getWorld().getMaxY())),
new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))),
new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))),
blockMask
);
@ -1501,12 +1501,12 @@ public class EditSession implements Extent, AutoCloseable {
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) {
@ -1551,12 +1551,12 @@ public class EditSession implements Extent, AutoCloseable {
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()) {
@ -1619,12 +1619,12 @@ public class EditSession implements Extent, AutoCloseable {
final 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) {
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 ||
@ -1690,7 +1690,7 @@ public class EditSession implements Extent, AutoCloseable {
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
@ -1700,13 +1700,13 @@ public class EditSession implements Extent, AutoCloseable {
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;
}
@ -1743,7 +1743,7 @@ public class EditSession implements Extent, AutoCloseable {
final ArbitraryShape shape = new ArbitraryShape(region) {
@Override
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);
@ -1834,22 +1834,22 @@ public class EditSession implements Extent, AutoCloseable {
for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) {
recurseHollow(region, new BlockVector3(x, y, minZ), outside);
recurseHollow(region, new BlockVector3(x, y, maxZ), outside);
recurseHollow(region, BlockVector3.at(x, y, minZ), outside);
recurseHollow(region, BlockVector3.at(x, y, maxZ), outside);
}
}
for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) {
recurseHollow(region, new BlockVector3(minX, y, z), outside);
recurseHollow(region, new BlockVector3(maxX, y, z), outside);
recurseHollow(region, BlockVector3.at(minX, y, z), outside);
recurseHollow(region, BlockVector3.at(maxX, y, z), outside);
}
}
for (int z = minZ; z <= maxZ; ++z) {
for (int x = minX; x <= maxX; ++x) {
recurseHollow(region, new BlockVector3(x, minY, z), outside);
recurseHollow(region, new BlockVector3(x, maxY, z), outside);
recurseHollow(region, BlockVector3.at(x, minY, z), outside);
recurseHollow(region, BlockVector3.at(x, maxY, z), outside);
}
}
@ -1910,7 +1910,7 @@ public class EditSession implements Extent, AutoCloseable {
int dx = Math.abs(x2 - x1), dy = Math.abs(y2 - y1), dz = Math.abs(z2 - z1);
if (dx + dy + dz == 0) {
vset.add(new BlockVector3(tipx, tipy, tipz));
vset.add(BlockVector3.at(tipx, tipy, tipz));
notdrawn = false;
}
@ -1920,7 +1920,7 @@ public class EditSession implements Extent, AutoCloseable {
tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dx) * (y2 - y1 > 0 ? 1 : -1));
tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dx) * (z2 - z1 > 0 ? 1 : -1));
vset.add(new BlockVector3(tipx, tipy, tipz));
vset.add(BlockVector3.at(tipx, tipy, tipz));
}
notdrawn = false;
}
@ -1931,7 +1931,7 @@ public class EditSession implements Extent, AutoCloseable {
tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dy) * (x2 - x1 > 0 ? 1 : -1));
tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dy) * (z2 - z1 > 0 ? 1 : -1));
vset.add(new BlockVector3(tipx, tipy, tipz));
vset.add(BlockVector3.at(tipx, tipy, tipz));
}
notdrawn = false;
}
@ -1942,7 +1942,7 @@ public class EditSession implements Extent, AutoCloseable {
tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dz) * (y2-y1>0 ? 1 : -1));
tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dz) * (x2-x1>0 ? 1 : -1));
vset.add(new BlockVector3(tipx, tipy, tipz));
vset.add(BlockVector3.at(tipx, tipy, tipz));
}
notdrawn = false;
}
@ -2019,7 +2019,7 @@ public class EditSession implements Extent, AutoCloseable {
for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) {
for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) {
if (hypot(loopx - tipx, loopy - tipy, loopz - tipz) <= radius) {
returnset.add(new BlockVector3(loopx, loopy, loopz));
returnset.add(BlockVector3.at(loopx, loopy, loopz));
}
}
}
@ -2032,12 +2032,12 @@ public class EditSession implements Extent, AutoCloseable {
Set<BlockVector3> returnset = new HashSet<>();
for (BlockVector3 v : vset) {
double x = v.getX(), y = v.getY(), z = v.getZ();
if (!(vset.contains(new BlockVector3(x + 1, y, z)) &&
vset.contains(new BlockVector3(x - 1, y, z)) &&
vset.contains(new BlockVector3(x, y + 1, z)) &&
vset.contains(new BlockVector3(x, y - 1, z)) &&
vset.contains(new BlockVector3(x, y, z + 1)) &&
vset.contains(new BlockVector3(x, y, z - 1)))) {
if (!(vset.contains(BlockVector3.at(x + 1, y, z)) &&
vset.contains(BlockVector3.at(x - 1, y, z)) &&
vset.contains(BlockVector3.at(x, y + 1, z)) &&
vset.contains(BlockVector3.at(x, y - 1, z)) &&
vset.contains(BlockVector3.at(x, y, z + 1)) &&
vset.contains(BlockVector3.at(x, y, z - 1)))) {
returnset.add(v);
}
}
@ -2083,7 +2083,7 @@ public class EditSession implements Extent, AutoCloseable {
final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) {
@Override
protected BaseBiome getBiome(int x, int z, 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);

View File

@ -662,7 +662,7 @@ public class LocalSession {
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

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

View File

@ -224,8 +224,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);
player.print("Chunks selected: ("
+ min2D.getBlockX() + ", " + min2D.getBlockZ() + ") - ("
@ -240,14 +240,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);
player.print("Chunk selected: "
@ -320,8 +320,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);
@ -564,15 +564,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

@ -69,7 +69,7 @@ public class AreaPickaxe implements BlockTool {
for (int x = ox - range; x <= ox + range; ++x) {
for (int y = oy - range; y <= oy + range; ++y) {
for (int z = oz - range; z <= oz + range; ++z) {
BlockVector3 pos = new BlockVector3(x, y, z);
BlockVector3 pos = BlockVector3.at(x, y, z);
if (editSession.getBlock(pos).getBlockType() != initialType) {
continue;
}

View File

@ -46,14 +46,14 @@ public class GravityBrush implements Brush {
double y = startY;
final List<BlockStateHolder> blockTypes = new ArrayList<>();
for (; y > position.getBlockY() - size; --y) {
final BlockVector3 pt = new BlockVector3(x, y, z);
final BlockVector3 pt = BlockVector3.at(x, y, z);
final BlockStateHolder block = editSession.getBlock(pt);
if (!block.getBlockType().getMaterial().isAir()) {
blockTypes.add(block);
editSession.setBlock(pt, BlockTypes.AIR.getDefaultState());
}
}
BlockVector3 pt = new BlockVector3(x, y, z);
BlockVector3 pt = BlockVector3.at(x, y, z);
Collections.reverse(blockTypes);
for (int i = 0; i < blockTypes.size();) {
if (editSession.getBlock(pt).getBlockType().getMaterial().isAir()) {

View File

@ -135,7 +135,7 @@ class DefaultMaskParser extends InputParser<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 '$':

View File

@ -106,7 +106,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;
@ -114,7 +114,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (free == 2) {
if (y - 1 != origY) {
setPosition(new Vector3(x + 0.5, y - 2 + 1, z + 0.5));
setPosition(Vector3.at(x + 0.5, y - 2 + 1, z + 0.5));
}
return;
@ -132,10 +132,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 + 1, z + 0.5));
setPosition(Vector3.at(x + 0.5, y + 1, z + 0.5));
return;
}
@ -160,7 +160,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
byte spots = 0;
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()) {
++free;
} else {
free = 0;
@ -169,7 +169,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (free == 2) {
++spots;
if (spots == 2) {
final BlockVector3 platform = new BlockVector3(x, y - 2, z);
final BlockVector3 platform = BlockVector3.at(x, y - 2, z);
final BlockStateHolder block = world.getBlock(platform);
final com.sk89q.worldedit.world.block.BlockType type = block.getBlockType();
@ -200,7 +200,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
byte free = 0;
while (y >= 1) {
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;
@ -211,7 +211,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
// lightly and also check to see if there's something to
// stand upon
while (y >= 0) {
final BlockVector3 platform = new BlockVector3(x, y, z);
final BlockVector3 platform = BlockVector3.at(x, y, z);
final BlockStateHolder block = world.getBlock(platform);
final BlockType type = block.getBlockType();
@ -249,13 +249,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;
@ -283,7 +283,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;
@ -301,14 +301,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

@ -28,7 +28,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

@ -116,12 +116,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));
@ -205,7 +205,7 @@ public class MCEditSchematicReader extends NBTSchematicReader {
}
}
BlockVector3 vec = new BlockVector3(x, y, z);
BlockVector3 vec = BlockVector3.at(x, y, z);
tileEntitiesMap.put(vec, values);
}
@ -219,7 +219,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

@ -109,14 +109,14 @@ public class SpongeSchematicReader extends NBTSchematicReader {
throw new IOException("Invalid offset specified in schematic.");
}
BlockVector3 min = new BlockVector3(offsetParts[0], offsetParts[1], offsetParts[2]);
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 = 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));
} else {
@ -159,7 +159,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
for (Map<String, Tag> tileEntity : tileEntityTags) {
int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
tileEntitiesMap.put(new BlockVector3(pos[0], pos[1], pos[2]), tileEntity);
tileEntitiesMap.put(BlockVector3.at(pos[0], pos[1], pos[2]), tileEntity);
}
} catch (Exception e) {
throw new IOException("Failed to load Tile Entities: " + e.getMessage());
@ -192,7 +192,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
int z = (index % (width * length)) / width;
int x = (index % (width * length)) % width;
BlockState state = palette.get(value);
BlockVector3 pt = new BlockVector3(x, y, z);
BlockVector3 pt = BlockVector3.at(x, y, z);
try {
if (tileEntitiesMap.containsKey(pt)) {
Map<String, Tag> values = Maps.newHashMap(tileEntitiesMap.get(pt));

View File

@ -126,7 +126,7 @@ 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<>();

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

@ -86,7 +86,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

@ -135,7 +135,7 @@ public class ExtentEntityCopy implements EntityFunction {
boolean hasFacing = tag.containsKey("Facing");
if (hasTilePosition) {
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"));
BlockVector3 newTilePosition = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint();
CompoundTagBuilder builder = tag.createBuilder()

View File

@ -37,7 +37,6 @@ import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.visitor.EntityVisitor;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
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;

View File

@ -89,7 +89,7 @@ public class RepeatingExtentPattern extends AbstractPattern {
int x = base.getBlockX() % size.getBlockX();
int y = base.getBlockY() % size.getBlockY();
int z = base.getBlockZ() % size.getBlockZ();
return extent.getFullBlock(new BlockVector3(x, y, z));
return extent.getFullBlock(BlockVector3.at(x, y, z));
}
}

View File

@ -71,7 +71,7 @@ public abstract class BreadthFirstSearch implements Operation {
* <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 new BlockVector3(1, 0, 1)}.</p>
* {@code BlockVector3.at(1, 0, 1)}.</p>
*
* <p>The list of directions can be cleared.</p>
*
@ -85,22 +85,22 @@ public abstract class BreadthFirstSearch implements Operation {
* Add the directions along the axes as directions to visit.
*/
protected void addAxes() {
directions.add(new BlockVector3(0, -1, 0));
directions.add(new BlockVector3(0, 1, 0));
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(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(new BlockVector3(1, 0, 1));
directions.add(new BlockVector3(-1, 0, -1));
directions.add(new BlockVector3(1, 0, -1));
directions.add(new BlockVector3(-1, 0, 1));
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));
}
/**

View File

@ -53,11 +53,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

@ -40,11 +40,11 @@ public class NonRisingVisitor extends RecursiveVisitor {
super(mask, function);
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

@ -392,7 +392,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);
@ -405,7 +405,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);
@ -419,7 +419,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 final 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 final 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 final 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 final 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 final 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 final class BlockVector2 {
newZ += other.z;
}
return new BlockVector2(newX, newZ);
return BlockVector2.at(newX, newZ);
}
/**
@ -193,7 +203,7 @@ public final 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 final class BlockVector2 {
newZ -= other.z;
}
return new BlockVector2(newX, newZ);
return BlockVector2.at(newX, newZ);
}
/**
@ -232,7 +242,7 @@ public final 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 final class BlockVector2 {
newZ *= other.z;
}
return new BlockVector2(newX, newZ);
return BlockVector2.at(newX, newZ);
}
/**
@ -280,7 +290,7 @@ public final 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 final 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 final 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 final 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 final class BlockVector2 {
}
public Vector2 toVector2() {
return new Vector2(x, z);
return Vector2.at(x, z);
}
/**
@ -480,7 +490,7 @@ public final 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 final 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 final 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 final 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 final 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 final 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 final 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 final 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 final class BlockVector3 {
newZ += other.z;
}
return new BlockVector3(newX, newY, newZ);
return BlockVector3.at(newX, newY, newZ);
}
/**
@ -230,7 +241,7 @@ public final 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 final class BlockVector3 {
newZ -= other.z;
}
return new BlockVector3(newX, newY, newZ);
return BlockVector3.at(newX, newY, newZ);
}
/**
@ -271,7 +282,7 @@ public final 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 final class BlockVector3 {
newZ *= other.z;
}
return new BlockVector3(newX, newY, newZ);
return BlockVector3.at(newX, newY, newZ);
}
/**
@ -321,7 +332,7 @@ public final 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 final 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 final 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 final 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 final 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 final 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

@ -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 final 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 final 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 final 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 final 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 final 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 final 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 final class Vector3 {
newZ += other.z;
}
return new Vector3(newX, newY, newZ);
return Vector3.at(newX, newY, newZ);
}
/**
@ -203,7 +211,7 @@ public final 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 final class Vector3 {
newZ -= other.z;
}
return new Vector3(newX, newY, newZ);
return Vector3.at(newX, newY, newZ);
}
/**
@ -244,7 +252,7 @@ public final 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 final class Vector3 {
newZ *= other.z;
}
return new Vector3(newX, newY, newZ);
return Vector3.at(newX, newY, newZ);
}
/**
@ -294,7 +302,7 @@ public final 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 final 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 final 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 final 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 final 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 final 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 final 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 final class Vector3 {
* @return a new {@link Vector2}
*/
public Vector2 toVector2() {
return new Vector2(x, z);
return Vector2.at(x, z);
}
@Override

View File

@ -134,17 +134,17 @@ public class HeightMap {
// Depending on growing or shrinking we need to start at the bottom or top
if (newHeight > curHeight) {
// Set the top block of the column to be the same type (this might go wrong with rounding)
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)));
session.setBlock(BlockVector3.at(xr, originY + y, zr), session.getBlock(BlockVector3.at(xr, originY + copyFrom, zr)));
++blocksChanged;
}
}
@ -152,18 +152,18 @@ 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)));
session.setBlock(BlockVector3.at(xr, originY + y, zr), session.getBlock(BlockVector3.at(xr, originY + copyFrom, zr)));
++blocksChanged;
}
// Set the top block of the column to be the same type
// (this could otherwise go wrong with rounding)
session.setBlock(new BlockVector3(xr, newHeight, zr), session.getBlock(new BlockVector3(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(new BlockVector3(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

@ -293,7 +293,7 @@ public class AffineTransform implements Transform {
@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

@ -91,10 +91,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;
}
@ -169,11 +169,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
));
@ -193,11 +193,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

@ -292,7 +292,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) {
chunks.add(new BlockVector2(x, z));
chunks.add(BlockVector2.at(x, z));
}
}
@ -309,7 +309,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));
}
}
}
@ -342,7 +342,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public BlockVector3 next() {
if (!hasNext()) throw new NoSuchElementException();
BlockVector3 answer = new BlockVector3(nextX, nextY, nextZ);
BlockVector3 answer = BlockVector3.at(nextX, nextY, nextZ);
if (++nextX > max.getBlockX()) {
nextX = min.getBlockX();
if (++nextY > max.getBlockY()) {
@ -373,7 +373,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public BlockVector2 next() {
if (!hasNext()) throw new NoSuchElementException();
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

@ -256,7 +256,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);
for (BlockVector3 change : changes) {
int height = maxY - minY;
int changeY = change.getBlockY();
@ -358,7 +358,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

@ -130,7 +130,7 @@ public class EllipsoidRegion extends AbstractRegion {
public void contract(BlockVector3... changes) throws RegionOperationException {
center = center.subtract(calculateDiff(changes));
Vector3 newRadius = radius.subtract(calculateChanges(changes));
radius = new Vector3(1.5, 1.5, 1.5).getMaximum(newRadius);
radius = Vector3.at(1.5, 1.5, 1.5).getMaximum(newRadius);
}
@Override
@ -185,11 +185,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

@ -65,7 +65,7 @@ public class FlatRegionIterator implements Iterator<BlockVector2> {
}
private void forward() {
while (hasNext() && !region.contains(new BlockVector3(nextX, y, nextZ))) {
while (hasNext() && !region.contains(BlockVector3.at(nextX, y, nextZ))) {
forwardOne();
}
}
@ -76,7 +76,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

@ -61,7 +61,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();
}
}
@ -70,7 +70,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

@ -109,7 +109,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);
}
@ -215,7 +215,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

@ -35,7 +35,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

@ -39,7 +39,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

@ -29,27 +29,27 @@ import javax.annotation.Nullable;
*/
public enum Direction {
NORTH(new Vector3(0, 0, -1), Flag.CARDINAL),
EAST(new Vector3(1, 0, 0), Flag.CARDINAL),
SOUTH(new Vector3(0, 0, 1), Flag.CARDINAL),
WEST(new Vector3(-1, 0, 0), Flag.CARDINAL),
NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL),
EAST(Vector3.at(1, 0, 0), Flag.CARDINAL),
SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL),
WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL),
UP(new Vector3(0, 1, 0), Flag.UPRIGHT),
DOWN(new Vector3(0, -1, 0), Flag.UPRIGHT),
UP(Vector3.at(0, 1, 0), Flag.UPRIGHT),
DOWN(Vector3.at(0, -1, 0), Flag.UPRIGHT),
NORTHEAST(new Vector3(1, 0, -1), Flag.ORDINAL),
NORTHWEST(new Vector3(-1, 0, -1), Flag.ORDINAL),
SOUTHEAST(new Vector3(1, 0, 1), Flag.ORDINAL),
SOUTHWEST(new Vector3(-1, 0, 1), Flag.ORDINAL),
NORTHEAST(Vector3.at(1, 0, -1), Flag.ORDINAL),
NORTHWEST(Vector3.at(-1, 0, -1), Flag.ORDINAL),
SOUTHEAST(Vector3.at(1, 0, 1), Flag.ORDINAL),
SOUTHWEST(Vector3.at(-1, 0, 1), Flag.ORDINAL),
WEST_NORTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
WEST_SOUTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
NORTH_NORTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
NORTH_NORTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
EAST_NORTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
EAST_SOUTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
SOUTH_SOUTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
SOUTH_SOUTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL);
WEST_NORTHWEST(Vector3.at(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
WEST_SOUTHWEST(Vector3.at(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
NORTH_NORTHWEST(Vector3.at(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
NORTH_NORTHEAST(Vector3.at(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
EAST_NORTHEAST(Vector3.at(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
EAST_SOUTHEAST(Vector3.at(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
SOUTH_SOUTHEAST(Vector3.at(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
SOUTH_SOUTHWEST(Vector3.at(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL);
private final Vector3 direction;
private final int flags;

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);
}
/**
@ -211,7 +211,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

@ -114,12 +114,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

@ -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

@ -200,7 +200,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

@ -126,7 +126,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

@ -80,7 +80,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);
}
/**

View File

@ -54,7 +54,7 @@ public class LocationTest {
@Test
public void testToVector() throws Exception {
World world = mock(World.class);
Vector3 position = new Vector3(1, 1, 1);
Vector3 position = Vector3.at(1, 1, 1);
Location location = new Location(world, position);
assertEquals(position, location.toVector());
}
@ -62,14 +62,14 @@ public class LocationTest {
@Test
public void testGetX() throws Exception {
World world = mock(World.class);
Location location = new Location(world, new Vector3(TEST_VALUE, 0, 0));
Location location = new Location(world, Vector3.at(TEST_VALUE, 0, 0));
assertEquals(TEST_VALUE, location.getX(), EPSILON);
}
@Test
public void testGetBlockX() throws Exception {
World world = mock(World.class);
Location location = new Location(world, new Vector3(TEST_VALUE, 0, 0));
Location location = new Location(world, Vector3.at(TEST_VALUE, 0, 0));
assertEquals(TEST_VALUE, location.getBlockX());
}
@ -87,14 +87,14 @@ public class LocationTest {
@Test
public void testGetY() throws Exception {
World world = mock(World.class);
Location location = new Location(world, new Vector3(0, TEST_VALUE, 0));
Location location = new Location(world, Vector3.at(0, TEST_VALUE, 0));
assertEquals(TEST_VALUE, location.getY(), EPSILON);
}
@Test
public void testGetBlockY() throws Exception {
World world = mock(World.class);
Location location = new Location(world, new Vector3(0, TEST_VALUE, 0));
Location location = new Location(world, Vector3.at(0, TEST_VALUE, 0));
assertEquals(TEST_VALUE, location.getBlockY());
}
@ -112,14 +112,14 @@ public class LocationTest {
@Test
public void testGetZ() throws Exception {
World world = mock(World.class);
Location location = new Location(world, new Vector3(0, 0, TEST_VALUE));
Location location = new Location(world, Vector3.at(0, 0, TEST_VALUE));
assertEquals(TEST_VALUE, location.getZ(), EPSILON);
}
@Test
public void testGetBlockZ() throws Exception {
World world = mock(World.class);
Location location = new Location(world, new Vector3(0, 0, TEST_VALUE));
Location location = new Location(world, Vector3.at(0, 0, TEST_VALUE));
assertEquals(TEST_VALUE, location.getBlockZ());
}

View File

@ -51,11 +51,11 @@ final class ForgeAdapter {
}
public static Vector3 adapt(Vec3d vector) {
return new Vector3(vector.x, vector.y, vector.z);
return Vector3.at(vector.x, vector.y, vector.z);
}
public static Vector3 adapt(BlockPos pos) {
return new Vector3(pos.getX(), pos.getY(), pos.getZ());
return Vector3.at(pos.getX(), pos.getY(), pos.getZ());
}
public static Vec3d toVec3(BlockVector3 vector) {

View File

@ -66,7 +66,7 @@ class ForgeEntity implements Entity {
public Location getLocation() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
Vector3 position = new Vector3(entity.posX, entity.posY, entity.posZ);
Vector3 position = Vector3.at(entity.posX, entity.posY, entity.posZ);
float yaw = entity.rotationYaw;
float pitch = entity.rotationPitch;

View File

@ -84,7 +84,7 @@ public class ForgePlayer extends AbstractPlayerActor {
@Override
public Location getLocation() {
Vector3 position = new Vector3(this.player.posX, this.player.posY, this.player.posZ);
Vector3 position = Vector3.at(this.player.posX, this.player.posY, this.player.posZ);
return new Location(
ForgeWorldEdit.inst.getWorld(this.player.world),
position,

View File

@ -522,7 +522,7 @@ public class ForgeWorld extends AbstractWorld {
public List<? extends Entity> getEntities(Region region) {
List<Entity> entities = new ArrayList<>();
for (net.minecraft.entity.Entity entity : getWorld().loadedEntityList) {
if (region.contains(new BlockVector3(entity.posX, entity.posY, entity.posZ))) {
if (region.contains(BlockVector3.at(entity.posX, entity.posY, entity.posZ))) {
entities.add(new ForgeEntity(entity));
}
}

View File

@ -249,7 +249,7 @@ public abstract class SpongeWorld extends AbstractWorld {
List<Entity> entities = new ArrayList<>();
for (org.spongepowered.api.entity.Entity entity : getWorld().getEntities()) {
org.spongepowered.api.world.Location<World> loc = entity.getLocation();
if (region.contains(new BlockVector3(loc.getX(), loc.getY(), loc.getZ()))) {
if (region.contains(BlockVector3.at(loc.getX(), loc.getY(), loc.getZ()))) {
entities.add(new SpongeEntity(entity));
}
}

View File

@ -57,7 +57,7 @@ public interface SpongeImplAdapter {
}
default Location adapt(org.spongepowered.api.world.Location<org.spongepowered.api.world.World> loc, Vector3d rot) {
Vector3 position = new Vector3(loc.getX(), loc.getY(), loc.getZ());
Vector3 position = Vector3.at(loc.getX(), loc.getY(), loc.getZ());
return new Location(getWorld(loc.getExtent()), position, (float) rot.getY(), (float) rot.getX());
}