PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
ChorusPlant.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\StaticSupportTrait;
32use function mt_rand;
33
34final class ChorusPlant extends Flowable{
35 use StaticSupportTrait;
36
37 protected function recalculateCollisionBoxes() : array{
38 $bb = AxisAlignedBB::one();
39 foreach($this->getAllSides() as $facing => $block){
40 $id = $block->getTypeId();
41 if($id !== BlockTypeIds::END_STONE && $id !== BlockTypeIds::CHORUS_FLOWER && !$block->hasSameTypeId($this)){
42 $bb->trim($facing, 2 / 16);
43 }
44 }
45
46 return [$bb];
47 }
48
49 private function canBeSupportedBy(Block $block) : bool{
50 return $block->hasSameTypeId($this) || $block->getTypeId() === BlockTypeIds::END_STONE;
51 }
52
53 private function canBeSupportedAt(Block $block) : bool{
54 $position = $block->position;
55 $world = $position->getWorld();
56
57 $down = $world->getBlock($position->down());
58 $verticalAir = $down->getTypeId() === BlockTypeIds::AIR || $world->getBlock($position->up())->getTypeId() === BlockTypeIds::AIR;
59
60 foreach($position->sidesAroundAxis(Axis::Y) as $sidePosition){
61 $block = $world->getBlock($sidePosition);
62
63 if($block->getTypeId() === BlockTypeIds::CHORUS_PLANT){
64 if(!$verticalAir){
65 return false;
66 }
67
68 if($this->canBeSupportedBy($block->getSide(Facing::DOWN))){
69 return true;
70 }
71 }
72 }
73
74 return $this->canBeSupportedBy($down);
75 }
76
77 public function getDropsForCompatibleTool(Item $item) : array{
78 if(mt_rand(0, 1) === 1){
79 return [VanillaItems::CHORUS_FRUIT()];
80 }
81
82 return [];
83 }
84}
getDropsForCompatibleTool(Item $item)