Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent() === true) {
             $this->getLevel()->useBreakOn($this);
             return Level::BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if (mt_rand(0, 2) == 1) {
             if ($this->meta < 0x7) {
                 $block = clone $this;
                 ++$block->meta;
                 Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
                 if (!$ev->isCancelled()) {
                     $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
                 } else {
                     return Level::BLOCK_UPDATE_RANDOM;
                 }
             }
         } else {
             return Level::BLOCK_UPDATE_RANDOM;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         $down = $this->getSide(0);
         $up = $this->getSide(1);
         if ($down->getId() !== self::SAND and $down->getId() !== self::CACTUS) {
             $this->getLevel()->scheduleUpdate($this, 0);
         } else {
             for ($side = 2; $side <= 5; ++$side) {
                 $b = $this->getSide($side);
                 if (!$b->canBeFlowedInto() && $b->getId() !== Block::SNOW_LAYER) {
                     // Snow can be stacked to a full block beside a cactus without destroying the cactus.
                     $this->getLevel()->useBreakOn($this);
                 }
             }
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if ($this->getSide(0)->getId() !== self::CACTUS) {
             if ($this->meta == 0xf) {
                 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 Cactus()));
                         if (!$ev->isCancelled()) {
                             $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                         }
                     }
                 }
                 $this->meta = 0;
                 $this->getLevel()->setBlock($this, $this);
             } else {
                 ++$this->meta;
                 $this->getLevel()->setBlock($this, $this);
             }
         }
     } elseif ($type === Level::BLOCK_UPDATE_SCHEDULED) {
         $this->getLevel()->useBreakOn($this);
     }
     return false;
 }
Ejemplo n.º 4
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent() === true) {
             $this->getLevel()->useBreakOn($this);
             return Level::BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if (mt_rand(0, 2) == 1) {
             if ($this->meta < 0x7) {
                 $block = clone $this;
                 ++$block->meta;
                 Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
                 if (!$ev->isCancelled()) {
                     $this->getLevel()->setBlock($this, $ev->getNewState(), true);
                 }
                 return Level::BLOCK_UPDATE_RANDOM;
             } else {
                 for ($side = 2; $side <= 5; ++$side) {
                     $b = $this->getSide($side);
                     if ($b->getId() === self::MELON_BLOCK) {
                         return Level::BLOCK_UPDATE_RANDOM;
                     }
                 }
                 $side = $this->getSide(mt_rand(2, 5));
                 $d = $side->getSide(0);
                 if ($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)) {
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($side, $ev->getNewState(), true);
                     }
                 }
             }
         }
         return Level::BLOCK_UPDATE_RANDOM;
     }
     return false;
 }