本文整理汇总了PHP中pocketmine\item\Item::getDamage方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::getDamage方法的具体用法?PHP Item::getDamage怎么用?PHP Item::getDamage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\item\Item
的用法示例。
在下文中一共展示了Item::getDamage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($this->meta < 0x7 && $item->getID() === Item::DYE && $item->getDamage() === 0xf) {
//Bonemeal
$block = clone $this;
$block->meta += mt_rand(2, 5);
if ($block->meta > 0x7) {
$block->meta = 0x7;
}
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if (!$ev->isCancelled()) {
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
if ($player->isSurvival()) {
$item->count--;
}
return true;
}
}
return false;
}
示例2: onActivate
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;
}
示例3: str
/**
* 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;
}
示例4: onActivate
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;
}
示例5: 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;
}
示例6: onActivate
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;
}
示例7: 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;
}
示例8: setItem
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());
}
}
示例9: onActivate
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;
}
}
示例10: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($item->getID() === Item::DYE and $item->getDamage() === 0xf) {
//Bonemeal
$this->meta = 0x7;
$this->getLevel()->setBlock($this, $this, true, true);
$item->count--;
return true;
}
return false;
}
示例11: onActivate
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;
}
示例12: putItemHelper
/**
* @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;
}
示例13: place
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
{
if ($face !== 0) {
$this->getLevel()->setBlock($block, Block::get(MainClass::BLOCK_SKULL, 0), true, true);
$nbt = new Compound("", [new String("id", Tile::SKULL), new Int("x", $block->x), new Int("y", $block->y), new Int("z", $block->z), new Byte("SkullType", $item->getDamage()), new Byte("Rot", floor($player->yaw * 16 / 360 + 0.5) & 0xf)]);
$chunk = $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4);
$pot = Tile::createTile("Skull", $chunk, $nbt);
$this->getLevel()->setBlock($block, Block::get(MainClass::BLOCK_SKULL, $face), true, true);
return true;
}
return false;
}
示例14: 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;
}
示例15: onActivate
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;
}