diff --git a/src/Entity.php b/src/Entity.php index e41f9665c..e3ea2ae41 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -50,6 +50,8 @@ abstract class Entity extends Position{ public $lastUpdate; public $maxFireTicks; public $fireTicks; + public $namedtag; + protected $inWater; public $noDamageTicks; private $justCreated; @@ -75,7 +77,7 @@ abstract class Entity extends Position{ $this->level = $level; $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); - $this->setPosition(new Vector3($this->namedtag->x, $this->namedtag->y, $this->namedtag->z)); + $this->setPosition(new Vector3($this->namedtag->Pos[0], $this->namedtag->Pos[1], $this->namedtag->Pos[2])); $index = PMFLevel::getIndex($this->x >> 4, $this->z >> 4); $this->chunkIndex = $index; Entity::$list[$this->id] = $this; @@ -85,6 +87,12 @@ abstract class Entity extends Position{ $this->initEntity(); $this->server->api->dhandle("entity.add", $this); } + + public function saveNBT(){ + $this->namedtag->Pos[0] = $this->x; + $this->namedtag->Pos[1] = $this->y; + $this->namedtag->Pos[2] = $this->z; + } protected abstract function initEntity(); @@ -138,6 +146,8 @@ abstract class Entity extends Position{ Entity::$needUpdate[$this->id] = $this; } + public abstract function getMetadata(); + public function setOnFire($seconds){ $ticks = $seconds * 20; if($ticks > $this->fireTicks){ diff --git a/src/Player.php b/src/Player.php index c3393b706..b5bbd1e46 100644 --- a/src/Player.php +++ b/src/Player.php @@ -959,7 +959,7 @@ class Player{ $this->dataPacket($pk); $terrain = true; - foreach($this->server->api->player->getAll($this->level) as $player){ + foreach($this->level->getPlayers() as $player){ if($player !== $this and $player->entity instanceof Entity){ $pk = new MoveEntityPacket_PosRot; $pk->eid = $player->entity->eid; diff --git a/src/entity/HumanEntity.php b/src/entity/HumanEntity.php index 134e1e925..a5a96fad8 100644 --- a/src/entity/HumanEntity.php +++ b/src/entity/HumanEntity.php @@ -20,5 +20,50 @@ */ class HumanEntity extends CreatureEntity implements ProjectileSourceEntity{ + + protected $nameTag; + + protected function initEntity(){ + if(isset($this->namedtag->nameTag)){ + $this->nameTag = $this->namedtag->nameTag; + } + } + + public function spawnTo(Player $player){ + $pk = new AddPlayerPacket; + $pk->clientID = 0; + $pk->username = $this->nameTag; + $pk->eid = $this->id; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->yaw = 0; + $pk->pitch = 0; + $pk->unknown1 = 0; + $pk->unknown2 = 0; + $pk->metadata = $this->getMetadata(); + $player->dataPacket($pk); + + /* + $pk = new SetEntityMotionPacket; + $pk->eid = $this->id; + $pk->speedX = $this->velocity->x; + $pk->speedY = $this->velocity->y; + $pk->speedZ = $this->velocity->z; + $player->dataPacket($pk);*/ + $this->sendMotion($player); + + /* + $pk = new PlayerEquipmentPacket; + $pk->eid = $this->id; + $pk->item = $this->player->getSlot($this->player->slot)->getID(); + $pk->meta = $this->player->getSlot($this->player->slot)->getMetadata(); + $pk->slot = 0; + $player->dataPacket($pk);*/ + + $this->sendEquipment($player) + + $this->sendArmor($player); + } } \ No newline at end of file