PocketMine-MP 5.16.1 git-585aee9386a787c95e73dd0a05ffca8329606b68
DoublePlant.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
32
33class DoublePlant extends Flowable{
34 protected bool $top = false;
35
36 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
37 $w->bool($this->top);
38 }
39
40 public function isTop() : bool{ return $this->top; }
41
43 public function setTop(bool $top) : self{
44 $this->top = $top;
45 return $this;
46 }
47
48 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
49 $down = $blockReplace->getSide(Facing::DOWN);
50 if($down->hasTypeTag(BlockTypeTags::DIRT) && $blockReplace->getSide(Facing::UP)->canBeReplaced()){
51 $top = clone $this;
52 $top->top = true;
53 $tx->addBlock($blockReplace->position, $this)->addBlock($blockReplace->position->getSide(Facing::UP), $top);
54 return true;
55 }
56
57 return false;
58 }
59
63 public function isValidHalfPlant() : bool{
64 $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
65
66 return (
67 $other instanceof DoublePlant &&
68 $other->hasSameTypeId($this) &&
69 $other->top !== $this->top
70 );
71 }
72
73 public function onNearbyBlockChange() : void{
74 $down = $this->getSide(Facing::DOWN);
75 if(!$this->isValidHalfPlant() || (!$this->top && !$down->hasTypeTag(BlockTypeTags::DIRT) && !$down->hasTypeTag(BlockTypeTags::MUD))){
76 $this->position->getWorld()->useBreakOn($this->position);
77 }
78 }
79
80 public function getDrops(Item $item) : array{
81 return $this->top ? parent::getDrops($item) : [];
82 }
83
84 public function getAffectedBlocks() : array{
85 if($this->isValidHalfPlant()){
86 return [$this, $this->getSide($this->top ? Facing::DOWN : Facing::UP)];
87 }
88
89 return parent::getAffectedBlocks();
90 }
91
92 public function getFlameEncouragement() : int{
93 return 60;
94 }
95
96 public function getFlammability() : int{
97 return 100;
98 }
99}
getSide(int $side, int $step=1)
Definition: Block.php:768
hasSameTypeId(Block $other)
Definition: Block.php:184
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition: DoublePlant.php:36
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition: DoublePlant.php:48
addBlock(Vector3 $pos, Block $state)