minor tweaks to fort, ladder, sign and young person's guide.
This commit is contained in:
parent
964aba1278
commit
c7e2eeed85
6 changed files with 105 additions and 82 deletions
|
@ -818,7 +818,8 @@ through arrays. The following loop prints out all of the players on
|
||||||
the server...
|
the server...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var players = server.onlinePlayers;
|
var utils = require('utils');
|
||||||
|
var players = utils.players();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while ( i < players.length ) {
|
while ( i < players.length ) {
|
||||||
console.log( players[i] );
|
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
|
Let's see it in action, the following code will `console.log()` (print) the
|
||||||
name of each online player in the server console window...
|
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
|
... 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`
|
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.
|
give every player the ability to fly.
|
||||||
*/
|
*/
|
||||||
var utils = require('utils');
|
var utils = require('utils');
|
||||||
utils.foreach( server.onlinePlayers, function( player ) {
|
var players = utils.players();
|
||||||
player.setAllowFlight(true);
|
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.
|
Play a Cat's Meow sound for each player.
|
||||||
*/
|
*/
|
||||||
var utils = require('utils');
|
var utils = require('utils');
|
||||||
utils.foreach( server.onlinePlayers, function( player ) {
|
var players = utils.players();
|
||||||
player.playSound(player.location,
|
var sounds = require('sounds');
|
||||||
org.bukkit.Sound.CAT_MEOW,
|
utils.foreach( players, function( player ) {
|
||||||
1,
|
sounds.catMeow( player );
|
||||||
1);
|
|
||||||
} );
|
} );
|
||||||
```
|
```
|
||||||
|
|
||||||
### Exercise
|
### Exercise
|
||||||
Try changing the above function so that different sounds are played
|
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
|
instead of a Cat's Meow. To see all of the possible sounds that can be
|
||||||
Sound class][soundapi] to see all of the possible sounds that can be
|
played, load the sounds module at the in-game prompt using the following statement:
|
||||||
played.
|
|
||||||
|
/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
|
Loops are a key part of programming in any language. Javascript
|
||||||
provides `for` and `while` statements for looping and many javascript
|
provides `for` and `while` statements for looping and many javascript
|
||||||
|
|
30
src/docs/templates/ypgpm.md
vendored
30
src/docs/templates/ypgpm.md
vendored
|
@ -782,7 +782,8 @@ through arrays. The following loop prints out all of the players on
|
||||||
the server...
|
the server...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var players = server.onlinePlayers;
|
var utils = require('utils');
|
||||||
|
var players = utils.players();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while ( i < players.length ) {
|
while ( i < players.length ) {
|
||||||
console.log( players[i] );
|
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
|
Let's see it in action, the following code will `console.log()` (print) the
|
||||||
name of each online player in the server console window...
|
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
|
... 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`
|
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.
|
give every player the ability to fly.
|
||||||
*/
|
*/
|
||||||
var utils = require('utils');
|
var utils = require('utils');
|
||||||
utils.foreach( server.onlinePlayers, function( player ) {
|
var players = utils.players();
|
||||||
player.setAllowFlight(true);
|
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.
|
Play a Cat's Meow sound for each player.
|
||||||
*/
|
*/
|
||||||
var utils = require('utils');
|
var utils = require('utils');
|
||||||
utils.foreach( server.onlinePlayers, function( player ) {
|
var players = utils.players();
|
||||||
player.playSound(player.location,
|
var sounds = require('sounds');
|
||||||
org.bukkit.Sound.CAT_MEOW,
|
utils.foreach( players, function( player ) {
|
||||||
1,
|
sounds.catMeow( player );
|
||||||
1);
|
|
||||||
} );
|
} );
|
||||||
```
|
```
|
||||||
|
|
||||||
### Exercise
|
### Exercise
|
||||||
Try changing the above function so that different sounds are played
|
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
|
instead of a Cat's Meow. To see all of the possible sounds that can be
|
||||||
Sound class][soundapi] to see all of the possible sounds that can be
|
played, load the sounds module at the in-game prompt using the following statement:
|
||||||
played.
|
|
||||||
|
/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
|
Loops are a key part of programming in any language. Javascript
|
||||||
provides `for` and `while` statements for looping and many javascript
|
provides `for` and `while` statements for looping and many javascript
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
'use strict';
|
||||||
var Drone = require('../drone').Drone;
|
var Drone = require('../drone').Drone;
|
||||||
var blocks = require('blocks');
|
var blocks = require('blocks');
|
||||||
//
|
//
|
||||||
|
@ -6,8 +7,7 @@ var blocks = require('blocks');
|
||||||
function fort( side, height ) {
|
function fort( side, height ) {
|
||||||
var turret,
|
var turret,
|
||||||
i,
|
i,
|
||||||
torch,
|
torch;
|
||||||
ladder;
|
|
||||||
|
|
||||||
if ( typeof side == 'undefined' ) {
|
if ( typeof side == 'undefined' ) {
|
||||||
side = 18;
|
side = 18;
|
||||||
|
@ -93,6 +93,7 @@ function fort( side, height ) {
|
||||||
.right((side/2)-3)
|
.right((side/2)-3)
|
||||||
.fwd(1) // move inside fort
|
.fwd(1) // move inside fort
|
||||||
.turn(2)
|
.turn(2)
|
||||||
|
.box(blocks.air, 1, height-1, 1)
|
||||||
.ladder(height-1)
|
.ladder(height-1)
|
||||||
.move('fort');
|
.move('fort');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
/*global require, setInterval, clearInterval, __plugin, exports*/
|
||||||
/*
|
/*
|
||||||
Experimental:
|
Experimental:
|
||||||
Point at a block and issue the following ...
|
Point at a block and issue the following ...
|
||||||
|
@ -8,44 +10,20 @@
|
||||||
/js clock.stop24();
|
/js clock.stop24();
|
||||||
... stops the clock...
|
... stops the clock...
|
||||||
*/
|
*/
|
||||||
var Drone = require('../drone').Drone;
|
var Drone = require('../drone').Drone,
|
||||||
var blocktype = require('../blocktype');
|
blocktype = require('../blocktype'),
|
||||||
|
blocks = require('blocks');
|
||||||
|
|
||||||
|
|
||||||
exports.LCDClock = function(drone, fgColor,bgColor,border) {
|
exports.LCDClock = function(drone, fgColor,bgColor,border) {
|
||||||
|
|
||||||
var lastSecs = [0,0,0,0],
|
var lastSecs = [0,0,0,0],
|
||||||
world = drone.world,
|
world = drone.world,
|
||||||
intervalId = -1;
|
intervalId = -1;
|
||||||
|
|
||||||
if ( typeof bgColor == 'undefined' ) {
|
function update(secs) {
|
||||||
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) {
|
|
||||||
var digits = [0,0,0,0],
|
var digits = [0,0,0,0],
|
||||||
s = secs % 60;
|
s = secs % 60,
|
||||||
m = (secs - s) / 60;
|
m = (secs - s) / 60;
|
||||||
digits[3] = s%10;
|
digits[3] = s%10;
|
||||||
digits[2] = (s-digits[3])/10;
|
digits[2] = (s-digits[3])/10;
|
||||||
|
@ -70,6 +48,31 @@ exports.LCDClock = function(drone, fgColor,bgColor,border) {
|
||||||
lastSecs[3] = digits[3];
|
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 );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,9 @@ A ladder 10 blocks high will be created at the point you were looking at.
|
||||||
##### 3.0.3
|
##### 3.0.3
|
||||||
***/
|
***/
|
||||||
var blocks = require('blocks');
|
var blocks = require('blocks');
|
||||||
|
|
||||||
function ladder( height ){
|
function ladder( height ){
|
||||||
|
this.then(function ladderLater(){
|
||||||
var block = this.getBlock();
|
var block = this.getBlock();
|
||||||
if (block.typeId == blocks.air || block.typeId == blocks.ladder){
|
if (block.typeId == blocks.air || block.typeId == blocks.ladder){
|
||||||
this.box(blocks.ladder, 1, height, 1);
|
this.box(blocks.ladder, 1, height, 1);
|
||||||
|
@ -36,5 +38,6 @@ function ladder( height ){
|
||||||
.box(blocks.ladder, 1, height, 1)
|
.box(blocks.ladder, 1, height, 1)
|
||||||
.fwd();
|
.fwd();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Drone.extend( ladder );
|
Drone.extend( ladder );
|
||||||
|
|
|
@ -59,6 +59,7 @@ To create a free-standing sign...
|
||||||
***/
|
***/
|
||||||
function putSign( drone, texts, blockId, meta ) {
|
function putSign( drone, texts, blockId, meta ) {
|
||||||
var i,
|
var i,
|
||||||
|
len = texts.length,
|
||||||
block,
|
block,
|
||||||
state,
|
state,
|
||||||
getState,
|
getState,
|
||||||
|
@ -74,23 +75,26 @@ function putSign( drone, texts, blockId, meta ) {
|
||||||
var sign = block.getTileEntity();
|
var sign = block.getTileEntity();
|
||||||
return sign.setTextOnLine;
|
return sign.setTextOnLine;
|
||||||
};
|
};
|
||||||
setLine = function( block, i, text) {
|
setLine = function( block, i) {
|
||||||
var sign = block.getTileEntity();
|
var sign = block.getTileEntity();
|
||||||
sign.setTextOnLine( text, i );
|
sign.setTextOnLine( texts[i], i );
|
||||||
sign.update();
|
sign.update();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (__plugin.bukkit){
|
if (__plugin.bukkit){
|
||||||
isSign = function(block){ return block.state && block.state.setLine; };
|
isSign = function(block){ return block.state && block.state.setLine; };
|
||||||
setLine = function( block, i, text) {
|
setLine = function( block, i) {
|
||||||
var sign = block.state;
|
var sign = block.state;
|
||||||
sign.setLine( i, text );
|
sign.setLine( i, texts[i] );
|
||||||
sign.update(true);
|
sign.update(true);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if ( isSign(block) ) {
|
if ( isSign(block) ) {
|
||||||
for ( i = 0; i < texts.length; i++ ) {
|
if (len > 4){
|
||||||
setLine(block, i % 4, texts[ i ] );
|
len = 4;
|
||||||
|
}
|
||||||
|
for ( i = 0; i < len; i++ ) {
|
||||||
|
setLine(block, i, texts[ i ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue