This repository has been archived on 2021-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
scriptcraft/src/main/js/plugins/drone/contrib/hangtorch.js

70 lines
1.5 KiB
JavaScript
Raw Normal View History

'use strict';
/*global require, __plugin, org*/
var Drone = require('drone'),
blocks = require('blocks');
2015-01-16 22:20:34 +01:00
/************************************************************************
### Drone.hangtorch() method
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();
```
***/
function canHang( block ) {
if (__plugin.bukkit){
2015-01-16 22:20:34 +01:00
var bkMaterial = org.bukkit.Material;
if ( block.type.equals(bkMaterial.AIR) ||
block.type.equals(bkMaterial.VINE) ) {
return true;
}
2014-02-16 19:31:09 +01:00
}
if (__plugin.canary){
if (block.typeId == blocks.air ||
2015-03-05 22:15:56 +01:00
block.typeId == blocks.vines ) {
return true;
}
}
return false;
2014-02-16 19:31:09 +01:00
}
2014-08-23 17:45:43 +02:00
function hangtorch() {
var torch = blocks.torch + ':' + Drone.PLAYER_TORCH_FACING[this.dir];
2014-02-16 19:31:09 +01:00
var moves = 0;
var block = this.getBlock();
2014-02-16 19:31:09 +01:00
while ( !canHang(block) ){
2014-02-16 19:31:09 +01:00
moves++;
this.back();
if (moves == 10){
this
.fwd(moves);
console.log('nowhere to hang torch');
2014-02-16 19:31:09 +01:00
return;
}
block = this.getBlock();
2014-02-16 19:31:09 +01:00
}
this
.box(torch)
.fwd(moves);
2014-08-23 17:45:43 +02:00
}
Drone.extend(hangtorch);