diff --git a/docs/API-Reference.md b/docs/API-Reference.md index ffc0c30..1a5626c 100644 --- a/docs/API-Reference.md +++ b/docs/API-Reference.md @@ -383,6 +383,7 @@ Walter Higgins * [Drone.door2() method](#dronedoor2-method) * [Drone.door2_iron() method](#dronedoor2_iron-method) * [Drone.garden() method](#dronegarden-method) + * [Drone.ladder() method](#droneladder-method) * [Drone Movement](#drone-movement) * [Drone Positional Info](#drone-positional-info) * [Drone Markers](#drone-markers) @@ -390,6 +391,8 @@ Walter Higgins * [Drone.prism0() method](#droneprism0-method) * [Drone.rainbow() method](#dronerainbow-method) * [Drone.rand() method](#dronerand-method) + * [Drone.wallsign() method](#dronewallsign-method) + * [Drone.signpost() method](#dronesignpost-method) * [Drone.sign() method](#dronesign-method) * [Drone.sphere() method](#dronesphere-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... - var theDrone = new Drone(); + var theDrone = new Drone(self); theDrone.up().left().box(blocks.oak).down().fwd(3).cylinder0(blocks.lava,8); ### 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 ... - 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... @@ -4145,7 +4148,7 @@ Drones can be created in any of the following ways... 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... @@ -4156,9 +4159,9 @@ Drones can be created in any of the following ways... | 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. @@ -4184,7 +4187,7 @@ Drones can be created in any of the following ways... #### 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 * y (optional) : The y 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... - var drone = new Drone(); + var drone = new Drone(self); drone.box(blocks.wool.black, 4, 9, 1); ![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... - var drone = new Drone(); + var drone = new Drone(self); drone.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) +### 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 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. +### 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 +Deprecated: Use signpost() or wallsign() methods instead. + Signs must use block 63 (stand-alone signs) or 68 (signs on walls) #### Parameters diff --git a/src/main/js/modules/blockhelper.js b/src/main/js/modules/blockhelper.js index d91f8f4..4902bc5 100644 --- a/src/main/js/modules/blockhelper.js +++ b/src/main/js/modules/blockhelper.js @@ -1,48 +1,70 @@ 'use strict'; -/*global module,exports,require,Packages*/ -var Facing = Packages.net.minecraft.util.EnumFacing; -var DoorHalf = Packages.net.minecraft.block.BlockDoor.EnumDoorHalf; -var HingePosition = Packages.net.minecraft.block.BlockDoor.EnumHingePosition; -var DyeColor = Packages.net.minecraft.item.EnumDyeColor; -var table = { - facing: [ Facing.EAST, Facing.SOUTH, Facing.WEST, Facing.NORTH], - half: { upper: DoorHalf.UPPER, lower: DoorHalf.LOWER }, - hinge: { left: HingePosition.LEFT, right: HingePosition.RIGHT }, - color: { - black: DyeColor.BLACK, - blue: DyeColor.BLUE, - brown: DyeColor.BROWN, - cyan: DyeColor.CYAN, - gray: DyeColor.GRAY, - green: DyeColor.GREEN, - lightblue: DyeColor.LIGHT_BLUE, - lime: DyeColor.LIME, - magenta: DyeColor.MAGENTA, - orange: DyeColor.ORANGE, - 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 - } -}; +/*global module, exports, require, Packages, __plugin, server*/ +var Facing = Packages.net.minecraft.util.EnumFacing, + DoorHalf = Packages.net.minecraft.block.BlockDoor.EnumDoorHalf, + HingePosition = Packages.net.minecraft.block.BlockDoor.EnumHingePosition, + DyeColor = Packages.net.minecraft.item.EnumDyeColor, + blocks = require('blocks'), + bountiful = false; + +if (__plugin.canary){ + bountiful = parseFloat(server.canaryModVersion) > 1.7; +} + +var lookup = {}; +function initLookup(){ + lookup = { + facing: { + 0: Facing.EAST, + 1: Facing.SOUTH, + 2: Facing.WEST, + 3: Facing.NORTH, + 5: Facing.UP, + east: Facing.EAST, + south: Facing.SOUTH, + west: Facing.WEST, + north: Facing.NORTH, + up: Facing.UP, + down: Facing.DOWN + }, + half: { upper: DoorHalf.UPPER, lower: DoorHalf.LOWER }, + hinge: { left: HingePosition.LEFT, right: HingePosition.RIGHT }, + color: { + black: DyeColor.BLACK, + blue: DyeColor.BLUE, + brown: DyeColor.BROWN, + cyan: DyeColor.CYAN, + gray: DyeColor.GRAY, + green: DyeColor.GREEN, + lightblue: DyeColor.LIGHT_BLUE, + lime: DyeColor.LIME, + magenta: DyeColor.MAGENTA, + orange: DyeColor.ORANGE, + 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 ){ var result; @@ -57,8 +79,8 @@ function property( block ){ console.warn(block + ' has no property named ' + name); return result; } - if (table[bp.name]){ - value = table[bp.name][value]; + if (lookup[bp.name]){ + value = lookup[bp.name][value]; } block.setPropertyValue(bp, value); return result; @@ -67,3 +89,88 @@ function property( block ){ return result; } 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; diff --git a/src/main/js/modules/blocks.js b/src/main/js/modules/blocks.js index fbf7bf4..9cd6668 100644 --- a/src/main/js/modules/blocks.js +++ b/src/main/js/modules/blocks.js @@ -168,6 +168,20 @@ var blocks = { dragon_egg: 122, redstone_lamp: 123, 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: { snow: 78, stone: 44, diff --git a/src/main/js/plugins/drone/contrib/cottage.js b/src/main/js/plugins/drone/contrib/cottage.js index 15f62d1..d5d7fa6 100644 --- a/src/main/js/plugins/drone/contrib/cottage.js +++ b/src/main/js/plugins/drone/contrib/cottage.js @@ -1,5 +1,5 @@ var Drone = require('../drone').Drone; - +var blocks = require('blocks'); // // usage: // [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( ) { this.chkpt('cottage') - .box0(48,7,2,6) // 4 walls + .box0( blocks.moss_stone, 7, 2, 6) // 4 walls .right(3) .door() // door front and center .up(1) .left(2) - .box(102) // windows to left and right + .box( blocks.glass_pane ) // windows to left and right .right(4) - .box(102) + .box( blocks.glass_pane ) .left(5) .up() - .prism0(53,7,6) + .prism0( blocks.stairs.oak, 7, 6) .down() .right(4) - .sign(['Home','Sweet','Home'],68) + .back() + .wallsign(['Home','Sweet','Home']) + .fwd() .move('cottage'); } // @@ -43,7 +45,7 @@ function cottage_road( numberCottages ) { var cottagesPerSide = Math.floor(numberCottages/2); this .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() .right() // now centered in middle of road .chkpt('cr'); // will be returning to this position later @@ -68,7 +70,7 @@ function cottage_road( numberCottages ) { function pathAndCottage( drone ) { drone .down() - .box(43,1,1,5) + .box(blocks.double_slab.stone, 1, 1, 5) .fwd(5) .left(3) .up() @@ -88,7 +90,7 @@ function cottage_road( numberCottages ) { pathAndCottage( this.turn() ).move( 'r' + i ); } // 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); diff --git a/src/main/js/plugins/drone/contrib/fort.js b/src/main/js/plugins/drone/contrib/fort.js index 5e5782a..22083d9 100644 --- a/src/main/js/plugins/drone/contrib/fort.js +++ b/src/main/js/plugins/drone/contrib/fort.js @@ -4,8 +4,7 @@ var blocks = require('blocks'); // constructs a medieval fort // function fort( side, height ) { - var brick = 98, - turret, + var turret, i, torch, ladder; @@ -30,9 +29,12 @@ function fort( side, height ) { // // build walls. // - this.chkpt('fort') - .down().chessboard(blocks.wool.black, blocks.wool.white, side).up() - .box0(brick,side,height-1,side) + this + .chkpt('fort') + .down() + .chessboard( blocks.wool.black, blocks.wool.white, side) + .up() + .box0( blocks.brick.stone, side, height - 1, side) .up(height-1); // // build battlements @@ -40,37 +42,41 @@ function fort( side, height ) { for ( i = 0; i <= 3; i++ ) { turret = [ - '109:'+ Drone.PLAYER_STAIRS_FACING[this.dir], - '109:'+ Drone.PLAYER_STAIRS_FACING[(this.dir+2)%4] + blocks.stairs.stone , + 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() - .box('50:5') + .box(blocks.torch + ':5') .down() // light a torch on each corner .fwd() - .boxa(turret,1,1,side-2) - .fwd(side-2) + .boxa( turret, 1, 1, side-2) + .fwd( side-2 ) .turn(); } // // build battlement's floor // - this.move('fort') + 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) )) + this + .box0(blocks.slab.oak, side - ( 2 + (i * 2) ), 1, side - ( 2 + ( i * 2) )) .fwd() .right(); } // // add door // - torch = '50:' + Drone.PLAYER_TORCH_FACING[this.dir]; - this.move('fort') + torch = blocks.torch + ':' + Drone.PLAYER_TORCH_FACING[this.dir]; + this + .move('fort') .right((side/2)-1) .door2() // double doors .back() @@ -82,11 +88,12 @@ function fort( side, height ) { // // add ladder up to battlements // - ladder = '65:' + Drone.PLAYER_SIGN_FACING[(this.dir+2)%4]; - this.move('fort') + this + .move('fort') .right((side/2)-3) .fwd(1) // move inside fort - .box(ladder, 1,height-1,1) + .turn(2) + .ladder(height-1) .move('fort'); } Drone.extend(fort); diff --git a/src/main/js/plugins/drone/contrib/spiral_stairs.js b/src/main/js/plugins/drone/contrib/spiral_stairs.js index 43e4f9d..7f52b14 100644 --- a/src/main/js/plugins/drone/contrib/spiral_stairs.js +++ b/src/main/js/plugins/drone/contrib/spiral_stairs.js @@ -35,13 +35,16 @@ function spiral_stairs(stairBlock, flights){ for (var i = 0; i < flights; i++){ this - .box(blocks.stairs[stairBlock] + ':' + Drone.PLAYER_STAIRS_FACING[this.dir]) - .up().fwd() - .box(blocks.stairs[stairBlock] + ':' + Drone.PLAYER_STAIRS_FACING[this.dir]) - .up().fwd() + .box(blocks.stairs[stairBlock] ) + .up() + .fwd() + .box(blocks.stairs[stairBlock] ) + .up() + .fwd() .box(blocks.slab[stairBlock]) - .turn().fwd(); + .turn() + .fwd(); } - return this.move('spiral_stairs'); + this.move('spiral_stairs'); } Drone.extend(spiral_stairs); diff --git a/src/main/js/plugins/drone/contrib/temple.js b/src/main/js/plugins/drone/contrib/temple.js index 0597e0a..a04b197 100644 --- a/src/main/js/plugins/drone/contrib/temple.js +++ b/src/main/js/plugins/drone/contrib/temple.js @@ -1,4 +1,5 @@ var Drone = require('../drone').Drone; +var blocks = require('blocks'); // // constructs a mayan temple // @@ -6,20 +7,18 @@ function temple( side ) { if ( !side ) { side = 20; } - var stone = '98:1'; - var stair = '109:' + Drone.PLAYER_STAIRS_FACING[ this.dir ]; - this.chkpt('temple'); while ( side > 4 ) { var middle = Math.round( (side-2) / 2 ); - this.chkpt('corner') - .box( stone, side, 1, side ) + this + .chkpt('temple-corner') + .box( blocks.brick.mossy, side, 1, side ) .right( middle ) - .box( stair ) + .box( blocks.stairs.stone ) .right() - .box( stair ) - .move('corner') + .box( blocks.stairs.stone ) + .move('temple-corner') .up() .fwd() .right(); @@ -28,4 +27,4 @@ function temple( side ) { this.move('temple'); } -Drone.extend(temple); +Drone.extend( temple ); diff --git a/src/main/js/plugins/drone/doors.js b/src/main/js/plugins/drone/doors.js index d269b86..ed56db1 100644 --- a/src/main/js/plugins/drone/doors.js +++ b/src/main/js/plugins/drone/doors.js @@ -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... - var drone = new Drone(); + var drone = new Drone(self); drone.door(); To create an iron door... diff --git a/src/main/js/plugins/drone/drone.js b/src/main/js/plugins/drone/drone.js index 17e0947..be4a2eb 100644 --- a/src/main/js/plugins/drone/drone.js +++ b/src/main/js/plugins/drone/drone.js @@ -1,13 +1,9 @@ /*global __plugin, require, org, setTimeout, addUnloadHandler, exports, global, Packages*/ var utils = require('utils'), blocks = require('blocks'), - bountiful = false, THOUSAND = 1000, MILLION = THOUSAND * THOUSAND; -if (__plugin.canary){ - bountiful = parseFloat(server.canaryModVersion) > 1.7; -} /********************************************************************* ## 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... - var theDrone = new Drone(); + var theDrone = new Drone(self); theDrone.up().left().box(blocks.oak).down().fwd(3).cylinder0(blocks.lava,8); ### 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 ... - 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... @@ -51,7 +47,7 @@ Drones can be created in any of the following ways... 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... @@ -62,9 +58,9 @@ Drones can be created in any of the following ways... | 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. @@ -90,7 +86,7 @@ Drones can be created in any of the following ways... #### 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 * y (optional) : The y 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... - var drone = new Drone(); + var drone = new Drone(self); drone.box(blocks.wool.black, 4, 9, 1); ![box example 1](img/boxex1.png) @@ -310,114 +306,26 @@ function getDirFromRotation( location ) { return 0; // east 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 ) { if ( typeof metadata == 'undefined' ) { metadata = 0; } var block = world.getBlockAt( x, y, z ), placed = false; - - if ( block.typeId != blockId || block.data != metadata ) { - if (__plugin.canary) { - if ( bountiful){ - placed = bountifulPutBlock(block, blockId, metadata, dir); - } - if (!placed){ - world.setBlockAt(x, y, z, blockId, metadata); - } - } - if (__plugin.bukkit) { - block.setTypeIdAndData( blockId, metadata, false ); - block.data = metadata; - } + + if (block.typeId === blockId && block.data === metadata) { + return; + } + if (__plugin.canary) { + var BlockType = Packages.net.canarymod.api.world.blocks.BlockType; + block.type = BlockType.fromId(blockId); + var applyProperties = require('blockhelper').applyProperties; + applyProperties(block, metadata); + block.update(); + } + if (__plugin.bukkit) { + block.setTypeIdAndData( blockId, metadata, false ); + block.data = metadata; } } @@ -657,7 +565,6 @@ Drone.prototype.setBlock = function(blockType, data, ox, oy, oz){ oz = 0; 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){ _traverse[this.dir].width(this, width, callback); }; @@ -838,36 +745,59 @@ function _getBlockIdAndMeta( b ) { bs, md, 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; sp = bs.indexOf(':' ); if ( sp == -1 ) { - 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; - } - } + b = parseInt( bs ); return [ b, defaultMeta ]; } b = parseInt(bs.substring(0,sp ) ); md = parseInt(bs.substring(sp+1,bs.length ) ); 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 = [{},{},{},{}]; // east function walkWidthEast( drone, n,callback ) { diff --git a/src/main/js/plugins/drone/ladder.js b/src/main/js/plugins/drone/ladder.js new file mode 100644 index 0000000..1116782 --- /dev/null +++ b/src/main/js/plugins/drone/ladder.js @@ -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 ); diff --git a/src/main/js/plugins/drone/sign.js b/src/main/js/plugins/drone/sign.js index 4db25c2..03659e1 100644 --- a/src/main/js/plugins/drone/sign.js +++ b/src/main/js/plugins/drone/sign.js @@ -2,8 +2,38 @@ /*global require, echo,__plugin*/ 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 +Deprecated: Use signpost() or wallsign() methods instead. + Signs must use block 63 (stand-alone signs) or 68 (signs on walls) #### 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 ) { if ( message.constructor != Array ) { message = [message]; @@ -72,25 +108,17 @@ function sign( message, block ) { block = bm[0]; var meta = bm[1]; 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 ) { echo( this.player, usage); } console.error(usage); 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(){ - putSign( this, message, block, meta); - if ( block == 68 ) { - this.fwd(); - } + putSign( this, message, block, meta); }); } Drone.extend(sign); +Drone.extend(signpost); +Drone.extend(wallsign); diff --git a/src/main/js/plugins/drone/stairs.js b/src/main/js/plugins/drone/stairs.js index e1f3621..7aa9fd4 100644 --- a/src/main/js/plugins/drone/stairs.js +++ b/src/main/js/plugins/drone/stairs.js @@ -38,9 +38,10 @@ function stairs(blockType, width, height){ if (typeof height === 'undefined') height = 1; this.chkpt('_stairs'); + var bm = this._getBlockIdAndMeta(blockType); while (height > 0) { this.traverseWidth(width, function(){ - this.setBlock(blockType, Drone.PLAYER_STAIRS_FACING[this.dir]); + this.setBlock(bm[0], bm[1]); }); this.fwd().up();