Adding a new example script fort.js for creating forts and castles.
This commit is contained in:
parent
88cafd6ee2
commit
d28faca04d
3 changed files with 64 additions and 2 deletions
|
@ -154,7 +154,12 @@ public class CommandScript extends CommandBase {
|
||||||
}
|
}
|
||||||
// Now evaluate the string we've colected.
|
// Now evaluate the string we've colected.
|
||||||
notifyAdmins(par1ICommandSender, "js> " + s, (Object[])args);
|
notifyAdmins(par1ICommandSender, "js> " + s, (Object[])args);
|
||||||
Object result = ctx.evaluateString(scope, s, "<cmd>", 1, null);
|
Object result = null;
|
||||||
|
try {
|
||||||
|
result = ctx.evaluateString(scope, s, "<cmd>", 1, null);
|
||||||
|
}catch(Exception e){
|
||||||
|
notifyAdmins(par1ICommandSender, "ERROR: " + e.getMessage(), (Object[])args);
|
||||||
|
}
|
||||||
if (result != null){
|
if (result != null){
|
||||||
notifyAdmins(par1ICommandSender, Context.toString(result), (Object[])args);
|
notifyAdmins(par1ICommandSender, Context.toString(result), (Object[])args);
|
||||||
}
|
}
|
||||||
|
|
4
drone.js
4
drone.js
|
@ -338,7 +338,9 @@ var Drone = {
|
||||||
// block dirs: 0 = east, 1 = west, 2 = south , 3 = north
|
// block dirs: 0 = east, 1 = west, 2 = south , 3 = north
|
||||||
// sign dirs: 5 = east, 3 = south, 4 = west, 2 = north
|
// sign dirs: 5 = east, 3 = south, 4 = west, 2 = north
|
||||||
Drone.PLAYER_STAIRS_FACING = [0,2,1,3];
|
Drone.PLAYER_STAIRS_FACING = [0,2,1,3];
|
||||||
Drone.PLAYER_SIGN_FACING = [4,2,5,3]; // for blocks 68 (wall signs) 65 (ladders) 61,62 (furnaces) 23 (dispenser) and 54 (chest)
|
// for blocks 68 (wall signs) 65 (ladders) 61,62 (furnaces) 23 (dispenser) and 54 (chest)
|
||||||
|
Drone.PLAYER_SIGN_FACING = [4,2,5,3];
|
||||||
|
Drone.PLAYER_TORCH_FACING = [2,4,1,3];
|
||||||
|
|
||||||
Drone.prototype.prism0 = function(block,w,d){
|
Drone.prototype.prism0 = function(block,w,d){
|
||||||
this.prism(block,w,d).fwd().right().prism(0,w-2,d-2).left().back();
|
this.prism(block,w,d).fwd().right().prism(0,w-2,d-2).left().back();
|
||||||
|
|
55
fort.js
Normal file
55
fort.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
var scriptDir = $SCRIPT_DIR;
|
||||||
|
load(scriptDir + "/drone.js");
|
||||||
|
|
||||||
|
function fort(d, side, h)
|
||||||
|
{
|
||||||
|
if (typeof d == "undefined")
|
||||||
|
d = new Drone();
|
||||||
|
if (typeof side == "undefined")
|
||||||
|
side = 18;
|
||||||
|
if (typeof h == "undefined")
|
||||||
|
h = 6;
|
||||||
|
if (h < 4 || side < 10)
|
||||||
|
throw new java.lang.RuntimeException("Forts must be at least 9 wide X 4 tall");
|
||||||
|
// make sure side is even
|
||||||
|
if (side%2)
|
||||||
|
side++;
|
||||||
|
var brick = 98;
|
||||||
|
// build walls.
|
||||||
|
d.chkpt('fort').box0(brick,side,h-1,side);
|
||||||
|
//
|
||||||
|
// build turrets
|
||||||
|
//
|
||||||
|
d.up(h-1);
|
||||||
|
for (i = 0;i <= 3;i++){
|
||||||
|
var turret = [];
|
||||||
|
d.box(brick) // solid brick corners
|
||||||
|
.up().box('50:5').down() // light a torch on each corner
|
||||||
|
.fwd();
|
||||||
|
turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[d.dir]);
|
||||||
|
turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[(d.dir+2)%4]);
|
||||||
|
d.box(turret,1,1,side-2).fwd(side-2).turn();
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// build battlements
|
||||||
|
//
|
||||||
|
d.move('fort');
|
||||||
|
d.up(h-2).fwd().right().box('44:5',side-2,1,side-2);
|
||||||
|
var battlementWidth = 3;
|
||||||
|
if (side <= 12)
|
||||||
|
battlementWidth = 2;
|
||||||
|
|
||||||
|
d.fwd(battlementWidth).right(battlementWidth).box(0,side-((1+battlementWidth)*2),1,side-((1+battlementWidth)*2));
|
||||||
|
//
|
||||||
|
// add door
|
||||||
|
//
|
||||||
|
var torch = '50:' + Drone.PLAYER_TORCH_FACING[d.dir];
|
||||||
|
d.move('fort').right((side/2)-1).door2() // double doors
|
||||||
|
.back().left().up().box(torch) // left torch
|
||||||
|
.right(3).box(torch); // right torch
|
||||||
|
//
|
||||||
|
// add ladder up to battlements
|
||||||
|
//
|
||||||
|
d.move('fort').right((side/2)-3).fwd(1).box('65:' + Drone.PLAYER_SIGN_FACING[(d.dir+2)%4], 1,h-1,1);
|
||||||
|
return d.move('fort');
|
||||||
|
};
|
Reference in a new issue