getId() final public method

final public getId ( ) : integer
return integer
Example #1
8
 /**
  * @param Item $item
  * @param int  $slot
  * @return CompoundTag
  */
 public static function putItemHelper(Item $item, $slot = null)
 {
     $tag = new CompoundTag(null, ["id" => new ShortTag("id", $item->getId()), "Count" => new ByteTag("Count", $item->getCount()), "Damage" => new ShortTag("Damage", $item->getDamage())]);
     if ($slot !== null) {
         $tag->Slot = new ByteTag("Slot", (int) $slot);
     }
     if ($item->hasCompoundTag()) {
         $tag->tag = clone $item->getNamedTag();
         $tag->tag->setName("tag");
     }
     return $tag;
 }
Example #2
4
 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if (!$tile instanceof ItemFrameTile) {
         $nbt = new CompoundTag("", [new StringTag("id", Tile::ITEM_FRAME), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z), new ByteTag("ItemRotation", 0), new FloatTag("ItemDropChance", 1.0)]);
         Tile::createTile(Tile::ITEM_FRAME, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
     }
     $tile = $this->getLevel()->getTile($this);
     if (!$tile instanceof ItemFrameTile) {
         return false;
     }
     if ($tile->getItem()->getId() === 0) {
         $tile->setItem(Item::get($item->getId(), $item->getDamage(), 1));
         if ($player instanceof Player) {
             if ($player->isSurvival()) {
                 $count = $item->getCount();
                 if (--$count <= 0) {
                     $player->getInventory()->setItemInHand(Item::get(Item::AIR));
                     return true;
                 }
                 $item->setCount($count);
                 $player->getInventory()->setItemInHand($item);
             }
         }
     } else {
         $itemRot = $tile->getItemRotation();
         if ($itemRot === 7) {
             $itemRot = 0;
         } else {
             $itemRot++;
         }
         $tile->setItemRotation($itemRot);
     }
     return true;
 }
Example #3
2
 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if ($this->meta == 0) {
         switch ($item->getId()) {
             case Item::BUCKET:
                 if ($item->getDamage() === 8) {
                     $this->meta = 6;
                     $this->getLevel()->setBlock($this, $this, true, false);
                     if ($player->isSurvival()) {
                         $item->setDamage(0);
                         $player->getInventory()->setItemInHand($item(), $player);
                     }
                 }
                 return true;
                 break;
         }
     }
     return false;
 }
Example #4
0
 protected function initEntity()
 {
     parent::initEntity();
     $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"];
     }
     if (!isset($this->namedtag->Item)) {
         $this->close();
         return;
     }
     $this->item = NBT::getItemHelper($this->namedtag->Item);
     if ($this->item->getId() <= 0) {
         $this->close();
         return;
     }
     $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
 }
Example #5
0
 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if ($tile instanceof FlowerPotTile) {
         if ($tile->getFlowerPotItem() === Item::AIR) {
             switch ($item->getId()) {
                 case Item::TALL_GRASS:
                     if ($item->getDamage() === 1) {
                         break;
                     }
                 case Item::SAPLING:
                 case Item::DEAD_BUSH:
                 case Item::DANDELION:
                 case Item::RED_FLOWER:
                 case Item::BROWN_MUSHROOM:
                 case Item::RED_MUSHROOM:
                 case Item::CACTUS:
                     $tile->setFlowerPotData($item->getId(), $item->getDamage());
                     $this->setDamage($item->getId());
                     $this->getLevel()->setBlock($this, $this, true, false);
                     if ($player->isSurvival()) {
                         $item->count--;
                     }
                     return true;
                     break;
             }
         }
     }
     return false;
 }
 /**
  * @param Item $item
  * @param int  $modifiedLevel
  * @return Enchantment[]
  */
 public static function getPossibleEnchantments(Item $item, int $modifiedLevel)
 {
     $result = [];
     $enchantmentIds = [];
     if ($item->getId() == Item::BOOK) {
         $enchantmentIds = array_keys(self::$map);
     } elseif ($item->isArmor()) {
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_PROTECTION;
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_FIRE_PROTECTION;
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_EXPLOSION_PROTECTION;
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_PROJECTILE_PROTECTION;
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_THORNS;
         if ($item->isBoots()) {
             $enchantmentIds[] = Enchantment::TYPE_ARMOR_FALL_PROTECTION;
         }
         if ($item->isHelmet()) {
             $enchantmentIds[] = Enchantment::TYPE_WATER_BREATHING;
             $enchantmentIds[] = Enchantment::TYPE_WATER_AFFINITY;
         }
     } elseif ($item->isSword()) {
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_SHARPNESS;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_SMITE;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_ARTHROPODS;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_KNOCKBACK;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_FIRE_ASPECT;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_LOOTING;
     } elseif ($item->isTool()) {
         $enchantmentIds[] = Enchantment::TYPE_MINING_EFFICIENCY;
         $enchantmentIds[] = Enchantment::TYPE_MINING_SILK_TOUCH;
         $enchantmentIds[] = Enchantment::TYPE_MINING_FORTUNE;
     } elseif ($item->getId() == Item::BOW) {
         $enchantmentIds[] = Enchantment::TYPE_BOW_POWER;
         $enchantmentIds[] = Enchantment::TYPE_BOW_KNOCKBACK;
         $enchantmentIds[] = Enchantment::TYPE_BOW_FLAME;
         $enchantmentIds[] = Enchantment::TYPE_BOW_INFINITY;
     } elseif ($item->getId() == Item::FISHING_ROD) {
         $enchantmentIds[] = Enchantment::TYPE_FISHING_FORTUNE;
         $enchantmentIds[] = Enchantment::TYPE_FISHING_LURE;
     }
     if ($item->isTool() || $item->isArmor()) {
         $enchantmentIds[] = Enchantment::TYPE_MINING_DURABILITY;
     }
     foreach ($enchantmentIds as $enchantmentId) {
         $enchantment = Enchantment::getEnchantment($enchantmentId);
         $ranges = self::$map[$enchantmentId];
         $i = 0;
         /** @var Range $range */
         foreach ($ranges as $range) {
             $i++;
             if (self::isInRange($range[0], $range[1], $modifiedLevel)) {
                 $result[] = $enchantment->setLevel($i);
             }
         }
     }
     return $result;
 }
