Skip to content

Commit

Permalink
Move vectors to static creators, for caching
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Oct 21, 2018
1 parent c8ddeca commit 953f6d2
Show file tree
Hide file tree
Showing 69 changed files with 369 additions and 337 deletions.
Expand Up @@ -240,7 +240,7 @@ public static org.bukkit.Location adapt(org.bukkit.World world, Location locatio
*/
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());
}

/**
Expand All @@ -251,7 +251,7 @@ public static Vector3 asVector(org.bukkit.Location location) {
*/
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());
}

/**
Expand Down
Expand Up @@ -175,7 +175,7 @@ public void floatAt(int x, int y, int z, boolean alwaysGlass) {
return;
}

setPosition(new Vector3(x + 0.5, y, z + 0.5));
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
player.setFlying(true);
}

Expand Down
Expand Up @@ -169,7 +169,7 @@ public boolean regenerate(Region region, EditSession editSession) {
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) {
Expand Down
Expand Up @@ -40,7 +40,7 @@ public EditSessionBlockChangeDelegate(EditSession editSession) {
@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;
}
Expand All @@ -49,7 +49,7 @@ public boolean setBlockData(int x, int y, int z, BlockData blockData) {

@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
Expand All @@ -59,7 +59,7 @@ public int getHeight() {

@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();
}

}
2 changes: 1 addition & 1 deletion worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java
Expand Up @@ -169,7 +169,7 @@ public static Class<? extends Tag> getTypeClass(int type) {
*/
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));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java
Expand Up @@ -215,7 +215,7 @@ public Vector3 getVector(String path) {
return null;
}

return new Vector3(x, y, z);
return Vector3.at(x, y, z);
}

/**
Expand All @@ -239,7 +239,7 @@ public Vector2 getVector2(String path) {
return null;
}

return new Vector2(x, z);
return Vector2.at(x, z);
}

/**
Expand Down Expand Up @@ -571,7 +571,7 @@ public List<Vector3> getVectorList(String path, List<Vector3> def) {
continue;
}

list.add(new Vector3(x, y, z));
list.add(Vector3.at(x, y, z));
}

return list;
Expand Down Expand Up @@ -601,7 +601,7 @@ public List<Vector2> getVector2List(String path, List<Vector2> def) {
continue;
}

list.add(new Vector2(x, z));
list.add(Vector2.at(x, z));
}

return list;
Expand Down Expand Up @@ -631,7 +631,7 @@ public List<BlockVector2> getBlockVector2List(String path, List<BlockVector2> de
continue;
}

list.add(new BlockVector2(x, z));
list.add(BlockVector2.at(x, z));
}

return list;
Expand Down
72 changes: 36 additions & 36 deletions worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java
Expand Up @@ -482,7 +482,7 @@ public BaseBlock getFullBlock(BlockVector3 position) {
*/
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;
Expand Down Expand Up @@ -713,7 +713,7 @@ public int fillXZ(BlockVector3 origin, Pattern pattern, double radius, int depth
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())),
Expand Down Expand Up @@ -904,8 +904,8 @@ public int center(Region region, Pattern pattern) throws MaxChangedBlocksExcepti
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);
}
Expand Down Expand Up @@ -1055,7 +1055,7 @@ public int overlayCuboidBlocks(Region region, Pattern pattern) throws MaxChanged
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);
Expand Down Expand Up @@ -1180,7 +1180,7 @@ public int drainArea(BlockVector3 origin, double radius) throws MaxChangedBlocks

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()));
Expand Down Expand Up @@ -1220,7 +1220,7 @@ public int fixLiquid(BlockVector3 origin, double radius, BlockType fluid) throws
// 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
);

Expand Down Expand Up @@ -1501,12 +1501,12 @@ public int thaw(BlockVector3 position, double radius)
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) {
Expand Down Expand Up @@ -1551,12 +1551,12 @@ public int simulateSnow(BlockVector3 position, double radius) throws MaxChangedB
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()) {
Expand Down Expand Up @@ -1619,12 +1619,12 @@ public int green(BlockVector3 position, double radius, boolean onlyNormalDirt)
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 ||
Expand Down Expand Up @@ -1690,7 +1690,7 @@ public int makeForest(BlockVector3 basePosition, int size, double density, TreeG
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
Expand All @@ -1700,13 +1700,13 @@ public int makeForest(BlockVector3 basePosition, int size, double density, TreeG

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;
}
Expand Down Expand Up @@ -1743,7 +1743,7 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
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);

Expand Down Expand Up @@ -1834,22 +1834,22 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws

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);
}
}

Expand Down Expand Up @@ -1910,7 +1910,7 @@ public int drawLine(Pattern pattern, BlockVector3 pos1, BlockVector3 pos2, doubl
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;
}

Expand All @@ -1920,7 +1920,7 @@ public int drawLine(Pattern pattern, BlockVector3 pos1, BlockVector3 pos2, doubl
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;
}
Expand All @@ -1931,7 +1931,7 @@ public int drawLine(Pattern pattern, BlockVector3 pos1, BlockVector3 pos2, doubl
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;
}
Expand All @@ -1942,7 +1942,7 @@ public int drawLine(Pattern pattern, BlockVector3 pos1, BlockVector3 pos2, doubl
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;
}
Expand Down Expand Up @@ -2019,7 +2019,7 @@ private static Set<BlockVector3> getBallooned(Set<BlockVector3> vset, double rad
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));
}
}
}
Expand All @@ -2032,12 +2032,12 @@ private static Set<BlockVector3> getHollowed(Set<BlockVector3> vset) {
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);
}
}
Expand Down Expand Up @@ -2083,7 +2083,7 @@ public int makeBiomeShape(final Region region, final Vector3 zero, final Vector3
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);

Expand Down
Expand Up @@ -662,7 +662,7 @@ public void updateServerCUI(Actor actor) {
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()
Expand Down
Expand Up @@ -29,16 +29,16 @@
*/
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;
Expand Down
Expand Up @@ -76,7 +76,7 @@ public void chunkInfo(Player player, LocalSession session, EditSession editSessi
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(
Expand Down

0 comments on commit 953f6d2

Please sign in to comment.