diff --git a/src/block/Block.php b/src/block/Block.php index 9172fc3c2..1002164ba 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -1030,7 +1030,7 @@ public function setLayer(int $layer) : static{ } public function isLayerSupported(int $layer) : bool{ - return $layer === 0; + return $layer === 0 || ($this->canBeSnowlogged() && $layer === 1); } /** @@ -1058,4 +1058,12 @@ public function canWaterlogged(Liquid $water) : bool{ public function isWaterlogged() : bool{ return $this->getBlockLayer(1) instanceof Water; } + + public function canBeSnowlogged() : bool{ + return false; + } + + public function isSnowlogged() : bool{ + return $this instanceof SnowLayer && $this->getBlockLayer(1)->canBeSnowlogged(); + } } diff --git a/src/block/Flower.php b/src/block/Flower.php index ef79813fe..1a79d855c 100644 --- a/src/block/Flower.php +++ b/src/block/Flower.php @@ -41,4 +41,8 @@ public function getFlameEncouragement() : int{ public function getFlammability() : int{ return 100; } + + public function canBeSnowlogged() : bool{ + return true; + } } diff --git a/src/block/RedMushroom.php b/src/block/RedMushroom.php index 81ab940f5..ed219c9fe 100644 --- a/src/block/RedMushroom.php +++ b/src/block/RedMushroom.php @@ -53,4 +53,8 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo return false; } + + public function canBeSnowlogged() : bool{ + return true; + } } diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index ae05ecd46..917dfa48c 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -92,7 +92,13 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo $this->layers = $blockReplace->layers + 1; } if($this->canBeSupportedAt($blockReplace)){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); + parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); + if($blockReplace->canBeSnowlogged()){ + $tx->addBlock($blockReplace->position, $blockReplace->setLayer(1)); + }elseif($blockReplace->isSnowlogged()){ + $tx->addBlock($blockReplace->position, $blockReplace->getBlockLayer(1)); + } + return true; } return false; @@ -114,8 +120,4 @@ public function getDropsForCompatibleTool(Item $item) : array{ VanillaItems::SNOWBALL()->setCount(max(1, (int) floor($this->layers / 2))) ]; } - - public function isLayerSupported(int $layer) : bool{ - return parent::isLayerSupported($layer) || $layer === 1; - } } diff --git a/src/block/TallGrass.php b/src/block/TallGrass.php index 459751c4e..ab8b923b2 100644 --- a/src/block/TallGrass.php +++ b/src/block/TallGrass.php @@ -35,4 +35,8 @@ private function canBeSupportedAt(Block $block) : bool{ $supportBlock = $block->getSide(Facing::DOWN); return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD); } + + public function canBeSnowlogged() : bool{ + return true; + } } diff --git a/src/entity/object/FallingBlock.php b/src/entity/object/FallingBlock.php index c43305b8e..027da9c22 100644 --- a/src/entity/object/FallingBlock.php +++ b/src/entity/object/FallingBlock.php @@ -25,6 +25,7 @@ use pocketmine\block\Block; use pocketmine\block\RuntimeBlockStateRegistry; +use pocketmine\block\SnowLayer; use pocketmine\block\utils\Fallable; use pocketmine\block\Water; use pocketmine\data\bedrock\block\BlockStateDeserializeException; @@ -143,7 +144,8 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{ $blockResult = $blockTarget ?? $this->block; $block = $world->getBlock($pos); - if(!$block->canBeReplaced() || !$world->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()) || ($this->onGround && abs($this->location->y - $this->location->getFloorY()) > 0.001)){ + $down = $world->getBlock($pos->down()); + if((!$block->canBeReplaced() || !$world->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()) || ($this->onGround && abs($this->location->y - $this->location->getFloorY()) > 0.001)) && !(($block instanceof SnowLayer || $down instanceof SnowLayer) && $blockResult instanceof SnowLayer)){ $world->dropItem($this->location, $this->block->asItem()); $world->addSound($pos->add(0.5, 0.5, 0.5), new BlockBreakSound($blockResult)); }else{ @@ -151,6 +153,21 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{ $ev->call(); if(!$ev->isCancelled()){ $b = $ev->getTo(); + if($b instanceof SnowLayer){ + $otherSnow = $down instanceof SnowLayer && $down->getLayers() < SnowLayer::MAX_LAYERS ? $down : $block; + if($block->canBeSnowlogged()){ + $world->setBlockLayer($pos, $block, 1); + }elseif($otherSnow instanceof SnowLayer){ + $layers = $otherSnow->getLayers() + $b->getLayers(); + $pos = $otherSnow->getPosition(); + if($layers > SnowLayer::MAX_LAYERS){ + $world->setBlock($pos->up(), $b->setLayers($layers - SnowLayer::MAX_LAYERS)); + $b->setLayers(SnowLayer::MAX_LAYERS); + }else{ + $world->setBlock($pos, $b->setLayers($layers)); + } + } + } $world->setBlock($pos, $b); if($block instanceof Water && $b->canWaterlogged($block)){ $world->setBlockLayer($pos, $block, 1);