mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Added flag to //smooth to only use "natural" blocks
This commit is contained in:
@ -2378,12 +2378,12 @@ public class EditSession {
|
||||
* maximal height
|
||||
* @return height of highest block found or 'minY'
|
||||
*/
|
||||
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
|
||||
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, boolean naturalOnly) {
|
||||
for (int y = maxY; y >= minY; --y) {
|
||||
Vector pt = new Vector(x, y, z);
|
||||
int id = getBlockType(pt);
|
||||
|
||||
if (!BlockType.canPassThrough(id) /*id == 1 // stone
|
||||
if (naturalOnly ?
|
||||
id == 1 // stone
|
||||
|| id == 2 // grass
|
||||
|| id == 3 // dirt
|
||||
|| id == 7 // bedrock
|
||||
@ -2400,8 +2400,8 @@ public class EditSession {
|
||||
|| id == 16 // gold ore
|
||||
|| id == 56 // diamond ore
|
||||
|| id == 73 // redstone ore
|
||||
|| id == 74 // redstone ore (active)*/
|
||||
) {
|
||||
|| id == 74 // redstone ore (active)
|
||||
: !BlockType.canPassThrough(id)) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class HeightMap {
|
||||
* @param region
|
||||
*/
|
||||
|
||||
public HeightMap(EditSession session, Region region) {
|
||||
public HeightMap(EditSession session, Region region, boolean naturalOnly) {
|
||||
this.session = session;
|
||||
this.region = region;
|
||||
|
||||
@ -60,7 +60,7 @@ public class HeightMap {
|
||||
data = new int[width * height];
|
||||
for (int z = 0; z < height; ++z) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
data[z * width + x] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY);
|
||||
data[z * width + x] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY, naturalOnly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +171,7 @@ public class BrushCommands {
|
||||
@Command(
|
||||
aliases = {"smooth"},
|
||||
usage = "[size] [iterations]",
|
||||
flags = "n",
|
||||
desc = "Choose the terrain softener brush",
|
||||
min = 0,
|
||||
max = 2
|
||||
@ -193,9 +194,9 @@ public class BrushCommands {
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
tool.setSize(radius);
|
||||
tool.setBrush(new SmoothBrush(iterations), "worldedit.brush.smooth");
|
||||
tool.setBrush(new SmoothBrush(iterations, args.hasFlag('n')), "worldedit.brush.smooth");
|
||||
|
||||
player.print(String.format("Smooth brush equipped (%.0f x %dx).",
|
||||
player.print(String.format("Smooth brush equipped (%.0f x %dx, using " + (args.hasFlag('n') ? "natural blocks only" : "any block") + ").",
|
||||
radius, iterations));
|
||||
}
|
||||
|
||||
|
@ -186,6 +186,7 @@ public class RegionCommands {
|
||||
@Command(
|
||||
aliases = {"/smooth"},
|
||||
usage = "[iterations]",
|
||||
flags = "n",
|
||||
desc = "Smooth the elevation in the selection",
|
||||
min = 0,
|
||||
max = 1
|
||||
@ -201,7 +202,7 @@ public class RegionCommands {
|
||||
iterations = args.getInteger(0);
|
||||
}
|
||||
|
||||
HeightMap heightMap = new HeightMap(editSession, session.getSelection(player.getWorld()));
|
||||
HeightMap heightMap = new HeightMap(editSession, session.getSelection(player.getWorld()), args.hasFlag('n'));
|
||||
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
|
||||
int affected = heightMap.applyFilter(filter, iterations);
|
||||
player.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
|
||||
|
@ -31,9 +31,11 @@ import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
public class SmoothBrush implements Brush {
|
||||
private int iterations;
|
||||
private boolean naturalOnly;
|
||||
|
||||
public SmoothBrush(int iterations) {
|
||||
public SmoothBrush(int iterations, boolean naturalOnly) {
|
||||
this.iterations = iterations;
|
||||
this.naturalOnly = naturalOnly;
|
||||
}
|
||||
|
||||
public void build(EditSession editSession, Vector pos, Pattern mat, double size)
|
||||
@ -42,7 +44,7 @@ public class SmoothBrush implements Brush {
|
||||
Vector min = pos.subtract(rad, rad, rad);
|
||||
Vector max = pos.add(rad, rad + 10, rad);
|
||||
Region region = new CuboidRegion(min, max);
|
||||
HeightMap heightMap = new HeightMap(editSession, region);
|
||||
HeightMap heightMap = new HeightMap(editSession, region, naturalOnly);
|
||||
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
|
||||
heightMap.applyFilter(filter, iterations);
|
||||
}
|
||||
|
Reference in New Issue
Block a user