diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index f3a97ea6..67981e29 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -48,6 +48,13 @@ class LevelAPI{ if(!isset($entity["id"])){ break; } + + $entity["x"] = $entity["Pos"][0]; + $entity["y"] = $entity["Pos"][1]; + $entity["z"] = $entity["Pos"][2]; + $entity["yaw"] = $entity["Rotation"][0]; + $entity["pitch"] = $entity["Rotation"][1]; + if($entity["id"] === 64){ //Item Drop $e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, $entity["Item"]["id"], [ "meta" => $entity["Item"]["Damage"], @@ -60,15 +67,15 @@ class LevelAPI{ ]); }elseif($entity["id"] === FALLING_SAND){ $e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity); - $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); + //$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); $e->setHealth($entity["Health"]); }elseif(Utils::getEntityTypeByID($entity["id"]) === ENTITY_OBJECT){ //Object $e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity); - $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); + //$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); $e->setHealth(1); }else{ $e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity); - $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); + //$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); $e->setHealth($entity["Health"]); } } diff --git a/src/entity/Creature.php b/src/entity/Creature.php index 3e821027..f5653d5b 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -12,4 +12,31 @@ abstract class Creature extends Living{ //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); $this->size = 1; } + + public function spawn($player){ + if(!($player instanceof Player)){ + $player = $this->server->api->player->get($player); + } + if($player->eid === $this->eid or $this->closed !== false or ($player->level !== $this->level and $this->class !== ENTITY_PLAYER)){ + return false; + } + $pk = new AddMobPacket; + $pk->eid = $this->eid; + $pk->type = $this->type; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->yaw = $this->yaw; + $pk->pitch = $this->pitch; + $pk->metadata = $this->getMetadata(); + $player->dataPacket($pk); + + $pk = new SetEntityMotionPacket; + $pk->eid = $this->eid; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); + } + } \ No newline at end of file diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 58c1a388..b18fb98c 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -64,12 +64,12 @@ class Entity extends Position{ $this->name = ""; $this->tickCounter = 0; $this->server->query("INSERT OR REPLACE INTO entities (EID, level, type, class, health, hasUpdate) VALUES (".$this->eid.", '".$this->level->getName()."', ".$this->type.", ".$this->class.", ".$this->health.", 0);"); - $this->x = isset($this->data["x"]) ? (float) $this->data["x"]:0; - $this->y = isset($this->data["y"]) ? (float) $this->data["y"]:0; - $this->z = isset($this->data["z"]) ? (float) $this->data["z"]:0; - $this->speedX = isset($this->data["speedX"]) ? (float) $this->data["speedX"]:0; - $this->speedY = isset($this->data["speedY"]) ? (float) $this->data["speedY"]:0; - $this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"]:0; + $this->x = isset($this->data["x"]) ? (float) $this->data["x"] : 0; + $this->y = isset($this->data["y"]) ? (float) $this->data["y"] : 0; + $this->z = isset($this->data["z"]) ? (float) $this->data["z"] : 0; + $this->speedX = isset($this->data["speedX"]) ? (float) $this->data["speedX"] : 0; + $this->speedY = isset($this->data["speedY"]) ? (float) $this->data["speedY"] : 0; + $this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0; $this->speed = 0; $this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"]:0; $this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"]:0; @@ -627,25 +627,6 @@ class Entity extends Position{ $pk->metadata = $this->getMetadata(); $player->dataPacket($pk); - $pk = new SetEntityMotionPacket; - $pk->eid = $this->eid; - $pk->speedX = $this->speedX; - $pk->speedY = $this->speedY; - $pk->speedZ = $this->speedZ; - $player->dataPacket($pk); - break; - case ENTITY_MOB: - $pk = new AddMobPacket; - $pk->eid = $this->eid; - $pk->type = $this->type; - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $pk->yaw = $this->yaw; - $pk->pitch = $this->pitch; - $pk->metadata = $this->getMetadata(); - $player->dataPacket($pk); - $pk = new SetEntityMotionPacket; $pk->eid = $this->eid; $pk->speedX = $this->speedX; diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index 7c1302da..9f0aa9f0 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -2,6 +2,8 @@ class Sheep extends Animal{ const TYPE = MOB_SHEEP; + const NOT_SHEARED = 0; + const SHEARED = 1; function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ parent::__construct($level, $eid, $class, $type, $data); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic"); @@ -24,10 +26,12 @@ class Sheep extends Animal{ public function getMetadata(){ $d = parent::getMetadata(); if(!isset($this->data["Sheared"])){ - $this->data["Sheared"] = 0; + $this->data["Sheared"] = NOT_SHEARED; + } + if(!isset($this->data["Color"])){ //Make a new random color if it is not in data $this->data["Color"] = $this->sheepColor(); } - $d[16]["value"] = (($this->data["Sheared"] == 1 ? 1:0) << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here... + $d[16]["value"] = (($this->data["Sheared"] == 1 ? Sheep::SHEARED : Sheep::NOT_SHEARED) << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here... return $d; } public function sheepColor(){