From b300c211859d128793a397618c32de9de059b78c Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 20 Dec 2018 13:43:01 +1000 Subject: [PATCH] Update draw.js and roof.js --- contrib/craftscripts/README.txt | 2 +- contrib/craftscripts/SUBMITTING.txt | 2 +- contrib/craftscripts/draw.js | 46 +++++++++++++------ contrib/craftscripts/quickshot.js | 10 ++-- contrib/craftscripts/roof.js | 14 +++--- .../util/formatting/ColorCodeBuilder.java | 2 +- 6 files changed, 47 insertions(+), 29 deletions(-) diff --git a/contrib/craftscripts/README.txt b/contrib/craftscripts/README.txt index 607196a4e..7638e67ed 100644 --- a/contrib/craftscripts/README.txt +++ b/contrib/craftscripts/README.txt @@ -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 diff --git a/contrib/craftscripts/SUBMITTING.txt b/contrib/craftscripts/SUBMITTING.txt index d39505cf5..b519effe8 100644 --- a/contrib/craftscripts/SUBMITTING.txt +++ b/contrib/craftscripts/SUBMITTING.txt @@ -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/ \ No newline at end of file +https://discord.gg/YKbmj7V or http://forum.sk89q.com/forums/craftscripts.6/ \ No newline at end of file diff --git a/contrib/craftscripts/draw.js b/contrib/craftscripts/draw.js index 0454864f3..bc78843b9 100644 --- a/contrib/craftscripts/draw.js +++ b/contrib/craftscripts/draw.js @@ -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, " "); -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]); } } } diff --git a/contrib/craftscripts/quickshot.js b/contrib/craftscripts/quickshot.js index e47820ea7..27480e282 100644 --- a/contrib/craftscripts/quickshot.js +++ b/contrib/craftscripts/quickshot.js @@ -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, diff --git a/contrib/craftscripts/roof.js b/contrib/craftscripts/roof.js index 35e03c244..b1201ea3a 100644 --- a/contrib/craftscripts/roof.js +++ b/contrib/craftscripts/roof.js @@ -16,20 +16,20 @@ * along with this program. If not, see . */ -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, ""); var blocktype = context.getBlock(argv[1]); -var cycles = region.getLength() +var cycles = region.getLength(); if (region.getWidth() > cycles){ cycles = region.getWidth(); @@ -40,12 +40,12 @@ 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)); - + blocks.setBlock(vec, blocktype); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java index 0134827f5..dbaa904ce 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java @@ -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());