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; }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL) { $faces = array_flip(array(2 => 2, 3 => 4, 4 => 5, 5 => 3)); if ($this->getSide(Vector3::getOppositeSide($faces[$this->meta % 4 + 2]))->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 < 8) { $block = clone $this; $block->meta += 4; 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; }
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; }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL) { if ($this->getSide(0)->getID() !== self::FARMLAND) { $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } } elseif ($type === Level::BLOCK_UPDATE_RANDOM) { if ($this->meta < 0x7) { parent::onUpdate(Level::BLOCK_UPDATE_RANDOM); } else { for ($side = 2; $side <= 5; $side++) { if ($this->getSide($side)->getID() === self::PUMPKIN) { return Level::BLOCK_UPDATE_RANDOM; } } $side = $this->getSide(mt_rand(2, 5)); if ($side->getID() === self::AIR && in_array($side->getSide(0)->getID(), [self::FARMLAND, self::GRASS, self::DIRT])) { Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, self::get(self::PUMPKIN))); if (!$ev->isCancelled()) { $this->getLevel()->setBlock($side, $ev->getNewState(), true); } } } return Level::BLOCK_UPDATE_RANDOM; } return false; }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL) { if ($this->getSide(0)->getID() !== self::FARMLAND) { $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } } elseif ($type === Level::BLOCK_UPDATE_RANDOM) { if ($this->meta < 0x7 && ($this->getSide(0)->getDamage() == 1 ? mt_rand(1, 2) : mt_rand(1, 3)) === 1) { // If wet farm : 1/2, else : 1/3 $block = clone $this; $block->meta += $this->getSide(0)->getDamage() == 1 ? 2 : 1; Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); if (!$ev->isCancelled()) { $this->getLevel()->setBlock($this, $ev->getNewState(), true, true); } } return Level::BLOCK_UPDATE_RANDOM; } return false; }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL) { if ($this->getSide(0)->getID() !== self::SOUL_SAND) { $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } } elseif ($type === Level::BLOCK_UPDATE_RANDOM) { if ($this->meta < 0x3 && mt_rand(1, 6) === 1) { // 1/6 $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); } } return Level::BLOCK_UPDATE_RANDOM; } return false; }
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; }
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()) { $this->getLevel()->useBreakOn($this); } } } } elseif ($type === Level::BLOCK_UPDATE_RANDOM) { if ($this->getSide(0)->getId() !== self::SAND and $this->getSide(0)->getId() !== self::CACTUS) { $this->getLevel()->scheduleUpdate($this, 0); } elseif ($this->getSide(1)->getId() === self::AIR) { if ($this->meta === 15) { if (!($this->getSide(0)->getId() === self::CACTUS && $this->getSide(0, 2)->getId() === self::CACTUS)) { $b = $this->getSide(1); 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; }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL) { $side = $this->getSide([3, 4, 2, 5][$this->meta % 4]); if (!($side->getID() === self::WOOD && $side->getDamage() === 3)) { $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } } elseif ($type === Level::BLOCK_UPDATE_RANDOM) { if ($this->meta < $this->meta % 4 + 8 && mt_rand(1, 5) === 1) { // 1/5 $block = clone $this; $block->meta += 4; Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); if (!$ev->isCancelled()) { $this->getLevel()->setBlock($this, $ev->getNewState(), true, true); } } return Level::BLOCK_UPDATE_RANDOM; } return false; }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL) { if ($this->getSide(0)->isTransparent()) { $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::PUMPKIN) { 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 Pumpkin())); if (!$ev->isCancelled()) { $this->getLevel()->setBlock($side, $ev->getNewState(), true); } } } } return Level::BLOCK_UPDATE_RANDOM; } return false; }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL) { $down = $this->getSide(0); if ($down->getId() !== self::SAND and $down->getId() !== self::CACTUS) { $this->getLevel()->useBreakOn($this); } else { for ($side = 2; $side <= 5; ++$side) { $b = $this->getSide($side); if (!$b->canBeFlowedInto()) { $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); } } } return false; }