From 1ce388ca0b977dd700d05a1756adc04714e3dccf Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 19 Sep 2021 15:59:16 +0100 Subject: [PATCH] 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. --- src/block/Liquid.php | 13 +++++++++++-- src/block/Water.php | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/block/Liquid.php b/src/block/Liquid.php index 677c3b0ae..6e3c8df35 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -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; } diff --git a/src/block/Water.php b/src/block/Water.php index a516d4064..ff638a8f9 100644 --- a/src/block/Water.php +++ b/src/block/Water.php @@ -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()){