2014-12-28 16:07:08 +01:00
|
|
|
'use strict';
|
2015-01-03 21:57:30 +01:00
|
|
|
/*global require, __plugin, Packages, org, echo, module */
|
2015-01-01 09:39:07 +01:00
|
|
|
var blocks = require('blocks');
|
2014-12-28 16:07:08 +01:00
|
|
|
/************************************************************************
|
|
|
|
### Drone Trees methods
|
|
|
|
|
|
|
|
* oak()
|
|
|
|
* spruce()
|
|
|
|
* birch()
|
|
|
|
* jungle()
|
|
|
|
|
|
|
|
#### Example
|
|
|
|
|
|
|
|
To create 4 trees in a row, point the cross-hairs at the ground then type `/js ` and ...
|
|
|
|
|
|
|
|
up( ).oak( ).right(8 ).spruce( ).right(8 ).birch( ).right(8 ).jungle( );
|
|
|
|
|
|
|
|
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).
|
|
|
|
|
|
|
|
![tree example](img/treeex1.png)
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
***/
|
|
|
|
function bukkitTreeFactory( k, v ) {
|
|
|
|
return function( ) {
|
|
|
|
var block = this.getBlock();
|
2015-01-01 09:39:07 +01:00
|
|
|
if ( block.typeId == blocks.grass ) {
|
2014-12-28 16:07:08 +01:00
|
|
|
this.up( );
|
|
|
|
}
|
|
|
|
var treeLoc = this.getLocation();
|
|
|
|
var successful = treeLoc.world.generateTree(treeLoc,v );
|
2015-01-01 09:39:07 +01:00
|
|
|
if ( block.typeId == blocks.grass ) {
|
2014-12-28 16:07:08 +01:00
|
|
|
this.down( );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function canaryTreeFactory( k, v ){
|
|
|
|
return function(){
|
2015-01-01 09:39:07 +01:00
|
|
|
var block = this.getBlock();
|
|
|
|
if ( block.typeId == blocks.grass ) {
|
|
|
|
this.up( );
|
|
|
|
}
|
|
|
|
var treeLoc = this.getLocation();
|
|
|
|
if (!treeLoc.world.generateTree){
|
|
|
|
var msg = k + '() is not supported in this version';
|
|
|
|
if (this.player){
|
|
|
|
echo(this.player, msg);
|
|
|
|
}
|
|
|
|
console.log(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var cmTreeType = Packages.net.canarymod.api.world.TreeType;
|
|
|
|
var trees = {
|
|
|
|
oak: cmTreeType.BIGOAK,
|
|
|
|
birch: cmTreeType.BIRCH,
|
|
|
|
jungle: cmTreeType.JUNGLE,
|
|
|
|
spruce: cmTreeType.SPRUCE
|
|
|
|
};
|
|
|
|
|
|
|
|
var successful = treeLoc.world.generateTree(treeLoc, trees[k] );
|
|
|
|
if ( block.typeId == blocks.grass ) {
|
|
|
|
this.down( );
|
|
|
|
}
|
2014-12-28 16:07:08 +01:00
|
|
|
};
|
|
|
|
}
|
2015-01-03 21:57:30 +01:00
|
|
|
module.exports = function (Drone){
|
2015-01-01 09:39:07 +01:00
|
|
|
var trees = {
|
|
|
|
oak: null,
|
|
|
|
birch: null,
|
|
|
|
jungle: null,
|
|
|
|
spruce: null
|
|
|
|
};
|
|
|
|
var p;
|
|
|
|
if (__plugin.canary){
|
|
|
|
for (p in trees ) {
|
|
|
|
Drone.extend(p, canaryTreeFactory ( p, trees[p] ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (__plugin.bukkit){
|
|
|
|
var bkTreeType = org.bukkit.TreeType;
|
|
|
|
trees = {
|
|
|
|
oak: bkTreeType.BIG_TREE ,
|
|
|
|
birch: bkTreeType.BIRCH ,
|
|
|
|
jungle: bkTreeType.JUNGLE,
|
|
|
|
spruce: bkTreeType.REDWOOD
|
|
|
|
};
|
|
|
|
for (p in trees ) {
|
|
|
|
Drone.extend(p, bukkitTreeFactory ( p, trees[p] ) );
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 21:57:30 +01:00
|
|
|
};
|
|
|
|
|