PocketMine-MP 5.18.1 git-9381fc4172e5dce4cada1cb356050c8a2ab57b94
SeaPickle.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
26use pocketmine\block\utils\SupportType;
33
34class SeaPickle extends Transparent{
35 public const MIN_COUNT = 1;
36 public const MAX_COUNT = 4;
37
38 protected int $count = self::MIN_COUNT;
39 protected bool $underwater = false;
40
41 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
42 $w->boundedIntAuto(self::MIN_COUNT, self::MAX_COUNT, $this->count);
43 $w->bool($this->underwater);
44 }
45
46 public function getCount() : int{ return $this->count; }
47
49 public function setCount(int $count) : self{
50 if($count < self::MIN_COUNT || $count > self::MAX_COUNT){
51 throw new \InvalidArgumentException("Count must be in range " . self::MIN_COUNT . " ... " . self::MAX_COUNT);
52 }
53 $this->count = $count;
54 return $this;
55 }
56
57 public function isUnderwater() : bool{ return $this->underwater; }
58
60 public function setUnderwater(bool $underwater) : self{
61 $this->underwater = $underwater;
62 return $this;
63 }
64
65 public function isSolid() : bool{
66 return false;
67 }
68
69 public function getLightLevel() : int{
70 return $this->underwater ? ($this->count + 1) * 3 : 0;
71 }
72
76 protected function recalculateCollisionBoxes() : array{
77 return [];
78 }
79
80 public function getSupportType(int $facing) : SupportType{
81 return SupportType::NONE;
82 }
83
84 public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
85 //TODO: proper placement logic (needs a supporting face below)
86 return ($blockReplace instanceof SeaPickle && $blockReplace->count < self::MAX_COUNT) || parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
87 }
88
89 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
90 $this->underwater = false; //TODO: implement this once we have new water logic in place
91 if($blockReplace instanceof SeaPickle && $blockReplace->count < self::MAX_COUNT){
92 $this->count = $blockReplace->count + 1;
93 }
94
95 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
96 }
97
98 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
99 //TODO: bonemeal logic (requires coral)
100 return parent::onInteract($item, $face, $clickVector, $player, $returnedItems);
101 }
102
103 public function getDropsForCompatibleTool(Item $item) : array{
104 return [$this->asItem()->setCount($this->count)];
105 }
106}
getDropsForCompatibleTool(Item $item)
Definition: SeaPickle.php:103
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition: SeaPickle.php:98
setUnderwater(bool $underwater)
Definition: SeaPickle.php:60
getSupportType(int $facing)
Definition: SeaPickle.php:80
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition: SeaPickle.php:89
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition: SeaPickle.php:41
canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock)
Definition: SeaPickle.php:84