minecraft.js
Version:
Minecraft data serialization/deserialization and networking
56 lines (47 loc) • 1.82 kB
JavaScript
var Vector3 = require(__dirname + '/vector3.js'),
TagFormat = require(__dirname + '/tagFormat.js'),
Item = require(__dirname + '/item.js');
/** @constructor */
var Player = module.exports = function(args) {
if(typeof args != 'object') args = {};
this.entityId = args.entityId || 0;
this.name = args.name || 'Player';
this.ping = 0;
this.position = args.position || new Vector3(0, 0, 0);
this.yaw = args.yaw || 0;
this.pitch = args.pitch || 0;
this.onGround = args.onGround || true;
this.stance = args.stance || 1.62;
this.health = args.health || 20;
this.food = args.hunger || 20;
this.foodSaturation = args.foodSaturation || 5;
this.isDead = args.isDead || false;
this.inventory = args.inventory || [];
this.abilities = {};
this.abilities.flying = args.flying || false;
this.abilities.instabuild = args.instabuild || false;
this.abilities.mayfly = args.mayFly || false;
this.abilities.invulnerable = args.invulnerable || false;
this.score = args.score || 0;
this.dimension = args.dimension || 0;
};
Player.prototype.getStance = function() {
var output = this.position.y + this.stance;
if(output < 0.1) return 1.62;
else return output;
};
Player.prototype.toTag = function() {
return this.tagFormat.encode(this);
};
Player.prototype.tagFormat = new TagFormat('compound', 'Player', 'player', [
new TagFormat('list', 'Inventory', 'inventory',
Item.prototype.tagFormat),
new TagFormat('compound', 'abilities', 'abilities', [
new TagFormat('byte', 'flying', 'flying'),
new TagFormat('byte', 'instabuild', 'instabuild'),
new TagFormat('byte', 'mayfly', 'mayFly'),
new TagFormat('byte', 'invulnerable', 'invulnerable')
]),
new TagFormat('int', 'Score', 'score'),
new TagFormat('int', 'Dimension', 'dimension')
]);