Flatten still liquid blocks into a liquid block property

This commit is contained in:
Dylan K. Taylor 2018-11-30 16:06:35 +00:00
parent ed531c0009
commit a2253e9e7d
6 changed files with 39 additions and 100 deletions

View File

@ -101,9 +101,13 @@ class BlockFactory{
self::registerBlock(new Bedrock());
self::registerBlock(new Water());
self::registerBlock(new StillWater());
$b = new Water();
$b->setStill();
self::registerBlock($b); //flattening hack
self::registerBlock(new Lava());
self::registerBlock(new StillLava());
$b = new Lava();
$b->setStill();
self::registerBlock($b); //flattening hack
self::registerBlock(new Sand(Block::SAND, 0, "Sand"));
self::registerBlock(new Sand(Block::SAND, 1, "Red Sand"));

View File

@ -32,28 +32,14 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
class Lava extends Liquid{
protected $id = self::FLOWING_LAVA;
public function __construct(){
parent::__construct(self::FLOWING_LAVA, self::STILL_LAVA, "Lava");
}
public function getLightLevel() : int{
return 15;
}
public function getName() : string{
return "Lava";
}
public function getStillForm() : Block{
return BlockFactory::get(Block::STILL_LAVA, $this->getDamage());
}
public function getFlowingForm() : Block{
return BlockFactory::get(Block::FLOWING_LAVA, $this->getDamage());
}
public function getBucketFillSound() : int{
return LevelSoundEventPacket::SOUND_BUCKET_FILL_LAVA;
}

View File

@ -31,6 +31,8 @@ use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
abstract class Liquid extends Transparent{
/** @var int */
private $stillId;
public $adjacentSources = 0;
@ -48,6 +50,17 @@ abstract class Liquid extends Transparent{
protected $falling = false;
/** @var int */
protected $decay = 0; //PC "level" property
/** @var bool */
protected $still = false;
public function __construct(int $id, int $stillId, string $name){
parent::__construct($id, 0, $name);
$this->stillId = $stillId;
}
public function getId() : int{
return $this->still ? $this->stillId : parent::getId();
}
protected function writeStateToMeta() : int{
return $this->decay | ($this->falling ? 0x08 : 0);
@ -94,9 +107,17 @@ abstract class Liquid extends Transparent{
return [];
}
abstract public function getStillForm() : Block;
public function getStillForm() : Block{
$b = clone $this;
$b->still = true;
return $b;
}
abstract public function getFlowingForm() : Block;
public function getFlowingForm() : Block{
$b = clone $this;
$b->still = false;
return $b;
}
abstract public function getBucketFillSound() : int;
@ -110,6 +131,14 @@ abstract class Liquid extends Transparent{
return (($this->falling ? 0 : $this->decay) + 1) / 9;
}
public function isStill() : bool{
return $this->still;
}
public function setStill(bool $still = true) : void{
$this->still = $still;
}
protected function getEffectiveFlowDecay(Block $block) : int{
if(!($block instanceof Liquid) or !$block->isSameType($this)){
return -1;

View File

@ -1,33 +0,0 @@
<?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;
class StillLava extends Lava{
protected $id = self::STILL_LAVA;
public function getName() : string{
return "Still Lava";
}
}

View File

@ -1,33 +0,0 @@
<?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;
class StillWater extends Water{
protected $id = self::STILL_WATER;
public function getName() : string{
return "Still Water";
}
}

View File

@ -28,28 +28,14 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
class Water extends Liquid{
protected $id = self::FLOWING_WATER;
public function __construct(){
}
public function getName() : string{
return "Water";
parent::__construct(self::FLOWING_WATER, self::STILL_WATER, "Water");
}
public function getLightFilter() : int{
return 2;
}
public function getStillForm() : Block{
return BlockFactory::get(Block::STILL_WATER, $this->getDamage());
}
public function getFlowingForm() : Block{
return BlockFactory::get(Block::FLOWING_WATER, $this->getDamage());
}
public function getBucketFillSound() : int{
return LevelSoundEventPacket::SOUND_BUCKET_FILL_WATER;
}