Liquid: add getMinAdjacentSourcesToFormSource(), remove circular dependency between Liquid and Water

this unpleasantly-named method allows controlling the source-forming behaviour of liquids by changing the required number of adjacent sources that must be present in order for a new source to form. This allows stuff like non-infinite water.
This commit is contained in:
Dylan K. Taylor 2021-09-19 15:59:16 +01:00
parent 971cbe3929
commit 1ce388ca0b
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 15 additions and 2 deletions

View File

@ -249,6 +249,14 @@ abstract class Liquid extends Transparent{
return 1;
}
/**
* Returns the number of source blocks of this liquid that must be horizontally adjacent to this block in order for
* this block to become a source block itself, or null if the liquid does not exhibit source-forming behaviour.
*/
public function getMinAdjacentSourcesToFormSource() : ?int{
return null;
}
public function onNearbyBlockChange() : void{
if(!$this->checkForHarden()){
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, $this->tickRate());
@ -279,9 +287,10 @@ abstract class Liquid extends Transparent{
$falling = true;
}
if($this->adjacentSources >= 2 and $this instanceof Water){
$minAdjacentSources = $this->getMinAdjacentSourcesToFormSource();
if($minAdjacentSources !== null && $this->adjacentSources >= $minAdjacentSources){
$bottomBlock = $world->getBlockAt($this->position->x, $this->position->y - 1, $this->position->z);
if($bottomBlock->isSolid() or ($bottomBlock instanceof Water and $bottomBlock->isSource())){
if($bottomBlock->isSolid() or ($bottomBlock instanceof Liquid and $bottomBlock->isSameType($this) and $bottomBlock->isSource())){
$newDecay = 0;
$falling = false;
}

View File

@ -46,6 +46,10 @@ class Water extends Liquid{
return 5;
}
public function getMinAdjacentSourcesToFormSource() : ?int{
return 2;
}
public function onEntityInside(Entity $entity) : bool{
$entity->resetFallDistance();
if($entity->isOnFire()){