mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2025-01-06 08:28:14 +01:00
CFI color masking
/2 cfi color <color image> [image or worldedit mask] [whiteonly=true] e.g. /2 cfi color file://color.png file://mask.png
This commit is contained in:
parent
ba15e28810
commit
cc7719e0e4
@ -507,14 +507,63 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setColor(BufferedImage img, BufferedImage mask, boolean white) {
|
||||||
|
if (img.getWidth() != getWidth() || img.getHeight() != getLength())
|
||||||
|
throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
|
||||||
|
if (mask.getWidth() != getWidth() || mask.getHeight() != getLength())
|
||||||
|
throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
|
||||||
|
modifiedMain = true;
|
||||||
|
TextureUtil textureUtil = getTextureUtil();
|
||||||
|
int index = 0;
|
||||||
|
for (int z = 0; z < getLength(); z++) {
|
||||||
|
for (int x = 0; x < getWidth(); x++, index++) {
|
||||||
|
int height = mask.getRGB(x, z) & 0xFF;
|
||||||
|
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
|
||||||
|
int color = img.getRGB(x, z);
|
||||||
|
BaseBlock block = textureUtil.getNearestBlock(color);
|
||||||
|
if (block != null) {
|
||||||
|
char combined = (char) block.getCombined();
|
||||||
|
main[index] = combined;
|
||||||
|
floor[index] = combined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(BufferedImage img, Mask mask, boolean white) {
|
||||||
|
if (img.getWidth() != getWidth() || img.getHeight() != getLength())
|
||||||
|
throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
|
||||||
|
modifiedMain = true;
|
||||||
|
TextureUtil textureUtil = getTextureUtil();
|
||||||
|
int index = 0;
|
||||||
|
for (int z = 0; z < getLength(); z++) {
|
||||||
|
mutable.mutZ(z);
|
||||||
|
for (int x = 0; x < getWidth(); x++, index++) {
|
||||||
|
mutable.mutX(x);
|
||||||
|
mutable.mutY(heights[index] & 0xFF);
|
||||||
|
if (mask.test(mutable)) {
|
||||||
|
int color = img.getRGB(x, z);
|
||||||
|
BaseBlock block = textureUtil.getNearestBlock(color);
|
||||||
|
if (block != null) {
|
||||||
|
char combined = (char) block.getCombined();
|
||||||
|
main[index] = combined;
|
||||||
|
floor[index] = combined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setColor(BufferedImage img) {
|
public void setColor(BufferedImage img) {
|
||||||
if (img.getWidth() != getWidth() || img.getHeight() != getLength())
|
if (img.getWidth() != getWidth() || img.getHeight() != getLength())
|
||||||
throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
|
throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
|
||||||
|
modifiedMain = true;
|
||||||
TextureUtil textureUtil = getTextureUtil();
|
TextureUtil textureUtil = getTextureUtil();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (int y = 0; y < img.getHeight(); y++) {
|
for (int z = 0; z < img.getHeight(); z++) {
|
||||||
for (int x = 0; x < img.getWidth(); x++) {
|
for (int x = 0; x < img.getWidth(); x++) {
|
||||||
int color = img.getRGB(x, y);
|
int color = img.getRGB(x, z);
|
||||||
BaseBlock block = textureUtil.getNearestBlock(color);
|
BaseBlock block = textureUtil.getNearestBlock(color);
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
char combined = (char) block.getCombined();
|
char combined = (char) block.getCombined();
|
||||||
|
@ -292,12 +292,25 @@ public class CreateFromImage extends Command {
|
|||||||
}
|
}
|
||||||
case "color":
|
case "color":
|
||||||
case "setcolor": {
|
case "setcolor": {
|
||||||
if (argList.size() != 2) {
|
if (argList.size() < 2) {
|
||||||
C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " <url>");
|
C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " <url> [mask] [whiteonly=true]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BufferedImage image = getImage(argList.get(1), fp);
|
BufferedImage image = getImage(argList.get(1), fp);
|
||||||
generator.setColor(image);
|
if (argList.size() > 2) {
|
||||||
|
String arg2 = argList.get(2);
|
||||||
|
if (arg2.startsWith("http") || arg2.startsWith("file://")) {
|
||||||
|
BufferedImage mask = getImage(arg2, fp);
|
||||||
|
boolean whiteOnly = argList.size() < 4 || Boolean.parseBoolean(argList.get(3));
|
||||||
|
generator.setColor(image, mask, whiteOnly);
|
||||||
|
} else {
|
||||||
|
Mask mask = we.getMaskFactory().parseFromInput(argList.get(1), context);
|
||||||
|
boolean whiteOnly = argList.size() < 4 || Boolean.parseBoolean(argList.get(3));
|
||||||
|
generator.setColor(image, mask, whiteOnly);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
generator.setColor(image);
|
||||||
|
}
|
||||||
player.sendMessage("Set color, what's next?");
|
player.sendMessage("Set color, what's next?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user