From b6fe231bc19fcd7dfdadc84bb0a8158c8aa3f39f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 18 Apr 2017 18:55:01 +0100 Subject: [PATCH] Added melting for ice and snow layers --- src/pocketmine/block/Ice.php | 12 ++++++++++++ src/pocketmine/block/SnowLayer.php | 15 +++++++++++---- src/pocketmine/block/StillWater.php | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index 7073d534a..7467a869d 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\level\Level; class Ice extends Transparent{ @@ -56,6 +57,17 @@ class Ice extends Transparent{ return true; } + public function onUpdate($type){ + if($type === Level::BLOCK_UPDATE_RANDOM){ + if($this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z) >= 12){ + $this->level->useBreakOn($this); + + return $type; + } + } + return false; + } + public function getDrops(Item $item){ return []; } diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index ebbe26c48..88702dcd5 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\Player; class SnowLayer extends Flowable{ @@ -54,8 +55,8 @@ class SnowLayer extends Flowable{ public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ - $down = $this->getSide(0); - if($down->isSolid()){ + if($block->getSide(Vector3::SIDE_DOWN)->isSolid()){ + //TODO: fix placement $this->getLevel()->setBlock($block, $this, true); return true; @@ -66,11 +67,17 @@ class SnowLayer extends Flowable{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->getId() === self::AIR){ //Replace with common break method - $this->getLevel()->setBlock($this, new Air(), true); + if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid()){ + $this->getLevel()->setBlock($this, Block::get(Block::AIR), false, false); return Level::BLOCK_UPDATE_NORMAL; } + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ + if($this->level->getBlockLightAt($this->x, $this->y, $this->z) >= 12){ + $this->getLevel()->setBlock($this, Block::get(Block::AIR), false, false); + + return Level::BLOCK_UPDATE_RANDOM; + } } return false; diff --git a/src/pocketmine/block/StillWater.php b/src/pocketmine/block/StillWater.php index 856f6fac0..b743f1a3e 100644 --- a/src/pocketmine/block/StillWater.php +++ b/src/pocketmine/block/StillWater.php @@ -30,6 +30,7 @@ class StillWater extends Water{ protected $id = self::STILL_WATER; public function onUpdate($type){ + //TODO: add freezing in cold biomes if($type !== Level::BLOCK_UPDATE_SCHEDULED){ return parent::onUpdate($type); }