Merge remote-tracking branch 'upstream/master' into breaking

This commit is contained in:
Jesse Boyd
2019-04-03 16:53:34 +11:00
281 changed files with 5963 additions and 5444 deletions

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;

View File

@ -346,16 +346,10 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
};
}
//<<<<<<< HEAD
@Override
public int size() {
return size;
}
//=======
// for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
// for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
// chunks.add(BlockVector2.at(x, z));
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
@Override
@ -394,27 +388,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
// private int ly = Integer.MIN_VALUE;
// private int lz = Integer.MIN_VALUE;
// private boolean lr, lry, lrz;
@Override
public boolean contains(int x, int y, int z) {
return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ && y >= this.minY && y <= this.maxY;
// if (z != lz) {
// lz = z;
// lrz = z >= this.minZ && z <= this.maxZ;
// if (y != ly) {
// ly = y;
// lry = y >= this.minY && y <= this.maxY;
// }
// lr = lrz && lry;
// } else if (y != ly) {
// ly = y;
// lry = y >= this.minY && y <= this.maxY;
// lr = lrz && lry;
// }
// return lr && (x >= this.minX && x <= this.maxX);
}
@Override
@ -467,7 +443,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public BlockVector3 next() {
//<<<<<<< HEAD
mutable.mutX(x);
mutable.mutY(y);
mutable.mutZ(z);
@ -503,17 +478,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
} else {
x = cbx;
z = cbz;
//=======
// if (!hasNext()) throw new NoSuchElementException();
// BlockVector3 answer = BlockVector3.at(nextX, nextY, nextZ);
// if (++nextX > max.getBlockX()) {
// nextX = min.getBlockX();
// if (++nextY > max.getBlockY()) {
// nextY = min.getBlockY();
// if (++nextZ > max.getBlockZ()) {
// nextX = Integer.MIN_VALUE;
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
}
} else {
x = cbx;
}
@ -540,16 +504,10 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
//<<<<<<< HEAD
public BlockVector3 next() {
mutable.mutX(nextX);
mutable.mutY(nextY);
mutable.mutZ(nextZ);
//=======
// public BlockVector2 next() {
// if (!hasNext()) throw new NoSuchElementException();
// BlockVector2 answer = BlockVector2.at(nextX, nextZ);
//>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
if (++nextX > max.getBlockX()) {
nextX = min.getBlockX();
if (++nextZ > max.getBlockZ()) {

View File

@ -105,7 +105,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
hasY = region.hasY;
}
@Override
@Override
public Vector3 getCenter() {
return center.toVector3((maxY + minY) / 2);
}
@ -306,7 +306,6 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
double dz = Math.abs(pz - center.getBlockZ()) * radiusInverse.getZ();
return dx * dx + dz * dz <= 1;
// return position.subtract(center).toVector2().divide(radius).lengthSq() <= 1;
}

View File

@ -117,10 +117,10 @@ public class EllipsoidRegion extends AbstractRegion {
return diff.divide(2).floor();
}
private BlockVector3 calculateChanges(BlockVector3... changes) {
BlockVector3 total = BlockVector3.ZERO;
private Vector3 calculateChanges(BlockVector3... changes) {
Vector3 total = Vector3.ZERO;
for (BlockVector3 change : changes) {
total = total.add(change.abs());
total = total.add(change.abs().toVector3());
}
return total.divide(2).floor();
@ -135,8 +135,8 @@ public class EllipsoidRegion extends AbstractRegion {
@Override
public void contract(BlockVector3... changes) throws RegionOperationException {
center = center.subtract(calculateDiff(changes));
Vector3 newRadius = radius.subtract(calculateChanges(changes).toVector3());
setRadius(Vector3.at(1.5, 1.5, 1.5).getMaximum(newRadius));
Vector3 newRadius = radius.subtract(calculateChanges(changes));
radius = Vector3.at(1.5, 1.5, 1.5).getMaximum(newRadius);
}
@Override
@ -214,31 +214,29 @@ public class EllipsoidRegion extends AbstractRegion {
}
@Override
// public boolean contains(Vector position) {
// int cx = position.getBlockX() - center.getBlockX();
// int cx2 = cx * cx;
// if (cx2 > radiusSqr.getBlockX()) {
// return false;
// }
// int cz = position.getBlockZ() - center.getBlockZ();
// int cz2 = cz * cz;
// if (cz2 > radiusSqr.getBlockZ()) {
// return false;
// }
// int cy = position.getBlockY() - center.getBlockY();
// int cy2 = cy * cy;
// if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) {
// return false;
// }
// if (sphere) {
// return cx2 + cy2 + cz2 <= radiusLengthSqr;
// }
// double cxd = (double) cx / radius.getBlockX();
// double cyd = (double) cy / radius.getBlockY();
// double czd = (double) cz / radius.getBlockZ();
// return cxd * cxd + cyd * cyd + czd * czd <= 1;
public boolean contains(BlockVector3 position) {
return position.subtract(center).divide(radius.toBlockPoint()).lengthSq() <= 1;
public boolean contains(BlockVector3 position) {
int cx = position.getBlockX() - center.getBlockX();
int cx2 = cx * cx;
if (cx2 > radiusSqr.getBlockX()) {
return false;
}
int cz = position.getBlockZ() - center.getBlockZ();
int cz2 = cz * cz;
if (cz2 > radiusSqr.getBlockZ()) {
return false;
}
int cy = position.getBlockY() - center.getBlockY();
int cy2 = cy * cy;
if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) {
return false;
}
if (sphere) {
return cx2 + cy2 + cz2 <= radiusLengthSqr;
}
double cxd = (double) cx / radius.getBlockX();
double cyd = (double) cy / radius.getBlockY();
double czd = (double) cz / radius.getBlockZ();
return cxd * cxd + cyd * cyd + czd * czd <= 1;
}
/**

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;

View File

@ -108,7 +108,6 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
*/
void shift(BlockVector3 change) throws RegionOperationException;
default boolean contains(int x, int y, int z) {
return contains(BlockVector3.at(x, y, z));
}
@ -128,6 +127,12 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
* @param position the position
* @return true if contained
*/
/**
* Returns true based on whether the region contains the point.
*
* @param position the position
* @return true if contained
*/
boolean contains(BlockVector3 position);
/**

View File

@ -21,8 +21,8 @@ package com.sk89q.worldedit.regions.iterator;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.FlatRegion;
import java.util.Iterator;

View File

@ -21,11 +21,12 @@ package com.sk89q.worldedit.regions.iterator;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class FlatRegionIterator implements Iterator<BlockVector2> {
@ -72,7 +73,7 @@ public class FlatRegionIterator implements Iterator<BlockVector2> {
@Override
public BlockVector2 next() {
if (!hasNext()) {
throw new java.util.NoSuchElementException();
throw new NoSuchElementException();
}
BlockVector2 answer = BlockVector2.at(nextX, nextZ);

View File

@ -174,7 +174,6 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
@Override
public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) {
BBC.SELECTOR_CENTER.send(player, pos, 0);
session.describeCUI(player);
}
@ -182,7 +181,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) {
Vector3 center = region.getCenter();
if (!center.equals(BlockVector3.ZERO)) {
if (!center.equals(Vector3.ZERO)) {
BBC.SELECTOR_RADIUS.send(player, NUMBER_FORMAT.format(region.getRadius().getX()) + "/" + NUMBER_FORMAT.format(region.getRadius().getZ()), region.getArea());
} else {
BBC.SELECTION_WAND.send(player);

View File

@ -24,7 +24,8 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.FlatRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
/**
* Generates solid and hollow shapes according to materials returned by the
@ -54,10 +55,10 @@ public abstract class ArbitraryBiomeShape {
cacheOffsetX = min.getBlockX() - 1;
cacheOffsetZ = min.getBlockZ() - 1;
cacheSizeX = (int) (max.getX() - cacheOffsetX + 2);
cacheSizeZ = (int) (max.getZ() - cacheOffsetZ + 2);
cacheSizeX = max.getX() - cacheOffsetX + 2;
cacheSizeZ = max.getZ() - cacheOffsetZ + 2;
cache = new BaseBiome[cacheSizeX * cacheSizeZ];
cache = new BiomeType[cacheSizeX * cacheSizeZ];
}
protected Iterable<BlockVector2> getExtent() {
@ -71,7 +72,7 @@ public abstract class ArbitraryBiomeShape {
* OUTSIDE = outside
* else = inside
*/
private final BaseBiome[] cache;
private final BiomeType[] cache;
/**
* Override this function to specify the shape to generate.
@ -81,17 +82,17 @@ public abstract class ArbitraryBiomeShape {
* @param defaultBaseBiome The default biome for the current column.
* @return material to place or null to not place anything.
*/
protected abstract BaseBiome getBiome(int x, int z, BaseBiome defaultBaseBiome);
protected abstract BiomeType getBiome(int x, int z, BiomeType defaultBaseBiome);
private BaseBiome getBiomeCached(int x, int z, BaseBiome baseBiome) {
private BiomeType getBiomeCached(int x, int z, BiomeType baseBiome) {
final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ;
final BaseBiome cacheEntry = cache[index];
final BiomeType cacheEntry = cache[index];
if (cacheEntry == null) {// unknown, fetch material
final BaseBiome material = getBiome(x, z, baseBiome);
final BiomeType material = getBiome(x, z, baseBiome);
if (material == null) {
// outside
cache[index] = OUTSIDE;
cache[index] = BiomeTypes.THE_VOID;
return null;
}
@ -99,7 +100,7 @@ public abstract class ArbitraryBiomeShape {
return material;
}
if (cacheEntry == OUTSIDE) {
if (cacheEntry == BiomeTypes.THE_VOID) {
// outside
return null;
}
@ -107,16 +108,16 @@ public abstract class ArbitraryBiomeShape {
return cacheEntry;
}
private boolean isInsideCached(int x, int z, BaseBiome baseBiome) {
private boolean isInsideCached(int x, int z, BiomeType baseBiome) {
final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ;
final BaseBiome cacheEntry = cache[index];
final BiomeType cacheEntry = cache[index];
if (cacheEntry == null) {
// unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape
return getBiomeCached(x, z, baseBiome) != null;
}
return cacheEntry != OUTSIDE;
return cacheEntry != BiomeTypes.THE_VOID;
}
/**
@ -127,7 +128,7 @@ public abstract class ArbitraryBiomeShape {
* @param hollow Specifies whether to generate a hollow shape.
* @return number of affected blocks.
*/
public int generate(EditSession editSession, BaseBiome baseBiome, boolean hollow) {
public int generate(EditSession editSession, BiomeType baseBiome, boolean hollow) {
int affected = 0;
for (BlockVector2 position : getExtent()) {
@ -135,8 +136,8 @@ public abstract class ArbitraryBiomeShape {
int z = position.getBlockZ();
if (!hollow) {
final BaseBiome material = getBiome(x, z, baseBiome);
if (material != null && material != OUTSIDE) {
final BiomeType material = getBiome(x, z, baseBiome);
if (material != null && material != BiomeTypes.THE_VOID) {
editSession.getWorld().setBiome(position, material);
++affected;
}
@ -144,7 +145,7 @@ public abstract class ArbitraryBiomeShape {
continue;
}
final BaseBiome material = getBiomeCached(x, z, baseBiome);
final BiomeType material = getBiomeCached(x, z, baseBiome);
if (material == null) {
continue;
}
@ -180,16 +181,4 @@ public abstract class ArbitraryBiomeShape {
return affected;
}
private static final BaseBiome OUTSIDE = new BaseBiome(0) {
@Override
public int hashCode() {
return 0;
}
@Override
public boolean equals(Object o) {
return this == o;
}
};
}

View File

@ -34,8 +34,36 @@ public abstract class ArbitraryShape {
protected final Region extent;
private int cacheOffsetX;
private int cacheOffsetY;
private int cacheOffsetZ;
private int cacheSizeX;
private int cacheSizeY;
private int cacheSizeZ;
/**
* Cache entires:
* 0 = unknown
* -1 = outside
* 1 = inside
*/
private final byte[] cache;
public ArbitraryShape(Region extent) {
this.extent = extent;
BlockVector3 min = extent.getMinimumPoint();
BlockVector3 max = extent.getMaximumPoint();
cacheOffsetX = min.getBlockX() - 1;
cacheOffsetY = min.getBlockY() - 1;
cacheOffsetZ = min.getBlockZ() - 1;
cacheSizeX = max.getX() - cacheOffsetX + 2;
cacheSizeY = max.getY() - cacheOffsetY + 2;
cacheSizeZ = max.getZ() - cacheOffsetZ + 2;
cache = new byte[cacheSizeX * cacheSizeY * cacheSizeZ];
}
protected Region getExtent() {
@ -81,6 +109,40 @@ public abstract class ArbitraryShape {
BaseBlock material = getMaterial(x, y, z, pattern.apply(position));
if (material == null) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
cache[index] = -1;
continue;
}
boolean draw = false;
do {
if (!isInsideCached(x + 1, y, z, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x - 1, y, z, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x, y, z + 1, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x, y, z - 1, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x, y + 1, z, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x, y - 1, z, pattern)) {
draw = true;
break;
}
} while (false);
if (!draw) {
continue;
}
@ -92,4 +154,27 @@ public abstract class ArbitraryShape {
return affected;
}
private boolean isInsideCached(int x, int y, int z, Pattern pattern) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
switch (cache[index]) {
case 0:
BaseBlock mat = getMaterial(x, y, z, pattern.apply(BlockVector3.at(x, y, z)));
if (mat == null) {
cache[index] = -1;
return false;
}
cache[index] = 1;
return true;
case -1:
// outside
return false;
default:
// inside
return true;
}
}
}