getDamage() final public method

final public getDamage ( )
Example #1
8
 /**
  * @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;
 }
Example #2
4
 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;
 }
Example #3
2
 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;
 }
Example #4
1
 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;
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 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;
 }
Example #7
0
 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;
 }
Example #8
0
 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;
 }
Example #9
0
 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());
     }
 }
Example #10
0
 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;
     }
 }
Example #11
0
 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;
 }
Example #12
0
 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;
 }
 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;
 }
Example #14
0
 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;
 }
Example #15
0
 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;
 }
Example #16
0
 public function saveNBT()
 {
     $this->namedtag->Item = new Compound("Item", ["id" => new Short("id", $this->item->getID()), "Damage" => new Short("Damage", $this->item->getDamage()), "Count" => new Byte("Count", $this->item->getCount())]);
     $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);
     }
 }
 public function spawnTo(Player $player)
 {
     $app = new AddPlayerPacket();
     $app->clientID = $this->eid();
     $app->username = $this->nameTag;
     $app->eid = $this->eid();
     $app->x = $this->x;
     $app->y = $this->y;
     $app->z = $this->z;
     $app->speedX = 0;
     $app->speedY = 0;
     $app->speedZ = 0;
     $app->yaw = $this->yaw;
     $app->pitch = $this->pitch;
     $app->item = $this->item->getId();
     $app->meta = $this->item->getDamage();
     $app->skin = $this->skin;
     $app->slim = $this->slim;
     $app->metadata = $this->metadata;
     $player->dataPacket($app);
     $this->player = $player;
     $this->setDataFlag(Human::DATA_PLAYER_FLAGS, Human::DATA_PLAYER_FLAG_SLEEP, false);
     $this->setDataProperty(Human::DATA_PLAYER_BED_POSITION, Entity::DATA_TYPE_POS, [0, 0, 0]);
 }
Example #18
0
 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;
 }
Example #19
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf) {
         $block = clone $this;
         if ($block->meta > 7) {
             return false;
         }
         $block->meta += 4;
         Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
         if (!$ev->isCancelled()) {
             $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
         }
         $item->count--;
         return true;
     }
     return false;
 }
Example #20
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $down = $this->getSide(0);
     if ($face !== 0 && $fy > 0.5 && $target->getId() !== self::SKULL_BLOCK && !$down instanceof SkullBlock) {
         $this->getLevel()->setBlock($block, Block::get(Block::SKULL_BLOCK, 0), true, true);
         if ($face === 1) {
             $rot = new Byte("Rot", floor($player->yaw * 16 / 360 + 0.5) & 0xf);
         } else {
             $rot = new Byte("Rot", 0);
         }
         $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()), $rot]);
         $chunk = $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4);
         $pot = Tile::createTile("Skull", $chunk, $nbt);
         $this->getLevel()->setBlock($block, Block::get(Block::SKULL_BLOCK, $face), true, true);
         return true;
     }
     return false;
 }
Example #21
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($face !== 0) {
         $this->meta = $face;
         if ($face === 1) {
             $rot = floor($player->yaw * 16 / 360 + 0.5) & 0xf;
         } else {
             $rot = $face;
         }
         $this->getLevel()->setBlock($block, $this, true);
         $nbt = new CompoundTag("", [new StringTag("id", Tile::SKULL), new ByteTag("SkullType", $item->getDamage()), new ByteTag("Rot", $rot), new IntTag("x", (int) $this->x), new IntTag("y", (int) $this->y), new IntTag("z", (int) $this->z)]);
         if ($item->hasCustomName()) {
             $nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
         }
         /** @var Spawnable $tile */
         Tile::createTile("Skull", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         return true;
     }
     return false;
 }
Example #22
0
 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) {
                     $this->getLevel()->setBlock($b, new Sugarcane(), true);
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
Example #23
0
 public final function equals(Item $item, $checkDamage = true, $checkCompound = true)
 {
     return $this->id === $item->getId() and ($checkDamage === false or $this->getDamage() === $item->getDamage()) and ($checkCompound === false or $this->getCompoundTag() === $item->getCompoundTag());
 }
 public function putSlot(Item $item)
 {
     if ($item->getId() === 0) {
         $this->putShort(0);
         return;
     }
     $this->putShort($item->getId());
     $this->putByte($item->getCount());
     $this->putShort($item->getDamage() === null ? -1 : $item->getDamage());
     $nbt = $item->getCompoundTag();
     $this->putLShort(strlen($nbt));
     $this->put($nbt);
 }
 /**
  * @param Item $input
  * 
  * @return BrewingRecipe
  */
 public function matchBrewingRecipe(Item $input)
 {
     if (isset($this->BrewingRecipes[$input->getId() . ":" . $input->getDamage()])) {
         return $this->BrewingRecipes[$input->getId() . ":" . $input->getDamage()];
     } elseif (isset($this->BrewingRecipes[$input->getId() . ":?"])) {
         return $this->BrewingRecipes[$input->getId() . ":?"];
     }
     return null;
 }
Example #26
0
 /**
  * @param Item $input
  * @param Item $potion
  *
  * @return BrewingRecipe
  */
 public function matchBrewingRecipe(Item $input, Item $potion)
 {
     if (isset($this->brewingRecipes[$input->getId() . ":" . ($potion->getDamage() === null ? "0" : $potion->getDamage())])) {
         return $this->brewingRecipes[$input->getId() . ":" . ($potion->getDamage() === null ? "0" : $potion->getDamage())];
     }
     return null;
 }
 public function __construct(Vector3 $pos, Item $item)
 {
     parent::__construct($pos, Particle::TYPE_ITEM_BREAK, $item->getId() << 16 | $item->getDamage());
 }
Example #28
0
 public function checkIngredient(Item $item)
 {
     if (isset(self::$ingredients[$item->getId()])) {
         if (self::$ingredients[$item->getId()] === $item->getDamage()) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param Item $item
  * @param Level $level
  * @return bool
  */
 public function isItemBannedInLevel(Item $item, Level $level)
 {
     return in_array($item->getId() . ":" . $item->getDamage(), $this->getConfig()->getNested("level." . strtolower($level->getName()) . ".bannedItems"));
 }
Example #30
-1
 /**
  * @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;
     if ($item->getId() > 0 and $item->getCount() > 0) {
         $itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4), 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" => new Compound("Item", ["id" => new Short("id", $item->getId()), "Damage" => new Short("Damage", $item->getDamage()), "Count" => new Byte("Count", $item->getCount())]), "PickupDelay" => new Short("PickupDelay", $delay)]));
         $itemEntity->spawnToAll();
     }
 }