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
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
4 changed files with 39 additions and 27 deletions

View File

@ -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);
}

View File

@ -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<String, String> 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);

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,16 +131,22 @@ 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);