LevelProvider: Added methods to get and set rain/lightning level and times

This commit is contained in:
Dylan K. Taylor 2018-01-17 16:48:19 +00:00
parent 91064b3209
commit 9b49d09714
3 changed files with 119 additions and 1 deletions

View File

@ -152,6 +152,50 @@ interface LevelProvider{
*/
public function setDifficulty(int $difficulty);
/**
* Returns the time in ticks to the next rain level change.
* @return int
*/
public function getRainTime() : int;
/**
* Sets the time in ticks to the next rain level change.
* @param int $ticks
*/
public function setRainTime(int $ticks) : void;
/**
* @return float 0.0 - 1.0
*/
public function getRainLevel() : float;
/**
* @param float $level 0.0 - 1.0
*/
public function setRainLevel(float $level) : void;
/**
* Returns the time in ticks to the next lightning level change.
* @return int
*/
public function getLightningTime() : int;
/**
* Sets the time in ticks to the next lightning level change.
* @param int $ticks
*/
public function setLightningTime(int $ticks) : void;
/**
* @return float 0.0 - 1.0
*/
public function getLightningLevel() : float;
/**
* @param float $level 0.0 - 1.0
*/
public function setLightningLevel(float $level) : void;
/**
* Performs garbage collection in the level provider, such as cleaning up regions in Region-based worlds.
*/

View File

@ -266,6 +266,38 @@ class LevelDB extends BaseLevelProvider{
$this->levelData->setInt("Difficulty", $difficulty); //yes, this is intended! (in PE: int, PC: byte)
}
public function getRainTime() : int{
return $this->levelData->getInt("rainTime", 0);
}
public function setRainTime(int $ticks) : void{
$this->levelData->setInt("rainTime", $ticks);
}
public function getRainLevel() : float{
return $this->levelData->getFloat("rainLevel", 0.0);
}
public function setRainLevel(float $level) : void{
$this->levelData->setFloat("rainLevel", $level);
}
public function getLightningTime() : int{
return $this->levelData->getInt("lightningTime", 0);
}
public function setLightningTime(int $ticks) : void{
$this->levelData->setInt("lightningTime", $ticks);
}
public function getLightningLevel() : float{
return $this->levelData->getFloat("lightningLevel", 0.0);
}
public function setLightningLevel(float $level) : void{
$this->levelData->setFloat("lightningLevel", $level);
}
/**
* @param int $chunkX
* @param int $chunkZ

View File

@ -33,7 +33,7 @@ use pocketmine\level\Level;
use pocketmine\nbt\BigEndianNBTStream;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\{
ByteArrayTag, ByteTag, CompoundTag, IntArrayTag, IntTag, ListTag, LongTag, StringTag
ByteArrayTag, ByteTag, CompoundTag, FloatTag, IntArrayTag, IntTag, ListTag, LongTag, StringTag
};
use pocketmine\utils\MainLogger;
@ -268,6 +268,48 @@ class McRegion extends BaseLevelProvider{
$this->levelData->setByte("Difficulty", $difficulty);
}
public function getRainTime() : int{
return $this->levelData->getInt("rainTime", 0);
}
public function setRainTime(int $ticks) : void{
$this->levelData->setInt("rainTime", $ticks);
}
public function getRainLevel() : float{
if($this->levelData->hasTag("rainLevel", FloatTag::class)){ //PocketMine/MCPE
return $this->levelData->getFloat("rainLevel");
}
return (float) $this->levelData->getByte("raining", 0); //PC vanilla
}
public function setRainLevel(float $level) : void{
$this->levelData->setFloat("rainLevel", $level); //PocketMine/MCPE
$this->levelData->setByte("raining", (int) ceil($level)); //PC vanilla
}
public function getLightningTime() : int{
return $this->levelData->getInt("thunderTime", 0);
}
public function setLightningTime(int $ticks) : void{
$this->levelData->setInt("thunderTime", $ticks);
}
public function getLightningLevel() : float{
if($this->levelData->hasTag("lightningLevel", FloatTag::class)){ //PocketMine/MCPE
return $this->levelData->getFloat("lightningLevel");
}
return (float) $this->levelData->getByte("thundering", 0); //PC vanilla
}
public function setLightningLevel(float $level) : void{
$this->levelData->setFloat("lightningLevel", $level); //PocketMine/MCPE
$this->levelData->setByte("thundering", (int) ceil($level)); //PC vanilla
}
public function doGarbageCollection(){
$limit = time() - 300;
foreach($this->regions as $index => $region){