Modernized pom, readmes.

This commit is contained in:
sk89q
2012-10-19 21:01:44 -07:00
parent 9faa9507b0
commit 2a93baf15b
13 changed files with 1203 additions and 636 deletions

View File

@ -0,0 +1,15 @@
CraftScripts are script files for WorldEdit that let you write world
editing scripts with JavaScript easily.
Example usage:
/cs maze.js lightstone 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
that you have installed WorldEdit for
(see http://wiki.sk89q.com/wiki/WorldEdit/Installation).
In order to be able to use CraftScripts, you must install the Rhino JavaScript library.
The installation page linked above has information about that. More information
about scripts in general can be found at
http://wiki.sk89q.com/wiki/WorldEdit/Scripting

View File

@ -0,0 +1,10 @@
Write a cool script? Send it to sk89q (somehow) or you can submit a pull
request on https://github.com/sk89q/worldedit. He will consider your script
for inclusion in WorldEdit releases. Please license your script with a
permissive open source license such as GPLv2, MIT, BSD, WTFPL, etc.
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/

View File

@ -0,0 +1,150 @@
// $Id$
/*
* Very bad image drawer
* Copyright (C) 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
importPackage(Packages.java.io);
importPackage(Packages.java.awt);
importPackage(Packages.javax.imageio);
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.blocks);
function makeColor(r, g, b) {
return new Color(r / 255, g / 255, b / 255);
}
var clothColors = [
makeColor(254, 254, 254), // White - fixed so white gets picked over pink for white pixels
makeColor(255, 100, 0), // Orange
makeColor(200, 0, 200), // Magenta
makeColor(87, 132, 223), // Light blue
makeColor(255, 255, 0), // Yellow
makeColor(0, 255, 0), // Green
makeColor(255, 180, 200), // Pink
makeColor(72, 72, 72), // Gray
makeColor(173, 173, 173), // Light grey
makeColor(0, 100, 160), // Cyan
makeColor(120, 0, 200), // Purple
makeColor(0, 0, 175), // Blue
makeColor(100, 60, 0), // Brown
makeColor(48, 80, 0), // Cactus green
makeColor(255, 0, 0), // Red
makeColor(0, 0, 0), // Black
]
var clothColorsOpt = [
makeColor(178, 178, 178), // White
makeColor(187, 102, 44), // Orange
makeColor(152, 61, 161), // Magenta
makeColor(84, 111, 170), // Light blue
makeColor(156, 145, 23), // Yellow
makeColor(47, 151, 38), // Green
makeColor(174, 105, 124), // Pink
makeColor(53, 53, 53), // Gray
makeColor(127, 133, 133), // Light grey
makeColor(32, 94, 120), // Cyan
makeColor(103, 43, 156), // Purple
makeColor(31, 41, 123), // Blue
makeColor(68, 41, 22), // Brown
makeColor(44, 61, 19), // Cactus green
makeColor(131, 36, 32), // Red
makeColor(21, 18, 18), // Black
]
var clothColorsOptHD = [
makeColor(168, 168, 168), // White
makeColor(143, 59, 0), // Orange
makeColor(152, 0, 67), // Magenta
makeColor(0, 153, 153), // Light blue
makeColor(150, 150, 0), // Yellow
makeColor(59, 143, 0), // Green
makeColor(167, 83, 125), // Pink
makeColor(64, 64, 64), // Gray
makeColor(101, 101, 101), // Light grey
makeColor(0, 83, 83), // Cyan
makeColor(43, 12, 75), // Purple
makeColor(0, 38, 77), // Blue
makeColor(52, 25, 0), // Brown
makeColor(10, 76, 10), // Cactus green
makeColor(127, 9, 9), // Red
makeColor(17, 17, 17), // Black
]
// http://stackoverflow.com/questions/2103368/color-logic-algorithm/2103608#2103608
function colorDistance(c1, c2) {
var rmean = (c1.getRed() + c2.getRed()) / 2;
var r = c1.getRed() - c2.getRed();
var g = c1.getGreen() - c2.getGreen();
var b = c1.getBlue() - c2.getBlue();
var weightR = 2 + rmean/256;
var weightG = 4.0;
var weightB = 2 + (255-rmean)/256
return Math.sqrt(weightR*r*r + weightG*g*g + weightB*b*b);
}
function findClosestWoolColor(col, clothColors) {
var closestId = 0;
var closestDistance = colorDistance(col, clothColors[0]);
for(var i = 1; i < clothColors.length; i++) {
var dist = colorDistance(col, clothColors[i]);
if(dist < closestDistance) {
closestId = i;
closestDistance = dist;
}
}
return closestId;
}
context.checkArgs(1, 3, "<image> <orientation> <palette>");
var f = context.getSafeFile("drawings", argv[1]);
var sess = context.remember();
var upright = argv[2] == "v";
var colors = clothColors;
if(argv[3] == "opt") {
colors = clothColorsOpt;
player.print("Using optimized palette");
} else if(argv[3] == "optHD") {
colors = clothColorsOptHD;
player.print("Using optimized HD palette");
}
if (!f.exists()) {
player.printError("Specified file doesn't exist.");
} else {
var img = ImageIO.read(f);
var width = img.getWidth();
var height = img.getHeight();
var origin = player.getBlockIn();
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
var c = new Color(img.getRGB(x, y));
var data = findClosestWoolColor(c,colors);
// 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));
} else {
sess.setBlock(origin.add(x, height - y, 0), new BaseBlock(35, data));
}
}
}
}

View File

@ -0,0 +1,132 @@
// $Id$
/*
* Maze generator CraftScript for WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.blocks);
context.checkArgs(1, -1, "<block> [width] [length]");
var sess = context.remember();
// This may throw an exception that is caught by the script processor
var block = context.getBlock(argv[1]);
var w = argv.length > 2 ? parseInt(argv[2]) : 5;
var h = argv.length > 3 ? parseInt(argv[3]) : 5;
function id(x, y) {
return y * (w + 1) + x;
}
function $x(i) {
return i % (w + 1);
}
function $y(i) {
return Math.floor(i / (w + 1));
}
function shuffle(arr) {
var i = arr.length;
if (i == 0) return false;
while (--i) {
var j = Math.floor(Math.random() * (i + 1));
var tempi = arr[i];
var tempj = arr[j];
arr[i] = tempj;
arr[j] = tempi;
}
}
var stack = [];
var visited = {};
var noWallLeft = new Array(w * h);
var noWallAbove = new Array(w * h);
var current = 0;
stack.push(id(0, 0))
while (stack.length > 0) {
var cell = stack.pop();
var x = $x(cell), y = $y(cell);
visited[cell] = true;
var neighbors = []
if (x > 0) neighbors.push(id(x - 1, y));
if (x < w - 1) neighbors.push(id(x + 1, y));
if (y > 0) neighbors.push(id(x, y - 1));
if (y < h - 1) neighbors.push(id(x, y + 1));
shuffle(neighbors);
while (neighbors.length > 0) {
var neighbor = neighbors.pop();
var nx = $x(neighbor), ny = $y(neighbor);
if (visited[neighbor] != true) {
stack.push(cell);
if (y == ny) {
if (nx < x) {
noWallLeft[cell] = true;
} else {
noWallLeft[neighbor] = true;
}
} else {
if (ny < y) {
noWallAbove[cell] = true;
} else {
noWallAbove[neighbor] = true;
}
}
stack.push(neighbor);
break;
}
}
}
/*for (var y = -1; y < h; y++) {
var line = "";
for (var x = 0; x <= w; x++) {
var cell = id(x, y)
var l = y >= 0 ? (noWallLeft[cell] ? "_" : "|") : "_";
var b = x < w ? (noWallAbove[id(x, y + 1)] ? " " : "_") : "";
line += l + b;
}
context.print(line);
}*/
var origin = player.getBlockIn();
for (var y = 0; y <= h; y++) {
for (var x = 0; x <= w; x++) {
var cell = id(x, y)
if (!noWallLeft[cell] && y < h) {
sess.setBlock(origin.add(x * 2 - 1, 0, y * 2), block);
sess.setBlock(origin.add(x * 2 - 1, 1, y * 2), block);
}
if (!noWallAbove[cell] && x < w) {
sess.setBlock(origin.add(x * 2, 0, y * 2 - 1), block);
sess.setBlock(origin.add(x * 2, 1, y * 2 - 1), block);
}
sess.setBlock(origin.add(x * 2 - 1, 0, y * 2 - 1), block);
sess.setBlock(origin.add(x * 2 - 1, 1, y * 2 - 1), block);
}
}

View File

@ -0,0 +1,135 @@
// $Id$
/*
* Quick shot music layout
* Copyright (C) 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 pitches = {
"f#": 0,
"gb": 0,
"g": 1,
"g#": 2,
"ab": 2,
"a": 3,
"a#": 4,
"bb": 4,
"b": 5,
"c": 6,
"c#": 7,
"db": 7,
"d": 8,
"d#": 9,
"eb": 9,
"e": 10,
"f": 11,
"f#": 12,
"gb": 12,
}
function generate(dir, notes) {
var sess = context.remember();
var origin = player.getBlockOn();
var vec = dir.vector();
var right = dir.leftVector().multiply(-1);
var base = new BaseBlock(BlockID.DIRT);
var instrument = new BaseBlock(BlockID.DIRT);
var noteTorch = new BaseBlock(BlockID.REDSTONE_TORCH_ON, torchDirs[dir][1]);
var backTorch = new BaseBlock(BlockID.REDSTONE_TORCH_ON, torchDirs[dir][0]);
var wire = new BaseBlock(BlockID.REDSTONE_WIRE);
var length = 4;
for (var i = 0; i < notes.length; i++) {
var note = new NoteBlock();
note.setNote(notes[i]);
var offset = origin.add(vec.multiply(i * length));
sess.setBlock(offset, base);
sess.setBlock(offset.add(0, 1, 0), wire);
var forward1 = offset.add(vec.multiply(1));
sess.setBlock(forward1.add(0, 1, 0), base);
sess.setBlock(forward1.add(right.multiply(1)).add(0, 0, 0), instrument);
sess.setBlock(forward1.add(right.multiply(1)).add(0, 1, 0), noteTorch);
sess.setBlock(forward1.add(right.multiply(1)).add(0, 2, 0), note);
sess.setBlock(forward1.add(right.multiply(2)), base);
sess.setBlock(forward1.add(right.multiply(2)).add(0, 1, 0), wire);
var forward2 = offset.add(vec.multiply(2));
sess.setBlock(forward2.add(0, 1, 0), base);
sess.setBlock(forward2.add(0, 2, 0), wire);
sess.setBlock(forward2.add(right.multiply(1)).add(0, 1, 0), base);
sess.setBlock(forward2.add(right.multiply(1)).add(0, 2, 0), wire);
sess.setBlock(forward2.add(right.multiply(2)).add(0, 1, 0), base);
sess.setBlock(forward2.add(right.multiply(2)).add(0, 2, 0), wire);
var forward3 = offset.add(vec.multiply(3));
sess.setBlock(forward3.add(0, 1, 0), backTorch);
}
}
function main() {
context.checkArgs(1, -1, "<note1> [note2] [note...]");
var dir = player.getCardinalDirection();
if (!dir.isOrthogonal()) {
context.error("You need to be facing at a right angle to the world.");
return;
}
var pattern = new RegExp("^([0-9])(.*)$");
var notes = [];
for (var i = 1; i < argv.length; i++) {
var m = pattern.exec(argv[i])
if (m == null) {
context.error("Bad format (expected [octave][note]): " + argv[i]);
return;
}
var octave = parseInt(m[1]);
var n = m[2].toLowerCase();
if (octave < 1 || octave > 2) {
context.error("Valid octaves: 1 2");
return;
}
if (!(n in pitches)) {
context.error("Unknown note: " + n);
return;
}
notes.push((octave - 1) * 12 + pitches[n]);
}
context.print(notes);
generate(dir, notes);
}
main();

View File

@ -0,0 +1,53 @@
// $Id$
/*
* Copyright (c) 2011 Bentech
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.blocks);
var blocks = context.remember();
var session = context.getSession();
var region = session.getRegion();
context.checkArgs(1, 1, "<type>");
var blocktype = context.getBlock(argv[1]);
var cycles = region.getLength()
if (region.getWidth() > cycles){
cycles = region.getWidth();
}
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(
region.getMinimumPoint().getX() + (w + c),
region.getMaximumPoint().getY() + c,
region.getMinimumPoint().getZ() + (l + c));
blocks.setBlock(vec, blocktype);
}
}
}
}