Example #1
0
 public function saveNBT()
 {
     parent::saveNBT();
     $this->namedtag->Item = $this->item->nbtSerialize();
     $this->namedtag->Health = new ShortTag("Health", $this->getHealth());
     $this->namedtag->Age = new ShortTag("Age", $this->age);
     $this->namedtag->PickupDelay = new ShortTag("PickupDelay", $this->pickupDelay);
     if ($this->owner !== null) {
         $this->namedtag->Owner = new StringTag("Owner", $this->owner);
     }
     if ($this->thrower !== null) {
         $this->namedtag->Thrower = new StringTag("Thrower", $this->thrower);
     }
 }
Example #2
0
 /**
  * This method should not be used by plugins, use the Inventory
  *
  * @param int  $index
  * @param Item $item
  *
  * @return bool
  */
 public function setItem($index, Item $item)
 {
     $i = $this->getSlotIndex($index);
     $d = $item->nbtSerialize($index);
     if ($item->getId() === Item::AIR or $item->getCount() <= 0) {
         if ($i >= 0) {
             unset($this->namedtag->Items[$i]);
         }
     } elseif ($i < 0) {
         for ($i = 0; $i <= $this->getSize(); ++$i) {
             if (!isset($this->namedtag->Items[$i])) {
                 break;
             }
         }
         $this->namedtag->Items[$i] = $d;
     } else {
         $this->namedtag->Items[$i] = $d;
     }
     return true;
 }
Example #3
0
 /**
  * @param Vector3 $source
  * @param Item    $item
  * @param Vector3 $motion
  * @param int     $delay
  */
 public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, int $delay = 10)
 {
     $motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;
     $itemTag = $item->nbtSerialize();
     $itemTag->setName("Item");
     if ($item->getId() > 0 and $item->getCount() > 0) {
         $itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4, true), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $source->getX()), new DoubleTag("", $source->getY()), new DoubleTag("", $source->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion->x), new DoubleTag("", $motion->y), new DoubleTag("", $motion->z)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $itemTag, "PickupDelay" => new ShortTag("PickupDelay", $delay)]));
         $itemEntity->spawnToAll();
     }
 }