fix //image ane image brush

fixes #208 and fixes #698
This commit is contained in:
dordsor21
2020-12-17 20:19:54 +00:00
parent 94a14b03b6
commit d379b0af9b
4 changed files with 39 additions and 27 deletions

View File

@ -85,7 +85,6 @@ import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.CreatureButcher;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.binding.ProvideBindings;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.Contextual;
@ -130,6 +129,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.nio.file.FileSystems;
import java.util.List;
@ -498,22 +498,23 @@ public class BrushCommands {
set(context, brush).setSize(radius).setFill(fill);
}
@Command(
name = "image",
@Command(name = "image",
desc = "Use a height map to paint a surface",
descFooter = "Use a height map to paint any surface.\n"
)
@CommandPermissions("worldedit.brush.stencil")
public void imageBrush(LocalSession session, InjectedValueAccess context,
@Arg(desc = "The size of the brush", def = "5")
Expression radius, ProvideBindings.ImageUri imageUri,
@Arg(def = "1", desc = "scale height")
double yscale,
@Switch(name = 'a', desc = "Use image Alpha")
boolean alpha,
@Switch(name = 'f', desc = "Blend the image with existing terrain")
boolean fadeOut) throws WorldEditException, IOException {
BufferedImage image = imageUri.load();
descFooter = "Use a height map to paint any surface.\n")
@CommandPermissions("worldedit.brush.image")
public void imageBrush(LocalSession session,
InjectedValueAccess context,
@Arg(desc = "Image URL (imgur only)") String imageURL,
@Arg(desc = "The size of the brush", def = "5") Expression radius,
@Arg(def = "1", desc = "scale height") double yscale,
@Switch(name = 'a', desc = "Use image Alpha") boolean alpha,
@Switch(name = 'f', desc = "Blend the image with existing terrain") boolean fadeOut)
throws WorldEditException, IOException {
URL url = new URL(imageURL);
if (!url.getHost().equalsIgnoreCase("i.imgur.com")) {
throw new IOException("Only i.imgur.com links are allowed!");
}
BufferedImage image = MainUtil.readImage(url);
worldEdit.checkMaxBrushRadius(radius);
if (yscale != 1) {
ImageUtil.scaleAlpha(image, yscale);

View File

@ -58,7 +58,7 @@ import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch;
import org.jetbrains.annotations.Range;
import java.awt.RenderingHints;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
@ -131,20 +131,26 @@ public class GenerationCommands {
)
@CommandPermissions("worldedit.generation.image")
@Logging(PLACEMENT)
public void image(Actor actor, LocalSession session, EditSession editSession, String argStr, @Arg(desc = "boolean", def = "true") boolean randomize,
@Arg(desc = "TODO", def = "100") int threshold, @Arg(desc = "BlockVector2", def = "") BlockVector2 dimensions) throws WorldEditException, IOException {
public void image(Actor actor,
LocalSession session,
EditSession editSession,
@Arg(desc = "Image URL (imgur only)") String imageURL,
@Arg(desc = "boolean", def = "true") boolean randomize,
@Arg(desc = "TODO", def = "100") int threshold,
@Arg(desc = "BlockVector2", def = "") BlockVector2 dimensions) throws WorldEditException, IOException {
TextureUtil tu = Fawe.get().getCachedTextureUtil(randomize, 0, threshold);
URL url = new URL(argStr);
URL url = new URL(imageURL);
if (!url.getHost().equalsIgnoreCase("i.imgur.com")) {
throw new IOException("Only i.imgur.com links are allowed!");
}
BufferedImage image = MainUtil.readImage(url);
if (dimensions != null) {
image = ImageUtil.getScaledInstance(image, dimensions.getBlockX(), dimensions.getBlockZ(), RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
image = ImageUtil.getScaledInstance(image, dimensions.getBlockX(), dimensions.getBlockZ(),
RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
}
BlockVector3 pos1 = session.getPlacementPosition(actor);
BlockVector3 pos2 = pos1.add(image.getWidth() - 1, 0, image.getHeight() - 1);
BlockVector3 pos1 = session.getPlacementPosition(actor);
BlockVector3 pos2 = pos1.add(image.getWidth() - 1, 0, image.getHeight() - 1);
CuboidRegion region = new CuboidRegion(pos1, pos2);
int[] count = new int[1];
final BufferedImage finalImage = image;