diff --git a/src/classes/Player.php b/src/classes/Player.php index ac8218885..7d7e7c203 100644 --- a/src/classes/Player.php +++ b/src/classes/Player.php @@ -238,9 +238,20 @@ class Player{ break; } $this->dataPacket(MC_ANIMATE, array( - "eid" => $data["eid"], - "action" => $data["action"], - )); + "eid" => $data["eid"], + "action" => $data["action"], + )); + break; + case "entity.metadata": + if($data->eid === $this->eid){ + $eid = 0; + }else{ + $eid = $data->eid; + } + $this->dataPacket(MC_SET_ENTITY_DATA, array( + "eid" => $eid, + "metadata" => $data->getMetadata(), + )); break; case "entity.event": if($data["entity"]->eid === $this->eid){ @@ -448,6 +459,7 @@ class Player{ $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("entity.metadata", 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 3f25f66bf..e47e4c3ce 100644 --- a/src/classes/network/CustomPacketHandler.php +++ b/src/classes/network/CustomPacketHandler.php @@ -208,11 +208,7 @@ class CustomPacketHandler{ $this->raw .= Utils::writeFloat($this->data["x"]); $this->raw .= Utils::writeFloat($this->data["y"]); $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeMetadata(array( - 1 => array("type" => 1, "value" => 300), - 16 => array("type" => 0, "value" => 0), - 17 => array("type" => 6, "value" => array(0, 0, 0)), - )); + $this->raw .= Utils::writeMetadata($this->data["metadata"]); } break; case MC_ADD_PLAYER: @@ -231,11 +227,7 @@ class CustomPacketHandler{ $this->raw .= Utils::writeFloat($this->data["x"]); $this->raw .= Utils::writeFloat($this->data["y"]); $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeMetadata(array( - 1 => array("type" => 1, "value" => 300), - 16 => array("type" => 0, "value" => 0), - 17 => array("type" => 6, "value" => array(0, 0, 0)), - )); + $this->raw .= Utils::writeMetadata($this->data["metadata"]); } break; case MC_ADD_ENTITY: @@ -489,11 +481,10 @@ class CustomPacketHandler{ case MC_SET_ENTITY_DATA: if($this->c === false){ $this->data["eid"] = Utils::readInt($this->get(4)); + $this->data["metadata"] = Utils::readMetadata($this->get(true)); }else{ $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeMetadata(array( - - )); + $this->raw .= Utils::writeMetadata($this->data["metadata"]); } break; case MC_SET_HEALTH: diff --git a/src/classes/utils/Utils.php b/src/classes/utils/Utils.php index 7b2f3309d..ba9f78f7d 100644 --- a/src/classes/utils/Utils.php +++ b/src/classes/utils/Utils.php @@ -184,7 +184,7 @@ class Utils extends Thread{ $r = array(); $r[] = Utils::readLShort(substr($value, $offset, 2)); $offset += 2; - $r[] = Utils::readByte($value{$offset}); + $r[] = ord($value{$offset}); ++$offset; $r[] = Utils::readLShort(substr($value, $offset, 2)); $offset += 2; diff --git a/src/classes/world/Entity.php b/src/classes/world/Entity.php index 2c2a32ce1..4e3824cf9 100644 --- a/src/classes/world/Entity.php +++ b/src/classes/world/Entity.php @@ -47,6 +47,8 @@ class Entity extends stdClass{ $this->health = 20; $this->dmgcounter = array(0, 0); $this->air = 300; + $this->fire = 0; + $this->crouched = false; $this->invincible = false; $this->dead = false; $this->closed = false; @@ -87,6 +89,17 @@ class Entity extends stdClass{ if($this->closed === true){ return false; } + if($this->fire > 0){ + if(($this->fire % 20) === 0){ + $this->harm(1, "burning"); + } + $this->fire -= 10; + if($this->fire <= 0){ + $this->fire = 0; + $this->updateMetadata(); + } + } + $startX = (int) (round($this->x - 0.5) - 1); $startY = (int) (round($this->y) - 1); $startZ = (int) (round($this->z - 0.5) - 1); @@ -100,21 +113,30 @@ class Entity extends stdClass{ switch($b[0]){ case 8: case 9: //Drowing + if($this->fire > 0 and $this->inBlock($x, $y, $z)){ + $this->fire = 0; + $this->updateMetadata(); + } if($this->air <= 0){ $this->harm(2, "water"); }elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){ $this->air -= 10; + $this->updateMetadata(); } break; case 10: //Lava damage case 11: if($this->inBlock($x, $y, $z)){ $this->harm(5, "lava"); + $this->fire = 300; + $this->updateMetadata(); } break; case 51: //Fire block damage if($this->inBlock($x, $y, $z)){ $this->harm(1, "fire"); + $this->fire = 300; + $this->updateMetadata(); } break; case 81: //Cactus damage @@ -179,6 +201,22 @@ class Entity extends stdClass{ return null; } } + + public function getMetadata(){ + $flags = 0; + $flags |= $this->fire > 0 ? 1:0; + $flags |= ($this->crouched === true ? 1:0) << 1; + return array( + 0 => array("type" => 0, "value" => $flags), + 1 => array("type" => 1, "value" => $this->air), + 16 => array("type" => 0, "value" => 0), + 17 => array("type" => 6, "value" => array(0, 0, 0)), + ); + } + + public function updateMetadata(){ + $this->server->api->dhandle("entity.metadata", $this); + } public function spawn($player){ if(!is_object($player)){ @@ -196,6 +234,7 @@ class Entity extends stdClass{ "x" => $this->x, "y" => $this->y, "z" => $this->z, + "metadata" => $this->getMetadata(), )); $player->dataPacket(MC_PLAYER_EQUIPMENT, array( "eid" => $this->eid, @@ -221,6 +260,7 @@ class Entity extends stdClass{ "x" => $this->x, "y" => $this->y, "z" => $this->z, + "metadata" => $this->getMetadata(), )); break; case ENTITY_OBJECT: @@ -357,6 +397,10 @@ class Entity extends stdClass{ )); } if($this->health <= 0 and $this->dead === false){ + $this->air = 300; + $this->fire = 0; + $this->crouched = false; + $this->updateMetadata(); $this->dead = true; if($this->player !== false){ $this->server->api->dhandle("player.death", array("name" => $this->name, "cause" => $cause));