useOn() public method

public useOn ( Entity | Block $object ) : boolean
$object pocketmine\entity\Entity | pocketmine\block\Block
return boolean
Example #1
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 #2
0
 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;
 }
Example #3
0
 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;
 }
Example #4
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 #5
0
 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;
 }
Example #6
0
 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;
 }
Example #7
0
 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;
 }