From 55cd1f263dc5488e1efba2c1667b924b849f3431 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 3 Feb 2019 12:05:08 +0000 Subject: [PATCH] SnowLayer: implement layers, closes #2657 --- src/pocketmine/block/SnowLayer.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index a998a78bc..f4ab36765 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -27,9 +27,12 @@ use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\TieredTool; +use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; +use function floor; +use function max; class SnowLayer extends Flowable{ @@ -74,7 +77,18 @@ class SnowLayer extends Flowable{ return TieredTool::TIER_WOODEN; } + protected function recalculateBoundingBox() : ?AxisAlignedBB{ + //TODO: this zero-height BB is intended to stay in lockstep with a MCPE bug + return AxisAlignedBB::one()->trim(Facing::UP, $this->layers >= 4 ? 0.5 : 1); + } + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ + if($blockReplace instanceof SnowLayer){ + if($blockReplace->layers >= 8){ + return false; + } + $this->layers = $blockReplace->layers + 1; + } if($blockReplace->getSide(Facing::DOWN)->isSolid()){ //TODO: fix placement return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -101,7 +115,7 @@ class SnowLayer extends Flowable{ public function getDropsForCompatibleTool(Item $item) : array{ return [ - ItemFactory::get(Item::SNOWBALL) //TODO: check layer count + ItemFactory::get(Item::SNOWBALL, 0, max(1, (int) floor($this->layers / 2))) ]; }