Add -s flag for heightmap to disable smoothing

This commit is contained in:
Jesse Boyd 2017-04-21 05:28:01 +10:00
parent ac5d5de394
commit 0fd7786f82
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 26 additions and 21 deletions

View File

@ -13,8 +13,8 @@ import java.io.InputStream;
public class FlattenBrush extends HeightBrush {
public FlattenBrush(InputStream stream, int rotation, double yscale, boolean layers, Clipboard clipboard, ScalableHeightMap.Shape shape) {
super(stream, rotation, yscale, layers, clipboard, shape);
public FlattenBrush(InputStream stream, int rotation, double yscale, boolean layers, boolean smooth, Clipboard clipboard, ScalableHeightMap.Shape shape) {
super(stream, rotation, yscale, layers, smooth, clipboard, shape);
}
@Override
@ -26,6 +26,6 @@ public class FlattenBrush extends HeightBrush {
}
HeightMap map = getHeightMap();
map.setSize(size);
map.perform(editSession, mask, position, size, rotation, yscale, true, true, layers);
map.perform(editSession, mask, position, size, rotation, yscale, smooth, true, layers);
}
}

View File

@ -24,15 +24,17 @@ public class HeightBrush implements Brush {
public final int rotation;
public final double yscale;
public final boolean layers;
public final boolean smooth;
public HeightBrush(InputStream stream, int rotation, double yscale, boolean layers, Clipboard clipboard) {
this(stream, rotation, yscale, layers, clipboard, ScalableHeightMap.Shape.CONE);
public HeightBrush(InputStream stream, int rotation, double yscale, boolean layers, boolean smooth, Clipboard clipboard) {
this(stream, rotation, yscale, layers, smooth, clipboard, ScalableHeightMap.Shape.CONE);
}
public HeightBrush(InputStream stream, int rotation, double yscale, boolean layers, Clipboard clipboard, ScalableHeightMap.Shape shape) {
public HeightBrush(InputStream stream, int rotation, double yscale, boolean layers, boolean smooth, Clipboard clipboard, ScalableHeightMap.Shape shape) {
this.rotation = (rotation / 90) % 4;
this.yscale = yscale;
this.layers = layers;
this.smooth = smooth;
if (stream != null) {
try {
heightMap = ScalableHeightMap.fromPNG(stream);
@ -70,6 +72,6 @@ public class HeightBrush implements Brush {
}
HeightMap map = getHeightMap();
map.setSize(size);
map.perform(editSession, mask, position, size, rotation, yscale, true, false, layers);
map.perform(editSession, mask, position, size, rotation, yscale, smooth, false, layers);
}
}

View File

@ -778,13 +778,14 @@ public class BrushCommands {
help =
"This brush raises and lowers land.\n" +
"The -r flag enables random off-axis rotation\n" +
"The -l flag will work on snow layers",
"The -l flag will work on snow layers\n" +
"The -s flag disables smoothing",
min = 1,
max = 4
)
@CommandPermissions("worldedit.brush.height")
public void heightBrush(Player player, LocalSession session, @Optional("5") double radius, @Optional("") final String filename, @Optional("0") final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers) throws WorldEditException {
terrainBrush(player, session, radius, filename, rotation, yscale, false, randomRotate, layers, ScalableHeightMap.Shape.CONE);
public void heightBrush(Player player, LocalSession session, @Optional("5") double radius, @Optional("") final String filename, @Optional("0") final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth) throws WorldEditException {
terrainBrush(player, session, radius, filename, rotation, yscale, false, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE);
}
@Command(
@ -795,13 +796,14 @@ public class BrushCommands {
help =
"This brush flattens terrain and creates cliffs.\n" +
"The -r flag enables random off-axis rotation\n" +
"The -l flag will work on snow layers",
"The -l flag will work on snow layers\n" +
"The -s flag disables smoothing",
min = 1,
max = 4
)
@CommandPermissions("worldedit.brush.height")
public void cliffBrush(Player player, LocalSession session, @Optional("5") double radius, @Optional("") final String filename, @Optional("0") final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers) throws WorldEditException {
terrainBrush(player, session, radius, filename, rotation, yscale, true, randomRotate, layers, ScalableHeightMap.Shape.CYLINDER);
public void cliffBrush(Player player, LocalSession session, @Optional("5") double radius, @Optional("") final String filename, @Optional("0") final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth) throws WorldEditException {
terrainBrush(player, session, radius, filename, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CYLINDER);
}
@Command(
@ -810,14 +812,15 @@ public class BrushCommands {
flags = "h",
help = "Flatten brush makes terrain flatter\n" +
"The -r flag enables random off-axis rotation\n" +
"The -l flag will work on snow layers",
"The -l flag will work on snow layers\n" +
"The -s flag disables smoothing",
desc = "This brush raises and lowers land towards the clicked point\n",
min = 1,
max = 4
)
@CommandPermissions("worldedit.brush.height")
public void flattenBrush(Player player, LocalSession session, @Optional("5") double radius, @Optional("") final String filename, @Optional("0") final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers) throws WorldEditException {
terrainBrush(player, session, radius, filename, rotation, yscale, true, randomRotate, layers, ScalableHeightMap.Shape.CONE);
public void flattenBrush(Player player, LocalSession session, @Optional("5") double radius, @Optional("") final String filename, @Optional("0") final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth) throws WorldEditException {
terrainBrush(player, session, radius, filename, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE);
}
private InputStream getHeightmapStream(String filename) {
@ -851,7 +854,7 @@ public class BrushCommands {
return null;
}
private void terrainBrush(Player player, LocalSession session, double radius, String filename, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, ScalableHeightMap.Shape shape) throws WorldEditException {
private void terrainBrush(Player player, LocalSession session, double radius, String filename, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
InputStream stream = getHeightmapStream(filename);
BrushTool tool = session.getBrushTool(player);
@ -859,15 +862,15 @@ public class BrushCommands {
HeightBrush brush;
if (flat) {
try {
brush = new FlattenBrush(stream, rotation, yscale, layers, filename.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null, shape);
brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, filename.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null, shape);
} catch (EmptyClipboardException ignore) {
brush = new FlattenBrush(stream, rotation, yscale, layers, null, shape);
brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, null, shape);
}
} else {
try {
brush = new HeightBrush(stream, rotation, yscale, layers, filename.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null);
brush = new HeightBrush(stream, rotation, yscale, layers, smooth, filename.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null);
} catch (EmptyClipboardException ignore) {
brush = new HeightBrush(stream, rotation, yscale, layers, null);
brush = new HeightBrush(stream, rotation, yscale, layers, smooth, null);
}
}
tool.setBrush(brush, "worldedit.brush.height", player);