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