mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
This commit is contained in:
parent
7a34a05b64
commit
f1e98da01f
@ -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();
|
||||||
|
@ -77,14 +77,9 @@ public class Naturalizer implements LayerFunction {
|
|||||||
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)) {
|
private boolean naturalize(BlockVector3 position, int depth) throws WorldEditException {
|
||||||
return false;
|
return editSession.setBlock(position, getTargetBlock(depth));
|
||||||
}
|
|
||||||
return editSession.setBlock(position, targetBlock);
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(BlockVector3 position, int depth) throws WorldEditException {
|
public boolean apply(BlockVector3 position, int depth) throws WorldEditException {
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user