Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
walterhiggins / trampoline.js
Last active August 29, 2015 14:15
Trampoline Version 1
/*global require, events */
var blocks = require('blocks'),
sounds = require('sounds');
function bounceOn___(event){
var player = event.player;
var bounce = 0.75;
var location = player.location;
// need to convert coordinates to integers
var x = Math.floor(location.x);
var Drone = require('drone');
var blocks = require('blocks');
function skyscraper( floors ) {
var i = 0;
if ( typeof floors == 'undefined' ) {
floors = 10;
}
this.chkpt('skyscraper');
for ( i = 0; i < floors; i++ ) {
this
var sounds = require('sounds');
function howl(event){
sounds.wolfHowl(event.block);
}
events.blockDestroy(howl);
var inventory = require('inventory'),
items = require('items'),
utils = require('utils');
function giveCookie(player){
inventory(player).add( items.cookie(1) )
}
utils.players(giveCookie);
var teleport = require('teleport'),
arrowsport = {},
handler;
function onArrowHit( event ) {
var projectile = event.projectile,
shooter = projectile.owner,
cmArrow = Packages.net.canarymod.api.entity.Arrow,
cmPlayer = Packages.net.canarymod.api.entity.living.humanoid.Player,
@walterhiggins
walterhiggins / nashorn-macos-1.8.0_40.md
Last active August 29, 2015 14:22
Nashorn class cast exception for vararg method params
@walterhiggins
walterhiggins / writing-minecraft-plugins-errata.md
Last active May 15, 2016 19:01
Writing Minecraft Plugins: Errata

A Beginner's Guide to Writing Minecraft Plugins: Errata

Introduction

This is list of errors and their corrections that were found after the book was published. This document is a work in progress. If you find additional mistakes in the book please email walter.higgins@gmail.com.

Chapter 7

Page 84, Listing 7.3

The following code is listed with no explanation of the === operator and how it differs from the == operator which is explained in Chapter 3 (Comparing numbers):

/*
testing a forgetful memoized promise: A promise, memoized which is forgotten after a given duration.
*/
var Q = require('q');
var _ = require('underscore');
function expensive( req ){
var result = Q.defer();
var msg = JSON.stringify(req);
console.log(new Date() + ' about to do something expensive: ' + msg);

Some notes on the ScriptCraft Workshop for CoderDojo@IBM

There were some very good ideas for improvements and additions. One attendee wondered if it was possible to populate buildings as they were built. I thought I'd already written a spawn module to do this but it turns out I hadn't. I've just added a spawn module to version 3.1.11 which is out today (21st Nov 2015). Get it here http://scriptcraftjs.org/download/latest/

The Drone now also has a spawn method so you can for example unleash a horde of zombies by combining the spawn(), movement and times() functions like this...

/js spawn('ZOMBIE').fwd().times(10)
var lightning = require('lightning');
events.projectileHit( function(event) {
if ( entities.arrow( event.projectile ) &&
entities.player( event.projectile.owner ) ) {
lightning( event.projectile );
}
}