Example #7
0
 /**
  * Given an pocketmine\item\Item object, it returns a friendly name
  * for it.
  *
  * @param Item item
  * @return str
  */
 public static function str(Item $item)
 {
     if (self::$xnames == null) {
         self::initXnames();
     }
     if (isset(self::$xnames[$item->getId()])) {
         if (isset(self::$xnames[$item->getId()][$item->getDamage()])) {
             return self::$xnames[$item->getId()][$item->getDamage()];
         } elseif (isset(self::$xnames[$item->getId()]["*"])) {
             return self::$xnames[$item->getId()]["*"];
         } else {
             return self::$xnames[$item->getId()][0];
         }
     }
     $n = $item->getName();
     if ($n != "Unknown") {
         return $n;
     }
     if (count(self::$items) == 0) {
         $constants = array_keys((new \ReflectionClass("pocketmine\\item\\Item"))->getConstants());
         foreach ($constants as $constant) {
             $id = constant("pocketmine\\item\\Item::{$constant}");
             $constant = str_replace("_", " ", $constant);
             self::$items[$id] = $constant;
         }
     }
     if (isset(self::$items[$item->getId()])) {
         return self::$items[$item->getId()];
     }
     return $n;
 }
Example #8
0
 /**
  * @param string $name
  * @param array|Item[] $items
  */
 public function __construct($name, array $items)
 {
     $this->name = $name;
     foreach ($items as $i) {
         if (!$i instanceof Item) {
             $i = explode(" ", $i);
             if (count($i) > 1) {
                 $amount = $i[1];
                 unset($i[1]);
             } else {
                 $amount = 1;
             }
             $i = explode(":", $i[0]);
             if (count($i) > 1) {
                 $id = $i[0];
                 $meta = $i[1];
             } else {
                 $id = $i[0];
                 $meta = 0;
             }
             $i = new Item($id, $meta, $amount);
         }
         $this->items[$i->getId()] = $i;
     }
 }
