Update draw.js and roof.js

This commit is contained in:
Matthew Miller 2018-12-20 13:43:01 +10:00 committed by IronApollo
parent 45f1de6009
commit 7a9bd226ce
6 changed files with 47 additions and 29 deletions

View File

@ -2,7 +2,7 @@ CraftScripts are script files for WorldEdit that let you write world
editing scripts with JavaScript easily.
Example usage:
/cs maze.js lightstone 10 10
/cs maze.js glowstone 10 10
You may or may not install these scripts -- it is optional. If you are, however,
place the entire craftscripts/ folder into the respective directory for the platform

View File

@ -7,4 +7,4 @@ Note: Legally you should not release things to the public domain as not
all countries have the concept of public domain in their copyright law.
You can also post your scripts here:
http://forum.sk89q.com/forums/craftscripts.6/
https://discord.gg/YKbmj7V or http://forum.sk89q.com/forums/craftscripts.6/

View File

@ -43,8 +43,26 @@ var clothColors = [
makeColor(100, 60, 0), // Brown
makeColor(48, 80, 0), // Cactus green
makeColor(255, 0, 0), // Red
makeColor(0, 0, 0), // Black
]
makeColor(0, 0, 0) // Black
];
var clothBlocks = [
context.getBlock("white_wool"),
context.getBlock("orange_wool"),
context.getBlock("magenta_wool"),
context.getBlock("light_blue_wool"),
context.getBlock("yellow_wool"),
context.getBlock("lime_wool"),
context.getBlock("pink_wool"),
context.getBlock("gray_wool"),
context.getBlock("light_gray_wool"),
context.getBlock("cyan_wool"),
context.getBlock("purple_wool"),
context.getBlock("blue_wool"),
context.getBlock("brown_wool"),
context.getBlock("green_wool"),
context.getBlock("red_wool"),
context.getBlock("black_wool")
];
var clothColorsOpt = [
makeColor(178, 178, 178), // White
makeColor(187, 102, 44), // Orange
@ -61,8 +79,8 @@ var clothColorsOpt = [
makeColor(68, 41, 22), // Brown
makeColor(44, 61, 19), // Cactus green
makeColor(131, 36, 32), // Red
makeColor(21, 18, 18), // Black
]
makeColor(21, 18, 18) // Black
];
var clothColorsOptHD = [
makeColor(168, 168, 168), // White
makeColor(143, 59, 0), // Orange
@ -79,8 +97,8 @@ var clothColorsOptHD = [
makeColor(52, 25, 0), // Brown
makeColor(10, 76, 10), // Cactus green
makeColor(127, 9, 9), // Red
makeColor(17, 17, 17), // Black
]
makeColor(17, 17, 17) // Black
];
// http://stackoverflow.com/questions/2103368/color-logic-algorithm/2103608#2103608
function colorDistance(c1, c2) {
@ -90,7 +108,7 @@ function colorDistance(c1, c2) {
var b = c1.getBlue() - c2.getBlue();
var weightR = 2 + rmean/256;
var weightG = 4.0;
var weightB = 2 + (255-rmean)/256
var weightB = 2 + (255-rmean)/256;
return Math.sqrt(weightR*r*r + weightG*g*g + weightB*b*b);
}
@ -113,14 +131,14 @@ function findClosestWoolColor(col, clothColors) {
context.checkArgs(1, 3, "<image> <orientation> <palette>");
var f = context.getSafeFile("drawings", argv[1]);
var f = context.getSafeOpenFile("drawings", argv[1], "png", ["png", "jpg", "jpeg", "bmp"]);
var sess = context.remember();
var upright = argv[2] == "v";
var upright = argv[2] === "v";
var colors = clothColors;
if(argv[3] == "opt") {
if(argv[3] === "opt") {
colors = clothColorsOpt;
player.print("Using optimized palette");
} else if(argv[3] == "optHD") {
} else if(argv[3] === "optHD") {
colors = clothColorsOptHD;
player.print("Using optimized HD palette");
}
@ -132,7 +150,7 @@ if (!f.exists()) {
var width = img.getWidth();
var height = img.getHeight();
var origin = player.getBlockIn();
var origin = player.getBlockIn().toVector().toBlockPoint();
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
@ -141,9 +159,9 @@ if (!f.exists()) {
// Added this to enable the user to create images upright
// rather than flat on the ground
if (!upright) {
sess.setBlock(origin.add(x, 0, y), new BaseBlock(35, data));
sess.setBlock(origin.add(x, 0, y), clothBlocks[data]);
} else {
sess.setBlock(origin.add(x, height - y, 0), new BaseBlock(35, data));
sess.setBlock(origin.add(x, height - y, 0), clothBlocks[data]);
}
}
}

View File

@ -20,11 +20,11 @@
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.blocks);
var torchDirs = {}
torchDirs[PlayerDirection.NORTH] = [2, 4];
torchDirs[PlayerDirection.SOUTH] = [1, 3];
torchDirs[PlayerDirection.WEST] = [3, 2];
torchDirs[PlayerDirection.EAST] = [4, 1];
var torchDirs = {};
torchDirs[Direction.NORTH] = [2, 4];
torchDirs[Direction.SOUTH] = [1, 3];
torchDirs[Direction.WEST] = [3, 2];
torchDirs[Direction.EAST] = [4, 1];
var pitches = {
"f#": 0,

View File

@ -16,20 +16,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
importPackage(Packages.java.io);
importPackage(Packages.java.awt);
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.math);
importPackage(Packages.com.sk89q.worldedit.blocks);
var blocks = context.remember();
var session = context.getSession();
var region = session.getRegion();
var player = context.getPlayer();
var region = session.getRegionSelector(player.getWorld()).getRegion();
context.checkArgs(1, 1, "<type>");
var blocktype = context.getBlock(argv[1]);
var cycles = region.getLength()
var cycles = region.getLength();
if (region.getWidth() > cycles){
cycles = region.getWidth();
@ -40,8 +40,8 @@ cycles = cycles / 2;
for (var c = 0; c < cycles; c++) {
for (var w = 0; w < region.getWidth() - (c * 2); w++) {
for (var l = 0; l < region.getLength() - (c * 2); l++) {
if (w == 0 || w == (region.getWidth() - (c * 2)) - 1 || l == 0 || l == (region.getLength() - (c * 2)) - 1) {
var vec = new Vector(
if (w === 0 || w === (region.getWidth() - (c * 2)) - 1 || l === 0 || l === (region.getLength() - (c * 2)) - 1) {
var vec = BlockVector3.at(
region.getMinimumPoint().getX() + (w + c),
region.getMaximumPoint().getY() + c,
region.getMinimumPoint().getZ() + (l + c));

View File

@ -127,7 +127,7 @@ public class ColorCodeBuilder {
} else if (!resetFrom.hasEqualFormatting(resetTo) ||
(resetFrom.getColor() != null && resetTo.getColor() == null)) {
// Have to set reset code and add back all the formatting codes
return String.valueOf(Style.RESET) + getCode(resetTo);
return Style.RESET + getCode(resetTo);
} else {
if (resetFrom.getColor() != resetTo.getColor()) {
return String.valueOf(resetTo.getColor());