minecraft.js
Version:
Minecraft data serialization/deserialization and networking
30 lines (25 loc) • 845 B
JavaScript
var TagFormat = require(__dirname + '/tagFormat.js'),
Enchantment = require(__dirname + '/enchantment.js');
/** @constructor */
var Item = module.exports = function(args) {
if(typeof args != 'object') args = {};
this.id = args.id || 0;
this.damage = args.damage || 0;
this.count = args.count || 1;
this.slot = args.slot || 0;
this.tag = {};
this.tag.ench = args.enchantments || [];
};
Item.prototype.toTag = function() {
return this.tagFormat.encode(this);
};
Item.prototype.tagFormat = new TagFormat('compound', [
new TagFormat('long', 'id', 'id'),
new TagFormat('long', 'Damage', 'damage'),
new TagFormat('long', 'Count', 'count'),
new TagFormat('long', 'Slot', 'slot'),
new TagFormat('long', 'tag', 'tag', [
new TagFormat('list', 'ench', 'ench',
Enchantment.prototype.tagFormat)
])
]);