From a2253e9e7db867d187a5c512dd2248f2455b2150 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 30 Nov 2018 16:06:35 +0000 Subject: [PATCH] Flatten still liquid blocks into a liquid block property --- src/pocketmine/block/BlockFactory.php | 8 +++++-- src/pocketmine/block/Lava.php | 16 +------------ src/pocketmine/block/Liquid.php | 33 +++++++++++++++++++++++++-- src/pocketmine/block/StillLava.php | 33 --------------------------- src/pocketmine/block/StillWater.php | 33 --------------------------- src/pocketmine/block/Water.php | 16 +------------ 6 files changed, 39 insertions(+), 100 deletions(-) delete mode 100644 src/pocketmine/block/StillLava.php delete mode 100644 src/pocketmine/block/StillWater.php diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index b6c1a9efd..d72db93e2 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -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")); diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 5e6c6e2f7..7e57418d1 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -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; } diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index 01e369ee3..af8dde96e 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -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; diff --git a/src/pocketmine/block/StillLava.php b/src/pocketmine/block/StillLava.php deleted file mode 100644 index b4130a739..000000000 --- a/src/pocketmine/block/StillLava.php +++ /dev/null @@ -1,33 +0,0 @@ -getDamage()); - } - - public function getFlowingForm() : Block{ - return BlockFactory::get(Block::FLOWING_WATER, $this->getDamage()); - } - public function getBucketFillSound() : int{ return LevelSoundEventPacket::SOUND_BUCKET_FILL_WATER; }