This webpage is about how to implement scripting in minecraft. Scripting should allow both scripting blocks, items and monsters (NPC), and the server admins to change the served world.
Game content is defined through blocks, items and monsters. Those three types of content should be scriptable. Scripts of such game content are text files stored in a file system like that:
default package creeper script.js redstone block script.js redstone dust item script.js cool user extension from sulai elevator catapult books with some interesting content action pack from CompanionCube chaos gun ammo
Each level-2 subfolder contains a script.js (as shown in the default package). This script defines the behavior of blocks, items and monsters. More content may be downloaded from various websites. When the server starts up, the server admin may choose, what user extensions packs he wants to allow on his world:
[x] default package (Mojang) [ ] cool user extension from sulai [x] action pack from CompanionCube
On startup, those scripted definitions are loaded into the game. If clients connect to that server, not only the world map, but also the scriped definitions are downloaded. If CompanionCube's ammo is defined to be produced by some recipe, any user connected to that server may now produce ammo.
Of course if those scripted components are downloaded from the server, security is most important. We don't want a server that would crash the game because of some bad code. I propose to use Mozzilla's Rhino JavaScript, which lets the java programmer [ http://www.docjar.com/docs/api/org/mozilla/javascript/ClassShutter.html restrict script access to a blacklist of java methods].
Script Examples
This is what a server admin needs to type into console if he wants to place a monster:
createMonster("creeper", 20, 10);
This is what a server admin needs to do if he wants to create a 40x40 platform around the spawn point:
createBlockRect("sand stone", -20, -20, 20, 20);
This is a NPC salesman who sells redstone for some coal and flees from foes.
getType() { return "monster"; } // if hit, run away function onHit() { message("ouch!"); setDestiny( rnd(40)-20 , rnd(40)-20 ); } function onCollect(obj) { // if moving, stop setDestiny(0,0); // player throws coal at NPC: do the deal if( obj.getName()=="coal" ) { message("thanks man!"); throw(createObject("redstone dust")); } // player throws something else: give it back else { message("I only deal with coal"); throw(obj); } }
This is redstone written in script:
function getType() { return "block"; } function getName() { return "redstone"; }
function getHardness() { return 10000; } function init() { setTexture("redstone.png") } function onHit() { setEmitedLight(10); } function onBreak() { spawn("redstone dust", 4); }
This is redstone dust written in script:
function getType(){ return "object"; } function getName() { return "redstone dust"; } function getRecipe() { return null } function init() { setTexture("redstone dust.png"); } function onPut(x,y,z) { put("redstone wire", x, y, z); removeObject(this); }