Automatically apply correct facing metadata if missing from certain blocks. apply this metadata as properties in 1.8. (Part of work preparing for 1.8)

This commit is contained in:
walterhiggins 2014-12-30 14:54:38 +00:00
parent 63c1a69ead
commit 1a0b71f92e
12 changed files with 426 additions and 245 deletions

View file

@ -383,6 +383,7 @@ Walter Higgins
* [Drone.door2() method](#dronedoor2-method) * [Drone.door2() method](#dronedoor2-method)
* [Drone.door2_iron() method](#dronedoor2_iron-method) * [Drone.door2_iron() method](#dronedoor2_iron-method)
* [Drone.garden() method](#dronegarden-method) * [Drone.garden() method](#dronegarden-method)
* [Drone.ladder() method](#droneladder-method)
* [Drone Movement](#drone-movement) * [Drone Movement](#drone-movement)
* [Drone Positional Info](#drone-positional-info) * [Drone Positional Info](#drone-positional-info)
* [Drone Markers](#drone-markers) * [Drone Markers](#drone-markers)
@ -390,6 +391,8 @@ Walter Higgins
* [Drone.prism0() method](#droneprism0-method) * [Drone.prism0() method](#droneprism0-method)
* [Drone.rainbow() method](#dronerainbow-method) * [Drone.rainbow() method](#dronerainbow-method)
* [Drone.rand() method](#dronerand-method) * [Drone.rand() method](#dronerand-method)
* [Drone.wallsign() method](#dronewallsign-method)
* [Drone.signpost() method](#dronesignpost-method)
* [Drone.sign() method](#dronesign-method) * [Drone.sign() method](#dronesign-method)
* [Drone.sphere() method](#dronesphere-method) * [Drone.sphere() method](#dronesphere-method)
* [Drone.sphere0() method](#dronesphere0-method) * [Drone.sphere0() method](#dronesphere0-method)
@ -4113,7 +4116,7 @@ The Drone is a convenience class for building. It can be used for...
It uses a fluent interface which means all of the Drone's methods return `this` and can be chained together like so... It uses a fluent interface which means all of the Drone's methods return `this` and can be chained together like so...
var theDrone = new Drone(); var theDrone = new Drone(self);
theDrone.up().left().box(blocks.oak).down().fwd(3).cylinder0(blocks.lava,8); theDrone.up().left().box(blocks.oak).down().fwd(3).cylinder0(blocks.lava,8);
### Constructing a Drone Object ### Constructing a Drone Object
@ -4126,7 +4129,7 @@ Drones can be created in any of the following ways...
... creates a 1x1x1 wooden block at the cross-hairs or player's location and returns a Drone object. This might look odd (if you're familiar with Java's Object-dot-method syntax) but all of the Drone class's methods are also global functions that return new Drone objects. This is short-hand for creating drones and is useful for playing around with Drones at the in-game command prompt. It's shorter than typing ... ... creates a 1x1x1 wooden block at the cross-hairs or player's location and returns a Drone object. This might look odd (if you're familiar with Java's Object-dot-method syntax) but all of the Drone class's methods are also global functions that return new Drone objects. This is short-hand for creating drones and is useful for playing around with Drones at the in-game command prompt. It's shorter than typing ...
var d = new Drone().box( blocks.oak ) var d = new Drone(self).box( blocks.oak )
... All of the Drone's methods return `this` so you can chain operations together like this... ... All of the Drone's methods return `this` so you can chain operations together like this...
@ -4145,7 +4148,7 @@ Drones can be created in any of the following ways...
2. Using the following form... 2. Using the following form...
d = new Drone() d = new Drone(self)
...will create a new Drone. If the cross-hairs are pointing at a block at the time then, that block's location becomes the drone's starting point. If the cross-hairs are _not_ pointing at a block, then the drone's starting location will be 2 blocks directly in front of the player. TIP: Building always happens right and front of the drone's position... ...will create a new Drone. If the cross-hairs are pointing at a block at the time then, that block's location becomes the drone's starting point. If the cross-hairs are _not_ pointing at a block, then the drone's starting location will be 2 blocks directly in front of the player. TIP: Building always happens right and front of the drone's position...
@ -4156,9 +4159,9 @@ Drones can be created in any of the following ways...
| |
D----> D---->
For convenience you can use a _corner stone_ to begin building. The corner stone should be located just above ground level. If the cross-hair is point at or into ground level when you create a new Drone(), then building begins at that point. You can get around this by pointing at a 'corner stone' just above ground level or alternatively use the following statement... For convenience you can use a _corner stone_ to begin building. The corner stone should be located just above ground level. If the cross-hair is point at or into ground level when you create a new Drone() with either a player or location given as a parameter, then building begins at the location the player was looking at or at the location. You can get around this by pointing at a 'corner stone' just above ground level or alternatively use the following statement...
d = new Drone().up(); d = new Drone(self).up();
... which will move the drone up one block as soon as it's created. ... which will move the drone up one block as soon as it's created.
@ -4184,7 +4187,7 @@ Drones can be created in any of the following ways...
#### Parameters #### Parameters
* location (optional) : *NB* If an `org.bukkit.Location` object is provided as a parameter, then it should be the only parameter. * location (optional) : *NB* If a `Location` object is provided as a parameter, then it should be the only parameter.
* x (optional) : The x coordinate of the Drone * x (optional) : The x coordinate of the Drone
* y (optional) : The y coordinate of the Drone * y (optional) : The y coordinate of the Drone
* z (optional) : The z coordinate of the Drone * z (optional) : The z coordinate of the Drone
@ -4211,7 +4214,7 @@ To create a black structure 4 blocks wide, 9 blocks tall and 1 block long...
... or the following code does the same but creates a variable that can be used for further methods... ... or the following code does the same but creates a variable that can be used for further methods...
var drone = new Drone(); var drone = new Drone(self);
drone.box(blocks.wool.black, 4, 9, 1); drone.box(blocks.wool.black, 4, 9, 1);
![box example 1](img/boxex1.png) ![box example 1](img/boxex1.png)
@ -4562,7 +4565,7 @@ create a door - if a parameter is supplied an Iron door is created otherwise a w
To create a wooden door at the crosshairs/drone's location... To create a wooden door at the crosshairs/drone's location...
var drone = new Drone(); var drone = new Drone(self);
drone.door(); drone.door();
To create an iron door... To create an iron door...
@ -4612,6 +4615,29 @@ To create a garden 10 blocks wide by 5 blocks long...
![garden example](img/gardenex1.png) ![garden example](img/gardenex1.png)
### Drone.ladder() method
Creates a ladder extending skyward.
#### Parameters
* height (optional - default 1)
#### Example
To create a ladder extending 10 blocks high:
var drone = new Drone(self);
drone.ladder(10)
At the in-game prompt, look at a block and then type:
/js ladder(10)
A ladder 10 blocks high will be created at the point you were looking at.
#### Since
##### 3.0.3
### Drone Movement ### Drone Movement
Drones can move freely in minecraft's 3-D world. You control the Drones can move freely in minecraft's 3-D world. You control the
@ -4732,8 +4758,38 @@ to place random blocks stone has a 50% chance of being picked,
regular stone has a 50% chance, mossy stone has a 30% chance and cracked stone has just a 20% chance of being picked. regular stone has a 50% chance, mossy stone has a 30% chance and cracked stone has just a 20% chance of being picked.
### Drone.wallsign() method
Creates a wall sign (A sign attached to a wall)
#### Parameters
* message - can be a string or an array of strings
#### Example
drone.wallsign(['Welcome','to','Scriptopia']);
![wall sign](img/signex2.png)
### Drone.signpost() method
Creates a free-standing signpost
#### Parameters
* message - can be a string or an array of strings
#### Example
drone.signpost(['Hello','World']);
![ground sign](img/signex1.png)
### Drone.sign() method ### Drone.sign() method
Deprecated: Use signpost() or wallsign() methods instead.
Signs must use block 63 (stand-alone signs) or 68 (signs on walls) Signs must use block 63 (stand-alone signs) or 68 (signs on walls)
#### Parameters #### Parameters

View file

@ -1,48 +1,70 @@
'use strict'; 'use strict';
/*global module,exports,require,Packages*/ /*global module, exports, require, Packages, __plugin, server*/
var Facing = Packages.net.minecraft.util.EnumFacing; var Facing = Packages.net.minecraft.util.EnumFacing,
var DoorHalf = Packages.net.minecraft.block.BlockDoor.EnumDoorHalf; DoorHalf = Packages.net.minecraft.block.BlockDoor.EnumDoorHalf,
var HingePosition = Packages.net.minecraft.block.BlockDoor.EnumHingePosition; HingePosition = Packages.net.minecraft.block.BlockDoor.EnumHingePosition,
var DyeColor = Packages.net.minecraft.item.EnumDyeColor; DyeColor = Packages.net.minecraft.item.EnumDyeColor,
var table = { blocks = require('blocks'),
facing: [ Facing.EAST, Facing.SOUTH, Facing.WEST, Facing.NORTH], bountiful = false;
half: { upper: DoorHalf.UPPER, lower: DoorHalf.LOWER },
hinge: { left: HingePosition.LEFT, right: HingePosition.RIGHT }, if (__plugin.canary){
color: { bountiful = parseFloat(server.canaryModVersion) > 1.7;
black: DyeColor.BLACK, }
blue: DyeColor.BLUE,
brown: DyeColor.BROWN, var lookup = {};
cyan: DyeColor.CYAN, function initLookup(){
gray: DyeColor.GRAY, lookup = {
green: DyeColor.GREEN, facing: {
lightblue: DyeColor.LIGHT_BLUE, 0: Facing.EAST,
lime: DyeColor.LIME, 1: Facing.SOUTH,
magenta: DyeColor.MAGENTA, 2: Facing.WEST,
orange: DyeColor.ORANGE, 3: Facing.NORTH,
pink: DyeColor.PINK, 5: Facing.UP,
purple: DyeColor.PURPLE, east: Facing.EAST,
red: DyeColor.RED, south: Facing.SOUTH,
silver: DyeColor.SILVER, west: Facing.WEST,
white: DyeColor.WHITE, north: Facing.NORTH,
yellow: DyeColor.YELLOW, up: Facing.UP,
0: DyeColor.WHITE, down: Facing.DOWN
1: DyeColor.ORANGE, },
2: DyeColor.MAGENTA, half: { upper: DoorHalf.UPPER, lower: DoorHalf.LOWER },
3: DyeColor.LIGHT_BLUE, hinge: { left: HingePosition.LEFT, right: HingePosition.RIGHT },
4: DyeColor.YELLOW, color: {
5: DyeColor.LIME, black: DyeColor.BLACK,
6: DyeColor.PINK, blue: DyeColor.BLUE,
7: DyeColor.GRAY, brown: DyeColor.BROWN,
8: DyeColor.SILVER, cyan: DyeColor.CYAN,
9: DyeColor.CYAN, gray: DyeColor.GRAY,
10: DyeColor.PURPLE, green: DyeColor.GREEN,
11: DyeColor.BLUE, lightblue: DyeColor.LIGHT_BLUE,
12: DyeColor.BROWN, lime: DyeColor.LIME,
13: DyeColor.GREEN, magenta: DyeColor.MAGENTA,
14: DyeColor.RED, orange: DyeColor.ORANGE,
15: DyeColor.BLACK pink: DyeColor.PINK,
} purple: DyeColor.PURPLE,
}; red: DyeColor.RED,
silver: DyeColor.SILVER,
white: DyeColor.WHITE,
yellow: DyeColor.YELLOW,
0: DyeColor.WHITE,
1: DyeColor.ORANGE,
2: DyeColor.MAGENTA,
3: DyeColor.LIGHT_BLUE,
4: DyeColor.YELLOW,
5: DyeColor.LIME,
6: DyeColor.PINK,
7: DyeColor.GRAY,
8: DyeColor.SILVER,
9: DyeColor.CYAN,
10: DyeColor.PURPLE,
11: DyeColor.BLUE,
12: DyeColor.BROWN,
13: DyeColor.GREEN,
14: DyeColor.RED,
15: DyeColor.BLACK
}
};
}
function property( block ){ function property( block ){
var result; var result;
@ -57,8 +79,8 @@ function property( block ){
console.warn(block + ' has no property named ' + name); console.warn(block + ' has no property named ' + name);
return result; return result;
} }
if (table[bp.name]){ if (lookup[bp.name]){
value = table[bp.name][value]; value = lookup[bp.name][value];
} }
block.setPropertyValue(bp, value); block.setPropertyValue(bp, value);
return result; return result;
@ -67,3 +89,88 @@ function property( block ){
return result; return result;
} }
exports.property = property; exports.property = property;
/*
blocks which have facing
*/
function applyFacing( block, metadata ){
function face(direction){
property(block).set('facing', lookup.facing[direction]);
}
switch( block.typeId ){
case blocks.stairs.oak:
case blocks.stairs.cobblestone:
case blocks.stairs.brick:
case blocks.stairs.stone:
case blocks.stairs.nether:
case blocks.stairs.sandstone:
case blocks.stairs.spruce:
case blocks.stairs.jungle:
case blocks.stairs.quartz:
face( ['east','west','south','north'][metadata] );
break;
case blocks.sign:
case blocks.ladder:
// bug: furnace, chest, dispenser don't always use the right metadata
case blocks.furnace:
case blocks.furnace_burning:
case blocks.chest:
case blocks.enderchest:
case blocks.dispenser:
face( [null,null,'north','south','west','east'][metadata] );
break;
case blocks.torch:
face( ['up'/* default */,'east','west','south','north','up'][metadata] );
break;
}
}
function applyColors( block, metadata ){
switch( block.typeId){
case blocks.wool.white:
case blocks.stained_clay.white:
case blocks.stained_glass.white:
case blocks.carpet.white:
property(block).set('color',metadata);
}
}
function applyRotation( block, metadata ){
switch (block.typeId){
case blocks.sign_post:
if (metadata !== 0){
property(block).set('rotation', new Packages.java.lang.Integer(metadata));
}
}
}
function applyDoors( block, metadata ){
switch (block.typeId){
case blocks.door_wood:
case blocks.door_iron:
switch (metadata) {
case 8:
property(block).set('hinge','left');
property(block).set('half','upper');
break;
case 9:
property(block).set('hinge','right');
property(block).set('half','upper');
break;
default:
property(block).set('facing',metadata);
property(block).set('half','lower');
}
}
}
function applyProperties( block, metadata ){
if (!bountiful){
block.data = metadata;
return;
}
if (!lookup.facing){
initLookup();
}
applyFacing( block, metadata );
applyColors( block, metadata );
applyRotation( block, metadata );
applyDoors( block, metadata );
}
exports.applyProperties = applyProperties;

View file

@ -168,6 +168,20 @@ var blocks = {
dragon_egg: 122, dragon_egg: 122,
redstone_lamp: 123, redstone_lamp: 123,
redstone_lamp_active: 124, redstone_lamp_active: 124,
//http://minecraft.gamepedia.com/Data_values#Double_Stone_Slabs
double_slab: {
stone: 43,
sandstone: '43:1',
wooden: '43:2',
cobblestone: '43:3',
brick: '43:4',
stonebrick: '43:5',
netherbrick:'43:6',
quartz: '43:7',
smooth_stone: '43:8',
smooth_sandstone: '43:9',
tile_quartz: '43:15'
},
slab: { slab: {
snow: 78, snow: 78,
stone: 44, stone: 44,

View file

@ -1,5 +1,5 @@
var Drone = require('../drone').Drone; var Drone = require('../drone').Drone;
var blocks = require('blocks');
// //
// usage: // usage:
// [1] to build a cottage at the player's current location or the cross-hairs location... // [1] to build a cottage at the player's current location or the cross-hairs location...
@ -12,20 +12,22 @@ var Drone = require('../drone').Drone;
// //
function cottage( ) { function cottage( ) {
this.chkpt('cottage') this.chkpt('cottage')
.box0(48,7,2,6) // 4 walls .box0( blocks.moss_stone, 7, 2, 6) // 4 walls
.right(3) .right(3)
.door() // door front and center .door() // door front and center
.up(1) .up(1)
.left(2) .left(2)
.box(102) // windows to left and right .box( blocks.glass_pane ) // windows to left and right
.right(4) .right(4)
.box(102) .box( blocks.glass_pane )
.left(5) .left(5)
.up() .up()
.prism0(53,7,6) .prism0( blocks.stairs.oak, 7, 6)
.down() .down()
.right(4) .right(4)
.sign(['Home','Sweet','Home'],68) .back()
.wallsign(['Home','Sweet','Home'])
.fwd()
.move('cottage'); .move('cottage');
} }
// //
@ -43,7 +45,7 @@ function cottage_road( numberCottages ) {
var cottagesPerSide = Math.floor(numberCottages/2); var cottagesPerSide = Math.floor(numberCottages/2);
this this
.chkpt('cottage_road') // make sure the drone's state is saved. .chkpt('cottage_road') // make sure the drone's state is saved.
.box( 43, 3, 1, cottagesPerSide * ( distanceBetweenTrees + 1 ) ) // build the road .box( blocks.double_slab.stone, 3, 1, cottagesPerSide * ( distanceBetweenTrees + 1 ) ) // build the road
.up() .up()
.right() // now centered in middle of road .right() // now centered in middle of road
.chkpt('cr'); // will be returning to this position later .chkpt('cr'); // will be returning to this position later
@ -68,7 +70,7 @@ function cottage_road( numberCottages ) {
function pathAndCottage( drone ) { function pathAndCottage( drone ) {
drone drone
.down() .down()
.box(43,1,1,5) .box(blocks.double_slab.stone, 1, 1, 5)
.fwd(5) .fwd(5)
.left(3) .left(3)
.up() .up()
@ -88,7 +90,7 @@ function cottage_road( numberCottages ) {
pathAndCottage( this.turn() ).move( 'r' + i ); pathAndCottage( this.turn() ).move( 'r' + i );
} }
// return drone to where it was at start of function // return drone to where it was at start of function
return this.move('cottage_road'); this.move('cottage_road');
} }
Drone.extend(cottage_road); Drone.extend(cottage_road);
Drone.extend(cottage); Drone.extend(cottage);

View file

@ -4,8 +4,7 @@ var blocks = require('blocks');
// constructs a medieval fort // constructs a medieval fort
// //
function fort( side, height ) { function fort( side, height ) {
var brick = 98, var turret,
turret,
i, i,
torch, torch,
ladder; ladder;
@ -30,9 +29,12 @@ function fort( side, height ) {
// //
// build walls. // build walls.
// //
this.chkpt('fort') this
.down().chessboard(blocks.wool.black, blocks.wool.white, side).up() .chkpt('fort')
.box0(brick,side,height-1,side) .down()
.chessboard( blocks.wool.black, blocks.wool.white, side)
.up()
.box0( blocks.brick.stone, side, height - 1, side)
.up(height-1); .up(height-1);
// //
// build battlements // build battlements
@ -40,37 +42,41 @@ function fort( side, height ) {
for ( i = 0; i <= 3; i++ ) { for ( i = 0; i <= 3; i++ ) {
turret = [ turret = [
'109:'+ Drone.PLAYER_STAIRS_FACING[this.dir], blocks.stairs.stone ,
'109:'+ Drone.PLAYER_STAIRS_FACING[(this.dir+2)%4] blocks.stairs.stone + ':'+ Drone.PLAYER_STAIRS_FACING[ (this.dir + 2) % 4 ]
]; ];
this.box(brick) // solid brick corners this
.box( blocks.brick.stone ) // solid brick corners
.up() .up()
.box('50:5') .box(blocks.torch + ':5')
.down() // light a torch on each corner .down() // light a torch on each corner
.fwd() .fwd()
.boxa(turret,1,1,side-2) .boxa( turret, 1, 1, side-2)
.fwd(side-2) .fwd( side-2 )
.turn(); .turn();
} }
// //
// build battlement's floor // build battlement's floor
// //
this.move('fort') this
.move('fort')
.up(height-2) .up(height-2)
.fwd() .fwd()
.right(); .right();
for ( i = 0; i < battlementWidth; i++ ) { for ( i = 0; i < battlementWidth; i++ ) {
this.box0('126:0', side - ( 2 + (i * 2) ), 1, side - ( 2 + ( i * 2) )) this
.box0(blocks.slab.oak, side - ( 2 + (i * 2) ), 1, side - ( 2 + ( i * 2) ))
.fwd() .fwd()
.right(); .right();
} }
// //
// add door // add door
// //
torch = '50:' + Drone.PLAYER_TORCH_FACING[this.dir]; torch = blocks.torch + ':' + Drone.PLAYER_TORCH_FACING[this.dir];
this.move('fort') this
.move('fort')
.right((side/2)-1) .right((side/2)-1)
.door2() // double doors .door2() // double doors
.back() .back()
@ -82,11 +88,12 @@ function fort( side, height ) {
// //
// add ladder up to battlements // add ladder up to battlements
// //
ladder = '65:' + Drone.PLAYER_SIGN_FACING[(this.dir+2)%4]; this
this.move('fort') .move('fort')
.right((side/2)-3) .right((side/2)-3)
.fwd(1) // move inside fort .fwd(1) // move inside fort
.box(ladder, 1,height-1,1) .turn(2)
.ladder(height-1)
.move('fort'); .move('fort');
} }
Drone.extend(fort); Drone.extend(fort);

View file

@ -35,13 +35,16 @@ function spiral_stairs(stairBlock, flights){
for (var i = 0; i < flights; i++){ for (var i = 0; i < flights; i++){
this this
.box(blocks.stairs[stairBlock] + ':' + Drone.PLAYER_STAIRS_FACING[this.dir]) .box(blocks.stairs[stairBlock] )
.up().fwd() .up()
.box(blocks.stairs[stairBlock] + ':' + Drone.PLAYER_STAIRS_FACING[this.dir]) .fwd()
.up().fwd() .box(blocks.stairs[stairBlock] )
.up()
.fwd()
.box(blocks.slab[stairBlock]) .box(blocks.slab[stairBlock])
.turn().fwd(); .turn()
.fwd();
} }
return this.move('spiral_stairs'); this.move('spiral_stairs');
} }
Drone.extend(spiral_stairs); Drone.extend(spiral_stairs);

View file

@ -1,4 +1,5 @@
var Drone = require('../drone').Drone; var Drone = require('../drone').Drone;
var blocks = require('blocks');
// //
// constructs a mayan temple // constructs a mayan temple
// //
@ -6,20 +7,18 @@ function temple( side ) {
if ( !side ) { if ( !side ) {
side = 20; side = 20;
} }
var stone = '98:1';
var stair = '109:' + Drone.PLAYER_STAIRS_FACING[ this.dir ];
this.chkpt('temple'); this.chkpt('temple');
while ( side > 4 ) { while ( side > 4 ) {
var middle = Math.round( (side-2) / 2 ); var middle = Math.round( (side-2) / 2 );
this.chkpt('corner') this
.box( stone, side, 1, side ) .chkpt('temple-corner')
.box( blocks.brick.mossy, side, 1, side )
.right( middle ) .right( middle )
.box( stair ) .box( blocks.stairs.stone )
.right() .right()
.box( stair ) .box( blocks.stairs.stone )
.move('corner') .move('temple-corner')
.up() .up()
.fwd() .fwd()
.right(); .right();
@ -28,4 +27,4 @@ function temple( side ) {
this.move('temple'); this.move('temple');
} }
Drone.extend(temple); Drone.extend( temple );

View file

@ -11,7 +11,7 @@ create a door - if a parameter is supplied an Iron door is created otherwise a w
To create a wooden door at the crosshairs/drone's location... To create a wooden door at the crosshairs/drone's location...
var drone = new Drone(); var drone = new Drone(self);
drone.door(); drone.door();
To create an iron door... To create an iron door...

View file

@ -1,13 +1,9 @@
/*global __plugin, require, org, setTimeout, addUnloadHandler, exports, global, Packages*/ /*global __plugin, require, org, setTimeout, addUnloadHandler, exports, global, Packages*/
var utils = require('utils'), var utils = require('utils'),
blocks = require('blocks'), blocks = require('blocks'),
bountiful = false,
THOUSAND = 1000, THOUSAND = 1000,
MILLION = THOUSAND * THOUSAND; MILLION = THOUSAND * THOUSAND;
if (__plugin.canary){
bountiful = parseFloat(server.canaryModVersion) > 1.7;
}
/********************************************************************* /*********************************************************************
## Drone Plugin ## Drone Plugin
@ -19,7 +15,7 @@ The Drone is a convenience class for building. It can be used for...
It uses a fluent interface which means all of the Drone's methods return `this` and can be chained together like so... It uses a fluent interface which means all of the Drone's methods return `this` and can be chained together like so...
var theDrone = new Drone(); var theDrone = new Drone(self);
theDrone.up().left().box(blocks.oak).down().fwd(3).cylinder0(blocks.lava,8); theDrone.up().left().box(blocks.oak).down().fwd(3).cylinder0(blocks.lava,8);
### Constructing a Drone Object ### Constructing a Drone Object
@ -32,7 +28,7 @@ Drones can be created in any of the following ways...
... creates a 1x1x1 wooden block at the cross-hairs or player's location and returns a Drone object. This might look odd (if you're familiar with Java's Object-dot-method syntax) but all of the Drone class's methods are also global functions that return new Drone objects. This is short-hand for creating drones and is useful for playing around with Drones at the in-game command prompt. It's shorter than typing ... ... creates a 1x1x1 wooden block at the cross-hairs or player's location and returns a Drone object. This might look odd (if you're familiar with Java's Object-dot-method syntax) but all of the Drone class's methods are also global functions that return new Drone objects. This is short-hand for creating drones and is useful for playing around with Drones at the in-game command prompt. It's shorter than typing ...
var d = new Drone().box( blocks.oak ) var d = new Drone(self).box( blocks.oak )
... All of the Drone's methods return `this` so you can chain operations together like this... ... All of the Drone's methods return `this` so you can chain operations together like this...
@ -51,7 +47,7 @@ Drones can be created in any of the following ways...
2. Using the following form... 2. Using the following form...
d = new Drone() d = new Drone(self)
...will create a new Drone. If the cross-hairs are pointing at a block at the time then, that block's location becomes the drone's starting point. If the cross-hairs are _not_ pointing at a block, then the drone's starting location will be 2 blocks directly in front of the player. TIP: Building always happens right and front of the drone's position... ...will create a new Drone. If the cross-hairs are pointing at a block at the time then, that block's location becomes the drone's starting point. If the cross-hairs are _not_ pointing at a block, then the drone's starting location will be 2 blocks directly in front of the player. TIP: Building always happens right and front of the drone's position...
@ -62,9 +58,9 @@ Drones can be created in any of the following ways...
| |
D----> D---->
For convenience you can use a _corner stone_ to begin building. The corner stone should be located just above ground level. If the cross-hair is point at or into ground level when you create a new Drone(), then building begins at that point. You can get around this by pointing at a 'corner stone' just above ground level or alternatively use the following statement... For convenience you can use a _corner stone_ to begin building. The corner stone should be located just above ground level. If the cross-hair is point at or into ground level when you create a new Drone() with either a player or location given as a parameter, then building begins at the location the player was looking at or at the location. You can get around this by pointing at a 'corner stone' just above ground level or alternatively use the following statement...
d = new Drone().up(); d = new Drone(self).up();
... which will move the drone up one block as soon as it's created. ... which will move the drone up one block as soon as it's created.
@ -90,7 +86,7 @@ Drones can be created in any of the following ways...
#### Parameters #### Parameters
* location (optional) : *NB* If an `org.bukkit.Location` object is provided as a parameter, then it should be the only parameter. * location (optional) : *NB* If a `Location` object is provided as a parameter, then it should be the only parameter.
* x (optional) : The x coordinate of the Drone * x (optional) : The x coordinate of the Drone
* y (optional) : The y coordinate of the Drone * y (optional) : The y coordinate of the Drone
* z (optional) : The z coordinate of the Drone * z (optional) : The z coordinate of the Drone
@ -117,7 +113,7 @@ To create a black structure 4 blocks wide, 9 blocks tall and 1 block long...
... or the following code does the same but creates a variable that can be used for further methods... ... or the following code does the same but creates a variable that can be used for further methods...
var drone = new Drone(); var drone = new Drone(self);
drone.box(blocks.wool.black, 4, 9, 1); drone.box(blocks.wool.black, 4, 9, 1);
![box example 1](img/boxex1.png) ![box example 1](img/boxex1.png)
@ -310,114 +306,26 @@ function getDirFromRotation( location ) {
return 0; // east return 0; // east
return 1; // south return 1; // south
} }
/*
certain block-types in Minecraft 1.8 have properties which must be set. The old
data value is deprecated.
*/
function bountifulPutBlock(block, blockId, metadata, dir){
var prop = require('blockhelper').property;
var BlockType = Packages.net.canarymod.api.world.blocks.BlockType;
block.type = BlockType.fromId(blockId);
switch (blockId)
{
/*
dyed materials
*/
case blocks.wool.white:
case blocks.stained_clay.white:
case blocks.stained_glass.white:
case blocks.carpet.white:
prop(block).set('color',metadata);
block.update();
return true;
/*
torches
*/
case blocks.torch:
if (metadata >= 1 && metadata <= 4){
prop(block).set('facing', (dir + 2) % 4);
}
block.update();
return true;
/*
doors
*/
case blocks.door_wood:
case blocks.door_iron:
switch (metadata){
case 8:
prop(block).set('hinge','left');
prop(block).set('half','upper');
break;
case 9:
prop(block).set('hinge','right');
prop(block).set('half','upper');
break;
default:
prop(block).set('facing',metadata);
prop(block).set('half','lower');
}
block.update();
return true;
/*
stairs
*/
case blocks.stairs.oak:
case blocks.stairs.cobblestone:
case blocks.stairs.brick:
case blocks.stairs.stone:
case blocks.stairs.nether:
case blocks.stairs.sandstone:
case blocks.stairs.spruce:
case blocks.stairs.jungle:
case blocks.stairs.quartz:
prop(block).set('facing', dir);
block.update();
return true;
/*
ladder
*/
case blocks.ladder:
prop(block).set('facing',dir);
block.update();
return true;
/*
signs
*/
case blocks.sign:
// facing
prop(block).set('facing', (dir+2) % 4);
block.update();
return true;
case blocks.sign_post:
// rotation
if (metadata !== 0)
prop(block).set('rotation', new Packages.java.lang.Integer(metadata));
block.update();
return true;
}
return false;
}
function putBlock( x, y, z, blockId, metadata, world, dir ) { function putBlock( x, y, z, blockId, metadata, world, dir ) {
if ( typeof metadata == 'undefined' ) { if ( typeof metadata == 'undefined' ) {
metadata = 0; metadata = 0;
} }
var block = world.getBlockAt( x, y, z ), var block = world.getBlockAt( x, y, z ),
placed = false; placed = false;
if ( block.typeId != blockId || block.data != metadata ) { if (block.typeId === blockId && block.data === metadata) {
if (__plugin.canary) { return;
if ( bountiful){ }
placed = bountifulPutBlock(block, blockId, metadata, dir); if (__plugin.canary) {
} var BlockType = Packages.net.canarymod.api.world.blocks.BlockType;
if (!placed){ block.type = BlockType.fromId(blockId);
world.setBlockAt(x, y, z, blockId, metadata); var applyProperties = require('blockhelper').applyProperties;
} applyProperties(block, metadata);
} block.update();
if (__plugin.bukkit) { }
block.setTypeIdAndData( blockId, metadata, false ); if (__plugin.bukkit) {
block.data = metadata; block.setTypeIdAndData( blockId, metadata, false );
} block.data = metadata;
} }
} }
@ -657,7 +565,6 @@ Drone.prototype.setBlock = function(blockType, data, ox, oy, oz){
oz = 0; oz = 0;
putBlock(this.x + ox, this.y + oy, this.z + oz, blockType, data, this.world, this.dir); putBlock(this.x + ox, this.y + oy, this.z + oz, blockType, data, this.world, this.dir);
}; };
Drone.prototype.bountiful = bountiful;
Drone.prototype.traverseWidth = function(width, callback){ Drone.prototype.traverseWidth = function(width, callback){
_traverse[this.dir].width(this, width, callback); _traverse[this.dir].width(this, width, callback);
}; };
@ -838,36 +745,59 @@ function _getBlockIdAndMeta( b ) {
bs, bs,
md, md,
sp; sp;
if ( typeof b == 'string' ) { if (typeof b === 'number' || /^[0-9]+$/.test(b)) {
// wph 20130414 - use sensible defaults for certain blocks e.g. stairs
// should face the drone.
switch (b) {
case blocks.stairs.oak:
case blocks.stairs.cobblestone:
case blocks.stairs.brick:
case blocks.stairs.stone:
case blocks.stairs.nether:
case blocks.stairs.sandstone:
case blocks.stairs.spruce:
case blocks.stairs.jungle:
case blocks.stairs.quartz:
defaultMeta = Drone.PLAYER_STAIRS_FACING[ this.dir % 4 ];
break;
case blocks.sign:
case blocks.ladder:
// bug: furnace, chest, dispenser don't always use the right metadata
case blocks.furnace:
case blocks.furnace_burning:
case blocks.chest:
case blocks.enderchest:
case blocks.dispenser:
defaultMeta = Drone.PLAYER_SIGN_FACING[ this.dir % 4 ];
break;
case blocks.sign_post:
defaultMeta = ( 12 + ( ( this.dir + 2 ) * 4 ) ) % 16;
break;
}
return [ b, defaultMeta ];
}
if ( typeof b === 'string' ) {
bs = b; bs = b;
sp = bs.indexOf(':' ); sp = bs.indexOf(':' );
if ( sp == -1 ) { if ( sp == -1 ) {
b = parseInt(bs ); b = parseInt( bs );
// wph 20130414 - use sensible defaults for certain blocks e.g. stairs
// should face the drone.
for ( i in blocks.stairs ) {
if ( blocks.stairs[i] === b ) {
defaultMeta = Drone.PLAYER_STAIRS_FACING[this.dir];
break;
}
}
return [ b, defaultMeta ]; return [ b, defaultMeta ];
} }
b = parseInt(bs.substring(0,sp ) ); b = parseInt(bs.substring(0,sp ) );
md = parseInt(bs.substring(sp+1,bs.length ) ); md = parseInt(bs.substring(sp+1,bs.length ) );
return [b,md]; return [b,md];
}else{
// wph 20130414 - use sensible defaults for certain blocks e.g. stairs
// should face the drone.
for ( i in blocks.stairs ) {
if ( blocks.stairs[i] === b ) {
defaultMeta = Drone.PLAYER_STAIRS_FACING[this.dir];
break;
}
}
return [ b, defaultMeta ];
} }
}; if (b.id){
// wph 20141230 we are dealing with an object
var blockInfo = b;
var metadata = {};
for (i in b){
if (i !== 'id')
metadata[i] = b[i];
}
return [b.id, metadata];
}
}
var _traverse = [{},{},{},{}]; var _traverse = [{},{},{},{}];
// east // east
function walkWidthEast( drone, n,callback ) { function walkWidthEast( drone, n,callback ) {

View file

@ -0,0 +1,34 @@
'use strict';
var Drone = require('./drone').Drone;
/************************************************************************
### Drone.ladder() method
Creates a ladder extending skyward.
#### Parameters
* height (optional - default 1)
#### Example
To create a ladder extending 10 blocks high:
var drone = new Drone(self);
drone.ladder(10)
At the in-game prompt, look at a block and then type:
/js ladder(10)
A ladder 10 blocks high will be created at the point you were looking at.
#### Since
##### 3.0.3
***/
var blocks = require('blocks');
function ladder( height ){
// var metadata = Drone.PLAYER_SIGN_FACING[(this.dir+2) % 4];
// this.box( blocks.ladder + ':' + metadata, 1, height, 1);
this.box(blocks.ladder, 1, height, 1);
}
Drone.extend( ladder );

View file

@ -2,8 +2,38 @@
/*global require, echo,__plugin*/ /*global require, echo,__plugin*/
var Drone = require('./drone').Drone; var Drone = require('./drone').Drone;
/************************************************************************ /************************************************************************
### Drone.wallsign() method
Creates a wall sign (A sign attached to a wall)
#### Parameters
* message - can be a string or an array of strings
#### Example
drone.wallsign(['Welcome','to','Scriptopia']);
![wall sign](img/signex2.png)
### Drone.signpost() method
Creates a free-standing signpost
#### Parameters
* message - can be a string or an array of strings
#### Example
drone.signpost(['Hello','World']);
![ground sign](img/signex1.png)
### Drone.sign() method ### Drone.sign() method
Deprecated: Use signpost() or wallsign() methods instead.
Signs must use block 63 (stand-alone signs) or 68 (signs on walls) Signs must use block 63 (stand-alone signs) or 68 (signs on walls)
#### Parameters #### Parameters
@ -64,6 +94,12 @@ function putSign( drone, texts, blockId, meta ) {
} }
} }
}; };
function signpost( message ){
this.sign(message, 63);
}
function wallsign( message ){
this.sign(message, 68);
}
function sign( message, block ) { function sign( message, block ) {
if ( message.constructor != Array ) { if ( message.constructor != Array ) {
message = [message]; message = [message];
@ -72,25 +108,17 @@ function sign( message, block ) {
block = bm[0]; block = bm[0];
var meta = bm[1]; var meta = bm[1];
if ( block != 63 && block != 68 ) { if ( block != 63 && block != 68 ) {
var usage = 'Usage: sign("message", "63:1") or sign("message","68:1")'; var usage = 'Usage: sign("message", 63) or sign("message", 68)';
if ( this.player ) { if ( this.player ) {
echo( this.player, usage); echo( this.player, usage);
} }
console.error(usage); console.error(usage);
return; return;
} }
if ( block == 68 ) {
meta = Drone.PLAYER_SIGN_FACING[ this.dir % 4 ];
this.back();
}
if ( block == 63 ) {
meta = ( 12 + ( ( this.dir + 2 ) * 4 ) ) % 16;
}
this.then(function(){ this.then(function(){
putSign( this, message, block, meta); putSign( this, message, block, meta);
if ( block == 68 ) {
this.fwd();
}
}); });
} }
Drone.extend(sign); Drone.extend(sign);
Drone.extend(signpost);
Drone.extend(wallsign);

View file

@ -38,9 +38,10 @@ function stairs(blockType, width, height){
if (typeof height === 'undefined') if (typeof height === 'undefined')
height = 1; height = 1;
this.chkpt('_stairs'); this.chkpt('_stairs');
var bm = this._getBlockIdAndMeta(blockType);
while (height > 0) { while (height > 0) {
this.traverseWidth(width, function(){ this.traverseWidth(width, function(){
this.setBlock(blockType, Drone.PLAYER_STAIRS_FACING[this.dir]); this.setBlock(bm[0], bm[1]);
}); });
this.fwd().up(); this.fwd().up();