2014-12-28 16:07:08 +01:00
|
|
|
'use strict';
|
|
|
|
/*global require, __plugin, org*/
|
2015-01-03 21:57:30 +01:00
|
|
|
var Drone = require('drone'),
|
2014-12-28 16:07:08 +01:00
|
|
|
blocks = require('blocks');
|
2015-01-16 22:20:34 +01:00
|
|
|
/************************************************************************
|
|
|
|
### Drone.hangtorch() method
|
2014-02-19 23:17:19 +01:00
|
|
|
|
2015-01-16 22:20:34 +01:00
|
|
|
Adds a hanging torch to a wall. This method will try to hang a torch
|
|
|
|
against a wall. It will traverse backwards until it finds a block
|
|
|
|
adjacent to air and hang the torch. If it can't find a block next to
|
|
|
|
air it will log a message in the server.
|
|
|
|
|
|
|
|
#### Example
|
|
|
|
|
|
|
|
At the in-game prompt you can create a hanging torch by looking at a
|
|
|
|
block and typing:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
/js hangtorch()
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively you can create a new Drone object from a Player or
|
|
|
|
Location object and call the hangtorch() method.
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
var d = new Drone(player);
|
|
|
|
d.hangtorch();
|
|
|
|
```
|
|
|
|
|
|
|
|
***/
|
2014-12-28 16:07:08 +01:00
|
|
|
function canHang( block ) {
|
2014-02-19 23:17:19 +01:00
|
|
|
|
2014-12-28 16:07:08 +01:00
|
|
|
if (__plugin.bukkit){
|
2015-01-16 22:20:34 +01:00
|
|
|
var bkMaterial = org.bukkit.Material;
|
2014-12-28 16:07:08 +01:00
|
|
|
if ( block.type.equals(bkMaterial.AIR) ||
|
|
|
|
block.type.equals(bkMaterial.VINE) ) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-16 19:31:09 +01:00
|
|
|
}
|
2014-12-28 16:07:08 +01:00
|
|
|
if (__plugin.canary){
|
|
|
|
if (block.typeId == blocks.air ||
|
2015-03-05 22:15:56 +01:00
|
|
|
block.typeId == blocks.vines ) {
|
2014-12-28 16:07:08 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-02-16 19:31:09 +01:00
|
|
|
}
|
2014-08-23 17:45:43 +02:00
|
|
|
function hangtorch() {
|
2015-01-03 21:57:30 +01:00
|
|
|
var torch = blocks.torch + ':' + Drone.PLAYER_TORCH_FACING[this.dir];
|
2014-02-16 19:31:09 +01:00
|
|
|
var moves = 0;
|
2014-12-28 16:07:08 +01:00
|
|
|
var block = this.getBlock();
|
2014-02-16 19:31:09 +01:00
|
|
|
|
2014-12-28 16:07:08 +01:00
|
|
|
while ( !canHang(block) ){
|
2014-02-16 19:31:09 +01:00
|
|
|
|
|
|
|
moves++;
|
|
|
|
this.back();
|
|
|
|
if (moves == 10){
|
2014-12-28 16:07:08 +01:00
|
|
|
this
|
|
|
|
.fwd(moves);
|
2014-02-19 01:15:44 +01:00
|
|
|
console.log('nowhere to hang torch');
|
2014-02-16 19:31:09 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-12-28 16:07:08 +01:00
|
|
|
block = this.getBlock();
|
2014-02-16 19:31:09 +01:00
|
|
|
}
|
2014-12-28 16:07:08 +01:00
|
|
|
this
|
|
|
|
.box(torch)
|
2014-02-19 01:15:44 +01:00
|
|
|
.fwd(moves);
|
2014-08-23 17:45:43 +02:00
|
|
|
}
|
|
|
|
Drone.extend(hangtorch);
|