Added melting for ice and snow layers

This commit is contained in:
Dylan K. Taylor 2017-04-18 18:55:01 +01:00
parent 3bd94c9da7
commit b6fe231bc1
3 changed files with 24 additions and 4 deletions

View File

@ -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 [];
}

View File

@ -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;

View File

@ -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);
}