本文整理汇总了PHP中pocketmine\item\Item类的典型用法代码示例。如果您正苦于以下问题:PHP Item类的具体用法?PHP Item怎么用?PHP Item使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Item类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDrops
public function getDrops(Item $item)
{
if ($item->isSword()) {
return [[Item::STRING, 0, 1]];
}
return [];
}
示例2: 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;
}
$this->item = NBT::getItemHelper($this->namedtag->Item);
if ($this->item->getId() <= 0) {
$this->close();
return;
}
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
}
示例3: getDrops
public function getDrops(Item $item)
{
if ($item->isPickaxe() >= Tool::TIER_WOODEN) {
return [[$this->id, $this->meta, 1]];
}
return [];
}
示例4: __construct
/**
* @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;
}
}
示例5: setRPGItem
public function setRPGItem(Item $item, $name, $desc, $class)
{
$classData = self::$ITEM_CLASS[$class];
$item->setCustomName($classData["COLOR"] . ToAruPG::getTranslation($classData["TID"]) . $name);
$item->getNamedTag()->desc = new String("desc", $desc);
return $item;
}
示例6: getDrops
public function getDrops(Item $item)
{
if ($item->isPickaxe()) {
return [[$this->id, 0, 1]];
}
return [];
}
示例7: getDrops
public function getDrops(Item $item)
{
if ($item->isShovel() !== false) {
return [[Item::SNOWBALL, 0, 1]];
}
return [];
}
示例8: place
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
{
$dispenser = null;
if ($player instanceof Player) {
$pitch = $player->getPitch();
if (abs($pitch) >= 45) {
if ($pitch < 0) {
$f = 4;
} else {
$f = 5;
}
} else {
$f = $player->getDirection();
}
} else {
$f = 0;
}
$faces = [3 => 3, 0 => 4, 2 => 5, 1 => 2, 4 => 0, 5 => 1];
$this->meta = $faces[$f];
$this->getLevel()->setBlock($block, $this, true, true);
$nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::DISPENSER), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
$nbt->Items->setTagType(NBT::TAG_Compound);
if ($item->hasCustomName()) {
$nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
}
if ($item->hasCustomBlockData()) {
foreach ($item->getCustomBlockData() as $key => $v) {
$nbt->{$key} = $v;
}
}
Tile::createTile(Tile::DISPENSER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
return true;
}
示例9: getDrops
public function getDrops(Item $item)
{
if ($item->isPickaxe() >= Tool::TIER_STONE) {
return [[Item::DYE, 4, mt_rand(4, 8)]];
}
return [];
}
示例10: onActivate
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;
}
示例11: getDrops
public function getDrops(Item $item)
{
if ($item->isPickaxe() >= Tool::TIER_IRON) {
return [[Item::EMERALD_BLOCK, 0, 1]];
}
return [];
}
示例12: onActivate
public function onActivate(Item $item, Player $player = null)
{
$tile = $this->getLevel()->getTile($this);
if ($tile instanceof FlowerPot) {
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());
if ($player->isSurvival()) {
//$item->setCount($item->getCount() - 1);
$item->count--;
}
return true;
break;
}
}
}
return false;
}
示例13: place
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
{
if ($face !== 0) {
$nbt = new CompoundTag("", ["id" => new StringTag("id", Tile::SIGN), "x" => new IntTag("x", $block->x), "y" => new IntTag("y", $block->y), "z" => new IntTag("z", $block->z), "Text1" => new StringTag("Text1", ""), "Text2" => new StringTag("Text2", ""), "Text3" => new StringTag("Text3", ""), "Text4" => new StringTag("Text4", "")]);
if ($player !== null) {
$nbt->Creator = new StringTag("Creator", $player->getRawUniqueId());
}
if ($item->hasCustomBlockData()) {
foreach ($item->getCustomBlockData() as $key => $v) {
$nbt->{$key} = $v;
}
}
if ($face === 1) {
$this->meta = floor(($player->yaw + 180) * 16 / 360 + 0.5) & 0xf;
$this->getLevel()->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true);
Tile::createTile(Tile::SIGN, $this->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt);
return true;
} else {
$this->meta = $face;
$this->getLevel()->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true);
Tile::createTile(Tile::SIGN, $this->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt);
return true;
}
}
return false;
}
示例14: getDrops
public function getDrops(Item $item)
{
if ($item->isPickaxe() >= 1) {
return [[Item::SLAB, 0, 2]];
}
return [];
}
示例15: onActivate
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;
}