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