Example #9
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === Dye::BONEMEAL) {
         $grow = false;
         if ($this->getSide(0)->getId() !== self::SUGARCANE_BLOCK && $this->getSide(0, 2)->getId() !== self::SUGARCANE_BLOCK) {
             for ($y = 1; $y < 2; $y++) {
                 $b = $this->getSide(1, $y);
                 if ($b->getId() === self::AIR) {
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                         $grow = true;
                     }
                     break;
                 } else {
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if ($grow && $player->isSurvival()) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
Example #10
0
 /**
  * Returns the change in inventory resulting from this transaction
  * @return Item[
  *				"in" => items added to the inventory
  *				"out" => items removed from the inventory
  * ]
  */
 public function getChange()
 {
     $sourceItem = $this->getInventory()->getItem($this->slot);
     if ($sourceItem->deepEquals($this->targetItem, true, true, true)) {
         //This should never happen, somehow a change happened where nothing changed
         return null;
     } elseif ($sourceItem->deepEquals($this->targetItem)) {
         //Same item, change of count
         $item = clone $sourceItem;
         $countDiff = $this->targetItem->getCount() - $sourceItem->getCount();
         $item->setCount(abs($countDiff));
         if ($countDiff < 0) {
             //Count decreased
             return ["in" => null, "out" => $item];
         } elseif ($countDiff > 0) {
             //Count increased
             return ["in" => $item, "out" => null];
         } else {
             //Should be impossible (identical items and no count change)
             //This should be caught by the first condition even if it was possible
             return null;
         }
     } elseif ($sourceItem->getId() !== Item::AIR and $this->targetItem->getId() === Item::AIR) {
         //Slot emptied (item removed)
         return ["in" => null, "out" => clone $sourceItem];
     } elseif ($sourceItem->getId() === Item::AIR and $this->targetItem->getId() !== Item::AIR) {
         //Slot filled (item added)
         return ["in" => $this->getTargetItem(), "out" => null];
     } else {
         //Some other slot change - an item swap (tool damage changes will be ignored as they are processed server-side before any change is sent by the client
         return ["in" => $this->getTargetItem(), "out" => clone $sourceItem];
     }
 }
Example #11
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf) {
         //Bonemeal
         if ($this->getSide(0)->getId() !== self::SUGARCANE_BLOCK) {
             for ($y = 1; $y < 3; ++$y) {
                 $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
                 if ($b->getId() === self::AIR) {
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                     }
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
Example #12
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf and $this->getDamage() === 1 || $this->getDamage() === 2) {
         $this->getLevel()->setBlock($this->getSide(1), new DoublePlant($this->getDamage() + 1 ^ 0x8));
         $this->getLevel()->setBlock($this, new DoublePlant($this->getDamage() + 1));
         return true;
     } else {
         return false;
     }
 }
Example #13
0
 public function setItem(Item $item)
 {
     $this->namedtag["item"] = $item->getId();
     $this->namedtag["mData"] = $item->getDamage();
     $this->spawnToAll();
     if ($this->chunk) {
         $this->chunk->setChanged();
         $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ());
     }
 }
Example #14
0
 /**
  * Count amount of items
  * @param Player $target
  * @param Item $item
  * @return int
  */
 public static function countInvItem(Player $target, Item $item)
 {
     $k = 0;
     foreach ($target->getInventory()->getContents() as $slot => &$inv) {
         if ($inv->getId() == $item->getId()) {
             $k += $inv->getCount();
         }
     }
     return $k;
 }
Example #15
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() == Item::SPAWN_EGG) {
         $tile = $this->getLevel()->getTile($this);
         if ($tile instanceof MobSpawner) {
             $tile->setEntityId($item->getDamage());
             return true;
         }
     }
     return false;
 }
Example #16
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::FLINT_STEEL) {
         $item->useOn($this);
         $this->getLevel()->setBlock($this, new Air(), true);
         $mot = (new Random())->nextSignedFloat() * M_PI * 2;
         $tnt = Entity::createEntity("PrimedTNT", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + 0.5), new DoubleTag("", $this->y), new DoubleTag("", $this->z + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($mot) * 0.02), new DoubleTag("", 0.2), new DoubleTag("", -cos($mot) * 0.02)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 80)]));
         $tnt->spawnToAll();
         return true;
     }
     return false;
 }
Example #17
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf) {
         //Bonemeal
         //TODO: change log type
         Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x7, false);
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
Example #18
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf) {
         $item->count--;
         TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
         return true;
     } elseif ($item->isHoe()) {
         $item->useOn($this);
         $this->getLevel()->setBlock($this, new Farmland());
         return true;
     }
     return false;
 }
Example #19
0
 public function saveNBT()
 {
     parent::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 spawnTo(Player $player)
 {
     $app = new AddPlayerPacket();
     $app->clientID = $this->eid();
     $app->username = $this->nameTag;
     $app->eid = $this->eid();
     $app->x = $this->x;
     $app->y = $this->y;
     $app->z = $this->z;
     $app->speedX = 0;
     $app->speedY = 0;
     $app->speedZ = 0;
     $app->yaw = $this->yaw;
     $app->pitch = $this->pitch;
     $app->item = $this->item->getId();
     $app->meta = $this->item->getDamage();
     $app->skin = $this->skin;
     $app->slim = $this->slim;
     $app->metadata = $this->metadata;
     $player->dataPacket($app);
     $this->player = $player;
     $this->setDataFlag(Human::DATA_PLAYER_FLAGS, Human::DATA_PLAYER_FLAG_SLEEP, false);
     $this->setDataProperty(Human::DATA_PLAYER_BED_POSITION, Entity::DATA_TYPE_POS, [0, 0, 0]);
 }
Example #21
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf) {
         $block = clone $this;
         if ($block->meta > 7) {
             return false;
         }
         $block->meta += 4;
         Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
         if (!$ev->isCancelled()) {
             $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
         }
         $item->count--;
         return true;
     }
     return false;
 }
