minor tweaks to fort, ladder, sign and young person's guide.

This commit is contained in:
walterhiggins 2015-01-03 09:50:37 +00:00
parent 964aba1278
commit c7e2eeed85
6 changed files with 105 additions and 82 deletions

View file

@ -818,7 +818,8 @@ through arrays. The following loop prints out all of the players on
the server...
```javascript
var players = server.onlinePlayers;
var utils = require('utils');
var players = utils.players();
var i = 0;
while ( i < players.length ) {
console.log( players[i] );
@ -847,7 +848,9 @@ loops. utils.foreach() takes two parameters...
Let's see it in action, the following code will `console.log()` (print) the
name of each online player in the server console window...
utils.foreach( server.onlinePlayers, console.log );
var utils = require('utils');
var players = utils.players;
utils.foreach( players, console.log );
... in the above example, the list of online players is processed one
at a time and each item (player) is passed to the `console.log`
@ -863,8 +866,9 @@ utils.foreach() function...
give every player the ability to fly.
*/
var utils = require('utils');
utils.foreach( server.onlinePlayers, function( player ) {
player.setAllowFlight(true);
var players = utils.players();
utils.foreach( players, function( player ) {
player.capabilities.setMayFly(true);
} );
```
@ -875,19 +879,21 @@ utils.foreach( server.onlinePlayers, function( player ) {
Play a Cat's Meow sound for each player.
*/
var utils = require('utils');
utils.foreach( server.onlinePlayers, function( player ) {
player.playSound(player.location,
org.bukkit.Sound.CAT_MEOW,
1,
1);
var players = utils.players();
var sounds = require('sounds');
utils.foreach( players, function( player ) {
sounds.catMeow( player );
} );
```
### Exercise
Try changing the above function so that different sounds are played
instead of a Cat's Meow. You'll need to lookup the [CanaryMod API's
Sound class][soundapi] to see all of the possible sounds that can be
played.
instead of a Cat's Meow. To see all of the possible sounds that can be
played, load the sounds module at the in-game prompt using the following statement:
/js var sounds = require('sounds');
... then type `/js sounds.` and press the TAB key to see a list of all possible sounds.
Loops are a key part of programming in any language. Javascript
provides `for` and `while` statements for looping and many javascript

View file

@ -782,7 +782,8 @@ through arrays. The following loop prints out all of the players on
the server...
```javascript
var players = server.onlinePlayers;
var utils = require('utils');
var players = utils.players();
var i = 0;
while ( i < players.length ) {
console.log( players[i] );
@ -811,7 +812,9 @@ loops. utils.foreach() takes two parameters...
Let's see it in action, the following code will `console.log()` (print) the
name of each online player in the server console window...
utils.foreach( server.onlinePlayers, console.log );
var utils = require('utils');
var players = utils.players;
utils.foreach( players, console.log );
... in the above example, the list of online players is processed one
at a time and each item (player) is passed to the `console.log`
@ -827,8 +830,9 @@ utils.foreach() function...
give every player the ability to fly.
*/
var utils = require('utils');
utils.foreach( server.onlinePlayers, function( player ) {
player.setAllowFlight(true);
var players = utils.players();
utils.foreach( players, function( player ) {
player.capabilities.setMayFly(true);
} );
```
@ -839,19 +843,21 @@ utils.foreach( server.onlinePlayers, function( player ) {
Play a Cat's Meow sound for each player.
*/
var utils = require('utils');
utils.foreach( server.onlinePlayers, function( player ) {
player.playSound(player.location,
org.bukkit.Sound.CAT_MEOW,
1,
1);
var players = utils.players();
var sounds = require('sounds');
utils.foreach( players, function( player ) {
sounds.catMeow( player );
} );
```
### Exercise
Try changing the above function so that different sounds are played
instead of a Cat's Meow. You'll need to lookup the [CanaryMod API's
Sound class][soundapi] to see all of the possible sounds that can be
played.
instead of a Cat's Meow. To see all of the possible sounds that can be
played, load the sounds module at the in-game prompt using the following statement:
/js var sounds = require('sounds');
... then type `/js sounds.` and press the TAB key to see a list of all possible sounds.
Loops are a key part of programming in any language. Javascript
provides `for` and `while` statements for looping and many javascript

View file

@ -1,3 +1,4 @@
'use strict';
var Drone = require('../drone').Drone;
var blocks = require('blocks');
//
@ -6,8 +7,7 @@ var blocks = require('blocks');
function fort( side, height ) {
var turret,
i,
torch,
ladder;
torch;
if ( typeof side == 'undefined' ) {
side = 18;
@ -93,6 +93,7 @@ function fort( side, height ) {
.right((side/2)-3)
.fwd(1) // move inside fort
.turn(2)
.box(blocks.air, 1, height-1, 1)
.ladder(height-1)
.move('fort');
}

View file

@ -1,3 +1,5 @@
'use strict';
/*global require, setInterval, clearInterval, __plugin, exports*/
/*
Experimental:
Point at a block and issue the following ...
@ -8,44 +10,20 @@
/js clock.stop24();
... stops the clock...
*/
var Drone = require('../drone').Drone;
var blocktype = require('../blocktype');
var Drone = require('../drone').Drone,
blocktype = require('../blocktype'),
blocks = require('blocks');
exports.LCDClock = function(drone, fgColor,bgColor,border) {
var lastSecs = [0,0,0,0],
world = drone.world,
intervalId = -1;
if ( typeof bgColor == 'undefined' ) {
bgColor = '35:15'; // black wool
}
if ( typeof fgColor == 'undefined' ) {
fgColor = 35 ; // white wool
}
if ( border ) {
drone.box(border,21,9,1);
drone.up().right();
}
drone.blocktype('00:00',fgColor,bgColor);
return {
start24: function( ) {
var clock = this;
function tick() {
var rolloverMins = 24*60;
var timeOfDayInMins = Math.floor(((world.totalTime + 6000) % 24000) / 16.6667);
timeOfDayInMins = timeOfDayInMins % rolloverMins;
console.log('Minecraft time: ' + world.totalTime + ' timeOfDayInMins: ' + timeOfDayInMins);
clock.update(timeOfDayInMins);
};
intervalId = setInterval(tick, 800);
},
stop24: function() {
clearInterval( intervalId );
},
update: function(secs) {
function update(secs) {
var digits = [0,0,0,0],
s = secs % 60;
s = secs % 60,
m = (secs - s) / 60;
digits[3] = s%10;
digits[2] = (s-digits[3])/10;
@ -70,6 +48,31 @@ exports.LCDClock = function(drone, fgColor,bgColor,border) {
lastSecs[3] = digits[3];
}
if ( typeof bgColor == 'undefined' ) {
bgColor = blocks.wool.black;
}
if ( typeof fgColor == 'undefined' ) {
fgColor = blocks.wool.white ; // white wool
}
if ( border ) {
drone.box(border,21,9,1);
drone.up().right();
}
drone.blocktype('00:00', fgColor, bgColor);
return {
start24: function( ) {
function tick() {
var rolloverMins = 24*60,
mcTime = __plugin.canary ? world.totalTime : world.time,
timeOfDayInMins = Math.floor(((mcTime + 6000) % 24000) / 16.6667);
timeOfDayInMins = timeOfDayInMins % rolloverMins;
update( timeOfDayInMins );
};
intervalId = setInterval(tick, 800);
},
stop24: function() {
clearInterval( intervalId );
}
};
};

View file

@ -26,7 +26,9 @@ A ladder 10 blocks high will be created at the point you were looking at.
##### 3.0.3
***/
var blocks = require('blocks');
function ladder( height ){
this.then(function ladderLater(){
var block = this.getBlock();
if (block.typeId == blocks.air || block.typeId == blocks.ladder){
this.box(blocks.ladder, 1, height, 1);
@ -36,5 +38,6 @@ function ladder( height ){
.box(blocks.ladder, 1, height, 1)
.fwd();
}
});
}
Drone.extend( ladder );

View file

@ -59,6 +59,7 @@ To create a free-standing sign...
***/
function putSign( drone, texts, blockId, meta ) {
var i,
len = texts.length,
block,
state,
getState,
@ -74,23 +75,26 @@ function putSign( drone, texts, blockId, meta ) {
var sign = block.getTileEntity();
return sign.setTextOnLine;
};
setLine = function( block, i, text) {
setLine = function( block, i) {
var sign = block.getTileEntity();
sign.setTextOnLine( text, i );
sign.setTextOnLine( texts[i], i );
sign.update();
};
}
if (__plugin.bukkit){
isSign = function(block){ return block.state && block.state.setLine; };
setLine = function( block, i, text) {
setLine = function( block, i) {
var sign = block.state;
sign.setLine( i, text );
sign.setLine( i, texts[i] );
sign.update(true);
};
}
if ( isSign(block) ) {
for ( i = 0; i < texts.length; i++ ) {
setLine(block, i % 4, texts[ i ] );
if (len > 4){
len = 4;
}
for ( i = 0; i < len; i++ ) {
setLine(block, i, texts[ i ] );
}
}
};