Various minor

Optimize Vector2D
Optimize HeightMap
Optimize biome changes
Reformatting of the MCA classes
This commit is contained in:
Jesse Boyd 2017-03-15 00:42:28 +11:00
parent d052725a7a
commit 54642914e5
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
13 changed files with 207 additions and 124 deletions

View File

@ -8,7 +8,7 @@ import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.MutableBlockVector2D;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.BukkitUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -89,12 +89,11 @@ public class BukkitChunk_All extends CharFaweChunk<Chunk, BukkitQueue_All> {
if (biomes != null) { if (biomes != null) {
final LocalWorld lw = BukkitUtil.getLocalWorld(world); final LocalWorld lw = BukkitUtil.getLocalWorld(world);
int index = 0; int index = 0;
Vector2D mutable = new Vector2D();
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
mutable.z = bx + z; int zz = bx + z;
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
mutable.x = bz + x; int xx = bz + x;
lw.setBiome(mutable, FaweCache.getBiome(biomes[index++] & 0xFF)); lw.setBiome(MutableBlockVector2D.get(xx, zz), FaweCache.getBiome(biomes[index++] & 0xFF));
} }
} }
} }

View File

@ -390,6 +390,8 @@ public class MCAChunk extends FaweChunk<Void> {
if (idsLayer == null) { if (idsLayer == null) {
idsLayer = this.ids[layer] = new byte[4096]; idsLayer = this.ids[layer] = new byte[4096];
this.data[layer] = new byte[2048]; this.data[layer] = new byte[2048];
this.skyLight[layer] = new byte[2048];
this.blockLight[layer] = new byte[2048];
} }
int j = FaweCache.CACHE_J[y][z & 15][x & 15]; int j = FaweCache.CACHE_J[y][z & 15][x & 15];
idsLayer[j] = (byte) id; idsLayer[j] = (byte) id;

View File

@ -263,7 +263,12 @@ public class MCAFile {
return null; return null;
} }
FastByteArrayOutputStream baos = new FastByteArrayOutputStream(buffer3); FastByteArrayOutputStream baos = new FastByteArrayOutputStream(buffer3);
DeflaterOutputStream deflater = new DeflaterOutputStream(baos, new Deflater(9), 1, true);
// PGZIPOutputStream deflater = new PGZIPOutputStream(baos);
// deflater.setStrategy(Deflater.FILTERED);
Deflater deflate = new Deflater(1);
deflate.setStrategy(Deflater.FILTERED);
DeflaterOutputStream deflater = new DeflaterOutputStream(baos, deflate, 1, true);
fieldBuf5.set(deflater, buffer2); fieldBuf5.set(deflater, buffer2);
BufferedOutputStream bos = new BufferedOutputStream(deflater, 1); BufferedOutputStream bos = new BufferedOutputStream(deflater, 1);
fieldBuf6.set(bos, buffer1); fieldBuf6.set(bos, buffer1);
@ -380,7 +385,7 @@ public class MCAFile {
MCAChunk cached = getCachedChunk(cx, cz); MCAChunk cached = getCachedChunk(cx, cz);
if (cached == null || !cached.isModified()) { if (cached == null || !cached.isModified()) {
start += size; start += size;
written = start; written = start + size;
continue; continue;
} else { } else {
newBytes = toBytes(cached); newBytes = toBytes(cached);
@ -398,26 +403,31 @@ public class MCAFile {
int newSize = (len + 4095) >> 12; int newSize = (len + 4095) >> 12;
int nextOffset2 = nextOffset; int nextOffset2 = nextOffset;
while (start + len > end) { while (start + len > end) {
int nextLoc = offsetMap.get(nextOffset2); Integer nextLoc = offsetMap.get(nextOffset2);
short nextCXZ = MathMan.unpairX(nextLoc); if (nextLoc != null) {
int nextCX = MathMan.unpairShortX(nextCXZ); short nextCXZ = MathMan.unpairX(nextLoc);
int nextCZ = MathMan.unpairShortY(nextCXZ); int nextCX = MathMan.unpairShortX(nextCXZ);
if (getCachedChunk(nextCX, nextCZ) == null) { int nextCZ = MathMan.unpairShortY(nextCXZ);
byte[] nextBytes = getChunkCompressedBytes(nextOffset2); if (getCachedChunk(nextCX, nextCZ) == null) {
relocate.put(pair, nextBytes); byte[] nextBytes = getChunkCompressedBytes(nextOffset2);
} relocate.put(pair, nextBytes);
}
// System.out.println("Relocating " + nextCX + "," + nextCZ); // System.out.println("Relocating " + nextCX + "," + nextCZ);
int nextSize = MathMan.unpairY(nextLoc) << 12; int nextSize = MathMan.unpairY(nextLoc) << 12;
end += nextSize; end += nextSize;
nextOffset2 += nextSize; nextOffset2 += nextSize;
} else {
end = start + len;
break;
}
} }
// System.out.println("Writing: " + cx + "," + cz); // System.out.println("Writing: " + cx + "," + cz);
writeSafe(start, newBytes); writeSafe(start, newBytes);
if (offset != start || end != start + size || oldSize != newSize) { if (offset != start || end != start + size || oldSize != newSize || true) {
// System.out.println("Header: " + cx + "," + cz + " | " + offset + "," + start + " | " + end + "," + (start + size) + " | " + size + " | " + start); // System.out.println("Header: " + cx + "," + cz + " | " + offset + "," + start + " | " + end + "," + (start + size) + " | " + size + " | " + start);
writeHeader(cx, cz, start >> 12, newSize); writeHeader(cx, cz, start >> 12, newSize);
} }
written = start + newBytes.length + 6; written = start + newBytes.length + 5;
start += newSize << 12; start += newSize << 12;
} }
raf.setLength(written); raf.setLength(written);

View File

@ -1,6 +1,6 @@
package com.boydti.fawe.object.change; package com.boydti.fawe.object.change;
import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.MutableBlockVector2D;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.history.change.Change;
@ -8,29 +8,27 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
public class MutableBiomeChange implements Change { public class MutableBiomeChange implements Change {
private Vector2D pos; private MutableBlockVector2D mutable = new MutableBlockVector2D();
private BaseBiome from; private BaseBiome from;
private BaseBiome to; private BaseBiome to;
public MutableBiomeChange() { public MutableBiomeChange() {
this.from = new BaseBiome(0); this.from = new BaseBiome(0);
this.to = new BaseBiome(0); this.to = new BaseBiome(0);
this.pos = new Vector2D();
} }
public void setBiome(int x, int z, int from, int to) { public void setBiome(int x, int z, int from, int to) {
this.pos.x = x; mutable.setComponents(x, z);
this.pos.z = z;
this.from.setId(from); this.from.setId(from);
this.to.setId(to); this.to.setId(to);
} }
@Override @Override
public void undo(UndoContext context) throws WorldEditException { public void undo(UndoContext context) throws WorldEditException {
context.getExtent().setBiome(pos, from); context.getExtent().setBiome(mutable, from);
} }
@Override @Override
public void redo(UndoContext context) throws WorldEditException { public void redo(UndoContext context) throws WorldEditException {
context.getExtent().setBiome(pos, to); context.getExtent().setBiome(mutable, to);
} }
} }

View File

@ -1,5 +1,6 @@
package com.boydti.fawe.object.extent; package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.MutableBlockVector2D;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -9,6 +10,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
public class OffsetExtent extends ResettableExtent { public class OffsetExtent extends ResettableExtent {
private final int dx, dy, dz; private final int dx, dy, dz;
private MutableBlockVector2D mutable = new MutableBlockVector2D();
public OffsetExtent(Extent parent, int dx, int dy, int dz) { public OffsetExtent(Extent parent, int dx, int dy, int dz) {
super(parent); super(parent);
@ -19,7 +21,7 @@ public class OffsetExtent extends ResettableExtent {
@Override @Override
public boolean setBiome(Vector2D position, BaseBiome biome) { public boolean setBiome(Vector2D position, BaseBiome biome) {
return super.setBiome(new Vector2D(position.getBlockX() + dx, position.getBlockZ() + dz), biome); return super.setBiome(mutable.setComponents(position.getBlockX() + dx, position.getBlockZ() + dz), biome);
} }
@Override @Override

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern; package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.MutableBlockVector2D;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
@ -10,6 +10,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
public class BiomePattern extends ExistingPattern { public class BiomePattern extends ExistingPattern {
private final BaseBiome biome; private final BaseBiome biome;
private BiomePatternException exception; private BiomePatternException exception;
private MutableBlockVector2D mutable = new MutableBlockVector2D();
public BiomePattern(Extent extent, BaseBiome biome) { public BiomePattern(Extent extent, BaseBiome biome) {
super(extent); super(extent);
@ -24,7 +25,7 @@ public class BiomePattern extends ExistingPattern {
@Override @Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
return extent.setBiome(new Vector2D(setPosition.getBlockX(), setPosition.getBlockZ()), biome); return extent.setBiome(mutable.setComponents(setPosition.getBlockX(), setPosition.getBlockZ()), biome);
} }
public class BiomePatternException extends RuntimeException { public class BiomePatternException extends RuntimeException {

View File

@ -3354,11 +3354,12 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
if (((containsBot2 && containsTop2)) && !containsBot1 && !containsTop1) { if (((containsBot2 && containsTop2)) && !containsBot1 && !containsTop1) {
continue; continue;
} }
final MutableBlockVector2D mutable = new MutableBlockVector2D();
RunnableVal<Vector2D> r = new RunnableVal<Vector2D>() { RunnableVal<Vector2D> r = new RunnableVal<Vector2D>() {
@Override @Override
public void run(Vector2D chunk) { public void run(Vector2D chunk) {
boolean conNextX = chunks.contains(new Vector2D(cx + 1, cz)); boolean conNextX = chunks.contains(mutable.setComponents(cx + 1, cz));
boolean conNextZ = chunks.contains(new Vector2D(cx, cz + 1)); boolean conNextZ = chunks.contains(mutable.setComponents(cx, cz + 1));
boolean containsAny = false; boolean containsAny = false;
if (cuboid && containsBot1 && containsBot2 && containsTop1 && containsTop2 && conNextX && conNextZ) { if (cuboid && containsBot1 && containsBot2 && containsTop1 && containsTop2 && conNextX && conNextZ) {
containsAny = true; containsAny = true;
@ -3393,7 +3394,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
if (!conNextZ) { if (!conNextZ) {
setExistingBlocks(new Vector(bx, 0, bz + 16), new Vector(bx + 15, getMaxY(), bz + 31)); setExistingBlocks(new Vector(bx, 0, bz + 16), new Vector(bx + 15, getMaxY(), bz + 31));
} }
if (!chunks.contains(new Vector2D(cx + 1, cz + 1)) && !conNextX && !conNextZ) { if (!chunks.contains(mutable.setComponents(cx + 1, cz + 1)) && !conNextX && !conNextZ) {
setExistingBlocks(new Vector(bx + 16, 0, bz + 16), new Vector(bx + 31, getMaxY(), bz + 31)); setExistingBlocks(new Vector(bx + 16, 0, bz + 16), new Vector(bx + 31, getMaxY(), bz + 31));
} }
MutableBlockVector mutable = new MutableBlockVector(0,0,0); MutableBlockVector mutable = new MutableBlockVector(0,0,0);

View File

@ -8,7 +8,7 @@ public class MutableBlockVector extends BlockVector {
} }
}; };
public static Vector get(int x, int y, int z) { public static MutableBlockVector get(int x, int y, int z) {
return MUTABLE_CACHE.get().setComponents(x, y, z); return MUTABLE_CACHE.get().setComponents(x, y, z);
} }
@ -30,10 +30,18 @@ public class MutableBlockVector extends BlockVector {
} }
@Override @Override
public Vector setComponents(double x, double y, double z) { public MutableBlockVector setComponents(double x, double y, double z) {
return this.setComponents((int) x, (int) y, (int) z); return this.setComponents((int) x, (int) y, (int) z);
} }
@Override
public MutableBlockVector setComponents(int x, int y, int z) {
this.mutX(x);
this.mutY(y);
this.mutZ(z);
return this;
}
@Override @Override
public final void mutX(double x) { public final void mutX(double x) {
this.x = (int) x; this.x = (int) x;

View File

@ -0,0 +1,67 @@
package com.sk89q.worldedit;
public final class MutableBlockVector2D extends Vector2D {
private static ThreadLocal<MutableBlockVector2D> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector2D>() {
@Override
protected MutableBlockVector2D initialValue() {
return new MutableBlockVector2D();
}
};
public static MutableBlockVector2D get(int x, int z) {
return MUTABLE_CACHE.get().setComponents(x, z);
}
private int x, z;
public MutableBlockVector2D() {
this.x = 0;
this.z = 0;
}
@Override
public double getX() {
return x;
}
@Override
public double getZ() {
return z;
}
@Override
public int getBlockX() {
return x;
}
@Override
public int getBlockZ() {
return z;
}
public MutableBlockVector2D setComponents(int x, int z) {
this.x = x;
this.z = z;
return this;
}
public MutableBlockVector2D setComponents(double x, double z) {
return setComponents((int) x, (int) z);
}
public final void mutX(int x) {
this.x = x;
}
public void mutZ(int z) {
this.z = z;
}
public final void mutX(double x) {
this.x = (int) x;
}
public void mutZ(double z) {
this.z = (int) z;
}
}

View File

@ -30,7 +30,8 @@ public class Vector2D {
public static final Vector2D UNIT_Z = new Vector2D(0, 1); public static final Vector2D UNIT_Z = new Vector2D(0, 1);
public static final Vector2D ONE = new Vector2D(1, 1); public static final Vector2D ONE = new Vector2D(1, 1);
public double x, z; private double x;
private double z;
/** /**
* Construct an instance. * Construct an instance.
@ -71,8 +72,8 @@ public class Vector2D {
* @param other the other vector * @param other the other vector
*/ */
public Vector2D(Vector2D other) { public Vector2D(Vector2D other) {
this.x = other.x; this.x = other.getX();
this.z = other.z; this.z = other.getZ();
} }
/** /**
@ -100,7 +101,7 @@ public class Vector2D {
* @return the x coordinate * @return the x coordinate
*/ */
public int getBlockX() { public int getBlockX() {
return (int) Math.round(x); return (int) Math.round(getX());
} }
/** /**
@ -110,7 +111,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D setX(double x) { public Vector2D setX(double x) {
return new Vector2D(x, z); return new Vector2D(x, getZ());
} }
/** /**
@ -120,7 +121,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D setX(int x) { public Vector2D setX(int x) {
return new Vector2D(x, z); return new Vector2D(x, getZ());
} }
/** /**
@ -138,7 +139,7 @@ public class Vector2D {
* @return the z coordinate * @return the z coordinate
*/ */
public int getBlockZ() { public int getBlockZ() {
return (int) Math.round(z); return (int) Math.round(getZ());
} }
/** /**
@ -148,7 +149,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D setZ(double z) { public Vector2D setZ(double z) {
return new Vector2D(x, z); return new Vector2D(getX(), z);
} }
/** /**
@ -158,7 +159,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D setZ(int z) { public Vector2D setZ(int z) {
return new Vector2D(x, z); return new Vector2D(getX(), z);
} }
/** /**
@ -168,7 +169,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D add(Vector2D other) { public Vector2D add(Vector2D other) {
return new Vector2D(x + other.x, z + other.z); return new Vector2D(getX() + other.getX(), getZ() + other.getZ());
} }
/** /**
@ -179,7 +180,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D add(double x, double z) { public Vector2D add(double x, double z) {
return new Vector2D(this.x + x, this.z + z); return new Vector2D(this.getX() + x, this.getZ() + z);
} }
/** /**
@ -190,7 +191,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D add(int x, int z) { public Vector2D add(int x, int z) {
return new Vector2D(this.x + x, this.z + z); return new Vector2D(this.getX() + x, this.getZ() + z);
} }
/** /**
@ -201,11 +202,11 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D add(Vector2D... others) { public Vector2D add(Vector2D... others) {
double newX = x, newZ = z; double newX = getX(), newZ = getZ();
for (Vector2D other : others) { for (Vector2D other : others) {
newX += other.x; newX += other.getX();
newZ += other.z; newZ += other.getZ();
} }
return new Vector2D(newX, newZ); return new Vector2D(newX, newZ);
@ -219,7 +220,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D subtract(Vector2D other) { public Vector2D subtract(Vector2D other) {
return new Vector2D(x - other.x, z - other.z); return new Vector2D(getX() - other.getX(), getZ() - other.getZ());
} }
/** /**
@ -231,7 +232,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D subtract(double x, double z) { public Vector2D subtract(double x, double z) {
return new Vector2D(this.x - x, this.z - z); return new Vector2D(this.getX() - x, this.getZ() - z);
} }
/** /**
@ -243,7 +244,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D subtract(int x, int z) { public Vector2D subtract(int x, int z) {
return new Vector2D(this.x - x, this.z - z); return new Vector2D(this.getX() - x, this.getZ() - z);
} }
/** /**
@ -254,11 +255,11 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D subtract(Vector2D... others) { public Vector2D subtract(Vector2D... others) {
double newX = x, newZ = z; double newX = getX(), newZ = getZ();
for (Vector2D other : others) { for (Vector2D other : others) {
newX -= other.x; newX -= other.getX();
newZ -= other.z; newZ -= other.getZ();
} }
return new Vector2D(newX, newZ); return new Vector2D(newX, newZ);
@ -271,7 +272,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D multiply(Vector2D other) { public Vector2D multiply(Vector2D other) {
return new Vector2D(x * other.x, z * other.z); return new Vector2D(getX() * other.getX(), getZ() * other.getZ());
} }
/** /**
@ -282,7 +283,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D multiply(double x, double z) { public Vector2D multiply(double x, double z) {
return new Vector2D(this.x * x, this.z * z); return new Vector2D(this.getX() * x, this.getZ() * z);
} }
/** /**
@ -293,7 +294,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D multiply(int x, int z) { public Vector2D multiply(int x, int z) {
return new Vector2D(this.x * x, this.z * z); return new Vector2D(this.getX() * x, this.getZ() * z);
} }
/** /**
@ -303,11 +304,11 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D multiply(Vector2D... others) { public Vector2D multiply(Vector2D... others) {
double newX = x, newZ = z; double newX = getX(), newZ = getZ();
for (Vector2D other : others) { for (Vector2D other : others) {
newX *= other.x; newX *= other.getX();
newZ *= other.z; newZ *= other.getZ();
} }
return new Vector2D(newX, newZ); return new Vector2D(newX, newZ);
@ -320,7 +321,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D multiply(double n) { public Vector2D multiply(double n) {
return new Vector2D(this.x * n, this.z * n); return new Vector2D(this.getX() * n, this.getZ() * n);
} }
/** /**
@ -330,7 +331,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D multiply(float n) { public Vector2D multiply(float n) {
return new Vector2D(this.x * n, this.z * n); return new Vector2D(this.getX() * n, this.getZ() * n);
} }
/** /**
@ -340,7 +341,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D multiply(int n) { public Vector2D multiply(int n) {
return new Vector2D(this.x * n, this.z * n); return new Vector2D(this.getX() * n, this.getZ() * n);
} }
/** /**
@ -350,7 +351,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D divide(Vector2D other) { public Vector2D divide(Vector2D other) {
return new Vector2D(x / other.x, z / other.z); return new Vector2D(getX() / other.getX(), getZ() / other.getZ());
} }
/** /**
@ -361,7 +362,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D divide(double x, double z) { public Vector2D divide(double x, double z) {
return new Vector2D(this.x / x, this.z / z); return new Vector2D(this.getX() / x, this.getZ() / z);
} }
/** /**
@ -372,7 +373,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D divide(int x, int z) { public Vector2D divide(int x, int z) {
return new Vector2D(this.x / x, this.z / z); return new Vector2D(this.getX() / x, this.getZ() / z);
} }
/** /**
@ -382,7 +383,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D divide(int n) { public Vector2D divide(int n) {
return new Vector2D(x / n, z / n); return new Vector2D(getX() / n, getZ() / n);
} }
/** /**
@ -392,7 +393,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D divide(double n) { public Vector2D divide(double n) {
return new Vector2D(x / n, z / n); return new Vector2D(getX() / n, getZ() / n);
} }
/** /**
@ -402,7 +403,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D divide(float n) { public Vector2D divide(float n) {
return new Vector2D(x / n, z / n); return new Vector2D(getX() / n, getZ() / n);
} }
/** /**
@ -411,7 +412,7 @@ public class Vector2D {
* @return length * @return length
*/ */
public double length() { public double length() {
return Math.sqrt(x * x + z * z); return Math.sqrt(getX() * getX() + getZ() * getZ());
} }
/** /**
@ -420,7 +421,7 @@ public class Vector2D {
* @return length, squared * @return length, squared
*/ */
public double lengthSq() { public double lengthSq() {
return x * x + z * z; return getX() * getX() + getZ() * getZ();
} }
/** /**
@ -430,7 +431,7 @@ public class Vector2D {
* @return distance * @return distance
*/ */
public double distance(Vector2D other) { public double distance(Vector2D other) {
return Math.sqrt(Math.pow(other.x - x, 2) + Math.pow(other.z - z, 2)); return Math.sqrt(Math.pow(other.getX() - getX(), 2) + Math.pow(other.getZ() - getZ(), 2));
} }
/** /**
@ -440,8 +441,8 @@ public class Vector2D {
* @return distance * @return distance
*/ */
public double distanceSq(Vector2D other) { public double distanceSq(Vector2D other) {
return Math.pow(other.x - x, 2) + return Math.pow(other.getX() - getX(), 2) +
Math.pow(other.z - z, 2); Math.pow(other.getZ() - getZ(), 2);
} }
/** /**
@ -461,7 +462,7 @@ public class Vector2D {
* @return the dot product of this and the other vector * @return the dot product of this and the other vector
*/ */
public double dot(Vector2D other) { public double dot(Vector2D other) {
return x * other.x + z * other.z; return getX() * other.getX() + getZ() * other.getZ();
} }
/** /**
@ -472,8 +473,8 @@ public class Vector2D {
* @return true if the vector is contained * @return true if the vector is contained
*/ */
public boolean containedWithin(Vector2D min, Vector2D max) { public boolean containedWithin(Vector2D min, Vector2D max) {
return x >= min.x && x <= max.x return getX() >= min.getX() && getX() <= max.getX()
&& z >= min.z && z <= max.z; && getZ() >= min.getZ() && getZ() <= max.getZ();
} }
/** /**
@ -494,7 +495,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D floor() { public Vector2D floor() {
return new Vector2D(Math.floor(x), Math.floor(z)); return new Vector2D(Math.floor(getX()), Math.floor(getZ()));
} }
/** /**
@ -503,7 +504,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D ceil() { public Vector2D ceil() {
return new Vector2D(Math.ceil(x), Math.ceil(z)); return new Vector2D(Math.ceil(getX()), Math.ceil(getZ()));
} }
/** /**
@ -514,7 +515,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D round() { public Vector2D round() {
return new Vector2D(Math.floor(x + 0.5), Math.floor(z + 0.5)); return new Vector2D(Math.floor(getX() + 0.5), Math.floor(getZ() + 0.5));
} }
/** /**
@ -524,7 +525,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector2D positive() { public Vector2D positive() {
return new Vector2D(Math.abs(x), Math.abs(z)); return new Vector2D(Math.abs(getX()), Math.abs(getZ()));
} }
/** /**
@ -540,8 +541,8 @@ public class Vector2D {
*/ */
public Vector2D transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { public Vector2D transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle); angle = Math.toRadians(angle);
double x = this.x - aboutX; double x = this.getX() - aboutX;
double z = this.z - aboutZ; double z = this.getZ() - aboutZ;
double x2 = x * Math.cos(angle) - z * Math.sin(angle); double x2 = x * Math.cos(angle) - z * Math.sin(angle);
double z2 = x * Math.sin(angle) + z * Math.cos(angle); double z2 = x * Math.sin(angle) + z * Math.cos(angle);
return new Vector2D( return new Vector2D(
@ -557,28 +558,28 @@ public class Vector2D {
* @return true if collinear * @return true if collinear
*/ */
public boolean isCollinearWith(Vector2D other) { public boolean isCollinearWith(Vector2D other) {
if (x == 0 && z == 0) { if (getX() == 0 && getZ() == 0) {
// this is a zero vector // this is a zero vector
return true; return true;
} }
final double otherX = other.x; final double otherX = other.getX();
final double otherZ = other.z; final double otherZ = other.getZ();
if (otherX == 0 && otherZ == 0) { if (otherX == 0 && otherZ == 0) {
// other is a zero vector // other is a zero vector
return true; return true;
} }
if ((x == 0) != (otherX == 0)) return false; if ((getX() == 0) != (otherX == 0)) return false;
if ((z == 0) != (otherZ == 0)) return false; if ((getZ() == 0) != (otherZ == 0)) return false;
final double quotientX = otherX / x; final double quotientX = otherX / getX();
if (!Double.isNaN(quotientX)) { if (!Double.isNaN(quotientX)) {
return other.equals(multiply(quotientX)); return other.equals(multiply(quotientX));
} }
final double quotientZ = otherZ / z; final double quotientZ = otherZ / getZ();
if (!Double.isNaN(quotientZ)) { if (!Double.isNaN(quotientZ)) {
return other.equals(multiply(quotientZ)); return other.equals(multiply(quotientZ));
} }
@ -601,7 +602,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector toVector() { public Vector toVector() {
return new Vector(x, 0, z); return new Vector(getX(), 0, getZ());
} }
/** /**
@ -611,7 +612,7 @@ public class Vector2D {
* @return a new vector * @return a new vector
*/ */
public Vector toVector(double y) { public Vector toVector(double y) {
return new Vector(x, y, z); return new Vector(getX(), y, getZ());
} }
@Override @Override
@ -621,19 +622,19 @@ public class Vector2D {
} }
Vector2D other = (Vector2D) obj; Vector2D other = (Vector2D) obj;
return other.x == this.x && other.z == this.z; return other.getX() == this.getX() && other.getZ() == this.getZ();
} }
@Override @Override
public int hashCode() { public int hashCode() {
return ((new Double(x)).hashCode() >> 13) ^ return ((new Double(getX())).hashCode() >> 13) ^
(new Double(z)).hashCode(); (new Double(getZ())).hashCode();
} }
@Override @Override
public String toString() { public String toString() {
return "(" + x + ", " + z + ")"; return "(" + getX() + ", " + getZ() + ")";
} }
/** /**
@ -645,8 +646,8 @@ public class Vector2D {
*/ */
public static Vector2D getMinimum(Vector2D v1, Vector2D v2) { public static Vector2D getMinimum(Vector2D v1, Vector2D v2) {
return new Vector2D( return new Vector2D(
Math.min(v1.x, v2.x), Math.min(v1.getX(), v2.getX()),
Math.min(v1.z, v2.z) Math.min(v1.getZ(), v2.getZ())
); );
} }
@ -659,8 +660,8 @@ public class Vector2D {
*/ */
public static Vector2D getMaximum(Vector2D v1, Vector2D v2) { public static Vector2D getMaximum(Vector2D v1, Vector2D v2) {
return new Vector2D( return new Vector2D(
Math.max(v1.x, v2.x), Math.max(v1.getX(), v2.getX()),
Math.max(v1.z, v2.z) Math.max(v1.getZ(), v2.getZ())
); );
} }

View File

@ -79,7 +79,7 @@ public class HeightMap {
int x = pos.getBlockX(); int x = pos.getBlockX();
int z = pos.getBlockZ(); int z = pos.getBlockZ();
y = session.getNearestSurfaceLayer(x, z, y, 0, maxY); y = session.getNearestSurfaceLayer(x, z, y, 0, maxY);
data[(z - bz) * width + (x - bx)] = y; data[(z - bz) * width + (x - bx)] = 7 + (y << 3);
} }
} else { } else {
// Store current heightmap data // Store current heightmap data
@ -238,20 +238,13 @@ public class HeightMap {
++blocksChanged; ++blocksChanged;
// Grow -- start from 1 below top replacing airblocks // Grow -- start from 1 below top replacing airblocks
for (int y = newHeight - 1 - originY; y >= 0; --y) { for (int y = newHeight - 1 - originY; y >= curHeight; --y) {
int copyFrom = (int) (y * scale); int copyFrom = (int) (y * scale);
session.setBlock(xr, originY + y, zr, session.getBlock(xr, originY + copyFrom, zr)); session.setBlock(xr, originY + y, zr, session.getBlock(xr, originY + copyFrom, zr));
++blocksChanged; ++blocksChanged;
} }
} }
} else if (curHeight > newHeight) { } else if (curHeight > newHeight) {
// Shrink -- start from bottom
for (int y = 0; y < newHeight - originY; ++y) {
int copyFrom = (int) (y * scale);
session.setBlock(xr, originY + y, zr, session.getBlock(xr, originY + copyFrom, zr));
++blocksChanged;
}
// Set the top block of the column to be the same type // Set the top block of the column to be the same type
// (this could otherwise go wrong with rounding) // (this could otherwise go wrong with rounding)
session.setBlock(xr, newHeight, zr, session.getBlock(xr, curHeight, zr)); session.setBlock(xr, newHeight, zr, session.getBlock(xr, curHeight, zr));

View File

@ -24,6 +24,7 @@ import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.MutableBlockVector2D;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
@ -333,7 +334,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override @Override
public Iterator<Vector2D> iterator() { public Iterator<Vector2D> iterator() {
return new Iterator<Vector2D>() { return new Iterator<Vector2D>() {
private Vector2D pos = new Vector2D(minX, minZ); private MutableBlockVector2D pos = new MutableBlockVector2D().setComponents(minX, minZ);
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return pos != null; return pos != null;
@ -344,9 +345,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
Vector2D result = pos; Vector2D result = pos;
// calc next // calc next
if (pos.getX() < maxX) { if (pos.getX() < maxX) {
pos = new Vector2D(pos.getX() + 1, pos.getZ()); pos.setComponents(pos.getX() + 1, pos.getZ());
} else if (pos.getZ() < maxZ) { } else if (pos.getZ() < maxZ) {
pos = new Vector2D(minX, pos.getZ() + 1); pos.setComponents(minX, pos.getZ() + 1);
} else { } else {
pos = null; pos = null;
} }
@ -566,6 +567,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return new Iterable<Vector2D>() { return new Iterable<Vector2D>() {
@Override @Override
public Iterator<Vector2D> iterator() { public Iterator<Vector2D> iterator() {
MutableBlockVector2D mutable = new MutableBlockVector2D();
return new Iterator<Vector2D>() { return new Iterator<Vector2D>() {
private Vector min = getMinimumPoint(); private Vector min = getMinimumPoint();
private Vector max = getMaximumPoint(); private Vector max = getMaximumPoint();
@ -580,11 +582,11 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override @Override
public Vector2D next() { public Vector2D next() {
if (!hasNext()) throw new java.util.NoSuchElementException(); if (!hasNext()) throw new java.util.NoSuchElementException();
Vector2D answer = new Vector2D(nextX, nextZ); Vector2D answer = mutable.setComponents(nextX, nextZ);
if (++nextX > max.getBlockX()) { if (++nextZ > max.getBlockZ()) {
nextX = min.getBlockX(); nextZ = min.getBlockZ();
if (++nextZ > max.getBlockZ()) { if (++nextX > max.getBlockX()) {
nextX = Integer.MIN_VALUE; nextZ = Integer.MIN_VALUE;
} }
} }
return answer; return answer;

View File

@ -13,7 +13,7 @@ import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.MutableBlockVector2D;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@ -85,12 +85,11 @@ public class NukkitChunk extends CharFaweChunk<BaseFullChunk, NukkitQueue> {
final LocalWorld lw = NukkitUtil.getLocalWorld(world); final LocalWorld lw = NukkitUtil.getLocalWorld(world);
final byte[] biomes = getBiomeArray(); final byte[] biomes = getBiomeArray();
int index = 0; int index = 0;
Vector2D mutable = new Vector2D();
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
mutable.z = Z + z; int zz = Z + z;
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
mutable.x = X + x; int xx = X + x;
lw.setBiome(mutable, FaweCache.getBiome(biomes[index++] & 0xFF)); lw.setBiome(MutableBlockVector2D.get(xx, zz), FaweCache.getBiome(biomes[index++] & 0xFF));
} }
} }
} }