PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
block/TallGrass.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;
27use pocketmine\block\utils\TallGrassTrait;
33
34class TallGrass extends Flowable{
35 use TallGrassTrait;
36 use StaticSupportTrait;
37
39 private ?\Closure $doublePlantVariant;
40
44 public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, ?\Closure $doublePlantVariant = null){
45 parent::__construct($idInfo, $name, $typeInfo);
46 $this->doublePlantVariant = $doublePlantVariant;
47 }
48
49 private function canBeSupportedAt(Block $block) : bool{
50 $supportBlock = $block->getSide(Facing::DOWN);
51 return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
52 }
53
54 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
55 $world = $this->position->getWorld();
56 $upPos = $this->position->getSide(Facing::UP);
57 if(!$world->isInWorld($upPos->getFloorX(), $upPos->getFloorY(), $upPos->getFloorZ()) || $this->getSide(Facing::UP)->getTypeId() !== BlockTypeIds::AIR){
58 return false;
59 }
60
61 if($item instanceof Fertilizer && ($doubleVariant = $this->getDoublePlantVariant()) !== null){
62 $bottom = (clone $doubleVariant)->setTop(false);
63 $top = (clone $doubleVariant)->setTop(true);
64 $world->setBlock($this->position, $bottom);
65 $world->setBlock($this->position->getSide(Facing::UP), $top);
66 $item->pop();
67
68 return true;
69 }
70
71 return false;
72 }
73
74 private function getDoublePlantVariant() : ?DoublePlant{
75 return $this->doublePlantVariant !== null ? ($this->doublePlantVariant)() : null;
76 }
77}
hasTypeTag(string $tag)
Definition Block.php:217
getSide(Facing $side, int $step=1)
Definition Block.php:775
__construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, ?\Closure $doublePlantVariant=null)
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])