PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
Vine.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
34use function array_intersect_key;
35use function count;
36
37class Vine extends Flowable{
38
40 protected array $faces = [];
41
42 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
43 $w->horizontalFacingFlags($this->faces);
44 }
45
47 public function getFaces() : array{ return $this->faces; }
48
49 public function hasFace(int $face) : bool{
50 return isset($this->faces[$face]);
51 }
52
58 public function setFaces(array $faces) : self{
59 $uniqueFaces = [];
60 foreach($faces as $face){
61 if($face !== Facing::NORTH && $face !== Facing::SOUTH && $face !== Facing::WEST && $face !== Facing::EAST){
62 throw new \InvalidArgumentException("Facing can only be north, east, south or west");
63 }
64 $uniqueFaces[$face] = $face;
65 }
66 $this->faces = $uniqueFaces;
67 return $this;
68 }
69
71 public function setFace(int $face, bool $value) : self{
72 if($face !== Facing::NORTH && $face !== Facing::SOUTH && $face !== Facing::WEST && $face !== Facing::EAST){
73 throw new \InvalidArgumentException("Facing can only be north, east, south or west");
74 }
75 if($value){
76 $this->faces[$face] = $face;
77 }else{
78 unset($this->faces[$face]);
79 }
80 return $this;
81 }
82
83 public function hasEntityCollision() : bool{
84 return true;
85 }
86
87 public function canClimb() : bool{
88 return true;
89 }
90
91 public function canBeReplaced() : bool{
92 return true;
93 }
94
95 public function onEntityInside(Entity $entity) : bool{
96 $entity->resetFallDistance();
97 return true;
98 }
99
100 protected function recalculateCollisionBoxes() : array{
101 return [];
102 }
103
104 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
105 if(!$blockReplace->getSide(Facing::opposite($face))->isFullCube() || Facing::axis($face) === Axis::Y){
106 return false;
107 }
108
109 $this->faces = $blockReplace instanceof Vine ? $blockReplace->faces : [];
110 $this->faces[Facing::opposite($face)] = Facing::opposite($face);
111
112 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
113 }
114
115 public function onNearbyBlockChange() : void{
116 $changed = false;
117
118 $up = $this->getSide(Facing::UP);
119 //check which faces have corresponding vines in the block above
120 $supportedFaces = $up instanceof Vine ? array_intersect_key($this->faces, $up->faces) : [];
121
122 foreach($this->faces as $face){
123 if(!isset($supportedFaces[$face]) && !$this->getSide($face)->isSolid()){
124 unset($this->faces[$face]);
125 $changed = true;
126 }
127 }
128
129 if($changed){
130 $world = $this->position->getWorld();
131 if(count($this->faces) === 0){
132 $world->useBreakOn($this->position);
133 }else{
134 $world->setBlock($this->position, $this);
135 }
136 }
137 }
138
139 public function ticksRandomly() : bool{
140 return true;
141 }
142
143 public function onRandomTick() : void{
144 //TODO: vine growth
145 }
146
147 public function getDrops(Item $item) : array{
148 if(($item->getBlockToolType() & BlockToolType::SHEARS) !== 0){
149 return $this->getDropsForCompatibleTool($item);
150 }
151
152 return [];
153 }
154
155 public function getFlameEncouragement() : int{
156 return 15;
157 }
158
159 public function getFlammability() : int{
160 return 100;
161 }
162}
setFace(int $face, bool $value)
Definition Vine.php:71
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition Vine.php:42
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition Vine.php:104
onEntityInside(Entity $entity)
Definition Vine.php:95
setFaces(array $faces)
Definition Vine.php:58