diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 91f45f77b..ba1f9e974 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -36,6 +36,7 @@ class PlayerAPI{ $this->server->addHandler("player.death", array($this, "handle"), 1); $this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler")); $this->server->api->console->register("kill", "Kills a player", array($this, "commandHandler")); + $this->server->api->console->register("harm", "Harms a player", array($this, "commandHandler")); $this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler")); $this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler")); } @@ -138,6 +139,15 @@ class PlayerAPI{ console("[INFO] Usage: /kill "); } break; + case "harm": + $dmg = (int) array_shift($params); + $player = $this->get(implode(" ", $params)); + if($player !== false){ + $this->server->api->entity->harm($player->eid, $dmg, "console", true); + }else{ + console("[INFO] Usage: /harm "); + } + break; case "list": console("[INFO] Player list:"); foreach($this->server->clients as $c){ diff --git a/src/classes/Player.php b/src/classes/Player.php index e0c774bc9..1247b00a7 100644 --- a/src/classes/Player.php +++ b/src/classes/Player.php @@ -583,6 +583,30 @@ class Player{ } //$this->entity->setHealth($data["health"], "client"); break; + case MC_ENTITY_EVENT: + $data["eid"] = $this->eid; + switch($data["event"]){ + case 9: //Eating + $items = array( + 260 => 2, //Apples + 282 => 10, //Stew + 297 => 5, //Bread + 319 => 3, + 320 => 8, + 363 => 3, + 364 => 8, + ); + if(isset($items[$this->equipment[0]])){ + $this->removeItem($this->equipment[0], 0, 1); + $this->dataPacket(MC_ENTITY_EVENT, array( + "eid" => 0, + "event" => 9, + )); + $this->entity->heal($items[$this->equipment[0]], "eating"); + } + break; + } + break; case MC_DROP_ITEM: if($this->server->handle("player.drop", $data) !== false){ $this->server->api->block->drop($this->entity->x, $this->entity->y, $this->entity->z, $data["block"], $data["meta"], $data["stack"]); diff --git a/src/classes/network/CustomPacketHandler.php b/src/classes/network/CustomPacketHandler.php index 3c0456265..7db3f2da5 100644 --- a/src/classes/network/CustomPacketHandler.php +++ b/src/classes/network/CustomPacketHandler.php @@ -478,6 +478,9 @@ class CustomPacketHandler{ $this->raw .= Utils::writeInt($this->data["target"]);*/ } break; + case MC_PLAYER_ACTION: + //TODO + break; case MC_SET_ENTITY_DATA: if($this->c === false){ $this->data["eid"] = Utils::readInt($this->get(4)); diff --git a/src/classes/world/Entity.php b/src/classes/world/Entity.php index b80c06cae..0a0aabdf0 100644 --- a/src/classes/world/Entity.php +++ b/src/classes/world/Entity.php @@ -162,7 +162,7 @@ class Entity extends stdClass{ } if($this->y < -16){ - $this->harm(8, "void", true); //4 per second + $this->harm(8, "void", true); } if($this->fire > 0){ @@ -470,6 +470,10 @@ class Entity extends stdClass{ return $this->setHealth($this->getHealth() - ((int) $dmg), $cause, $force); } + public function heal($health, $cause = "generic"){ + return $this->setHealth(min(20, $this->getHealth() + ((int) $health)), $cause); + } + public function setHealth($health, $cause = "generic", $force = false){ $health = (int) $health; $harm = false;