So I know this is going to sound a little crazy, but hear me out. I think for the purposes of modding, an event-driven, asynchronous Javascript API would make it extremely easy for modders to develop and test mods, and open up the pool of potential modders beyond Java developers. Technically this is quite feasible, Rhino is an embeddable Javascript interpreter written entirely in Java.
To give an idea of what I’m talking about, here’s a “mod” that would add torches that “burn out” into the game.
The ultimate goal is to allow anything to be built with the engine, from a tower defense game to a harvest moon farming simulator without needing to know Java. The target user would be one that might not know how to use Eclipse or build systems, but who has done a little HTML/Javascript, and who can edit a text file and tell the game to reload. (or better yet, use the in-game editor)
If this is a direction people would like to consider, we would need to add the Rhino jar to the build, and create a number of Host Objects (Java objects that can be interacted with from Javascript), and start defining the game events that can be attached to.
== EDIT ==
My Groovy is a little rusty, but would look something like this:
To give an idea of what I’m talking about, here’s a “mod” that would add torches that “burn out” into the game.
Code:
// Game.addBlock accepts an object, reads the properties and creates a new
// block type and adds it to the game world. It returns a reference to the
// newly created block type.
Torch = Game.addBlock({
name: "Torch",
placedAs: "wallItem",
model: "litTorch"
});
UnlitTorch = Game.addBlock({
name: "Burnt Out Torch",
placedAs: "wallItem",
model: "unlitTorch"
});
// Blocks have a number of event handlers. Here, we are referencing the
// "onPlace" event handler, called when a player (or NPC) places this
// block
Torch.addEvent("onPlace", function(){
// Note that "this" refers to the current torch being placed
this.luminescence = 15;
this.fuel = 256;
});
// BlockSet is a Rhino Java Host Object that can contain arbitrary sets of
// blocks. It exists for the convenience of the modder for easy membership
// testing and iteration.
torches = new BlockSet();
// The Game object also has a number of event handlers, "loadChunk" is called
// every time a chunk is loaded into the game world (either by being newly
// created, or by being loaded from network or disk)
Game.addEvent("loadChunk", function() {
// Note that "this" refers to the current chunk being loaded
// this.blocks returns a read-only BlockSet
blocks = this.blocks;
for (var i = 0; i < blocks.length; i++) {
if (blocks.typeId == Torch.typeId) {
torches.add(block);
}
}
});
Game.addEvent("unloadChunk", function() {
// BlockSet.removeAll removes all blocks from the blockset that are also
// present in the collection passed as a parameter.
torches.removeAll(this.blocks);
});
// setTimeout and setInterval work exactly as expected
setInterval(function() {
for (var i = 0; i < torches.length; i++) {
torch = torches[i];
torch.fuel--;
torch.luminescence = Math.min(torch.fuel, 15);
if(torch.fuel == 0) {
torches.remove(torch);
torch.replaceWith(UnlitTorch);
}
}
}, 100000);
If this is a direction people would like to consider, we would need to add the Rhino jar to the build, and create a number of Host Objects (Java objects that can be interacted with from Javascript), and start defining the game events that can be attached to.
== EDIT ==
My Groovy is a little rusty, but would look something like this:
Code:
def Torch = Game.addBlock [
name: "Torch",
placedAs: "wallItem",
model: "litTorch"
]
def UnlitTorch = Game.addBlock [
name: "Burnt Out Torch",
placedAs: "wallItem",
model: "unlitTorch"
]
Torch.addEvent "onPlace", {
it.luminescence = 15
it.fuel = 256
}
torches = new BlockSet()
Game.addEvent "loadChunk" {
it.blocks.each {
if (it.typeId == Torch.typeId) {
torches.add block
}
}
}
Game.addEvent "unloadChunk", {
torches.removeAll it.blocks
}
Game.setInterval 100000 {
torches.each {
it.fuel--
it.luminescence = min(it.fuel, 15)
if(it.fuel == 0) {
torches.remove it
it.replaceWith UnlitTorch
}
}
}