コード例 #1
0
ファイル: FlowerPot.php プロジェクト: MunkySkunk/BukkitPE
 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->getDamage());
                     if ($player->isSurvival()) {
                         $item->count--;
                     }
                     return true;
                     break;
             }
         }
     }
     return false;
 }
コード例 #2
0
ファイル: Sugarcane.php プロジェクト: MunkySkunk/BukkitPE
 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;
 }
コード例 #3
0
ファイル: TallGrass.php プロジェクト: MunkySkunk/BukkitPE
 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;
     }
 }
コード例 #4
0
ファイル: NBT.php プロジェクト: MunkySkunk/BukkitPE
 /**
  * @param Item $item
  * @param int  $slot
  * @return Compound
  */
 public static function putItemHelper(Item $item, $slot = null)
 {
     $tag = new Compound(null, ["id" => new Short("id", $item->getId()), "Count" => new Byte("Count", $item->getCount()), "Damage" => new Short("Damage", $item->getDamage())]);
     if ($slot !== null) {
         $tag->Slot = new Byte("Slot", (int) $slot);
     }
     if ($item->hasCompoundTag()) {
         $tag->tag = clone $item->getNamedTag();
         $tag->tag->setName("tag");
     }
     return $tag;
 }
コード例 #5
0
ファイル: Sapling.php プロジェクト: MunkySkunk/BukkitPE
 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);
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
コード例 #6
0
ファイル: Grass.php プロジェクト: MunkySkunk/BukkitPE
 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;
 }
コード例 #7
0
ファイル: SkullBlock.php プロジェクト: MunkySkunk/BukkitPE
 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;
 }
コード例 #8
0
ファイル: Crops.php プロジェクト: MunkySkunk/BukkitPE
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf) {
         //Bonemeal
         $block = clone $this;
         $block->meta += mt_rand(2, 5);
         if ($block->meta > 7) {
             $block->meta = 7;
         }
         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;
 }
コード例 #9
0
ファイル: BaseInventory.php プロジェクト: MunkySkunk/BukkitPE
 public function first(Item $item)
 {
     $count = max(1, $item->getCount());
     $checkDamage = $item->getDamage() === null ? false : true;
     $checkTags = $item->getCompoundTag() === null ? false : true;
     foreach ($this->getContents() as $index => $i) {
         if ($item->equals($i, $checkDamage, $checkTags) and $i->getCount() >= $count) {
             return $index;
         }
     }
     return -1;
 }
コード例 #10
0
ファイル: Item.php プロジェクト: MunkySkunk/BukkitPE
 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());
 }
コード例 #11
0
 /**
  * @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;
 }
コード例 #12
0
 public function __construct(Vector3 $pos, Item $item)
 {
     parent::__construct($pos, Particle::TYPE_ITEM_BREAK, $item->getId() << 16 | $item->getDamage());
 }
コード例 #13
0
ファイル: BinaryStream.php プロジェクト: MunkySkunk/BukkitPE
 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->putShort(strlen($nbt));
     $this->put($nbt);
 }