本文整理汇总了PHP中pocketmine\nbt\NBT::getItemHelper方法的典型用法代码示例。如果您正苦于以下问题:PHP NBT::getItemHelper方法的具体用法?PHP NBT::getItemHelper怎么用?PHP NBT::getItemHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\nbt\NBT
的用法示例。
在下文中一共展示了NBT::getItemHelper方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initEntity
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;
}
assert($this->namedtag->Item instanceof CompoundTag);
$this->item = NBT::getItemHelper($this->namedtag->Item);
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
}
示例2: __construct
public function __construct(Human $player, $contents = null)
{
$this->hotbar = range(0, $this->getHotbarSize() - 1, 1);
parent::__construct($player, InventoryType::get(InventoryType::PLAYER));
if ($contents !== null) {
if ($contents instanceof ListTag) {
//Saved data to be loaded into the inventory
foreach ($contents as $item) {
if ($item["Slot"] >= 0 and $item["Slot"] < $this->getHotbarSize()) {
//Hotbar
if (isset($item["TrueSlot"])) {
//Valid slot was found, change the linkage to this slot
if (0 <= $item["TrueSlot"] and $item["TrueSlot"] < $this->getSize()) {
$this->hotbar[$item["Slot"]] = $item["TrueSlot"];
} elseif ($item["TrueSlot"] < 0) {
//Link to an empty slot (empty hand)
$this->hotbar[$item["Slot"]] = -1;
}
}
/* If TrueSlot is not set, leave the slot index as its default which was filled in above
* This only overwrites slot indexes for valid links */
} elseif ($item["Slot"] >= 100 and $item["Slot"] < 104) {
//Armor
$this->setItem($this->getSize() + $item["Slot"] - 100, NBT::getItemHelper($item), false);
} else {
$this->setItem($item["Slot"] - $this->getHotbarSize(), NBT::getItemHelper($item), false);
}
}
} else {
throw new \InvalidArgumentException("Expecting ListTag, received " . gettype($contents));
}
}
}
示例3: getItem
/**
* This method should not be used by plugins, use the Inventory
*
* @param int $index
*
* @return Item
*/
public function getItem($index)
{
$i = $this->getSlotIndex($index);
if ($i < 0) {
return Item::get(Item::AIR, 0, 0);
} else {
return NBT::getItemHelper($this->namedtag->Items[$i]);
}
}
示例4: place
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
{
if ($face > 1) {
$faces = [2 => 3, 3 => 2, 4 => 1, 5 => 4];
$itemTag = NBT::putItemHelper(Item::get(Item::AIR));
$itemTag->setName("Item");
$nbt = new CompoundTag("", [new StringTag("id", MainClass::TILE_ITEM_FRAME), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z), new CompoundTag("Item", $itemTag->getValue()), new FloatTag("ItemDropChance", 1.0), new ByteTag("ItemRotation", 0)]);
if ($item->hasCustomBlockData()) {
foreach ($item->getCustomBlockData() as $key => $value) {
//Reformat: support "Item" tag by give command
if ($key === "Item" and $value instanceof CompoundTag) {
$value = NBT::putItemHelper(NBT::getItemHelper($value));
$value->setName("Item");
}
$nbt->{$key} = $value;
}
}
//var_dump($nbt);//debug
Tile::createTile("ItemFrame", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
$this->getLevel()->setBlock($block, Block::get(MainClass::BLOCK_ITEM_FRAME, $faces[$face]), true, true);
return true;
}
return false;
}
示例5: initEntity
protected function initEntity()
{
$this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false);
$this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0]);
$this->inventory = new PlayerInventory($this);
if ($this instanceof Player) {
$this->addWindow($this->inventory, 0);
}
if (!$this instanceof Player) {
if (isset($this->namedtag->NameTag)) {
$this->setNameTag($this->namedtag["NameTag"]);
}
if (isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof Compound) {
$this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Slim"] > 0, $this->namedtag->Skin["Transparent"] > 0);
}
$this->uuid = UUID::fromData($this->getId(), $this->getSkinData(), $this->getNameTag());
}
if (isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof Enum) {
foreach ($this->namedtag->Inventory as $item) {
if ($item["Slot"] >= 0 and $item["Slot"] < 9) {
//Hotbar
$this->inventory->setHotbarSlotIndex($item["Slot"], isset($item["TrueSlot"]) ? $item["TrueSlot"] : -1);
} elseif ($item["Slot"] >= 100 and $item["Slot"] < 104) {
//Armor
$this->inventory->setItem($this->inventory->getSize() + $item["Slot"] - 100, NBT::getItemHelper($item));
} else {
$this->inventory->setItem($item["Slot"] - 9, NBT::getItemHelper($item));
}
}
}
parent::initEntity();
}
示例6: getItem
public function getItem()
{
return NBT::getItemHelper($this->namedtag->Item);
}
示例7: initEntity
protected function initEntity()
{
$this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false);
$this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0], false);
$this->inventory = new PlayerInventory($this);
if ($this instanceof Player) {
$this->addWindow($this->inventory, 0);
} else {
if (isset($this->namedtag->NameTag)) {
$this->setNameTag($this->namedtag["NameTag"]);
}
if (isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof CompoundTag) {
$this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Name"]);
}
$this->uuid = UUID::fromData($this->getId(), $this->getSkinData(), $this->getNameTag());
}
if (isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof ListTag) {
foreach ($this->namedtag->Inventory as $item) {
if ($item["Slot"] >= 0 and $item["Slot"] < 9) {
//Hotbar
$this->inventory->setHotbarSlotIndex($item["Slot"], isset($item["TrueSlot"]) ? $item["TrueSlot"] : -1);
} elseif ($item["Slot"] >= 100 and $item["Slot"] < 104) {
//Armor
$this->inventory->setItem($this->inventory->getSize() + $item["Slot"] - 100, NBT::getItemHelper($item));
} else {
$this->inventory->setItem($item["Slot"] - 9, NBT::getItemHelper($item));
}
}
}
parent::initEntity();
if (!isset($this->namedtag->foodLevel) or !$this->namedtag->foodLevel instanceof IntTag) {
$this->namedtag->foodLevel = new IntTag("foodLevel", $this->getFood());
} else {
$this->setFood($this->namedtag["foodLevel"]);
}
if (!isset($this->namedtag->foodExhaustionLevel) or !$this->namedtag->foodExhaustionLevel instanceof IntTag) {
$this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
} else {
$this->setExhaustion($this->namedtag["foodExhaustionLevel"]);
}
if (!isset($this->namedtag->foodSaturationLevel) or !$this->namedtag->foodSaturationLevel instanceof IntTag) {
$this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
} else {
$this->setSaturation($this->namedtag["foodSaturationLevel"]);
}
if (!isset($this->namedtag->foodTickTimer) or !$this->namedtag->foodTickTimer instanceof IntTag) {
$this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
} else {
$this->foodTickTimer = $this->namedtag["foodTickTimer"];
}
if (!isset($this->namedtag->XpLevel) or !$this->namedtag->XpLevel instanceof IntTag) {
$this->namedtag->XpLevel = new IntTag("XpLevel", $this->getXpLevel());
} else {
$this->setXpLevel($this->namedtag["XpLevel"]);
}
if (!isset($this->namedtag->XpP) or !$this->namedtag->XpP instanceof FloatTag) {
$this->namedtag->XpP = new FloatTag("XpP", $this->getXpProgress());
}
if (!isset($this->namedtag->XpTotal) or !$this->namedtag->XpTotal instanceof IntTag) {
$this->namedtag->XpTotal = new IntTag("XpTotal", $this->totalXp);
} else {
$this->totalXp = $this->namedtag["XpTotal"];
}
if (!isset($this->namedtag->XpSeed) or !$this->namedtag->XpSeed instanceof IntTag) {
$this->namedtag->XpSeed = new IntTag("XpSeed", $this->xpSeed ?? ($this->xpSeed = mt_rand(PHP_INT_MIN, PHP_INT_MAX)));
} else {
$this->xpSeed = $this->namedtag["XpSeed"];
}
}