Example #22
0
 public final function equals(Item $item, $checkDamage = true, $checkCompound = true)
 {
     return $this->id === $item->getId() and ($checkDamage === false or $this->getDamage() === $item->getDamage()) and ($checkCompound === false or $this->getCompoundTag() === $item->getCompoundTag());
 }
 public function putSlot(Item $item)
 {
     if ($item->getId() === 0) {
         $this->putShort(0);
         return;
     }
     $this->putShort($item->getId());
     $this->putByte($item->getCount());
     $this->putShort($item->getDamage() === null ? -1 : $item->getDamage());
     $nbt = $item->getCompoundTag();
     $this->putLShort(strlen($nbt));
     $this->put($nbt);
 }
 public function setItem($index, Item $item)
 {
     if ($index < 0 or $index >= $this->size) {
         return false;
     } elseif ($item->getId() === 0 or $item->getCount() <= 0) {
         return $this->clear($index);
     }
     if ($index >= $this->getSize()) {
         //Armor change
         Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $item, $index));
         if ($ev->isCancelled() and $this->getHolder() instanceof Human) {
             $this->sendArmorSlot($index, $this->getViewers());
             return false;
         }
         $item = $ev->getNewItem();
     } else {
         Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($this->getHolder(), $this->getItem($index), $item, $index));
         if ($ev->isCancelled()) {
             $this->sendSlot($index, $this->getViewers());
             return false;
         }
         $item = $ev->getNewItem();
     }
     $old = $this->getItem($index);
     $this->slots[$index] = clone $item;
     $this->onSlotChange($index, $old);
     return true;
 }
 /**
  * @param Item $input
  * 
  * @return BrewingRecipe
  */
 public function matchBrewingRecipe(Item $input)
 {
     if (isset($this->BrewingRecipes[$input->getId() . ":" . $input->getDamage()])) {
         return $this->BrewingRecipes[$input->getId() . ":" . $input->getDamage()];
     } elseif (isset($this->BrewingRecipes[$input->getId() . ":?"])) {
         return $this->BrewingRecipes[$input->getId() . ":?"];
     }
     return null;
 }
Example #26
0
 /**
  * @param Item $input
  * @param Item $potion
  *
  * @return BrewingRecipe
  */
 public function matchBrewingRecipe(Item $input, Item $potion)
 {
     if (isset($this->brewingRecipes[$input->getId() . ":" . ($potion->getDamage() === null ? "0" : $potion->getDamage())])) {
         return $this->brewingRecipes[$input->getId() . ":" . ($potion->getDamage() === null ? "0" : $potion->getDamage())];
     }
     return null;
 }
Example #27
0
 public function checkIngredient(Item $item)
 {
     if (isset(self::$ingredients[$item->getId()])) {
         if (self::$ingredients[$item->getId()] === $item->getDamage()) {
             return true;
         }
     }
     return false;
 }
 public function __construct(Vector3 $pos, Item $item)
 {
     parent::__construct($pos, Particle::TYPE_ITEM_BREAK, $item->getId() << 16 | $item->getDamage());
 }
 /**
  * @param Item $item
  * @param Level $level
  * @return bool
  */
 public function isItemBannedInLevel(Item $item, Level $level)
 {
     return in_array($item->getId() . ":" . $item->getDamage(), $this->getConfig()->getNested("level." . strtolower($level->getName()) . ".bannedItems"));
 }
Example #30
-1
 /**
  * @param Vector3 $source
  * @param Item    $item
  * @param Vector3 $motion
  * @param int     $delay
  */
 public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10)
 {
     $motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;
     if ($item->getId() > 0 and $item->getCount() > 0) {
         $itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $source->getX()), new Double("", $source->getY()), new Double("", $source->getZ())]), "Motion" => new Enum("Motion", [new Double("", $motion->x), new Double("", $motion->y), new Double("", $motion->z)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)]), "Health" => new Short("Health", 5), "Item" => new Compound("Item", ["id" => new Short("id", $item->getId()), "Damage" => new Short("Damage", $item->getDamage()), "Count" => new Byte("Count", $item->getCount())]), "PickupDelay" => new Short("PickupDelay", $delay)]));
         $itemEntity->spawnToAll();
     }
 }