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;
}