Entity harm sound

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-26 18:24:10 +01:00
parent 88725100a0
commit 234aee9dfa
5 changed files with 28 additions and 2 deletions

View File

@ -239,6 +239,17 @@ class Player{
"action" => $data["action"],
));
break;
case "entity.event":
if($data["entity"]->eid === $this->eid){
$eid = 0;
}else{
$eid = $data["entity"]->eid;
}
$this->dataPacket(MC_ENTITY_EVENT, array(
"eid" => $eid,
"event" => $data["event"],
));
break;
case "server.chat":
if(($data instanceof Container) === true){
if(!$data->check($this->username)){
@ -419,6 +430,7 @@ class Player{
$this->evid[] = $this->server->event("entity.remove", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.move", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.event", array($this, "eventHandler"));
$this->evid[] = $this->server->event("player.equipment.change", array($this, "eventHandler"));
$this->evid[] = $this->server->event("player.pickup", array($this, "eventHandler"));
$this->evid[] = $this->server->event("block.change", array($this, "eventHandler"));

View File

@ -416,6 +416,15 @@ class CustomPacketHandler{
}
}
break;
case MC_ENTITY_EVENT:
if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4));
$this->data["event"] = ord($this->get(1));
}else{
$this->raw .= Utils::writeInt($this->data["eid"]);
$this->raw .= chr($this->data["event"]);
}
break;
case MC_REQUEST_CHUNK:
if($this->c === false){
$this->data["x"] = Utils::readInt($this->get(4));

View File

@ -331,7 +331,9 @@ class Entity extends stdClass{
public function setHealth($health, $cause = "", $force = false){
$health = (int) $health;
$harm = false;
if($health < $this->health){
$harm = true;
$dmg = $this->health - $health;
if(($this->server->gamemode === 0 or $force === true) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and !$this->dead){
$this->dmgcounter = array(microtime(true) + 0.5, $dmg);
@ -344,6 +346,9 @@ class Entity extends stdClass{
if($this->server->api->dhandle("entity.health.change", array("entity" => $this, "eid" => $this->eid, "health" => $health, "cause" => $cause)) !== false){
$this->health = min(127, max(-127, $health));
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
if($harm === true){
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 2)); //Ouch! sound
}
if($this->player instanceof Player){
$this->player->dataPacket(MC_SET_HEALTH, array(
"health" => $this->health,

View File

@ -25,8 +25,6 @@ the Free Software Foundation, either version 3 of the License, or
*/
//Protocol Version: 5
define("MC_KEEP_ALIVE", 0x00);
@ -62,6 +60,7 @@ define("MC_UPDATE_BLOCK", 0x97);
define("MC_EXPLOSION", 0x99);
define("MC_ENTITY_EVENT", 0x9c);
define("MC_REQUEST_CHUNK", 0x9d);
define("MC_CHUNK_DATA", 0x9e);

View File

@ -62,6 +62,7 @@ $dataName = array(
MC_EXPLOSION => "Explosion",
MC_ENTITY_EVENT => "EntityEvent",
MC_REQUEST_CHUNK => "RequestChunk",
MC_CHUNK_DATA => "ChunkData",