PocketMine-MP 5.28.1 git-88cdc2eb67c40075559c3ef51418b418cd5488e9
Loading...
Searching...
No Matches
PopulationUtils.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
25
30
34final class PopulationUtils{
35
36 private static function setOrGenerateChunk(SimpleChunkManager $manager, Generator $generator, int $chunkX, int $chunkZ, ?Chunk $chunk) : Chunk{
37 $manager->setChunk($chunkX, $chunkZ, $chunk ?? new Chunk([], false));
38 if($chunk === null){
39 $generator->generateChunk($manager, $chunkX, $chunkZ);
40 $chunk = $manager->getChunk($chunkX, $chunkZ);
41 if($chunk === null){
42 throw new AssumptionFailedError("We just set this chunk, so it must exist");
43 }
44 }
45 return $chunk;
46 }
47
55 public static function populateChunkWithAdjacents(int $minY, int $maxY, Generator $generator, int $chunkX, int $chunkZ, ?Chunk $centerChunk, array $adjacentChunks) : array{
56 $manager = new SimpleChunkManager($minY, $maxY);
57 self::setOrGenerateChunk($manager, $generator, $chunkX, $chunkZ, $centerChunk);
58
59 $resultChunks = []; //this is just to keep phpstan's type inference happy
60 foreach($adjacentChunks as $relativeChunkHash => $c){
61 World::getXZ($relativeChunkHash, $relativeX, $relativeZ);
62 $resultChunks[$relativeChunkHash] = self::setOrGenerateChunk($manager, $generator, $chunkX + $relativeX, $chunkZ + $relativeZ, $c);
63 }
64 $adjacentChunks = $resultChunks;
65
66 $generator->populateChunk($manager, $chunkX, $chunkZ);
67 $centerChunk = $manager->getChunk($chunkX, $chunkZ);
68 if($centerChunk === null){
69 throw new AssumptionFailedError("We just generated this chunk, so it must exist");
70 }
71 $centerChunk->setPopulated();
72 return [$centerChunk, $adjacentChunks];
73 }
74}
static getXZ(int $hash, ?int &$x, ?int &$z)
Definition World.php:448
static populateChunkWithAdjacents(int $minY, int $maxY, Generator $generator, int $chunkX, int $chunkZ, ?Chunk $centerChunk, array $adjacentChunks)