Drone.garden() is now non-destructive - won't destroy existing blocks.

This commit is contained in:
walterhiggins 2014-02-19 00:15:44 +00:00
parent ef02885613
commit d976563adf
4 changed files with 139 additions and 49 deletions

View file

@ -86,7 +86,9 @@ Walter Higgins
* [Drone.cylinder0() method](#dronecylinder0-method)
* [Drone.arc() method](#dronearc-method)
* [Drone.door() method](#dronedoor-method)
* [Drone.door_iron() method](#dronedoor_iron-method)
* [Drone.door2() method](#dronedoor2-method)
* [Drone.door2_iron() method](#dronedoor2_iron-method)
* [Drone.sign() method](#dronesign-method)
* [Drone Trees methods](#drone-trees-methods)
* [Drone.garden() method](#dronegarden-method)
@ -1760,7 +1762,11 @@ To create an iron door...
drone.door( blocks.door_iron );
![iron door](img/doorex1.png)
### Drone.door_iron() method
create an Iron door.
### Drone.door2() method
Create double doors (left and right side)
@ -1777,6 +1783,11 @@ To create double-doors at the cross-hairs/drone's location...
![double doors](img/door2ex1.png)
### Drone.door2_iron() method
Create double iron doors
### Drone.sign() method
Signs must use block 63 (stand-alone signs) or 68 (signs on walls)
@ -1854,7 +1865,12 @@ place random blocks stone, mossy stone and cracked stone (each block has the sam
to place random blocks stone has a 50% chance of being picked,
rand({blocks.brick.stone: 5, blocks.brick.mossy: 3, blocks.brick.cracked: 2},w,d,h)
var distribution = {};
distribution[ blocks.brick.stone ] = 5;
distribution[ blocks.brick.mossy ] = 3;
distribution[ blocks.brick.cracked ] = 2;
rand( distribution, width, height, depth)
regular stone has a 50% chance, mossy stone has a 30% chance and cracked stone has just a 20% chance of being picked.

View file

@ -4,6 +4,12 @@ var Drone = require('../drone').Drone;
// constructs a medieval fort
//
Drone.extend('fort', function( side, height ) {
var brick = 98,
turret,
i,
torch,
ladder;
if ( typeof side == 'undefined' ) {
side = 18;
}
@ -21,53 +27,65 @@ Drone.extend('fort', function( side, height ) {
if ( height < 4 || side < 10 ) {
throw new java.lang.RuntimeException('Forts must be at least 10 wide X 4 tall');
}
var brick = 98;
//
// build walls.
//
this.chkpt('fort').box0(brick,side,height-1,side);
this.chkpt('fort')
.box0(brick,side,height-1,side)
.up(height-1);
//
// build battlements
//
this.up(height-1);
for ( i = 0; i <= 3; i++ ) {
var turret = [];
turret = [
'109:'+ Drone.PLAYER_STAIRS_FACING[this.dir],
'109:'+ Drone.PLAYER_STAIRS_FACING[(this.dir+2)%4]
];
this.box(brick) // solid brick corners
.up().box('50:5').down() // light a torch on each corner
.fwd();
turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[this.dir]);
turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[(this.dir+2)%4]);
try {
this.boxa(turret,1,1,side-2).fwd(side-2).turn();
} catch( e ) {
console.log('ERROR: ' + e.toString());
}
.up()
.box('50:5')
.down() // light a torch on each corner
.fwd()
.boxa(turret,1,1,side-2)
.fwd(side-2)
.turn();
}
//
// build battlement's floor
//
this.move('fort');
this.up(height-2).fwd().right();
for ( var i = 0; i < battlementWidth; i++ ) {
this.box0('126:0', side - ( 2 + (i * 2) ), 1, side - ( 2 + ( i * 2) ));
this.fwd().right();
this.move('fort')
.up(height-2)
.fwd()
.right();
for ( i = 0; i < battlementWidth; i++ ) {
this.box0('126:0', side - ( 2 + (i * 2) ), 1, side - ( 2 + ( i * 2) ))
.fwd()
.right();
}
//
// add door
//
var torch = '50:' + Drone.PLAYER_TORCH_FACING[this.dir];
this.move('fort').right((side/2)-1).door2() // double doors
.back().left().up()
torch = '50:' + Drone.PLAYER_TORCH_FACING[this.dir];
this.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
//
var ladder = '65:' + Drone.PLAYER_SIGN_FACING[(this.dir+2)%4];
this.move('fort').right((side/2)-3).fwd(1) // move inside fort
.box(ladder, 1,height-1,1);
return this.move('fort');
ladder = '65:' + Drone.PLAYER_SIGN_FACING[(this.dir+2)%4];
this.move('fort')
.right((side/2)-3)
.fwd(1) // move inside fort
.box(ladder, 1,height-1,1)
.move('fort');
});

View file

@ -19,11 +19,11 @@ Drone.extend('hangtorch', function () {
this.back();
if (moves == 10){
this.fwd(moves);
console.log('no air to hang torch');
console.log('nowhere to hang torch');
return;
}
block = this.world.getBlockAt(this.x, this.y, this.z);
}
this.box(torch);
this.fwd(moves);
this.box(torch)
.fwd(moves);
});

View file

@ -3,8 +3,8 @@ var utils = require('utils'),
Location = org.bukkit.Location,
Player = org.bukkit.entity.Player,
Sign = org.bukkit.block.Sign,
TreeType = org.bukkit.TreeType;
TreeType = org.bukkit.TreeType,
Material = org.bukkit.Material;
/*********************************************************************
## Drone Plugin
@ -387,7 +387,11 @@ To create an iron door...
drone.door( blocks.door_iron );
![iron door](img/doorex1.png)
### Drone.door_iron() method
create an Iron door.
### Drone.door2() method
Create double doors (left and right side)
@ -404,6 +408,11 @@ To create double-doors at the cross-hairs/drone's location...
![double doors](img/door2ex1.png)
### Drone.door2_iron() method
Create double iron doors
### Drone.sign() method
Signs must use block 63 (stand-alone signs) or 68 (signs on walls)
@ -481,7 +490,12 @@ place random blocks stone, mossy stone and cracked stone (each block has the sam
to place random blocks stone has a 50% chance of being picked,
rand({blocks.brick.stone: 5, blocks.brick.mossy: 3, blocks.brick.cracked: 2},w,d,h)
var distribution = {};
distribution[ blocks.brick.stone ] = 5;
distribution[ blocks.brick.mossy ] = 3;
distribution[ blocks.brick.cracked ] = 2;
rand( distribution, width, height, depth)
regular stone has a 50% chance, mossy stone has a 30% chance and cracked stone has just a 20% chance of being picked.
@ -995,7 +1009,11 @@ Drone.extend( 'sign', function( message, block ) {
}
});
Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d ) {
Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d, overwrite ) {
if ( typeof overwrite == 'undefined' ) {
overwrite = true;
}
var properBlocks = [];
var len = blocks.length;
for ( var i = 0; i < len; i++ ) {
@ -1022,7 +1040,9 @@ Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d ) {
_traverse[dir].width( that, w, function( ) {
var block = that.world.getBlockAt( that.x, that.y, that.z );
var properBlock = properBlocks[ bi % len ];
block.setTypeIdAndData( properBlock[0], properBlock[1], false );
if (overwrite || block.type.equals(Material.AIR) ) {
block.setTypeIdAndData( properBlock[0], properBlock[1], false );
}
bi++;
});
});
@ -1107,6 +1127,14 @@ Drone.extend( 'door', function( door ) {
.down( );
} );
Drone.extend( 'door_iron', function( ) {
var door = 71;
this.cuboidX( door, this.dir )
.up( )
.cuboidX( door, 8 )
.down( );
} );
Drone.extend( 'door2' , function( door ) {
if ( typeof door == 'undefined' ) {
door = 64;
@ -1119,6 +1147,15 @@ Drone.extend( 'door2' , function( door ) {
.cuboidX( door, 9 ).down( )
.cuboidX( door, this.dir ).left( );
} );
Drone.extend( 'door2_iron' , function( door ) {
var door = 71;
this
.cuboidX( door, this.dir ).up( )
.cuboidX( door, 8 ).right( )
.cuboidX( door, 9 ).down( )
.cuboidX( door, this.dir ).left( );
} );
// player dirs: 0 = east, 1 = south, 2 = west, 3 = north
// block dirs: 0 = east, 1 = west, 2 = south , 3 = north
// sign dirs: 5 = east, 3 = south, 4 = west, 2 = north
@ -1712,18 +1749,32 @@ var _copy = function( name, w, h, d ) {
} );
Drone.clipBoard[name] = {dir: this.dir, blocks: ccContent};
};
var _garden = function( w,d ) {
var _garden = function( width, depth ) {
if ( typeof width == 'undefined' ) {
width = 10;
}
if ( typeof depth == 'undefined' ) {
depth = width;
}
var grass = 2,
red = 37,
yellow = 38,
longgrass = '31:1',
air = 0;
// make sure grass is present first
this.down( ).box(2,w,1,d ).up( );
this.down()
.box( grass, width, 1, depth )
.up( );
// make flowers more common than long grass
var dist = {37: 3, // red flower
38: 3, // yellow flower
'31:1': 2, // long grass
0: 1
};
return this.rand(dist,w,1,d );
var dist = { };
dist[red] = 3;
dist[yellow] = 3;
dist[longgrass] = 2;
dist[air] = 1;
return this.rand( dist, width, 1, depth, false /* don't overwrite */ );
};
var _rand = function( blockDistribution ) {
@ -1744,10 +1795,15 @@ var _rand = function( blockDistribution ) {
_fisherYates(blockDistribution );
return blockDistribution;
};
Drone.extend('rand',function( dist,w,h,d ) {
var randomized = _rand(dist );
this.boxa(randomized,w,h,d );
Drone.extend( 'rand', function( dist, width, height, depth, overwrite ) {
if ( typeof overwrite == 'undefined' ) {
overwrite = true;
}
var randomized = _rand( dist );
this.boxa( randomized, width, height, depth, overwrite);
} );
var _trees = {
oak: TreeType.BIG_TREE ,
birch: TreeType.BIRCH ,