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