mobs will spawn only in loaded chunks, entities in unloaded chunks will automatically *rip*

This commit is contained in:
GameHerobrine 2023-07-04 03:57:40 +03:00
parent bc979c2853
commit 8d1e76f84d
7 changed files with 21 additions and 12 deletions

View file

@ -19,7 +19,7 @@ class Level{
*/
public $entityList;
public $tiles, $blockUpdates, $nextSave, $players = [], $level, $mobSpawner;
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
public $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
private $generator;
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
@ -593,7 +593,7 @@ class Level{
*/
public function getBlockWithoutVector($x, $y, $z, $positionfy = true){
$b = $this->level->getBlock($x, $y, $z);
$b = $this->level->getBlock((int)$x, (int)$y, (int)$z);
return BlockAPI::get($b[0], $b[1], $positionfy ? new Position($x, $y, $z, $this) : false);
}

View file

@ -38,8 +38,9 @@ class MobSpawner{
}else{
return false;
}
$x = mt_rand(0,255);
$z = mt_rand(0,255);
$chunk = explode(".", array_rand($this->level->usedChunks, 1));
$x = $chunk[0] * 16;
$z = $chunk[1] * 16;
$y = $this->getSafeY($x, $z, $grassOnly, $type >= 32 && $type <= 36 && $type != 35);
if(!$y || $y < 0){
return false;

View file

@ -27,10 +27,10 @@ class NormalGenerator implements NewLevelGenerator{
$this->level = $level;
$this->random = $random;
$this->random->setSeed($this->level->getSeed());
$this->noiseHills = new NoiseGeneratorSimplex($this->random, 3);
$this->noisePatches = new NoiseGeneratorSimplex($this->random, 2);
$this->noisePatchesSmall = new NoiseGeneratorSimplex($this->random, 2);
$this->noiseBase = new NoiseGeneratorSimplex($this->random, 16);
$this->noiseHills = new NoiseGeneratorPerlin($this->random, 3);
$this->noisePatches = new NoiseGeneratorPerlin($this->random, 2);
$this->noisePatchesSmall = new NoiseGeneratorPerlin($this->random, 2);
$this->noiseBase = new NoiseGeneratorPerlin($this->random, 16);
$ores = new OrePopulator();
$ores->setOreTypes(array(
@ -72,7 +72,6 @@ class NormalGenerator implements NewLevelGenerator{
$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);
if($base[$i] < 0){
$base[$i] *= 0.5;
}