mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-18 19:55:33 +00:00
Flatten still liquid blocks into a liquid block property
This commit is contained in:
parent
ed531c0009
commit
a2253e9e7d
@ -101,9 +101,13 @@ class BlockFactory{
|
|||||||
|
|
||||||
self::registerBlock(new Bedrock());
|
self::registerBlock(new Bedrock());
|
||||||
self::registerBlock(new Water());
|
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 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, 0, "Sand"));
|
||||||
self::registerBlock(new Sand(Block::SAND, 1, "Red Sand"));
|
self::registerBlock(new Sand(Block::SAND, 1, "Red Sand"));
|
||||||
|
@ -32,28 +32,14 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
|||||||
|
|
||||||
class Lava extends Liquid{
|
class Lava extends Liquid{
|
||||||
|
|
||||||
protected $id = self::FLOWING_LAVA;
|
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
|
parent::__construct(self::FLOWING_LAVA, self::STILL_LAVA, "Lava");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLightLevel() : int{
|
public function getLightLevel() : int{
|
||||||
return 15;
|
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{
|
public function getBucketFillSound() : int{
|
||||||
return LevelSoundEventPacket::SOUND_BUCKET_FILL_LAVA;
|
return LevelSoundEventPacket::SOUND_BUCKET_FILL_LAVA;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ use pocketmine\math\Vector3;
|
|||||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||||
|
|
||||||
abstract class Liquid extends Transparent{
|
abstract class Liquid extends Transparent{
|
||||||
|
/** @var int */
|
||||||
|
private $stillId;
|
||||||
|
|
||||||
public $adjacentSources = 0;
|
public $adjacentSources = 0;
|
||||||
|
|
||||||
@ -48,6 +50,17 @@ abstract class Liquid extends Transparent{
|
|||||||
protected $falling = false;
|
protected $falling = false;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $decay = 0; //PC "level" property
|
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{
|
protected function writeStateToMeta() : int{
|
||||||
return $this->decay | ($this->falling ? 0x08 : 0);
|
return $this->decay | ($this->falling ? 0x08 : 0);
|
||||||
@ -94,9 +107,17 @@ abstract class Liquid extends Transparent{
|
|||||||
return [];
|
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;
|
abstract public function getBucketFillSound() : int;
|
||||||
|
|
||||||
@ -110,6 +131,14 @@ abstract class Liquid extends Transparent{
|
|||||||
return (($this->falling ? 0 : $this->decay) + 1) / 9;
|
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{
|
protected function getEffectiveFlowDecay(Block $block) : int{
|
||||||
if(!($block instanceof Liquid) or !$block->isSameType($this)){
|
if(!($block instanceof Liquid) or !$block->isSameType($this)){
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,28 +28,14 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
|||||||
|
|
||||||
class Water extends Liquid{
|
class Water extends Liquid{
|
||||||
|
|
||||||
protected $id = self::FLOWING_WATER;
|
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
|
parent::__construct(self::FLOWING_WATER, self::STILL_WATER, "Water");
|
||||||
}
|
|
||||||
|
|
||||||
public function getName() : string{
|
|
||||||
return "Water";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLightFilter() : int{
|
public function getLightFilter() : int{
|
||||||
return 2;
|
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{
|
public function getBucketFillSound() : int{
|
||||||
return LevelSoundEventPacket::SOUND_BUCKET_FILL_WATER;
|
return LevelSoundEventPacket::SOUND_BUCKET_FILL_WATER;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user