Skip to content

Commit

Permalink
Update draw.js and roof.js
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Dec 20, 2018
1 parent 5eb9b77 commit b300c21
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion contrib/craftscripts/README.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contrib/craftscripts/SUBMITTING.txt
Expand Up @@ -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/
46 changes: 32 additions & 14 deletions contrib/craftscripts/draw.js
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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);
}

Expand All @@ -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");
}
Expand All @@ -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++) {
Expand All @@ -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]);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions contrib/craftscripts/quickshot.js
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions contrib/craftscripts/roof.js
Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand Down
Expand Up @@ -127,7 +127,7 @@ public static String getAdditive(StyleSet resetTo, StyleSet resetFrom) {
} 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());
Expand Down

0 comments on commit b300c21

Please sign in to comment.