PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Normal.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 
22 namespace pocketmine\level\generator;
23 
39 use pocketmine\math\Vector3 as Vector3;
41 
42 class Normal extends Generator{
43 
45  private $populators = [];
47  private $level;
49  private $random;
50  private $worldHeight = 65;
51  private $waterHeight = 63;
53  private $noiseHills;
55  private $noiseBase;
56 
57  public function __construct(array $options = []){
58 
59  }
60 
61  public function getName(){
62  return "normal";
63  }
64 
65  public function getSettings(){
66  return [];
67  }
68 
69  public function init(GenerationChunkManager $level, Random $random){
70  $this->level = $level;
71  $this->random = $random;
72  $this->random->setSeed($this->level->getSeed());
73  $this->noiseHills = new Simplex($this->random, 3, 0.1, 12);
74  $this->noiseBase = new Simplex($this->random, 16, 0.6, 16);
75 
76 
77  $ores = new Ore();
78  $ores->setOreTypes([
79  new OreType(new CoalOre(), 20, 16, 0, 128),
80  new OreType(New IronOre(), 20, 8, 0, 64),
81  new OreType(new RedstoneOre(), 8, 7, 0, 16),
82  new OreType(new LapisOre(), 1, 6, 0, 32),
83  new OreType(new GoldOre(), 2, 8, 0, 32),
84  new OreType(new DiamondOre(), 1, 7, 0, 16),
85  new OreType(new Dirt(), 20, 32, 0, 128),
86  new OreType(new Gravel(), 10, 16, 0, 128),
87  ]);
88  $this->populators[] = $ores;
89 
90  $trees = new Tree();
91  $trees->setBaseAmount(1);
92  $trees->setRandomAmount(1);
93  $this->populators[] = $trees;
94 
95  $tallGrass = new TallGrass();
96  $tallGrass->setBaseAmount(5);
97  $tallGrass->setRandomAmount(0);
98  $this->populators[] = $tallGrass;
99  }
100 
101  public function generateChunk($chunkX, $chunkZ){
102  $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
103  $hills = [];
104  $base = [];
105  for($z = 0; $z < 16; ++$z){
106  for($x = 0; $x < 16; ++$x){
107  $i = ($z << 4) + $x;
108  $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
109  $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
110 
111  if($base[$i] < 0){
112  $base[$i] *= 0.5;
113  }
114  }
115  }
116 
117  $chunk = $this->level->getChunk($chunkX, $chunkZ);
118 
119  for($z = 0; $z < 16; ++$z){
120  for($x = 0; $x < 16; ++$x){
121  $i = ($z << 4) + $x;
122  $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 7;
123  $height = (int) $height;
124 
125  for($y = 0; $y < 128; ++$y){
126  $diff = $height - $y;
127  if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){
128  $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
129  }elseif($diff > 2){
130  $chunk->setBlockId($x, $y, $z, Block::STONE);
131  }elseif($diff > 0){
132  $chunk->setBlockId($x, $y, $z, Block::DIRT);
133  }elseif($y <= $this->waterHeight){
134  if(($this->waterHeight - $y) <= 1 and $diff === 0){
135  $chunk->setBlockId($x, $y, $z, Block::SAND);
136  }elseif($diff === 0){
137  $chunk->setBlockId($x, $y, $z, Block::DIRT);
138  }else{
139  $chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
140  }
141  }elseif($diff === 0){
142  $chunk->setBlockId($x, $y, $z, Block::GRASS);
143  }
144  }
145 
146  }
147  }
148 
149  }
150 
151  public function populateChunk($chunkX, $chunkZ){
152  $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
153  foreach($this->populators as $populator){
154  $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
155  $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
156  }
157  }
158 
159  public function getSpawn(){
160  return $this->level->getSafeSpawn(new Vector3(127.5, 128, 127.5));
161  }
162 
163 }