mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Entity harm sound
This commit is contained in:
parent
88725100a0
commit
234aee9dfa
@ -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"));
|
||||
|
@ -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));
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -62,6 +62,7 @@ $dataName = array(
|
||||
|
||||
MC_EXPLOSION => "Explosion",
|
||||
|
||||
MC_ENTITY_EVENT => "EntityEvent",
|
||||
MC_REQUEST_CHUNK => "RequestChunk",
|
||||
MC_CHUNK_DATA => "ChunkData",
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user