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