本文整理匯總了PHP中pocketmine\item\Item::useOn方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::useOn方法的具體用法?PHP Item::useOn怎麽用?PHP Item::useOn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\item\Item
的用法示例。
在下文中一共展示了Item::useOn方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onActivate
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;
} elseif ($item->isShovel() and $this->getSide(1)->getId() === Block::AIR) {
$item->useOn($this);
$this->getLevel()->setBlock($this, new GrassPath());
return \true;
}
return \false;
}
示例2: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($item->isHoe()) {
$item->useOn($this);
$this->getLevel()->setBlock($this, Block::get(Item::FARMLAND, 0), true);
return true;
}
return false;
}
示例3: onActivate
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;
}
示例4: onActivate
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;
}
示例5: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($item->getID() === Item::FLINT_STEEL) {
if (($player->gamemode & 0x1) === 0) {
$item->useOn($this);
}
$data = ["x" => $this->x + 0.5, "y" => $this->y + 0.5, "z" => $this->z + 0.5, "power" => 4, "fuse" => 20 * 4];
$this->getLevel()->setBlock($this, new Air(), false, false, true);
//TODO
//$e = Server::getInstance()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
//$e->spawnToAll();
return true;
}
return false;
}
示例6: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($item->getId() === Item::SAPLING || $item->getId() === Item::BROWN_MUSHROOM || $item->getId() === Item::RED_MUSHROOM || $item->getId() === Item::ROSE || $item->getId() === Item::DEAD_BUSH || $item->getId() === Item::DANDELION || $item->getId() === Item::TALL_GRASS || $item->getId() === Item::CACTUS) {
$item->useOn($this);
$meta = 0;
switch ($item->getId()) {
case ITEM::ROSE:
$meta = 1;
case Item::DANDELION:
$meta = 2;
case Item::RED_MUSHROOM:
$meta = 7;
case Item::BROWN_MUSHROOM:
$meta = 8;
case Item::CACTUS:
$meta = 9;
case Item::DEAD_BUSH:
$meta = 10;
case Item::SAPLING:
$species = $item->getDamage();
/*
* GENERIC(0x00),
* REDWOOD(0x01),
* BIRCH(0x02),
* JUNGLE(0x03),
* ACACIA(0x04),
* DARK_OAK(0x05),
*/
if ($species == 0x0) {
$meta = 3;
} elseif ($species == 0x1) {
$meta = 4;
} elseif ($species == 0x2) {
$meta = 5;
} elseif ($species == 0x3) {
$meta = 6;
} elseif ($species == 0x4) {
$meta = 12;
} else {
$meta = 13;
}
case Item::TALL_GRASS:
$species = $item->getDamage();
if ($species == 0x2) {
$meta = 11;
}
}
$this->setDamage($meta);
$this->getLevel()->setBlock($this, $this, true);
return true;
}
return false;
}
示例7: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($item->getId() === Item::FLINT_STEEL) {
$this->prime($player);
$this->getLevel()->setBlock($this, new Air(), true);
$item->useOn($this);
return true;
}
return false;
}