PocketMine-MP 5.16.1 git-585aee9386a787c95e73dd0a05ffca8329606b68
PinkPetals.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\StaticSupportTrait;
36
37class PinkPetals extends Flowable{
38 use HorizontalFacingTrait;
39 use StaticSupportTrait {
40 canBePlacedAt as supportedWhenPlacedAt;
41 }
42
43 public const MIN_COUNT = 1;
44 public const MAX_COUNT = 4;
45
46 protected int $count = self::MIN_COUNT;
47
48 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
49 $w->horizontalFacing($this->facing);
50 $w->boundedIntAuto(self::MIN_COUNT, self::MAX_COUNT, $this->count);
51 }
52
53 public function getCount() : int{
54 return $this->count;
55 }
56
58 public function setCount(int $count) : self{
59 if($count < self::MIN_COUNT || $count > self::MAX_COUNT){
60 throw new \InvalidArgumentException("Count must be in range " . self::MIN_COUNT . " ... " . self::MAX_COUNT);
61 }
62 $this->count = $count;
63 return $this;
64 }
65
66 private function canBeSupportedAt(Block $block) : bool{
67 $supportBlock = $block->getSide(Facing::DOWN);
68 //TODO: Moss block
69 return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
70 }
71
72 public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
73 return ($blockReplace instanceof PinkPetals && $blockReplace->count < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
74 }
75
76 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
77 if($blockReplace instanceof PinkPetals && $blockReplace->count < self::MAX_COUNT){
78 $this->count = $blockReplace->count + 1;
79 $this->facing = $blockReplace->facing;
80 }elseif($player !== null){
81 $this->facing = Facing::opposite($player->getHorizontalFacing());
82 }
83 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
84 }
85
86 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
87 if($item instanceof Fertilizer){
88 $grew = false;
89 if($this->count < self::MAX_COUNT){
90 $grew = BlockEventHelper::grow($this, (clone $this)->setCount($this->count + 1), $player);
91 }else{
92 $this->position->getWorld()->dropItem($this->position->add(0, 0.5, 0), $this->asItem());
93 $grew = true;
94 }
95 if($grew){
96 $item->pop();
97 return true;
98 }
99 }
100 return false;
101 }
102
103 public function getFlameEncouragement() : int{
104 return 60;
105 }
106
107 public function getFlammability() : int{
108 return 100;
109 }
110
111 public function getDropsForCompatibleTool(Item $item) : array{
112 return [$this->asItem()->setCount($this->count)];
113 }
114}
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition: PinkPetals.php:48
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition: PinkPetals.php:76
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition: PinkPetals.php:86
getDropsForCompatibleTool(Item $item)
Definition: PinkPetals.php:111
canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock)
Definition: PinkPetals.php:72
pop(int $count=1)
Definition: Item.php:430
boundedIntAuto(int $min, int $max, int &$value)