Flat brush shapes

This commit is contained in:
Jesse Boyd 2017-02-13 05:34:27 +11:00
parent 7069966f5f
commit 4d09354bd4
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 36 additions and 43 deletions

View File

@ -12,8 +12,8 @@ import java.io.InputStream;
public class FlattenBrush extends HeightBrush { public class FlattenBrush extends HeightBrush {
public FlattenBrush(InputStream stream, int rotation, double yscale, DoubleActionBrushTool tool, Clipboard clipboard) { public FlattenBrush(InputStream stream, int rotation, double yscale, DoubleActionBrushTool tool, Clipboard clipboard, ScalableHeightMap.Shape shape) {
super(stream, rotation, yscale, tool, clipboard, ScalableHeightMap.Shape.CYLINDER); super(stream, rotation, yscale, tool, clipboard, shape);
} }
@Override @Override

View File

@ -34,6 +34,7 @@ import com.boydti.fawe.object.brush.HeightBrush;
import com.boydti.fawe.object.brush.LineBrush; import com.boydti.fawe.object.brush.LineBrush;
import com.boydti.fawe.object.brush.RecurseBrush; import com.boydti.fawe.object.brush.RecurseBrush;
import com.boydti.fawe.object.brush.SplineBrush; import com.boydti.fawe.object.brush.SplineBrush;
import com.boydti.fawe.object.brush.heightmap.ScalableHeightMap;
import com.boydti.fawe.object.mask.IdMask; import com.boydti.fawe.object.mask.IdMask;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
@ -366,44 +367,22 @@ public class BrushCommands {
) )
@CommandPermissions("worldedit.brush.height") @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) throws WorldEditException { 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) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); terrainBrush(player, session, radius, filename, rotation, yscale, true, ScalableHeightMap.Shape.CONE);
String filenamePng = (filename.endsWith(".png") ? filename : filename + ".png"); }
File file = new File(Fawe.imp().getDirectory(), "heightmap" + File.separator + filenamePng);
InputStream stream = null;
if (!file.exists()) {
if (!filename.equals("#clipboard") && filename.length() >= 7) {
try {
URL url;
if (filename.startsWith("http")) {
url = new URL(filename);
if (!url.getHost().equals("i.imgur.com")) {
throw new FileNotFoundException(filename);
}
} else {
url = new URL("https://i.imgur.com/" + filenamePng);
}
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
stream = Channels.newInputStream(rbc);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
} else if (!filename.equalsIgnoreCase("#clipboard")){
try {
stream = new FileInputStream(file);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
DoubleActionBrushTool tool = session.getDoubleActionBrushTool(player.getItemInHand()); @Command(
tool.setSize(radius); aliases = { "cliff", "flatcylinder" },
try { usage = "[radius] [file|#clipboard|null] [rotation] [yscale]",
tool.setBrush(new HeightBrush(stream, rotation, yscale, tool, filename.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null), "worldedit.brush.height"); flags = "h",
} catch (EmptyClipboardException ignore) { desc = "Cliff brush",
tool.setBrush(new HeightBrush(stream, rotation, yscale, tool, null), "worldedit.brush.height"); help =
} "This brush flattens terrain and creates cliffs.\n",
player.print(BBC.getPrefix() + BBC.BRUSH_HEIGHT.f(radius)); 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) throws WorldEditException {
terrainBrush(player, session, radius, filename, rotation, yscale, true, ScalableHeightMap.Shape.CYLINDER);
} }
@Command( @Command(
@ -418,6 +397,10 @@ public class BrushCommands {
) )
@CommandPermissions("worldedit.brush.height") @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) throws WorldEditException { 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) throws WorldEditException {
terrainBrush(player, session, radius, filename, rotation, yscale, true, ScalableHeightMap.Shape.CONE);
}
private void terrainBrush(Player player, LocalSession session, double radius, String filename, int rotation, double yscale, boolean flat, ScalableHeightMap.Shape shape) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(radius);
String filenamePng = (filename.endsWith(".png") ? filename : filename + ".png"); String filenamePng = (filename.endsWith(".png") ? filename : filename + ".png");
File file = new File(Fawe.imp().getDirectory(), "heightmap" + File.separator + filenamePng); File file = new File(Fawe.imp().getDirectory(), "heightmap" + File.separator + filenamePng);
@ -450,14 +433,24 @@ public class BrushCommands {
DoubleActionBrushTool tool = session.getDoubleActionBrushTool(player.getItemInHand()); DoubleActionBrushTool tool = session.getDoubleActionBrushTool(player.getItemInHand());
tool.setSize(radius); tool.setSize(radius);
try { if (flat) {
tool.setBrush(new FlattenBrush(stream, rotation, yscale, tool, filename.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null), "worldedit.brush.height"); try {
} catch (EmptyClipboardException ignore) { tool.setBrush(new FlattenBrush(stream, rotation, yscale, tool, filename.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null, shape), "worldedit.brush.height");
tool.setBrush(new FlattenBrush(stream, rotation, yscale, tool, null), "worldedit.brush.height"); } catch (EmptyClipboardException ignore) {
tool.setBrush(new FlattenBrush(stream, rotation, yscale, tool, null, shape), "worldedit.brush.height");
}
} else {
try {
tool.setBrush(new HeightBrush(stream, rotation, yscale, tool, filename.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null), "worldedit.brush.height");
} catch (EmptyClipboardException ignore) {
tool.setBrush(new HeightBrush(stream, rotation, yscale, tool, null), "worldedit.brush.height");
}
} }
player.print(BBC.getPrefix() + BBC.BRUSH_HEIGHT.f(radius)); player.print(BBC.getPrefix() + BBC.BRUSH_HEIGHT.f(radius));
} }
@Command( @Command(
aliases = { "copypaste", "copy", "paste", "cp", "copypasta" }, aliases = { "copypaste", "copy", "paste", "cp", "copypasta" },
usage = "[depth]", usage = "[depth]",