minecraft.js
Version:
Minecraft data serialization/deserialization and networking
53 lines (45 loc) • 1.56 kB
JavaScript
var Vector3 = require(__dirname + '/vector3.js'),
TagFormat = require(__dirname + '/tagFormat.js');
/** @constructor */
var Entity = module.exports = function(args) {
if(typeof args != 'object') args = {};
this.entityId = args.entityId;
this.type = args.type;
this.id = args.id;
this.position = args.position || new Vector3(0.0, 0.0, 0.0);
this.motion = args.motion || new Vector3(0.0, 0.0, 0.0);
this.rotation = {};
this.rotation.yaw = args.yaw || 0.0;
this.rotation.pitch = args.pitch || 0.0;
this.fallDistance = args.fallDistance || 0.0;
this.fire = args.fire || 0;
this.air = args.air || 200;
this.onGround = args.onGround || true;
};
Entity.prototype.tagFormat = new TagFormat(
'compound',
[
new TagFormat('string', 'id', 'id'),
new TagFormat('list', 'Pos', 'pos', [
new TagFormat('double', 'X', 'x'),
new TagFormat('double', 'Y', 'y'),
new TagFormat('double', 'Z', 'z')
]),
new TagFormat('list', 'Motion', 'motion', [
new TagFormat('double', 'dX', 'x'),
new TagFormat('double', 'dY', 'y'),
new TagFormat('double', 'dZ', 'z')
]),
new TagFormat('list', 'Rotation', 'rotation', [
new TagFormat('double', 'Yaw', 'yaw'),
new TagFormat('double', 'Pitch', 'pitch')
]),
new TagFormat('float', 'FallDistance', 'fallDistance'),
new TagFormat('short', 'Fire', 'fire'),
new TagFormat('short', 'Air', 'air'),
new TagFormat('byte', 'OnGround', 'onGround')
]
);
Entity.prototype.toTag = function() {
return this.tagFormat.encode(this);
};