From d379b0af9b06d7e591e9105e467925ee4359a38e Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 17 Dec 2020 20:19:54 +0000 Subject: [PATCH] fix //image ane image brush fixes #208 and fixes #698 --- .../boydti/fawe/util/RandomTextureUtil.java | 3 ++ .../com/boydti/fawe/util/TextureUtil.java | 10 +++--- .../worldedit/command/BrushCommands.java | 33 ++++++++++--------- .../worldedit/command/GenerationCommands.java | 20 +++++++---- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/RandomTextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/RandomTextureUtil.java index bb2b23076..e47621944 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/RandomTextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/RandomTextureUtil.java @@ -1,5 +1,6 @@ package com.boydti.fawe.util; +import com.plotsquared.core.util.PseudoRandom; import com.sk89q.worldedit.world.block.BlockType; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @@ -34,6 +35,8 @@ public class RandomTextureUtil extends CachedTextureUtil { if (i < 0) { int i1 = -i; return -ThreadLocalRandom.current().nextInt(i1); + } else if( i == 0) { + return 0; } else { return ThreadLocalRandom.current().nextInt(i); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java index 6c112c83f..ab52685f5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java @@ -629,7 +629,6 @@ public class TextureUtil implements TextureHolder { mods.add(modId); } } - continue; } String modelsDir = "assets/%1$s/models/block/%2$s.json"; String texturesDir = "assets/%1$s/textures/%2$s.png"; @@ -638,14 +637,14 @@ public class TextureUtil implements TextureHolder { }.getType(); for (BlockType blockType : BlockTypesCache.values) { - if (!blockType.getMaterial().isFullCube()) { + if (!blockType.getMaterial().isFullCube() || blockType.getId().toLowerCase().contains("shulker")) { continue; } int combined = blockType.getInternalId(); String id = blockType.getId(); String[] split = id.split(":", 2); String name = split.length == 1 ? id : split[1]; - String nameSpace = split.length == 1 ? "minecraft" : split[0]; + String nameSpace = split.length == 1 ? "" : split[0]; Map texturesMap = new ConcurrentHashMap<>(); // Read models @@ -684,8 +683,11 @@ public class TextureUtil implements TextureHolder { continue; } + String[] texSplit = models.iterator().next().split(":"); + String texture = texSplit[texSplit.length - 1]; + textureFileName = - String.format(texturesDir, nameSpace, models.iterator().next()); + String.format(texturesDir, nameSpace, texture); } BufferedImage image = readImage(zipFile, textureFileName); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 916a93ae5..0e173d269 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -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); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index a7d65b216..4ceeef74e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -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;