namedtag->id = new String("id", "Item"); $this->setMaxHealth(5); $this->setHealth(@$this->namedtag["Health"]); if(isset($this->namedtag->Age)){ $this->age = $this->namedtag["Age"]; } if(isset($this->namedtag->PickupDelay)){ $this->pickupDelay = $this->namedtag["PickupDelay"]; } if(isset($this->namedtag->Owner)){ $this->owner = $this->namedtag["Owner"]; } if(isset($this->namedtag->Thrower)){ $this->thrower = $this->namedtag["Thrower"]; } $this->item = Item::get($this->namedtag->Item["id"], $this->namedtag->Item["Damage"], min(64, $this->namedtag->Item["Count"])); } public function attack($damage, $source = "generic"){ } public function heal($amount, $source = "generic"){ } public function saveNBT(){ $this->namedtag->Item = new Compound("Item", [ "id" => new Short("id", $this->item->getID()), "Damage" => new Short("Damage", $this->item->getDamage()), "Count" => new Byte("Count", $this->item->getCount()) ]); $this->namedtag->Health = new Short("Health", $this->getHealth()); $this->namedtag->Age = new Short("Age", $this->age); $this->namedtag->PickupDelay = new Short("PickupDelay", $this->pickupDelay); if($this->owner !== null){ $this->namedtag->Owner = new String("Owner", $this->owner); } if($this->thrower !== null){ $this->namedtag->Thrower = new String("Thrower", $this->thrower); } } public function getData(){ $flags = 0; $flags |= $this->fireTicks > 0 ? 1 : 0; return [ 0 => array("type" => 0, "value" => $flags), 1 => array("type" => 1, "value" => 0), 16 => array("type" => 0, "value" => 0), 17 => array("type" => 6, "value" => array(0, 0, 0)), ]; } /** * @return Item */ public function getItem(){ return $this->item; } /** * @return int */ public function getPickupDelay(){ return $this->pickupDelay; } /** * @param int $delay */ public function setPickupDelay($delay){ $this->pickupDelay = $delay; } /** * @return string */ public function getOwner(){ return $this->owner; } /** * @param string $owner */ public function setOwner($owner){ $this->owner = $owner; } /** * @return string */ public function getThrower(){ return $this->thrower; } /** * @param string $thrower */ public function setThrower($thrower){ $this->thrower = $thrower; } public function spawnTo(Player $player){ $pk = new AddItemEntityPacket(); $pk->eid = $this->getID(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->roll = 0; $pk->item = $this->getItem(); $pk->metadata = $this->getData(); $player->dataPacket($pk); $pk = new SetEntityMotionPacket; $pk->eid = $this->getID(); $pk->speedX = $this->motionX; $pk->speedY = $this->motionY; $pk->speedZ = $this->motionZ; $player->dataPacket($pk); parent::spawnTo($player); } }