mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
this is a reduced version compared to the original, due to the difficulty of getting rid of Facing values internally.
104 lines
3.4 KiB
PHP
104 lines
3.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\block;
|
|
|
|
use pocketmine\block\utils\SupportType;
|
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
|
use pocketmine\item\Item;
|
|
use pocketmine\math\Facing;
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\player\Player;
|
|
use pocketmine\world\BlockTransaction;
|
|
|
|
class SeaPickle extends Transparent{
|
|
public const MIN_COUNT = 1;
|
|
public const MAX_COUNT = 4;
|
|
|
|
protected int $count = self::MIN_COUNT;
|
|
protected bool $underwater = false;
|
|
|
|
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
|
$w->boundedIntAuto(self::MIN_COUNT, self::MAX_COUNT, $this->count);
|
|
$w->bool($this->underwater);
|
|
}
|
|
|
|
public function getCount() : int{ return $this->count; }
|
|
|
|
/** @return $this */
|
|
public function setCount(int $count) : self{
|
|
if($count < self::MIN_COUNT || $count > self::MAX_COUNT){
|
|
throw new \InvalidArgumentException("Count must be in range " . self::MIN_COUNT . " ... " . self::MAX_COUNT);
|
|
}
|
|
$this->count = $count;
|
|
return $this;
|
|
}
|
|
|
|
public function isUnderwater() : bool{ return $this->underwater; }
|
|
|
|
/** @return $this */
|
|
public function setUnderwater(bool $underwater) : self{
|
|
$this->underwater = $underwater;
|
|
return $this;
|
|
}
|
|
|
|
public function isSolid() : bool{
|
|
return false;
|
|
}
|
|
|
|
public function getLightLevel() : int{
|
|
return $this->underwater ? ($this->count + 1) * 3 : 0;
|
|
}
|
|
|
|
protected function recalculateCollisionBoxes() : array{
|
|
return [];
|
|
}
|
|
|
|
public function getSupportType(Facing $facing) : SupportType{
|
|
return SupportType::NONE;
|
|
}
|
|
|
|
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{
|
|
//TODO: proper placement logic (needs a supporting face below)
|
|
return ($blockReplace instanceof SeaPickle && $blockReplace->count < self::MAX_COUNT) || parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
|
|
}
|
|
|
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
$this->underwater = false; //TODO: implement this once we have new water logic in place
|
|
if($blockReplace instanceof SeaPickle && $blockReplace->count < self::MAX_COUNT){
|
|
$this->count = $blockReplace->count + 1;
|
|
}
|
|
|
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
}
|
|
|
|
public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
|
//TODO: bonemeal logic (requires coral)
|
|
return parent::onInteract($item, $face, $clickVector, $player, $returnedItems);
|
|
}
|
|
|
|
public function getDropsForCompatibleTool(Item $item) : array{
|
|
return [$this->asItem()->setCount($this->count)];
|
|
}
|
|
}
|