PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
NetherFungus.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;
35use pocketmine\world\generator\object\TreeType;
36use function mt_rand;
37
38class NetherFungus extends Flowable{
39 use StaticSupportTrait;
40
45 public function __construct(
46 BlockIdentifier $idInfo,
47 string $name,
48 BlockTypeInfo $typeInfo,
49 private readonly int $nyliumTypeId,
50 private readonly TreeType $treeType
51 ){
52 parent::__construct($idInfo, $name, $typeInfo);
53 }
54
55 private function canBeSupportedAt(Block $block) : bool{
56 //TODO: moss
57 $supportBlock = $block->getSide(Facing::DOWN);
58 return
59 $supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
60 $supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
61 $supportBlock->hasTypeTag(BlockTypeTags::NYLIUM) ||
62 $supportBlock->getTypeId() === BlockTypeIds::SOUL_SOIL;
63 }
64
65 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
66 if($item instanceof Fertilizer){
67 $item->pop();
68 if($this->getSide(Facing::DOWN)->getTypeId() === $this->nyliumTypeId && ($player === null || !$player->hasFiniteResources() || mt_rand(1, 100) <= 40)){
69 $this->grow($player);
70 }
71 return true;
72 }
73 return false;
74 }
75
76 private function grow(?Player $player) : void{
77 $random = new Random(mt_rand());
78 $tree = TreeFactory::get($random, $this->treeType);
79 $transaction = $tree?->getBlockTransaction($this->position->getWorld(), $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ(), $random);
80 if($transaction === null){
81 return;
82 }
83
84 $ev = new StructureGrowEvent($this, $transaction, $player);
85 $ev->call();
86 if(!$ev->isCancelled()){
87 $transaction->apply();
88 }
89 }
90}
hasTypeTag(string $tag)
Definition Block.php:217
getSide(Facing $side, int $step=1)
Definition Block.php:775
__construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, private readonly int $nyliumTypeId, private readonly TreeType $treeType)
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
pop(int $count=1)
Definition Item.php:431