Permalink
Browse files

Made recommended changes and fixed serialiser function for setHealth.

  • Loading branch information...
1 parent 438037f commit 9b91fbd0cda4b57acfd611554751fdfda7e1b56b @nickpoorman nickpoorman committed Jan 5, 2013
Showing with 13 additions and 14 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 lib/player.js
  3. +1 −1 lib/serialiser.js
  4. +1 −1 plugins/player-abilities.js
  5. +8 −10 plugins/player-fall.js
  6. +1 −1 plugins/player-health.js
View
@@ -1,3 +1,4 @@
/node_modules
/config.json
/map
+/server.js
View
@@ -15,7 +15,7 @@ var Player = module.exports = function Player(game, options) {
this.health = 20;
this.food = 20;
- this.food_saturation = 5;
+ this.saturation = 5;
if (typeof this.options.stance === "number") { this.stance = this.options.stance; }
if (typeof this.options.on_ground === "number") { this.on_ground = this.options.on_ground; }
View
@@ -142,7 +142,7 @@ Serialiser.prototype.write = function write(packet) {
}
case 0x08: {
- this.emit("data", S().uint8(packet.pid).int16be(packet.health).int16be(packet.health).floatbe(packet.saturation).result());
+ this.emit("data", S().uint8(packet.pid).int16be(packet.health).int16be(packet.food).floatbe(packet.saturation).result());
break;
}
@@ -15,7 +15,7 @@ module.exports = function() {
if(player.mode != creativeMode) {
// something weird is happening here, lets log it
- console.log('[Warning] Player client side game mode does not match server side!');
+ console.warn('[Warning] Player client side game mode does not match server side!');
}
player.flying = flying;
View
@@ -38,8 +38,6 @@ var on_fall = function on_fall(game, packet) {
block_z = z & 0x0f,
block_y = y;
- var that = this;
-
var WATER = 8;
var STATIONARY_WATER = 9;
@@ -50,29 +48,29 @@ var on_fall = function on_fall(game, packet) {
// try to guess if they are flying to begin with
// if the block below them is air then they are probably flying
// this is untested - might need to find a way to do this with the protocol
- if(typeof that.flying == "undefined") {
- that.flying = chunk.get_block_type(block_x, block_z, block_y - 1) == 0;
+ if(typeof this.flying == "undefined") {
+ this.flying = chunk.get_block_type(block_x, block_z, block_y - 1) == 0;
}
// don't apply fall if they are swimming
if(!swimming) {
// when on_ground changes from true to false start keeping track of distance
- if(that.on_ground && !packet["on_ground"]) {
- set_falling_pos(that);
+ if(this.on_ground && !packet["on_ground"]) {
+ set_falling_pos(this);
}
// Edge case:
// also when flying changes from true to false we need to set the height
// - this will get handled when the "flying",false event fires
// when it changes from false to true then calculate damage
- if(!that.on_ground && packet["on_ground"]) {
- var damage = Math.floor(that.start_falling_pos - packet.y - 3);
+ if(!this.on_ground && packet["on_ground"]) {
+ var damage = Math.floor(this.start_falling_pos - packet.y - 3);
//trigger a damage event on the player
- if(damage > 0) that.emit("damage", damage);
+ if(damage > 0) this.emit("damage", damage);
//TODO?: emit sound 0x3e
}
}
- });
+ }.bind(this));
};
View
@@ -25,7 +25,7 @@ var update_health = function update_health(game) {
// modify the players health to match the damage done
player.health -= player.damaged;
// send out necessary packet to update the health
- player.health < 0 ? player.kill() : player.setHealth(player.health, player.food, player.food_saturation);
+ player.health < 0 ? player.kill() : player.setHealth(player.health, player.food, player.saturation);
// reset the damage done
player.damaged = 0;
});

0 comments on commit 9b91fbd

Please sign in to comment.