PocketMine-MP 5.39.3 git-21ae710729750cd637333d673bbbbbc598fc659e
Loading...
Searching...
No Matches
Azalea.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;
37use pocketmine\world\generator\object\TreeType;
38use function mt_rand;
39
40class Azalea extends Flowable{
41 use StaticSupportTrait;
42
43 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
44 if($item instanceof Fertilizer){
45 $item->pop();
46 if($player === null || !$player->hasFiniteResources() || mt_rand(1, 100) <= 45){
47 $this->grow($player);
48 }
49 return true;
50 }
51
52 return false;
53 }
54
55 private function grow(?Player $player) : void{
56 $random = new Random(mt_rand());
57 $tree = TreeFactory::get($random, TreeType::AZALEA);
58 $transaction = $tree?->getBlockTransaction($this->position->getWorld(), $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ(), $random);
59 if($transaction === null){
60 return;
61 }
62
63 $ev = new StructureGrowEvent($this, $transaction, $player);
64 $ev->call();
65 if(!$ev->isCancelled()){
66 $transaction->apply();
67 }
68 }
69
70 protected function recalculateCollisionBoxes() : array{
71 return [
72 AxisAlignedBB::one()
73 ->squashedCopy(Axis::X, 6 / 16)
74 ->squashedCopy(Axis::Z, 6 / 16)
75 ->trimmedCopy(Facing::UP, 8 / 16),
76 AxisAlignedBB::one()->trimmedCopy(Facing::DOWN, 8 / 16)
77 ];
78 }
79
80 private function canBeSupportedAt(Block $block) : bool{
81 //TODO: Moss block
82 $supportBlock = $block->getSide(Facing::DOWN);
83 return $supportBlock->getTypeId() === BlockTypeIds::CLAY ||
84 $supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
85 $supportBlock->hasTypeTag(BlockTypeTags::MUD);
86 }
87}
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Azalea.php:43
pop(int $count=1)
Definition Item.php:431