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