|
/* |
|
Define a mod like follows: |
|
|
|
ipe.registerMod('modName', function(mod) { |
|
var redstonemod = mod.require('redstonemod') |
|
mod.api = { |
|
doRedstoneModThing: function() { |
|
redstonemod.explodeTheWorld() |
|
} |
|
} |
|
}) |
|
|
|
ipe.registerMod('otherModName', function(mod) { |
|
var modName = mod.require('modName') |
|
modName.doRedstoneModThing() |
|
}) |
|
|
|
Just paste the mod at the end of ipe.js BEFORE ipe.load() |
|
*/ |
|
|
|
var useItem, attackHook, modTick, procCmd, newLevel, leaveGame, entityAddedHook, entityRemovedHook, deathHook, levelEventHook, blockEventHook |
|
var ipe = (function() { |
|
var mods = [] |
|
|
|
function forEveryMod(onMod) { |
|
for (var i = 0; i < mods.length; i++) { |
|
onMod(mods[i]) |
|
} |
|
} |
|
|
|
useItem = function(x, y, z, itemId, blockId, side) { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.useItem instanceof Function) { |
|
mod.mod.api.useItem(x, y, z, itemId, blockId, side) |
|
} |
|
}) |
|
} |
|
attackHook = function(attacker, victim) { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.attackHook instanceof Function) { |
|
mod.mod.api.attackHook(attacker, victim) |
|
} |
|
}) |
|
} |
|
modTick = function() { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.modTick instanceof Function) { |
|
mod.mod.api.modTick() |
|
} |
|
}) |
|
} |
|
procCmd = function(cmd) { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.procCmd instanceof Function) { |
|
mod.mod.api.procCmd(cmd) |
|
} |
|
}) |
|
} |
|
newLevel = function() { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.newLevel instanceof Function) { |
|
mod.mod.api.newLevel() |
|
} |
|
}) |
|
} |
|
leaveGame = function() { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.leaveGame instanceof Function) { |
|
mod.mod.api.leaveGame() |
|
} |
|
}) |
|
} |
|
entityAddedHook = function(entity) { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.entityAddedHook instanceof Function) { |
|
mod.mod.api.entityAddedHook(entity) |
|
} |
|
}) |
|
} |
|
entityRemovedHook = function(entity) { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.entityRemovedHook instanceof Function) { |
|
mod.mod.api.entityRemovedHook(entity) |
|
} |
|
}) |
|
} |
|
deathHook = function(murderer, victim) { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.deathHook instanceof Function) { |
|
mod.mod.api.deathHook(murderer, victim) |
|
} |
|
}) |
|
} |
|
levelEventHook = function(entity, eventType, x, y, z, data) { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.levelEventHook instanceof Function) { |
|
mod.mod.api.levelEventHook(entity, eventType, x, y, z, data) |
|
} |
|
}) |
|
} |
|
blockEventHook = function(x, y, z, eventType, data) { |
|
forEveryMod(function(mod) { |
|
if (mod.mod.api.blockEventHook instanceof Function) { |
|
mod.mod.api.blockEventHook(x, y, z, eventType, data) |
|
} |
|
}) |
|
} |
|
|
|
return { |
|
registerMod: function(name, init) { |
|
mods.push({ |
|
name: name, |
|
loaded: false, |
|
mod: { |
|
init: init, |
|
loaded: false, |
|
api: {}, |
|
require: function(name) { |
|
for (var i = 0; i < mods.length; i++) { |
|
if (mods[i].name === name) { |
|
var mod = mods[i] |
|
if (!mod.loaded) { |
|
mod.mod.init(mod.mod) |
|
mod.loaded = true |
|
} |
|
return mod.mod.api |
|
} |
|
} |
|
throw new ReferenceError(name) |
|
} |
|
} |
|
}) |
|
}, |
|
load: function() { |
|
for (var i = 0; i < mods.length; i++) { |
|
if (mods[i].loaded) continue |
|
mods[i].mod.init(mods[i].mod) |
|
} |
|
} |
|
} |
|
})() |
|
|
|
// Place mods here |
|
|
|
ipe.load() |