PocketMine-MP 5.16.1 git-585aee9386a787c95e73dd0a05ffca8329606b68
BuddingAmethyst.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
26use pocketmine\block\utils\AmethystTrait;
30use function array_rand;
31use function mt_rand;
32
33final class BuddingAmethyst extends Opaque{
34 use AmethystTrait;
35
36 public function ticksRandomly() : bool{
37 return true;
38 }
39
40 public function onRandomTick() : void{
41 if(mt_rand(1, 5) === 1){
42 $face = Facing::ALL[array_rand(Facing::ALL)];
43
44 $adjacent = $this->getSide($face);
45 //TODO: amethyst buds can spawn in water - we need waterlogging support for this
46
47 $newStage = null;
48
49 if($adjacent->getTypeId() === BlockTypeIds::AIR){
50 $newStage = AmethystCluster::STAGE_SMALL_BUD;
51 }elseif(
52 $adjacent->getTypeId() === BlockTypeIds::AMETHYST_CLUSTER &&
53 $adjacent instanceof AmethystCluster &&
54 $adjacent->getStage() < AmethystCluster::STAGE_CLUSTER &&
55 $adjacent->getFacing() === $face
56 ){
57 $newStage = $adjacent->getStage() + 1;
58 }
59 if($newStage !== null){
60 BlockEventHelper::grow($adjacent, VanillaBlocks::AMETHYST_CLUSTER()->setStage($newStage)->setFacing($face), null);
61 }
62 }
63 }
64
65 public function getDropsForCompatibleTool(Item $item) : array{
66 return [];
67 }
68}