PocketMine-MP 5.33.2 git-919492bdcad8510eb6606439eb77e1c604f1d1ea
Loading...
Searching...
No Matches
BaseBigDripleaf.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
27use pocketmine\block\utils\HorizontalFacingOption;
28use pocketmine\block\utils\HorizontalFacingTrait;
29use pocketmine\block\utils\SupportType;
37
38abstract class BaseBigDripleaf extends Transparent implements HorizontalFacing{
39 use HorizontalFacingTrait;
40
41 abstract protected function isHead() : bool;
42
43 private function canBeSupportedBy(Block $block, bool $head) : bool{
44 //TODO: Moss block
45 return
46 ($block instanceof BaseBigDripleaf && $block->isHead() === $head) ||
47 $block->getTypeId() === BlockTypeIds::CLAY ||
48 $block->hasTypeTag(BlockTypeTags::DIRT) ||
49 $block->hasTypeTag(BlockTypeTags::MUD);
50 }
51
52 public function onNearbyBlockChange() : void{
53 if(
54 (!$this->isHead() && !$this->getSide(Facing::UP) instanceof BaseBigDripleaf) ||
55 !$this->canBeSupportedBy($this->getSide(Facing::DOWN), false)
56 ){
57 $this->position->getWorld()->useBreakOn($this->position);
58 }
59 }
60
61 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{
62 $block = $blockReplace->getSide(Facing::DOWN);
63 if(!$this->canBeSupportedBy($block, true)){
64 return false;
65 }
66 if($player !== null){
67 $this->facing = HorizontalFacingOption::fromFacing(Facing::opposite($player->getHorizontalFacing()));
68 }
69 if($block instanceof BaseBigDripleaf){
70 $this->facing = $block->facing;
71 $tx->addBlock($block->position, VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($this->facing));
72 }
73 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
74 }
75
76 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
77 if($item instanceof Fertilizer && $this->grow($player)){
78 $item->pop();
79 return true;
80 }
81 return false;
82 }
83
84 private function seekToHead() : ?BaseBigDripleaf{
85 if($this->isHead()){
86 return $this;
87 }
88 $step = 1;
89 while(($next = $this->getSide(Facing::UP, $step)) instanceof BaseBigDripleaf){
90 if($next->isHead()){
91 return $next;
92 }
93 $step++;
94 }
95 return null;
96 }
97
98 private function grow(?Player $player) : bool{
99 $head = $this->seekToHead();
100 if($head === null){
101 return false;
102 }
103 $pos = $head->position;
104 $up = $pos->up();
105 $world = $pos->getWorld();
106 if(
107 !$world->isInWorld($up->getFloorX(), $up->getFloorY(), $up->getFloorZ()) ||
108 $world->getBlock($up)->getTypeId() !== BlockTypeIds::AIR
109 ){
110 return false;
111 }
112
113 $tx = new BlockTransaction($world);
114
115 $tx->addBlock($pos, VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($head->facing));
116 $tx->addBlock($up, VanillaBlocks::BIG_DRIPLEAF_HEAD()->setFacing($head->facing));
117
118 $ev = new StructureGrowEvent($head, $tx, $player);
119 $ev->call();
120
121 if(!$ev->isCancelled()){
122 return $tx->apply();
123 }
124 return false;
125 }
126
127 public function getFlameEncouragement() : int{
128 return 15;
129 }
130
131 public function getFlammability() : int{
132 return 100;
133 }
134
135 public function getSupportType(Facing $facing) : SupportType{
136 return SupportType::NONE;
137 }
138}
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
hasTypeTag(string $tag)
Definition Block.php:215
getSide(Facing $side, int $step=1)
Definition Block.php:773
pop(int $count=1)
Definition Item.php:435
addBlock(Vector3 $pos, Block $state)