This commit is contained in:
Jesse Boyd 2019-06-29 03:29:53 +10:00
parent 7a34a05b64
commit f1e98da01f
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 15 additions and 20 deletions

View File

@ -26,6 +26,7 @@ public interface HeightMap {
default void applyHeightMapData(int[][] data, EditSession session, BlockVector3 pos, int size, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException { default void applyHeightMapData(int[][] data, EditSession session, BlockVector3 pos, int size, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException {
BlockVector3 top = session.getMaximumPoint(); BlockVector3 top = session.getMaximumPoint();
int maxY = top.getBlockY(); int maxY = top.getBlockY();
int diameter = 2 * size + 1;
Location min = new Location(session.getWorld(), pos.subtract(size, maxY, size).toVector3()); Location min = new Location(session.getWorld(), pos.subtract(size, maxY, size).toVector3());
BlockVector3 max = pos.add(size, maxY, size); BlockVector3 max = pos.add(size, maxY, size);
Region region = new CuboidRegion(session.getWorld(), min.toBlockPoint(), max); Region region = new CuboidRegion(session.getWorld(), min.toBlockPoint(), max);
@ -33,7 +34,6 @@ public interface HeightMap {
if (smooth) { if (smooth) {
try { try {
HeightMapFilter filter = (HeightMapFilter) HeightMapFilter.class.getConstructors()[0].newInstance(GaussianKernel.class.getConstructors()[0].newInstance(5, 1)); HeightMapFilter filter = (HeightMapFilter) HeightMapFilter.class.getConstructors()[0].newInstance(GaussianKernel.class.getConstructors()[0].newInstance(5, 1));
int diameter = 2 * size + 1;
data[1] = filter.filter(data[1], diameter, diameter); data[1] = filter.filter(data[1], diameter, diameter);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -76,15 +76,10 @@ public class Naturalizer implements LayerFunction {
default: default:
return BlockTypes.STONE.getDefaultState(); return BlockTypes.STONE.getDefaultState();
} }
}
private boolean naturalize(BlockVector3 position, int depth) throws WorldEditException {
BlockState block = editSession.getBlock(position);
BlockState targetBlock = getTargetBlock(depth);
if (block.equalsFuzzy(targetBlock)) {
return false;
} }
return editSession.setBlock(position, targetBlock);
private boolean naturalize(BlockVector3 position, int depth) throws WorldEditException {
return editSession.setBlock(position, getTargetBlock(depth));
} }
@Override @Override
public boolean apply(BlockVector3 position, int depth) throws WorldEditException { public boolean apply(BlockVector3 position, int depth) throws WorldEditException {

View File

@ -90,10 +90,10 @@ public class RepeatingExtentPattern extends AbstractExtentPattern {
@Override @Override
public BaseBlock apply(BlockVector3 position) { public BaseBlock apply(BlockVector3 position) {
int x = Math.abs(position.getX() + offset.getX()) % size.getBlockX(); int x = Math.abs(position.getX() + offset.getX()) % size.getBlockX() + origin.getX();
int y = Math.abs(position.getY() + offset.getY()) % size.getBlockY(); int y = Math.abs(position.getY() + offset.getY()) % size.getBlockY() + origin.getY();
int z = Math.abs(position.getZ() + offset.getZ()) % size.getBlockZ(); int z = Math.abs(position.getZ() + offset.getZ()) % size.getBlockZ() + origin.getZ();
return getExtent().getFullBlock(mutable.setComponents(x, y, z).add(origin)); return getExtent().getFullBlock(mutable.setComponents(x, y, z));
} }
} }

View File

@ -182,9 +182,10 @@ public class HeightMap {
// Apply heightmap // Apply heightmap
for (int z = 0; z < height; ++z) { for (int z = 0; z < height; ++z) {
int zr = z + originZ;
for (int x = 0; x < width; ++x) { for (int x = 0; x < width; ++x) {
int curHeight = this.data[index];
if (this.invalid != null && this.invalid[index]) continue; if (this.invalid != null && this.invalid[index]) continue;
int curHeight = this.data[index];
//Clamp newHeight within the selection area //Clamp newHeight within the selection area
int newHeight = Math.min(maxY4, data[index++]); int newHeight = Math.min(maxY4, data[index++]);
@ -194,7 +195,6 @@ public class HeightMap {
// Offset x,z to be 'real' coordinates // Offset x,z to be 'real' coordinates
int xr = x + originX; int xr = x + originX;
int zr = z + originZ;
// Depending on growing or shrinking we need to start at the bottom or top // Depending on growing or shrinking we need to start at the bottom or top
if (newHeight > curHeight) { if (newHeight > curHeight) {
@ -269,6 +269,7 @@ public class HeightMap {
// Apply heightmap // Apply heightmap
int index = 0; int index = 0;
for (int z = 0; z < height; ++z) { for (int z = 0; z < height; ++z) {
int zr = z + originZ;
for (int x = 0; x < width; ++x, index++) { for (int x = 0; x < width; ++x, index++) {
if (this.invalid != null && this.invalid[index]) continue; if (this.invalid != null && this.invalid[index]) continue;
@ -279,12 +280,11 @@ public class HeightMap {
// Offset x,z to be 'real' coordinates // Offset x,z to be 'real' coordinates
int xr = x + originX; int xr = x + originX;
int zr = z + originZ;
// Depending on growing or shrinking we need to start at the bottom or top // Depending on growing or shrinking we need to start at the bottom or top
if (newHeight > curHeight) { if (newHeight > curHeight) {
// Set the top block of the column to be the same type (this might go wrong with rounding) // Set the top block of the column to be the same type (this might go wrong with rounding)
BlockState existing = session.getBlock(BlockVector3.at(xr, curHeight, zr)); BlockState existing = session.getBlock(xr, curHeight, zr);
// Skip water/lava // Skip water/lava
if (existing.getBlockType().getMaterial().isMovementBlocker()) { if (existing.getBlockType().getMaterial().isMovementBlocker()) {
@ -295,18 +295,18 @@ public class HeightMap {
session.setBlock(xr, setY, zr, tmpBlock); session.setBlock(xr, setY, zr, tmpBlock);
++blocksChanged; ++blocksChanged;
} }
session.setBlock(BlockVector3.at(xr, newHeight, zr), existing); session.setBlock(xr, newHeight, zr, existing);
++blocksChanged; ++blocksChanged;
} }
} else if (curHeight > newHeight) { } else if (curHeight > newHeight) {
// 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(BlockVector3.at(xr, newHeight, zr), session.getBlock(BlockVector3.at(xr, curHeight, zr))); session.setBlock(xr, newHeight, zr, session.getBlock(xr, curHeight, zr));
++blocksChanged; ++blocksChanged;
// Fill rest with air // Fill rest with air
for (int y = newHeight + 1; y <= curHeight; ++y) { for (int y = newHeight + 1; y <= curHeight; ++y) {
session.setBlock(BlockVector3.at(xr, y, zr), fillerAir); session.setBlock(xr, y, zr, fillerAir);
++blocksChanged; ++blocksChanged;
} }
} }