line-wrap markdown comments
This commit is contained in:
parent
c9257b3038
commit
bbcdb48bef
1 changed files with 41 additions and 139 deletions
|
@ -13,8 +13,7 @@ The Drone is a convenience class for building. It can be used for...
|
||||||
1. Building
|
1. Building
|
||||||
2. Copying and Pasting
|
2. Copying and Pasting
|
||||||
|
|
||||||
It uses a fluent interface which means all of the Drone's methods return `this` and can
|
It uses a fluent interface which means all of the Drone's methods return `this` and can be chained together like so...
|
||||||
be chained together like so...
|
|
||||||
|
|
||||||
var theDrone = new Drone();
|
var theDrone = new Drone();
|
||||||
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);
|
||||||
|
@ -27,11 +26,7 @@ Drones can be created in any of the following ways...
|
||||||
|
|
||||||
var d = box( blocks.oak )
|
var d = box( blocks.oak )
|
||||||
|
|
||||||
... creates a 1x1x1 wooden block at the cross-hairs or player's location and returns a Drone
|
... 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 ...
|
||||||
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().box( blocks.oak )
|
||||||
|
|
||||||
|
@ -54,12 +49,7 @@ Drones can be created in any of the following ways...
|
||||||
|
|
||||||
d = new Drone()
|
d = new Drone()
|
||||||
|
|
||||||
...will create a new Drone. If the cross-hairs are pointing at a
|
...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...
|
||||||
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...
|
|
||||||
|
|
||||||
Plan View:
|
Plan View:
|
||||||
|
|
||||||
|
@ -68,12 +58,7 @@ Drones can be created in any of the following ways...
|
||||||
|
|
|
|
||||||
D---->
|
D---->
|
||||||
|
|
||||||
For convenience you can use a _corner stone_ to begin building.
|
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...
|
||||||
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...
|
|
||||||
|
|
||||||
d = new Drone().up();
|
d = new Drone().up();
|
||||||
|
|
||||||
|
@ -85,26 +70,15 @@ Drones can be created in any of the following ways...
|
||||||
|
|
||||||
d = new Drone(x,y,z,direction,world);
|
d = new Drone(x,y,z,direction,world);
|
||||||
|
|
||||||
This will create a new Drone at the location you specified using
|
This will create a new Drone at the location you specified using x, y, z In minecraft, the X axis runs west to east and the Z axis runs north to south. The direction parameter says what direction you want the drone to face: 0 = east, 1 = south, 2 = west, 3 = north. If the direction parameter is omitted, the player's direction is used instead. Both the `direction` and `world` parameters are optional.
|
||||||
x, y, z In minecraft, the X axis runs west to east and the Z axis runs
|
|
||||||
north to south. The direction parameter says what direction you want
|
|
||||||
the drone to face: 0 = east, 1 = south, 2 = west, 3 = north. If the
|
|
||||||
direction parameter is omitted, the player's direction is used
|
|
||||||
instead.
|
|
||||||
|
|
||||||
Both the `direction` and `world` parameters are optional.
|
|
||||||
|
|
||||||
4. Create a new Drone based on a Bukkit Location object...
|
4. Create a new Drone based on a Bukkit Location object...
|
||||||
|
|
||||||
d = new Drone(location);
|
d = new Drone(location);
|
||||||
|
|
||||||
This is useful when you want to create a drone at a given
|
This is useful when you want to create a drone at a given `org.bukkit.Location` . The `Location` class is used throughout the bukkit API. For example, if you want to create a drone when a block is broken at the block's location you would do so like this...
|
||||||
`org.bukkit.Location` . The `Location` class is used throughout
|
|
||||||
the bukkit API. For example, if you want to create a drone when a
|
|
||||||
block is broken at the block's location you would do so like
|
|
||||||
this...
|
|
||||||
|
|
||||||
events.blockBreak( function( event) {
|
events.blockBreak( function( event ) {
|
||||||
var location = event.block.location;
|
var location = event.block.location;
|
||||||
var drone = new Drone(location);
|
var drone = new Drone(location);
|
||||||
// do more stuff with the drone here...
|
// do more stuff with the drone here...
|
||||||
|
@ -126,13 +100,10 @@ the box() method is a convenience method for building things. (For the more perf
|
||||||
|
|
||||||
#### parameters
|
#### parameters
|
||||||
|
|
||||||
* b - the block id - e.g. 6 for an oak sapling or '6:2' for a birch sapling.
|
* b - the block id - e.g. 6 for an oak sapling or '6:2' for a birch sapling. Alternatively you can use any one of the `blocks` values e.g. `blocks.sapling.birch`
|
||||||
Alternatively you can use any one of the `blocks` values e.g. `blocks.sapling.birch`
|
|
||||||
* w (optional - default 1) - the width of the structure
|
* w (optional - default 1) - the width of the structure
|
||||||
* h (optional - default 1) - the height of the structure
|
* h (optional - default 1) - the height of the structure
|
||||||
* d (optional - default 1) - the depth of the structure - NB this is
|
* d (optional - default 1) - the depth of the structure - NB this is not how deep underground the structure lies - this is how far away (depth of field) from the drone the structure will extend.
|
||||||
not how deep underground the structure lies - this is how far
|
|
||||||
away (depth of field) from the drone the structure will extend.
|
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
|
@ -153,8 +124,7 @@ Another convenience method - this one creates 4 walls with no floor or ceiling.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
* block - the block id - e.g. 6 for an oak sapling or '6:2' for a birch sapling.
|
* block - the block id - e.g. 6 for an oak sapling or '6:2' for a birch sapling. Alternatively you can use any one of the `blocks` values e.g. `blocks.sapling.birch`
|
||||||
Alternatively you can use any one of the `blocks` values e.g. `blocks.sapling.birch`
|
|
||||||
* width (optional - default 1) - the width of the structure
|
* width (optional - default 1) - the width of the structure
|
||||||
* height (optional - default 1) - the height of the structure
|
* height (optional - default 1) - the height of the structure
|
||||||
* length (optional - default 1) - the length of the structure - how far
|
* length (optional - default 1) - the length of the structure - how far
|
||||||
|
@ -170,8 +140,7 @@ To create a stone building with the insided hollowed out 7 wide by 3 tall by 6 l
|
||||||
|
|
||||||
### Drone.boxa() method
|
### Drone.boxa() method
|
||||||
|
|
||||||
Construct a cuboid using an array of blocks. As the drone moves first along the width axis,
|
Construct a cuboid using an array of blocks. As the drone moves first along the width axis, then the height (y axis) then the length, each block is picked from the array and placed.
|
||||||
then the height (y axis) then the length, each block is picked from the array and placed.
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -193,8 +162,7 @@ Construct a rainbow-colored road 100 blocks long...
|
||||||
|
|
||||||
### 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 Drone's movement using any of the following methods..
|
||||||
Drone's movement using any of the following methods..
|
|
||||||
|
|
||||||
* up()
|
* up()
|
||||||
* down()
|
* down()
|
||||||
|
@ -204,16 +172,9 @@ Drone's movement using any of the following methods..
|
||||||
* back()
|
* back()
|
||||||
* turn()
|
* turn()
|
||||||
|
|
||||||
... Each of these methods takes a single optional parameter
|
... Each of these methods takes a single optional parameter `numBlocks` - the number of blocks to move in the given direction. If no parameter is given, the default is 1.
|
||||||
`numBlocks` - the number of blocks to move in the given direction. If
|
|
||||||
no parameter is given, the default is 1.
|
|
||||||
|
|
||||||
to change direction use the `turn()` method which also takes a single
|
To change direction use the `turn()` method which also takes a single optional parameter (numTurns) - the number of 90 degree turns to make. Turns are always clock-wise. If the drone is facing north, then drone.turn() will make the turn face east. If the drone is facing east then drone.turn(2) will make the drone turn twice so that it is facing west.
|
||||||
optional parameter (numTurns) - the number of 90 degree turns to make.
|
|
||||||
Turns are always clock-wise. If the drone is facing north, then
|
|
||||||
drone.turn() will make the turn face east. If the drone is facing east
|
|
||||||
then drone.turn(2) will make the drone turn twice so that it is facing
|
|
||||||
west.
|
|
||||||
|
|
||||||
### Drone Positional Info
|
### Drone Positional Info
|
||||||
|
|
||||||
|
@ -221,20 +182,14 @@ west.
|
||||||
|
|
||||||
### Drone Markers
|
### Drone Markers
|
||||||
|
|
||||||
Markers are useful when your Drone has to do a lot of work. You can
|
Markers are useful when your Drone has to do a lot of work. You can set a check-point and return to the check-point using the move() method. If your drone is about to undertake a lot of work - e.g. building a road, skyscraper or forest you should set a check-point before doing so if you want your drone to return to its current location.
|
||||||
set a check-point and return to the check-point using the move()
|
|
||||||
method. If your drone is about to undertake a lot of work -
|
|
||||||
e.g. building a road, skyscraper or forest you should set a
|
|
||||||
check-point before doing so if you want your drone to return to its
|
|
||||||
current location.
|
|
||||||
|
|
||||||
A 'start' checkpoint is automatically created when the Drone is first created.
|
A 'start' checkpoint is automatically created when the Drone is first created.
|
||||||
|
|
||||||
Markers are created and returned to using the followng two methods...
|
Markers are created and returned to using the followng two methods...
|
||||||
|
|
||||||
* chkpt - Saves the drone's current location so it can be returned to later.
|
* chkpt - Saves the drone's current location so it can be returned to later.
|
||||||
* move - moves the drone to a saved location. Alternatively you can provide an
|
* move - moves the drone to a saved location. Alternatively you can provide an org.bukkit.Location object or x,y,z and direction parameters.
|
||||||
org.bukkit.Location object or x,y,z and direction parameters.
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -260,8 +215,7 @@ Creates a prism. This is useful for roofs on houses.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
* block - the block id - e.g. 6 for an oak sapling or '6:2' for a birch sapling.
|
* block - the block id - e.g. 6 for an oak sapling or '6:2' for a birch sapling. Alternatively you can use any one of the `blocks` values e.g. `blocks.sapling.birch`
|
||||||
Alternatively you can use any one of the `blocks` values e.g. `blocks.sapling.birch`
|
|
||||||
* width - the width of the prism
|
* width - the width of the prism
|
||||||
* length - the length of the prism (will be 2 time its height)
|
* length - the length of the prism (will be 2 time its height)
|
||||||
|
|
||||||
|
@ -281,8 +235,7 @@ A convenience method for building cylinders. Building begins radius blocks to th
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
* block - the block id - e.g. 6 for an oak sapling or '6:2' for a birch sapling.
|
* block - the block id - e.g. 6 for an oak sapling or '6:2' for a birch sapling. Alternatively you can use any one of the `blocks` values e.g. `blocks.sapling.birch`
|
||||||
Alternatively you can use any one of the `blocks` values e.g. `blocks.sapling.birch`
|
|
||||||
* radius
|
* radius
|
||||||
* height
|
* height
|
||||||
|
|
||||||
|
@ -308,8 +261,7 @@ To create a hollow cylinder of Iron 7 blocks in radius and 1 block high...
|
||||||
|
|
||||||
### Drone.arc() method
|
### Drone.arc() method
|
||||||
|
|
||||||
The arc() method can be used to create 1 or more 90 degree arcs in the horizontal or vertical planes.
|
The arc() method can be used to create 1 or more 90 degree arcs in the horizontal or vertical planes. This method is called by cylinder() and cylinder0() and the sphere() and sphere0() methods.
|
||||||
This method is called by cylinder() and cylinder0() and the sphere() and sphere0() methods.
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -319,20 +271,10 @@ arc() takes a single parameter - an object with the following named properties..
|
||||||
* blockType - The type of block to use - this is the block Id only (no meta). See [Data Values][dv].
|
* blockType - The type of block to use - this is the block Id only (no meta). See [Data Values][dv].
|
||||||
* meta - The metadata value. See [Data Values][dv].
|
* meta - The metadata value. See [Data Values][dv].
|
||||||
* orientation (default: 'horizontal' ) - the orientation of the arc - can be 'vertical' or 'horizontal'.
|
* orientation (default: 'horizontal' ) - the orientation of the arc - can be 'vertical' or 'horizontal'.
|
||||||
* stack (default: 1 ) - the height or length of the arc (depending on
|
* stack (default: 1 ) - the height or length of the arc (depending on the orientation - if orientation is horizontal then this parameter refers to the height, if vertical then it refers to the length ).
|
||||||
the orientation - if orientation is horizontal then this parameter
|
* strokeWidth (default: 1 ) - the width of the stroke (how many blocks) - if drawing nested arcs it's usually a good idea to set strokeWidth to at least 2 so that there are no gaps between each arc. The arc method uses a [bresenham algorithm][bres] to plot points along the circumference.
|
||||||
refers to the height, if vertical then it refers to the length ).
|
|
||||||
* strokeWidth (default: 1 ) - the width of the stroke (how many
|
|
||||||
blocks) - if drawing nested arcs it's usually a good idea to set
|
|
||||||
strokeWidth to at least 2 so that there are no gaps between each
|
|
||||||
arc. The arc method uses a [bresenham algorithm][bres] to plot
|
|
||||||
points along the circumference.
|
|
||||||
* fill - If true (or present) then the arc will be filled in.
|
* fill - If true (or present) then the arc will be filled in.
|
||||||
* quadrants (default:
|
* quadrants (default: `{topleft:true,topright:true,bottomleft:true,bottomright:true}` - An object with 4 properties indicating which of the 4 quadrants of a circle to draw. If the quadrants property is absent then all 4 quadrants are drawn.
|
||||||
`{topleft:true,topright:true,bottomleft:true,bottomright:true}` - An
|
|
||||||
object with 4 properties indicating which of the 4 quadrants of a
|
|
||||||
circle to draw. If the quadrants property is absent then all 4
|
|
||||||
quadrants are drawn.
|
|
||||||
|
|
||||||
#### Examples
|
#### Examples
|
||||||
|
|
||||||
|
@ -435,16 +377,11 @@ To create 4 trees in a row, point the cross-hairs at the ground then type `/js `
|
||||||
|
|
||||||
up( ).oak( ).right(8 ).spruce( ).right(8 ).birch( ).right(8 ).jungle( );
|
up( ).oak( ).right(8 ).spruce( ).right(8 ).birch( ).right(8 ).jungle( );
|
||||||
|
|
||||||
Trees won't always generate unless the conditions are right. You
|
Trees won't always generate unless the conditions are right. You should use the tree methods when the drone is directly above the ground. Trees will usually grow if the drone's current location is occupied by Air and is directly above an area of grass (That is why the `up( )` method is called first).
|
||||||
should use the tree methods when the drone is directly above the
|
|
||||||
ground. Trees will usually grow if the drone's current location is
|
|
||||||
occupied by Air and is directly above an area of grass (That is why
|
|
||||||
the `up( )` method is called first).
|
|
||||||
|
|
||||||
![tree example](img/treeex1.png)
|
![tree example](img/treeex1.png)
|
||||||
|
|
||||||
None of the tree methods require parameters. Tree methods will only be successful
|
None of the tree methods require parameters. Tree methods will only be successful if the tree is placed on grass in a setting where trees can grow.
|
||||||
if the tree is placed on grass in a setting where trees can grow.
|
|
||||||
|
|
||||||
### Drone.garden() method
|
### Drone.garden() method
|
||||||
|
|
||||||
|
@ -465,8 +402,7 @@ To create a garden 10 blocks wide by 5 blocks long...
|
||||||
|
|
||||||
### Drone.rand() method
|
### Drone.rand() method
|
||||||
|
|
||||||
rand takes either an array (if each blockid has the same chance of occurring)
|
rand takes either an array (if each blockid has the same chance of occurring) or an object where each property is a blockid and the value is it's weight (an integer)
|
||||||
or an object where each property is a blockid and the value is it's weight (an integer)
|
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
|
@ -491,8 +427,7 @@ A drone can be used to copy and paste areas of the game world.
|
||||||
|
|
||||||
### Drone.copy() method
|
### Drone.copy() method
|
||||||
|
|
||||||
Copies an area so it can be pasted elsewhere. The name can be used for
|
Copies an area so it can be pasted elsewhere. The name can be used for pasting the copied area elsewhere...
|
||||||
pasting the copied area elsewhere...
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -511,9 +446,7 @@ Pastes a copied area to the current location.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
To copy a 10x5x10 area (using the drone's coordinates as the starting
|
To copy a 10x5x10 area (using the drone's coordinates as the starting point) into memory. the copied area can be referenced using the name 'somethingCool'. The drone moves 12 blocks right then pastes the copy.
|
||||||
point) into memory. the copied area can be referenced using the name
|
|
||||||
'somethingCool'. The drone moves 12 blocks right then pastes the copy.
|
|
||||||
|
|
||||||
drone.copy('somethingCool',10,5,10 )
|
drone.copy('somethingCool',10,5,10 )
|
||||||
.right(12 )
|
.right(12 )
|
||||||
|
@ -521,8 +454,7 @@ point) into memory. the copied area can be referenced using the name
|
||||||
|
|
||||||
### Chaining
|
### Chaining
|
||||||
|
|
||||||
All of the Drone methods return a Drone object, which means methods
|
All of the Drone methods return a Drone object, which means methods can be 'chained' together so instead of writing this...
|
||||||
can be 'chained' together so instead of writing this...
|
|
||||||
|
|
||||||
drone = new Drone();
|
drone = new Drone();
|
||||||
drone.fwd(3);
|
drone.fwd(3);
|
||||||
|
@ -536,17 +468,11 @@ can be 'chained' together so instead of writing this...
|
||||||
|
|
||||||
var drone = new Drone().fwd(3).left(2).box(2).up().box(2).down();
|
var drone = new Drone().fwd(3).left(2).box(2).up().box(2).down();
|
||||||
|
|
||||||
... since each Drone method is also a global function that constructs
|
... since each Drone method is also a global function that constructs a drone if none is supplied, you can shorten even further to just...
|
||||||
a drone if none is supplied, you can shorten even further to just...
|
|
||||||
|
|
||||||
fwd(3).left(2).box(2).up().box(2).down()
|
fwd(3).left(2).box(2).up().box(2).down()
|
||||||
|
|
||||||
The Drone object uses a [Fluent Interface][fl] to make ScriptCraft
|
The Drone object uses a [Fluent Interface][fl] to make ScriptCraft scripts more concise and easier to write and read. Minecraft's in-game command prompt is limited to about 80 characters so chaining drone commands together means more can be done before hitting the command prompt limit. For complex building you should save your commands in a new script file and load it using /js load()
|
||||||
scripts more concise and easier to write and read. Minecraft's
|
|
||||||
in-game command prompt is limited to about 80 characters so chaining
|
|
||||||
drone commands together means more can be done before hitting the
|
|
||||||
command prompt limit. For complex building you should save your
|
|
||||||
commands in a new script file and load it using /js load()
|
|
||||||
|
|
||||||
[fl]: http://en.wikipedia.org/wiki/Fluent_interface
|
[fl]: http://en.wikipedia.org/wiki/Fluent_interface
|
||||||
|
|
||||||
|
@ -559,8 +485,7 @@ commands in a new script file and load it using /js load()
|
||||||
|
|
||||||
### Extending Drone
|
### Extending Drone
|
||||||
|
|
||||||
The Drone object can be easily extended - new buidling recipes/blueprints can be added and can
|
The Drone object can be easily extended - new buidling recipes/blueprints can be added and can become part of a Drone's chain using the *static* method `Drone.extend`.
|
||||||
become part of a Drone's chain using the *static* method `Drone.extend`.
|
|
||||||
|
|
||||||
### Drone.extend() static method
|
### Drone.extend() static method
|
||||||
|
|
||||||
|
@ -573,7 +498,6 @@ Use this method to add new methods (which also become chainable global functions
|
||||||
|
|
||||||
Alternatively if you provide just a function as a parameter, then the function name will be used as the new method name. For example the following two approaches are both valid.
|
Alternatively if you provide just a function as a parameter, then the function name will be used as the new method name. For example the following two approaches are both valid.
|
||||||
|
|
||||||
|
|
||||||
#### Example 1 Using name and function as parameters
|
#### Example 1 Using name and function as parameters
|
||||||
|
|
||||||
// submitted by [edonaldson][edonaldson]
|
// submitted by [edonaldson][edonaldson]
|
||||||
|
@ -587,13 +511,14 @@ Alternatively if you provide just a function as a parameter, then the function n
|
||||||
|
|
||||||
#### Example 2 Using just a named function as a parameter
|
#### Example 2 Using just a named function as a parameter
|
||||||
|
|
||||||
Drone.extend(function pyramid( block,height) {
|
function pyramid( block,height) {
|
||||||
this.chkpt('pyramid');
|
this.chkpt('pyramid');
|
||||||
for ( var i = height; i > 0; i -= 2) {
|
for ( var i = height; i > 0; i -= 2) {
|
||||||
this.box(block, i, 1, i).up().right().fwd();
|
this.box(block, i, 1, i).up().right().fwd();
|
||||||
}
|
}
|
||||||
return this.move('pyramid');
|
return this.move('pyramid');
|
||||||
});
|
}
|
||||||
|
Drone.extend( pyramid );
|
||||||
|
|
||||||
Once the method is defined (it can be defined in a new pyramid.js file) it can be used like so...
|
Once the method is defined (it can be defined in a new pyramid.js file) it can be used like so...
|
||||||
|
|
||||||
|
@ -619,9 +544,7 @@ An array which can be used when constructing stairs facing in the Drone's direct
|
||||||
|
|
||||||
#### Drone.PLAYER_SIGN_FACING
|
#### Drone.PLAYER_SIGN_FACING
|
||||||
|
|
||||||
An array which can be used when placing signs so they face in a given direction.
|
An array which can be used when placing signs so they face in a given direction. This is used internally by the Drone.sign() method. It should also be used for placing any of the following blocks...
|
||||||
This is used internally by the Drone.sign() method. It should also be used for placing
|
|
||||||
any of the following blocks...
|
|
||||||
|
|
||||||
* chest
|
* chest
|
||||||
* ladder
|
* ladder
|
||||||
|
@ -830,46 +753,27 @@ Say you want to do the same thing over and over. You have a couple of options...
|
||||||
|
|
||||||
d = new Drone(); for ( var i =0;i < 4; i++) { d.cottage().right(8); }
|
d = new Drone(); for ( var i =0;i < 4; i++) { d.cottage().right(8); }
|
||||||
|
|
||||||
While this will fit on the in-game prompt, it's awkward. You need to
|
While this will fit on the in-game prompt, it's awkward. You need to declare a new Drone object first, then write a for loop to create the 4 cottages. It's also error prone, even the `for` loop is too much syntax for what should really be simple.
|
||||||
declare a new Drone object first, then write a for loop to create the
|
|
||||||
4 cottages. It's also error prone, even the `for` loop is too much
|
|
||||||
syntax for what should really be simple.
|
|
||||||
|
|
||||||
* You can use a while loop...
|
* You can use a while loop...
|
||||||
|
|
||||||
d = new Drone(); var i=4; while (i--) { d.cottage().right(8); }
|
d = new Drone(); var i=4; while (i--) { d.cottage().right(8); }
|
||||||
|
|
||||||
... which is slightly shorter but still too much syntax. Each of the
|
... which is slightly shorter but still too much syntax. Each of the above statements is fine for creating a 1-dimensional array of structures. But what if you want to create a 2-dimensional or 3-dimensional array of structures? Enter the `times()` method.
|
||||||
above statements is fine for creating a 1-dimensional array of
|
|
||||||
structures. But what if you want to create a 2-dimensional or
|
|
||||||
3-dimensional array of structures? Enter the `times()` method.
|
|
||||||
|
|
||||||
The `times()` method lets you repeat commands in a chain any number of
|
The `times()` method lets you repeat commands in a chain any number of times. So to create 4 cottages in a row you would use the following statement...
|
||||||
times. So to create 4 cottages in a row you would use the following
|
|
||||||
statement...
|
|
||||||
|
|
||||||
cottage().right(8).times(4);
|
cottage().right(8).times(4);
|
||||||
|
|
||||||
...which will build a cottage, then move right 8 blocks, then do it
|
...which will build a cottage, then move right 8 blocks, then do it again 4 times over so that at the end you will have 4 cottages in a row. What's more the `times()` method can be called more than once in a chain. So if you wanted to create a *grid* of 20 houses ( 4 x 5 ), you would do so using the following statement...
|
||||||
again 4 times over so that at the end you will have 4 cottages in a
|
|
||||||
row. What's more the `times()` method can be called more than once in
|
|
||||||
a chain. So if you wanted to create a *grid* of 20 houses ( 4 x 5 ),
|
|
||||||
you would do so using the following statement...
|
|
||||||
|
|
||||||
cottage().right(8).times(4).fwd(8).left(32).times(5);
|
cottage().right(8).times(4).fwd(8).left(32).times(5);
|
||||||
|
|
||||||
... breaking it down...
|
... breaking it down...
|
||||||
|
|
||||||
1. The first 3 calls in the chain ( `cottage()`, `right(8)`,
|
1. The first 3 calls in the chain ( `cottage()`, `right(8)`, `times(4)` ) build a single row of 4 cottages.
|
||||||
`times(4)` ) build a single row of 4 cottages.
|
|
||||||
|
|
||||||
2. The last 3 calls in the chain ( `fwd(8)`, `left(32)`, `times(5)` )
|
2. The last 3 calls in the chain ( `fwd(8)`, `left(32)`, `times(5)` ) move the drone forward 8 then left 32 blocks (4 x 8) to return to the original x coordinate, then everything in the chain is repeated again 5 times so that in the end, we have a grid of 20 cottages, 4 x 5. Normally this would require a nested loop but the `times()` method does away with the need for loops when repeating builds.
|
||||||
move the drone forward 8 then left 32 blocks (4 x 8) to return to
|
|
||||||
the original x coordinate, then everything in the chain is
|
|
||||||
repeated again 5 times so that in the end, we have a grid of 20
|
|
||||||
cottages, 4 x 5. Normally this would require a nested loop but
|
|
||||||
the `times()` method does away with the need for loops when
|
|
||||||
repeating builds.
|
|
||||||
|
|
||||||
Another example: This statement creates a row of trees 2 by 3 ...
|
Another example: This statement creates a row of trees 2 by 3 ...
|
||||||
|
|
||||||
|
@ -1914,5 +1818,3 @@ Drone.extend('cylinder', _cylinder1 );
|
||||||
// wph 20130130 - make this a method - extensions can use it.
|
// wph 20130130 - make this a method - extensions can use it.
|
||||||
//
|
//
|
||||||
Drone.prototype._getBlockIdAndMeta = _getBlockIdAndMeta;
|
Drone.prototype._getBlockIdAndMeta = _getBlockIdAndMeta;
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue