diff --git a/src/classes/Player.php b/src/classes/Player.php index e196e183..167bd6d4 100644 --- a/src/classes/Player.php +++ b/src/classes/Player.php @@ -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")); diff --git a/src/classes/network/CustomPacketHandler.php b/src/classes/network/CustomPacketHandler.php index a97cc5de..f772dde9 100644 --- a/src/classes/network/CustomPacketHandler.php +++ b/src/classes/network/CustomPacketHandler.php @@ -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)); diff --git a/src/classes/world/Entity.php b/src/classes/world/Entity.php index ed87f226..416c05c2 100644 --- a/src/classes/world/Entity.php +++ b/src/classes/world/Entity.php @@ -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, diff --git a/src/protocol/current.php b/src/protocol/current.php index e58ac84a..5b3d60c0 100644 --- a/src/protocol/current.php +++ b/src/protocol/current.php @@ -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); diff --git a/src/protocol/dataName.php b/src/protocol/dataName.php index b14604d0..9b5069ec 100644 --- a/src/protocol/dataName.php +++ b/src/protocol/dataName.php @@ -62,6 +62,7 @@ $dataName = array( MC_EXPLOSION => "Explosion", + MC_ENTITY_EVENT => "EntityEvent", MC_REQUEST_CHUNK => "RequestChunk", MC_CHUNK_DATA => "ChunkData",