Crops must have access to a light level of at least 9

This commit is contained in:
Dylan K. Taylor 2023-11-06 16:02:57 +00:00
parent d3b7861d1a
commit 457660235e
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 41 additions and 9 deletions

View File

@ -36,6 +36,8 @@ final class CropGrowthHelper{
private const IMPROPER_ARRANGEMENT_DIVISOR = 2;
private const MIN_LIGHT_LEVEL = 9;
private function __construct(){
//NOOP
}
@ -102,9 +104,17 @@ final class CropGrowthHelper{
return $result;
}
public static function hasEnoughLight(Block $block, int $minLevel = self::MIN_LIGHT_LEVEL) : bool{
$position = $block->getPosition();
$world = $position->getWorld();
//crop growth is not affected by time of day since 1.11 or so
return $world->getPotentialLight($position) >= $minLevel;
}
public static function canGrow(Block $block) : bool{
//while it may be tempting to use mt_rand(0, 25) < multiplier, this would make crops grow a bit faster than
//vanilla in most cases due to the remainder of 25 / multiplier not being discarded
return mt_rand(0, (int) (25 / self::calculateMultiplier($block))) === 0;
return mt_rand(0, (int) (25 / self::calculateMultiplier($block))) === 0 && self::hasEnoughLight($block);
}
}

View File

@ -1666,16 +1666,16 @@ class World implements ChunkManager{
}
/**
* Returns the highest available level of any type of light at the given coordinates, adjusted for the current
* weather and time of day.
* Returns the highest level of any type of light at the given coordinates, adjusted for the current weather and
* time of day.
*/
public function getFullLight(Vector3 $pos) : int{
return $this->getFullLightAt($pos->x, $pos->y, $pos->z);
}
/**
* Returns the highest available level of any type of light at the given coordinates, adjusted for the current
* weather and time of day.
* Returns the highest level of any type of light at the given coordinates, adjusted for the current weather and
* time of day.
*/
public function getFullLightAt(int $x, int $y, int $z) : int{
$skyLight = $this->getRealBlockSkyLightAt($x, $y, $z);
@ -1687,18 +1687,40 @@ class World implements ChunkManager{
}
/**
* Returns the highest available level of any type of light at, or adjacent to, the given coordinates, adjusted for
* the current weather and time of day.
* Returns the highest level of any type of light at, or adjacent to, the given coordinates, adjusted for the
* current weather and time of day.
*/
public function getHighestAdjacentFullLightAt(int $x, int $y, int $z) : int{
return $this->getHighestAdjacentLight($x, $y, $z, $this->getFullLightAt(...));
}
/**
* Returns the highest potential level of any type of light at the target coordinates.
* This is not affected by weather or time of day.
*/
public function getPotentialLight(Vector3 $pos) : int{
return $this->getPotentialLightAt($pos->x, $pos->y, $pos->z);
}
/**
* Returns the highest potential level of any type of light at the target coordinates.
* This is not affected by weather or time of day.
*/
public function getPotentialLightAt(int $x, int $y, int $z) : int{
return max($this->getPotentialBlockSkyLightAt($x, $y, $z), $this->getBlockLightAt($x, $y, $z));
}
/**
* Returns the highest potential level of any type of light at, or adjacent to, the given coordinates.
* This is not affected by weather or time of day.
*/
public function getHighestAdjacentPotentialLightAt(int $x, int $y, int $z) : int{
return $this->getHighestAdjacentLight($x, $y, $z, $this->getPotentialLightAt(...));
}
/**
* Returns the highest potential level of sky light at the target coordinates, regardless of the time of day or
* weather conditions.
* You usually don't want to use this for vanilla gameplay logic; prefer the real sky light instead.
* @see World::getRealBlockSkyLightAt()
*
* @return int 0-15
*/