PocketMine-MP 5.19.1 git-f1b1a7022d7dc67d012d8891bc4c23c2652c825e
Flat.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
33use function count;
34
35class Flat extends Generator{
36 private Chunk $chunk;
38 private array $populators = [];
39
40 private FlatGeneratorOptions $options;
41
45 public function __construct(int $seed, string $preset){
46 parent::__construct($seed, $preset !== "" ? $preset : "2;bedrock,2xdirt,grass;1;");
47 $this->options = FlatGeneratorOptions::parsePreset($this->preset);
48
49 if(isset($this->options->getExtraOptions()["decoration"])){
50 $ores = new Ore();
51 $stone = VanillaBlocks::STONE();
52 $ores->setOreTypes([
53 new OreType(VanillaBlocks::COAL_ORE(), $stone, 20, 16, 0, 128),
54 new OreType(VanillaBlocks::IRON_ORE(), $stone, 20, 8, 0, 64),
55 new OreType(VanillaBlocks::REDSTONE_ORE(), $stone, 8, 7, 0, 16),
56 new OreType(VanillaBlocks::LAPIS_LAZULI_ORE(), $stone, 1, 6, 0, 32),
57 new OreType(VanillaBlocks::GOLD_ORE(), $stone, 2, 8, 0, 32),
58 new OreType(VanillaBlocks::DIAMOND_ORE(), $stone, 1, 7, 0, 16),
59 new OreType(VanillaBlocks::DIRT(), $stone, 20, 32, 0, 128),
60 new OreType(VanillaBlocks::GRAVEL(), $stone, 10, 16, 0, 128)
61 ]);
62 $this->populators[] = $ores;
63 }
64
65 $this->generateBaseChunk();
66 }
67
68 protected function generateBaseChunk() : void{
69 $this->chunk = new Chunk([], false);
70
71 $structure = $this->options->getStructure();
72 $count = count($structure);
73 for($sy = 0; $sy < $count; $sy += SubChunk::EDGE_LENGTH){
74 $subchunk = $this->chunk->getSubChunk($sy >> SubChunk::COORD_BIT_SIZE);
75 for($y = 0; $y < SubChunk::EDGE_LENGTH && isset($structure[$y | $sy]); ++$y){
76 $id = $structure[$y | $sy];
77
78 for($Z = 0; $Z < SubChunk::EDGE_LENGTH; ++$Z){
79 for($X = 0; $X < SubChunk::EDGE_LENGTH; ++$X){
80 $subchunk->setBlockStateId($X, $y, $Z, $id);
81 }
82 }
83 }
84 }
85 }
86
87 public function generateChunk(ChunkManager $world, int $chunkX, int $chunkZ) : void{
88 $world->setChunk($chunkX, $chunkZ, clone $this->chunk);
89 }
90
91 public function populateChunk(ChunkManager $world, int $chunkX, int $chunkZ) : void{
92 $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->seed);
93 foreach($this->populators as $populator){
94 $populator->populate($world, $chunkX, $chunkZ, $this->random);
95 }
96
97 }
98}
__construct(int $seed, string $preset)
Definition: Flat.php:45