Skip to content

Commit

Permalink
Register inert items with item texture. Ref GH-12
Browse files Browse the repository at this point in the history
Fixes `/give webuser-1 wheat_seeds`, but many other items still need to
be added along with their display and texture names. Ref
PrismarineJS/minecraft-data#78
  • Loading branch information
deathcap committed Feb 7, 2016
1 parent bd4bbcf commit 1d961a4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/inert-blocks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const mcBlocks = require('../mcblocks');
const mcData = require('../mcdata');

module.exports = function(game, opts) {
return new BlocksPlugin(game, opts);
Expand All @@ -18,7 +18,7 @@ function BlocksPlugin(game, opts) {
}

BlocksPlugin.prototype.enable = function() {
const inertBlockProps = mcBlocks.inertBlockProps;
const inertBlockProps = mcData.inertBlockProps;
Object.keys(inertBlockProps).forEach((name) => {
const props = inertBlockProps[name];

Expand Down
30 changes: 6 additions & 24 deletions app/inert-items.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
'use strict';

const ITEMS_MC_VERSION = '1.8.9'; // TODO: 1.9?
const minecraft_data = require('minecraft-data');
const mcData = require('../mcdata');

module.exports = (game, opts) => {
return new InertItemsPlugin(game, opts);
};
module.exports.pluginInfo = {
loadAfter: [
'voxel-registry',
// Load after plugins which also register items - inert-items picks up the slack,
// registering all other items with otherwise no distinctive behavior
// TODO: needs a better mapping, e.g. iron_pickaxe MC is voxel-pickaxe pickaxeIron! (or we have two iron pickaxes, one inert one not)
'voxel-pickaxe',
'voxel-food',
]
loadAfter: [ 'voxel-registry' ]
};

class InertItemsPlugin
Expand All @@ -27,21 +19,11 @@ class InertItemsPlugin
}

enable() {
const itemsByName = minecraft_data(ITEMS_MC_VERSION).itemsByName;
const inertItemProps = mcData.inertItemProps;
Object.keys(inertItemProps).forEach((name) => {
const props = inertItemProps[name];

Object.keys(itemsByName).forEach((name) => {
const item = itemsByName[name];

// Only register items not already registered by other plugins
if (this.registry.getItemProps(name)) {
return;
}

const displayName = item.displayName;

console.log('registering item',name);
// TODO: add textures, but https://github.com/PrismarineJS/minecraft-data/issues/78
this.registry.registerItem(name, {displayName: displayName});
this.registry.registerItem(name, props);
});
}

Expand Down
1 change: 0 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"camera-debug": "^0.3.0",
"coffeeify": "^1.2.0",
"kb-bindings-ui": "^0.3.3",
"minecraft-data": "^0.19.1",
"voxel-artpacks": "^0.1.2",
"voxel-bedrock": "^1.0.1",
"voxel-blockdata": "^0.2.1",
Expand Down
2 changes: 1 addition & 1 deletion clientmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function ClientMC(game, opts) {
// Translate network block indices to our block names
// http://minecraft.gamepedia.com/Data_values#Block_IDs http://minecraft-ids.grahamedgecombe.com/
// TODO: get translation table from network protocol? I think Forge supports custom blocks with the map sent over the network?
opts.mcData = opts.mcBlocks || mcData.mcBlockID2Voxel;
opts.mcBlocks = opts.mcBlocks || mcData.mcBlockID2Voxel;

this.enable();
}
Expand Down
8 changes: 8 additions & 0 deletions mcdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,16 @@ Object.keys(mcBlockName2Voxel).forEach((mcName) => {
mcBlockID2Voxel[blockInfo.id] = ourName;
});


const inertItemProps = {
wheat_seeds: {itemTexture: 'items/seeds_wheat', displayName: 'Seeds'},
// TODO: more items
// TODO: default
};

module.exports = {
mcBlockName2Voxel,
mcBlockID2Voxel,
inertBlockProps,
inertItemProps,
};

0 comments on commit 1d961a4

Please sign in to comment.