本文整理汇总了PHP中pocketmine\nbt\NBT::putItemHelper方法的典型用法代码示例。如果您正苦于以下问题:PHP NBT::putItemHelper方法的具体用法?PHP NBT::putItemHelper怎么用?PHP NBT::putItemHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\nbt\NBT
的用法示例。
在下文中一共展示了NBT::putItemHelper方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setItem
public function setItem(Item $item, bool $setChanged = true)
{
$nbtItem = NBT::putItemHelper($item);
$nbtItem->setName("Item");
$this->namedtag->Item = $nbtItem;
if ($setChanged) {
$this->setChanged();
}
}
示例2: setItem
public function setItem(Item $item)
{
$tag = NBT::putItemHelper($item);
$tag->setName("Item");
$this->namedtag->Item = $tag;
$this->spawnToAll();
if ($this->chunk) {
$this->chunk->setChanged();
$this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ());
}
}
示例3: setItem
/**
* 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 = NBT::putItemHelper($item, $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;
}
示例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: saveNBT
public function saveNBT()
{
parent::saveNBT();
$this->namedtag->Item = NBT::putItemHelper($this->item);
$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);
}
}
示例6: dropItem
/**
* @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;
$itemTag = NBT::putItemHelper($item);
$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 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" => $itemTag, "PickupDelay" => new Short("PickupDelay", $delay)]));
$itemEntity->spawnToAll();
}
}
示例7: saveNBT
public function saveNBT()
{
parent::saveNBT();
$this->namedtag->Inventory = new Enum("Inventory", []);
$this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
if ($this->inventory !== null) {
for ($slot = 0; $slot < 9; ++$slot) {
$hotbarSlot = $this->inventory->getHotbarSlotIndex($slot);
if ($hotbarSlot !== -1) {
$item = $this->inventory->getItem($hotbarSlot);
if ($item->getId() !== 0 and $item->getCount() > 0) {
$tag = NBT::putItemHelper($item, $slot);
$tag->TrueSlot = new Byte("TrueSlot", $hotbarSlot);
$this->namedtag->Inventory[$slot] = $tag;
continue;
}
}
$this->namedtag->Inventory[$slot] = new Compound("", [new Byte("Count", 0), new Short("Damage", 0), new Byte("Slot", $slot), new Byte("TrueSlot", -1), new Short("id", 0)]);
}
//Normal inventory
$slotCount = Player::SURVIVAL_SLOTS + 9;
//$slotCount = (($this instanceof Player and ($this->gamemode & 0x01) === 1) ? Player::CREATIVE_SLOTS : Player::SURVIVAL_SLOTS) + 9;
for ($slot = 9; $slot < $slotCount; ++$slot) {
$item = $this->inventory->getItem($slot - 9);
$this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot);
}
//Armor
for ($slot = 100; $slot < 104; ++$slot) {
$item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100);
if ($item instanceof ItemItem and $item->getId() !== ItemItem::AIR) {
$this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot);
}
}
}
if (strlen($this->getSkinData()) > 0) {
$this->namedtag->Skin = new Compound("Skin", ["Data" => new String("Data", $this->getSkinData()), "Slim" => new Byte("Slim", $this->isSkinSlim() ? 1 : 0), "Transparent" => new Byte("Transparent", $this->isSkinTransparent() ? 1 : 0)]);
}
}
示例8: saveNBT
public function saveNBT()
{
parent::saveNBT();
$this->namedtag->Inventory = new ListTag("Inventory", []);
$this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
if ($this->inventory !== null) {
//Hotbar
for ($slot = 0; $slot < $this->inventory->getHotbarSize(); ++$slot) {
$inventorySlotIndex = $this->inventory->getHotbarSlotIndex($slot);
$item = $this->inventory->getItem($inventorySlotIndex);
$tag = NBT::putItemHelper($item, $slot);
$tag->TrueSlot = new ByteTag("TrueSlot", $inventorySlotIndex);
$this->namedtag->Inventory[$slot] = $tag;
}
//Normal inventory
$slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize();
for ($slot = $this->inventory->getHotbarSize(); $slot < $slotCount; ++$slot) {
$item = $this->inventory->getItem($slot - $this->inventory->getHotbarSize());
//As NBT, real inventory slots are slots 9-44, NOT 0-35
$this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot);
}
//Armour
for ($slot = 100; $slot < 104; ++$slot) {
$item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100);
if ($item instanceof ItemItem and $item->getId() !== ItemItem::AIR) {
$this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot);
}
}
}
if (strlen($this->getSkinData()) > 0) {
$this->namedtag->Skin = new CompoundTag("Skin", ["Data" => new StringTag("Data", $this->getSkinData()), "Name" => new StringTag("Name", $this->getSkinId())]);
}
//Xp
$this->namedtag->XpLevel = new IntTag("XpLevel", $this->getXpLevel());
$this->namedtag->XpTotal = new IntTag("XpTotal", $this->getTotalXp());
$this->namedtag->XpP = new FloatTag("XpP", $this->getXpProgress());
$this->namedtag->XpSeed = new IntTag("XpSeed", $this->getXpSeed());
//Food
$this->namedtag->foodLevel = new IntTag("foodLevel", $this->getFood());
$this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
$this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
$this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
}
示例9: activate
public function activate()
{
$itemIndex = [];
for ($i = 0; $i < $this->getSize(); $i++) {
$item = $this->getInventory()->getItem($i);
if ($item->getId() != Item::AIR) {
$itemIndex[] = [$i, $item];
}
}
$max = count($itemIndex) - 1;
if ($max < 0) {
$itemArr = null;
} elseif ($max == 0) {
$itemArr = $itemIndex[0];
} else {
$itemArr = $itemIndex[mt_rand(0, $max)];
}
if (is_array($itemArr)) {
/** @var Item $item */
$item = $itemArr[1];
$item->setCount($item->getCount() - 1);
$this->getInventory()->setItem($itemArr[0], $item->getCount() > 0 ? $item : Item::get(Item::AIR));
$motion = $this->getMotion();
$needItem = Item::get($item->getId(), $item->getDamage());
$block = $this->getLevel()->getBlock($this->add($motion[0], $motion[1], $motion[2]));
switch ($block->getId()) {
case Block::CHEST:
case Block::TRAPPED_CHEST:
case Block::DROPPER:
case Block::DISPENSER:
case Block::BREWING_STAND_BLOCK:
case Block::FURNACE:
$t = $this->getLevel()->getTile($block);
/** @var Chest|Dispenser|Dropper|BrewingStand|Furnace $t */
if ($t instanceof Tile) {
if ($t->getInventory()->canAddItem($needItem)) {
$t->getInventory()->addItem($needItem);
return;
}
}
}
$itemTag = NBT::putItemHelper($needItem);
$itemTag->setName("Item");
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $itemTag, "PickupDelay" => new ShortTag("PickupDelay", 10)]);
$f = 0.3;
$itemEntity = new ItemEntity($this->chunk, $nbt, $this);
$itemEntity->setMotion($itemEntity->getMotion()->multiply($f));
$itemEntity->spawnToAll();
for ($i = 1; $i < 10; $i++) {
$this->getLevel()->addParticle(new SmokeParticle($this->add($motion[0] * $i * 0.3 + 0.5, $motion[1] == 0 ? 0.5 : $motion[1] * $i * 0.3, $motion[2] * $i * 0.3 + 0.5)));
}
}
}
示例10: activate
public function activate()
{
$itemIndex = [];
for ($i = 0; $i < $this->getSize(); $i++) {
$item = $this->getInventory()->getItem($i);
if ($item->getId() != Item::AIR) {
$itemIndex[] = [$i, $item];
}
}
$max = count($itemIndex) - 1;
if ($max < 0) {
$itemArr = null;
} elseif ($max == 0) {
$itemArr = $itemIndex[0];
} else {
$itemArr = $itemIndex[mt_rand(0, $max)];
}
if (is_array($itemArr)) {
/** @var Item $item */
$item = $itemArr[1];
$item->setCount($item->getCount() - 1);
$this->getInventory()->setItem($itemArr[0], $item->getCount() > 0 ? $item : Item::get(Item::AIR));
$motion = $this->getMotion();
$needItem = Item::get($item->getId(), $item->getDamage());
$f = 1.5;
switch ($needItem->getId()) {
case Item::ARROW:
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Fire" => new ShortTag("Fire", 0)]);
$arrow = Entity::createEntity("Arrow", $this->chunk, $nbt);
$arrow->setMotion($arrow->getMotion()->multiply($f));
$arrow->spawnToAll();
break;
case Item::SNOWBALL:
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
$snowball = Entity::createEntity("Snowball", $this->chunk, $nbt);
$snowball->setMotion($snowball->getMotion()->multiply($f));
$snowball->spawnToAll();
break;
case Item::EGG:
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
$egg = Entity::createEntity("Egg", $this->chunk, $nbt);
$egg->setMotion($egg->getMotion()->multiply($f));
$egg->spawnToAll();
break;
case Item::SPLASH_POTION:
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "PotionId" => new ShortTag("PotionId", $item->getDamage())]);
$thrownPotion = Entity::createEntity("ThrownPotion", $this->chunk, $nbt);
$thrownPotion->setMotion($thrownPotion->getMotion()->multiply($f));
$thrownPotion->spawnToAll();
break;
case Item::ENCHANTING_BOTTLE:
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
$thrownExpBottle = Entity::createEntity("ThrownExpBottle", $this->chunk, $nbt);
$thrownExpBottle->setMotion($thrownExpBottle->getMotion()->multiply($f));
$thrownExpBottle->spawnToAll();
break;
default:
$itemTag = NBT::putItemHelper($needItem);
$itemTag->setName("Item");
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $itemTag, "PickupDelay" => new ShortTag("PickupDelay", 10)]);
$f = 0.3;
$itemEntity = new ItemEntity($this->chunk, $nbt, $this);
$itemEntity->setMotion($itemEntity->getMotion()->multiply($f));
$itemEntity->spawnToAll();
break;
}
for ($i = 1; $i < 10; $i++) {
$this->getLevel()->addParticle(new SmokeParticle($this->add($motion[0] * $i * 0.3 + 0.5, $motion[1] == 0 ? 0.5 : $motion[1] * $i * 0.3, $motion[2] * $i * 0.3 + 0.5)));
}
}
}
示例11: activate
public function activate()
{
$itemArr = [];
for ($i = 0; $i < $this->getInventory()->getSize(); $i++) {
$slot = $this->getInventory()->getItem($i);
if ($slot instanceof Item && $slot->getId() != 0) {
$itemArr[] = $slot;
}
}
if (!empty($itemArr)) {
/** @var Item $item */
$itema = $itemArr[array_rand($itemArr)];
$item = Item::get($itema->getId(), $itema->getDamage(), 1, $itema->getCompoundTag());
$this->getInventory()->removeItem($item);
$motion = $this->getMotion();
$needItem = Item::get($item->getId(), $item->getDamage());
$f = 1.5;
if ($needItem instanceof Launchable) {
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
$thrownEntity = Entity::createEntity($needItem->getEntityName(), $this->chunk, $nbt);
$thrownEntity->setMotion($thrownEntity->getMotion()->multiply($f));
$thrownEntity->spawnToAll();
} elseif ($needItem->getId() === Item::DYE && $needItem->getDamage() === Dye::BONEMEAL) {
// Add instanceof Dispenseable + switch function
$dispenseto = $this->getLevel()->getBlock($this->add($motion[0], $motion[1], $motion[2]));
if ($dispenseto instanceof Crops) {
$needItem->useOn($dispenseto);
}
} elseif ($needItem->getId() === Item::FLINT_AND_STEEL) {
// Add instanceof Dispenseable + switch function
$dispenseto = $this->getLevel()->getBlock($this->add($motion[0], $motion[1], $motion[2]));
$this->getLevel()->setBlock($dispenseto, new Fire());
$damage = $item->getDamage();
$item->setDamage($damage + 1);
} else {
$item = NBT::putItemHelper($needItem);
$item->setName("Item");
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $item, "PickupDelay" => new ShortTag("PickupDelay", 10)]);
$f = 0.3;
$itemEntity = new ItemEntity($this->chunk, $nbt, $this);
$itemEntity->setMotion($itemEntity->getMotion()->multiply($f));
$itemEntity->spawnToAll();
}
for ($i = 1; $i < 10; $i++) {
$this->getLevel()->addParticle(new SmokeParticle($this->add($motion[0] * $i * 0.3 + 0.5, $motion[1] == 0 ? 0.5 : $motion[1] * $i * 0.3, $motion[2] * $i * 0.3 + 0.5)));
}
}
}
示例12: activate
public function activate()
{
$itemArr = [];
for ($i = 0; $i < $this->getInventory()->getSize(); $i++) {
$slot = $this->getInventory()->getItem($i);
if ($slot instanceof Item && $slot->getId() != 0) {
$itemArr[] = $slot;
}
}
if (!empty($itemArr)) {
/** @var Item $item */
$itema = $itemArr[array_rand($itemArr)];
$item = Item::get($itema->getId(), $itema->getDamage(), 1, $itema->getCompoundTag());
$this->getInventory()->removeItem($item);
$motion = $this->getMotion();
$needItem = Item::get($item->getId(), $item->getDamage());
$item = NBT::putItemHelper($needItem);
$item->setName("Item");
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $item, "PickupDelay" => new ShortTag("PickupDelay", 10)]);
$f = 0.3;
$itemEntity = new ItemEntity($this->chunk, $nbt, $this);
$itemEntity->setMotion($itemEntity->getMotion()->multiply($f));
$itemEntity->spawnToAll();
}
}