mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 17:20:02 +00:00
Fixed Level generators
This commit is contained in:
parent
63f1f7581f
commit
cb2b08b248
@ -67,10 +67,10 @@ class Normal extends Generator{
|
||||
$this->level = $level;
|
||||
$this->random = $random;
|
||||
$this->random->setSeed($this->level->getSeed());
|
||||
$this->noiseHills = new Simplex($this->random, 3);
|
||||
$this->noisePatches = new Simplex($this->random, 2);
|
||||
$this->noisePatchesSmall = new Simplex($this->random, 2);
|
||||
$this->noiseBase = new Simplex($this->random, 16);
|
||||
$this->noiseHills = new Simplex($this->random, 3, 0.11, 12);
|
||||
$this->noisePatches = new Simplex($this->random, 2, 0.03, 16);
|
||||
$this->noisePatchesSmall = new Simplex($this->random, 2, 0.5, 4);
|
||||
$this->noiseBase = new Simplex($this->random, 16, 0.7, 16);
|
||||
|
||||
|
||||
$ores = new Ore();
|
||||
@ -106,10 +106,10 @@ class Normal extends Generator{
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$i = ($z << 4) + $x;
|
||||
$hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.11, 12, true);
|
||||
$patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true);
|
||||
$patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true);
|
||||
$base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 16, true);
|
||||
$hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
|
||||
$patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
|
||||
$patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
|
||||
$base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
|
||||
|
||||
if($base[$i] < 0){
|
||||
$base[$i] *= 0.5;
|
||||
|
@ -33,6 +33,8 @@ abstract class Generator{
|
||||
protected $offsetY = 0;
|
||||
protected $offsetZ = 0;
|
||||
protected $octaves = 8;
|
||||
protected $frequency;
|
||||
protected $amplitude;
|
||||
|
||||
public static function floor($x){
|
||||
return $x >= 0 ? (int) $x : (int) ($x - 1);
|
||||
@ -58,7 +60,7 @@ abstract class Generator{
|
||||
|
||||
abstract public function getNoise3D($x, $y, $z);
|
||||
|
||||
public function noise2D($x, $z, $frequency, $amplitude, $normalized = false){
|
||||
public function noise2D($x, $z, $normalized = false){
|
||||
$result = 0;
|
||||
$amp = 1;
|
||||
$freq = 1;
|
||||
@ -67,8 +69,8 @@ abstract class Generator{
|
||||
for($i = 0; $i < $this->octaves; ++$i){
|
||||
$result += $this->getNoise2D($x * $freq, $z * $freq) * $amp;
|
||||
$max += $amp;
|
||||
$freq *= $frequency;
|
||||
$amp *= $amplitude;
|
||||
$freq *= $this->frequency;
|
||||
$amp *= $this->amplitude;
|
||||
}
|
||||
if($normalized === true){
|
||||
$result /= $max;
|
||||
@ -77,7 +79,7 @@ abstract class Generator{
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function noise3D($x, $y, $z, $frequency, $amplitude, $normalized = false){
|
||||
public function noise3D($x, $y, $z, $normalized = false){
|
||||
$result = 0;
|
||||
$amp = 1;
|
||||
$freq = 1;
|
||||
@ -86,8 +88,8 @@ abstract class Generator{
|
||||
for($i = 0; $i < $this->octaves; ++$i){
|
||||
$result += $this->getNoise3D($x * $freq, $y * $freq, $z * $freq) * $amp;
|
||||
$max += $amp;
|
||||
$freq *= $frequency;
|
||||
$amp *= $amplitude;
|
||||
$freq *= $this->frequency;
|
||||
$amp *= $this->amplitude;
|
||||
}
|
||||
if($normalized === true){
|
||||
$result /= $max;
|
||||
|
@ -32,8 +32,10 @@ class Perlin extends Generator{
|
||||
];
|
||||
|
||||
|
||||
public function __construct(Random $random, $octaves){
|
||||
public function __construct(Random $random, $octaves, $frequency, $amplitude){
|
||||
$this->octaves = $octaves;
|
||||
$this->frequency = $frequency;
|
||||
$this->amplitude = $amplitude;
|
||||
$this->offsetX = $random->nextFloat() * 256;
|
||||
$this->offsetY = $random->nextFloat() * 256;
|
||||
$this->offsetZ = $random->nextFloat() * 256;
|
||||
|
@ -64,8 +64,9 @@ class Simplex extends Perlin{
|
||||
[2, 1, 0, 3], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [3, 1, 0, 2], [0, 0, 0, 0], [3, 2, 0, 1], [3, 2, 1, 0]];
|
||||
protected $offsetW;
|
||||
|
||||
public function __construct(Random $random, $octaves){
|
||||
parent::__construct($random, $octaves);
|
||||
|
||||
public function __construct(Random $random, $octaves, $frequency, $amplitude){
|
||||
parent::__construct($random, $octaves, $frequency, $amplitude);
|
||||
$this->offsetW = $random->nextFloat() * 256;
|
||||
self::$SQRT_3 = sqrt(3);
|
||||
self::$SQRT_5 = sqrt(5);
|
||||
|
Loading…
x
Reference in New Issue
Block a user