diff --git a/src/classes/PocketMinecraftServer.php b/src/classes/PocketMinecraftServer.php index d3bc63c7a..472065611 100644 --- a/src/classes/PocketMinecraftServer.php +++ b/src/classes/PocketMinecraftServer.php @@ -322,7 +322,7 @@ class PocketMinecraftServer{ "pitch" => $entity["Rotation"][1], )); }else{ - $e = $this->api->entity->add(ENTITY_MOB, $entity["id"]); + $e = $this->api->entity->add(ENTITY_MOB, $entity["id"], $entity); $e->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]); $e->setHealth($entity["Health"]); @@ -340,9 +340,7 @@ class PocketMinecraftServer{ $class = TILE_SIGN; break; } - if($class !== false){ - $t = $this->api->tileentity->add($class, $tile["x"], $tile["y"], $tile["z"], $tile); - } + $t = $this->api->tileentity->add($class, $tile["x"], $tile["y"], $tile["z"], $tile); } $this->action(1000000 * 60 * 15, '$this->api->chat->broadcast("Forcing save...");$this->save();'); } @@ -353,11 +351,57 @@ class PocketMinecraftServer{ $this->levelData["Time"] = $this->time; file_put_contents($this->mapDir."level.dat", serialize($this->levelData)); $this->map->saveMap($final); - console("[INFO] Saving entities..."); - foreach($this->entities as $entity){ - - } $this->trigger("server.save", $final); + console("[INFO] Saving entities..."); + if(count($this->entities) > 0){ + $entities = array(); + foreach($this->entities as $entity){ + if($entity->class === ENTITY_MOB){ + $entities[] = array( + "id" => $entity->type, + "Color" => @$entity->data["Color"], + "Sheared" => @$entity->data["Sheared"], + "Health" => $entity->health, + "Pos" => array( + 0 => $entity->x, + 1 => $entity->y, + 2 => $entity->z, + ), + "Rotation" => array( + 0 => $entity->yaw, + 1 => $entity->pitch, + ), + ); + }elseif($entity->class === ENTITY_ITEM){ + $entities[] = array( + "id" => 64, + "Item" => array( + "id" => $entity->type, + "Damage" => $entity->meta, + "Count" => $entity->stack, + ), + "Health" => $entity->health, + "Pos" => array( + 0 => $entity->x, + 1 => $entity->y, + 2 => $entity->z, + ), + "Rotation" => array( + 0 => 0, + 1 => 0, + ), + ); + } + } + file_put_contents($this->mapDir."entities.dat", serialize($entities)); + } + if(count($this->tileEntities) > 0){ + $tiles = array(); + foreach($this->tileEntities as $tile){ + $tiles[] = $tile->data; + } + file_put_contents($this->mapDir."tileEntities.dat", serialize($tiles)); + } } } diff --git a/src/classes/world/Entity.php b/src/classes/world/Entity.php index 87e3c58a1..a8f2c6b0b 100644 --- a/src/classes/world/Entity.php +++ b/src/classes/world/Entity.php @@ -27,13 +27,50 @@ the Free Software Foundation, either version 3 of the License, or define("ENTITY_PLAYER", 0); + define("ENTITY_MOB", 1); + define("MOB_CHICKEN", 10); + define("MOB_COW", 11); + define("MOB_PIG", 12); + define("MOB_SHEEP", 13); + + define("MOB_ZOMBIE", 32); + define("MOB_CREEPER", 33); + define("MOB_SKELETON", 34); + define("MOB_SPIDER", 35); + define("MOB_PIGMAN", 36); + define("ENTITY_OBJECT", 2); + define("ENTITY_ITEM", 3); + define("ENTITY_PAINTING", 4); class Entity extends stdClass{ - var $invincible, $air, $spawntime, $dmgcounter, $eid, $type, $name, $x, $y, $z, $speedX, $speedY, $speedZ, $speed, $last = array(0, 0, 0, 0), $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player, $onTick; + public $invincible; + public $age; + public $air; + public $spawntime; + public $dmgcounter; + public $eid; + public $type; + public $name; + public $x; + public $y; + public $z; + public $speedX; + public $speedY; + public $speedZ; + public $speed; + public $last = array(0, 0, 0, 0); + public $yaw; + public $pitch; + public $dead; + public $data; + public $class; + public $attach; + public $closed; + public $player; private $server; function __construct(PocketMinecraftServer $server, $eid, $class, $type = 0, $data = array()){ $this->server = $server; @@ -45,8 +82,9 @@ class Entity extends stdClass{ $this->data = $data; $this->status = 0; $this->health = 20; - $this->dmgcounter = array(0, 0); + $this->dmgcounter = array(0, 0, 0); $this->air = 300; + $this->onground = true; $this->fire = 0; $this->crouched = false; $this->invincible = false; @@ -57,7 +95,6 @@ class Entity extends stdClass{ $this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");"); $this->server->schedule(4, array($this, "update"), array(), true); $this->server->schedule(10, array($this, "environmentUpdate"), array(), true); - $this->metadata = array(); $this->x = isset($this->data["x"]) ? $this->data["x"]:0; $this->y = isset($this->data["y"]) ? $this->data["y"]:0; $this->z = isset($this->data["z"]) ? $this->data["z"]:0; @@ -77,9 +114,10 @@ class Entity extends stdClass{ case ENTITY_ITEM: $this->meta = (int) $this->data["meta"]; $this->stack = (int) $this->data["stack"]; - $this->setHealth(2, "generic"); + $this->setHealth(5, "generic"); break; case ENTITY_MOB: + $this->setHealth($this->data["Health"], "generic"); //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); break; case ENTITY_OBJECT: @@ -218,12 +256,16 @@ class Entity extends stdClass{ $flags = 0; $flags |= $this->fire > 0 ? 1:0; $flags |= ($this->crouched === true ? 1:0) << 1; - return array( + $d = 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)), ); + if($this->class === ENTITY_MOB and $this->type === MOB_SHEEP){ + $d[16]["value"] = (($this->data["Sheared"] == 1 ? 1:0) << 5) | ($this->data["Color"] & 0x0F); + } + return $d; } public function updateMetadata(){ @@ -390,7 +432,8 @@ class Entity extends stdClass{ $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); + $this->dmgcounter[0] = microtime(true) + 0.5; + $this->dmgcounter[1] = $dmg; }else{ return false; //Entity inmunity } diff --git a/src/classes/world/TileEntity.php b/src/classes/world/TileEntity.php index 10af394f2..2ed4d1b73 100644 --- a/src/classes/world/TileEntity.php +++ b/src/classes/world/TileEntity.php @@ -45,6 +45,9 @@ class TileEntity extends stdClass{ $this->class = (int) $class; $this->data = $data; $this->closed = false; + if($class === false){ + $this->closed = true; + } $this->name = ""; $this->id = (int) $id; $this->x = (int) $x; @@ -68,6 +71,9 @@ class TileEntity extends stdClass{ } public function spawn($player){ + if($this->closed){ + return false; + } if(!($player instanceof Player)){ $player = $this->server->api->player->get($player); }