diff --git a/app/app.js b/app/app.js index a604396..67d2ac1 100644 --- a/app/app.js +++ b/app/app.js @@ -36,8 +36,6 @@ const main = function() { 'voxel-wool': require('voxel-wool'), 'voxel-pumpkin': require('voxel-pumpkin'), 'voxel-blockdata': require('voxel-blockdata'), - './inert-blocks': require('./inert-blocks'), - './inert-items': require('./inert-items'), 'voxel-decorative': require('voxel-decorative'), 'voxel-land': require('voxel-land'), 'voxel-flatland': require('voxel-flatland'), @@ -120,8 +118,6 @@ const main = function() { 'voxel-wool': {}, 'voxel-pumpkin': {}, - './inert-blocks': {}, // misc inanimate opaque solid blocks - './inert-items': {}, 'voxel-decorative': {}, //'voxel-land': {registerBlocks: false}, 'voxel-flatland': {block: 'missing'}, diff --git a/app/bundled-index.html b/app/bundled-index.html new file mode 100644 index 0000000..6f28775 --- /dev/null +++ b/app/bundled-index.html @@ -0,0 +1,15 @@ + + + +voxel-clientmc + + + +Fork me on GitHub + + + diff --git a/app/inert-blocks.js b/app/inert-blocks.js deleted file mode 100644 index 33844c1..0000000 --- a/app/inert-blocks.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; - -const mcData = require('../mcdata'); - -module.exports = function(game, opts) { - return new BlocksPlugin(game, opts); -}; -module.exports.pluginInfo = { - loadAfter: ['voxel-registry'] -}; - -function BlocksPlugin(game, opts) { - - this.registry = game.plugins.get('voxel-registry'); - if (!this.registry) throw new Error('blocks requires voxel-registry plugin'); - - this.enable(); -} - -BlocksPlugin.prototype.enable = function() { - const inertBlockProps = mcData.inertBlockProps; - Object.keys(inertBlockProps).forEach((name) => { - const props = inertBlockProps[name]; - - this.registry.registerBlock(name, props); - }); -}; - -BlocksPlugin.prototype.disable = function() { - // TODO: unregister blocks -}; - diff --git a/app/inert-items.js b/app/inert-items.js deleted file mode 100644 index f683562..0000000 --- a/app/inert-items.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -const mcData = require('../mcdata'); - -module.exports = (game, opts) => { - return new InertItemsPlugin(game, opts); -}; -module.exports.pluginInfo = { - loadAfter: [ 'voxel-registry' ] -}; - -class InertItemsPlugin -{ - constructor(game, opts) { - this.registry = game.plugins.get('voxel-registry'); - if (!this.registry) throw new Error('blocks requires voxel-registry plugin'); - - this.enable(); - } - - enable() { - const inertItemProps = mcData.inertItemProps; - Object.keys(inertItemProps).forEach((name) => { - const props = inertItemProps[name]; - - this.registry.registerItem(name, props); - }); - } - - disable() { - // TODO: unregister items - } -} diff --git a/circle.yml b/circle.yml index 1dcea41..5bd25f4 100644 --- a/circle.yml +++ b/circle.yml @@ -12,6 +12,7 @@ checkout: - npm install - (cd app && npm install) - ./app/node_modules/.bin/browserify app/app.js > app/wsmc/src/main/resources/www/bundle.js + - cp ./app/bundled-index.html app/wsmc/src/main/resources/www/index.html # build wsmc/Java with the bundled voxel-clientmc - (cd app/wsmc && mvn package) diff --git a/clientmc.js b/clientmc.js index b43881c..98ed59c 100644 --- a/clientmc.js +++ b/clientmc.js @@ -93,14 +93,37 @@ class ClientMC extends EventEmitter this.enable(); } - enable() { - // only begin connecting to server after voxel-engine is initialized, + // Register our own blocks and items which aren't provided by other more specialized plugins + const inertBlockProps = mcData.inertBlockProps; + Object.keys(inertBlockProps).forEach((name) => { + const props = inertBlockProps[name]; + + this.registry.registerBlock(name, props); + }); + + const inertItemProps = mcData.inertItemProps; + Object.keys(inertItemProps).forEach((name) => { + const props = inertItemProps[name]; + + this.registry.registerItem(name, props); + }); + + // Begin connecting to server after voxel-engine is initialized, // since it shows chunks (game.showChunk) which requires engine initialization, // but plugins are "enabled" before the engine fully is this.game.on('engine-init', this.connectServer.bind(this)); } + disable() { + this.log('voxel-clientmc disabling'); + this.game.voxels.removeListener('missingChunk', this.missingChunk); + this.game.plugins.get('voxel-console').widget.removeListener('input', this.onConsoleInput); + this.ws.end(); + if (this.clearPositionUpdateTimer) this.clearPositionUpdateTimer(); + // TODO: unregister inert items/blocks + } + // TODO: refactor further into modules connectServer() { this.log('voxel-clientmc connecting...'); @@ -160,12 +183,4 @@ class ClientMC extends EventEmitter this.emit('connectServer'); } - - disable() { - this.log('voxel-clientmc disabling'); - this.game.voxels.removeListener('missingChunk', this.missingChunk); - this.game.plugins.get('voxel-console').widget.removeListener('input', this.onConsoleInput); - this.ws.end(); - if (this.clearPositionUpdateTimer) this.clearPositionUpdateTimer(); - } }