Skip to content

Commit

Permalink
Made recommended changes and fixed serialiser function for setHealth.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpoorman committed Jan 5, 2013
1 parent 438037f commit 9b91fbd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules /node_modules
/config.json /config.json
/map /map
/server.js
2 changes: 1 addition & 1 deletion lib/player.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Player = module.exports = function Player(game, options) {


this.health = 20; this.health = 20;
this.food = 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.stance === "number") { this.stance = this.options.stance; }
if (typeof this.options.on_ground === "number") { this.on_ground = this.options.on_ground; } if (typeof this.options.on_ground === "number") { this.on_ground = this.options.on_ground; }
Expand Down
2 changes: 1 addition & 1 deletion lib/serialiser.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Serialiser.prototype.write = function write(packet) {
} }


case 0x08: { 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; break;
} }


Expand Down
2 changes: 1 addition & 1 deletion plugins/player-abilities.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function() {


if(player.mode != creativeMode) { if(player.mode != creativeMode) {
// something weird is happening here, lets log it // 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; player.flying = flying;
Expand Down
18 changes: 8 additions & 10 deletions plugins/player-fall.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ var on_fall = function on_fall(game, packet) {
block_z = z & 0x0f, block_z = z & 0x0f,
block_y = y; block_y = y;


var that = this;

var WATER = 8; var WATER = 8;
var STATIONARY_WATER = 9; var STATIONARY_WATER = 9;


Expand All @@ -50,29 +48,29 @@ var on_fall = function on_fall(game, packet) {
// try to guess if they are flying to begin with // try to guess if they are flying to begin with
// if the block below them is air then they are probably flying // 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 // this is untested - might need to find a way to do this with the protocol
if(typeof that.flying == "undefined") { if(typeof this.flying == "undefined") {
that.flying = chunk.get_block_type(block_x, block_z, block_y - 1) == 0; this.flying = chunk.get_block_type(block_x, block_z, block_y - 1) == 0;
} }


// don't apply fall if they are swimming // don't apply fall if they are swimming
if(!swimming) { if(!swimming) {
// when on_ground changes from true to false start keeping track of distance // when on_ground changes from true to false start keeping track of distance
if(that.on_ground && !packet["on_ground"]) { if(this.on_ground && !packet["on_ground"]) {
set_falling_pos(that); set_falling_pos(this);
} }
// Edge case: // Edge case:
// also when flying changes from true to false we need to set the height // also when flying changes from true to false we need to set the height
// - this will get handled when the "flying",false event fires // - this will get handled when the "flying",false event fires


// when it changes from false to true then calculate damage // when it changes from false to true then calculate damage
if(!that.on_ground && packet["on_ground"]) { if(!this.on_ground && packet["on_ground"]) {
var damage = Math.floor(that.start_falling_pos - packet.y - 3); var damage = Math.floor(this.start_falling_pos - packet.y - 3);
//trigger a damage event on the player //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 //TODO?: emit sound 0x3e
} }
} }


}); }.bind(this));
}; };
2 changes: 1 addition & 1 deletion plugins/player-health.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var update_health = function update_health(game) {
// modify the players health to match the damage done // modify the players health to match the damage done
player.health -= player.damaged; player.health -= player.damaged;
// send out necessary packet to update the health // 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 // reset the damage done
player.damaged = 0; player.damaged = 0;
}); });
Expand Down

0 comments on commit 9b91fbd

Please sign in to comment.