Skip to content

Instantly share code, notes, and snippets.

@cmastudios
Last active December 10, 2015 08:38
Show Gist options
  • Save cmastudios/4409202 to your computer and use it in GitHub Desktop.
Save cmastudios/4409202 to your computer and use it in GitHub Desktop.
Zacraft-style plot boundary generator for WorldEdit craftscripts
/*
Copyright (c) 2012 Connor Monahan
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
importPackage(Packages.com.sk89q.worldedit.blocks);
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.foundation);
importPackage(Packages.org.bukkit);
var session = context.remember();
var origin = player.getPosition();
var region = context.getSession().getSelection(player.getWorld());
var changed = 0;
var min = region.getMinimumPoint();
var max = region.getMaximumPoint();
context.checkArgs(0, 1, "<interval>");
var interval = argv.length > 1 ? argv[1] : 10;
var minX = min.getBlockX();
var minY = min.getBlockY();
var minZ = min.getBlockZ();
var maxX = max.getBlockX();
var maxY = max.getBlockY();
var maxZ = max.getBlockZ();
var count = 0;
for (var x = minX; x < maxX; ++x) {
var block = new BlockVector(x, minY, minZ);
if (x == minX) {
session.setBlock(block, new BaseBlock(41));
session.setBlock(block.add(0, 1, 0), new BaseBlock(41));
session.setBlock(block.add(0, 2, 0), new BaseBlock(89));
changed+=3;
} else if (count % interval == 0) {
session.setBlock(block, new BaseBlock(41));
session.setBlock(block.add(0, 1, 0), new BaseBlock(41));
changed+=2;
} else {
session.setBlock(block, new BaseBlock(85));
changed++;
}
count++;
}
count = 1;
for (var z = minZ; z < maxZ; ++z) {
var block = new BlockVector(maxX, minY, z);
if (z == minZ) {
session.setBlock(block, new BaseBlock(41));
session.setBlock(block.add(0, 1, 0), new BaseBlock(41));
session.setBlock(block.add(0, 2, 0), new BaseBlock(89));
changed+=3;
} else if (count % interval == 0) {
session.setBlock(block, new BaseBlock(41));
session.setBlock(block.add(0, 1, 0), new BaseBlock(41));
changed+=2;
} else {
session.setBlock(block, new BaseBlock(85));
changed++;
}
count++;
}
count = 1;
for (var x = maxX; x > minX; --x) {
var block = new BlockVector(x, minY, maxZ);
if (x == maxX) {
session.setBlock(block, new BaseBlock(41));
session.setBlock(block.add(0, 1, 0), new BaseBlock(41));
session.setBlock(block.add(0, 2, 0), new BaseBlock(89));
changed+=3;
} else if (count % interval == 0) {
session.setBlock(block, new BaseBlock(41));
session.setBlock(block.add(0, 1, 0), new BaseBlock(41));
changed+=2;
} else {
session.setBlock(block, new BaseBlock(85));
changed++;
}
count++;
}
count = 1;
for (var z = maxZ; z > minZ; --z) {
var block = new BlockVector(minX, minY, z);
if (z == maxZ) {
session.setBlock(block, new BaseBlock(41));
session.setBlock(block.add(0, 1, 0), new BaseBlock(41));
session.setBlock(block.add(0, 2, 0), new BaseBlock(89));
changed+=3;
} else if (count % interval == 0) {
session.setBlock(block, new BaseBlock(41));
session.setBlock(block.add(0, 1, 0), new BaseBlock(41));
changed+=2;
} else {
session.setBlock(block, new BaseBlock(85));
changed++;
}
count++;
}
player.print(changed + " block(s) have been changed.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment