mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
animals should spawn only on grass, all entities should spawn on any height
This commit is contained in:
parent
001fab922f
commit
8a5611c25c
1 changed files with 11 additions and 5 deletions
|
|
@ -30,15 +30,17 @@ class MobSpawner{
|
|||
if(self::$spawnAnimals && $this->level->isDay()){ //Animal
|
||||
$type = mt_rand(10, 13);
|
||||
$baby = false; //TODO baby
|
||||
$grassOnly = true;
|
||||
}elseif(self::$spawnMobs && $this->level->isNight()){ //Monster
|
||||
$type = mt_rand(32, 35);
|
||||
$grassOnly = false;
|
||||
$baby = 2;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
$x = mt_rand(0,255);
|
||||
$z = mt_rand(0,255);
|
||||
$y = $this->getSafeY($x, $z);
|
||||
$y = $this->getSafeY($x, $z, $grassOnly);
|
||||
if(!$y || $y < 0){
|
||||
return false;
|
||||
}
|
||||
|
|
@ -62,13 +64,17 @@ class MobSpawner{
|
|||
];
|
||||
}
|
||||
|
||||
protected function getSafeY($x, $z){ //first safe block
|
||||
protected function getSafeY($x, $z, $grassOnly = false){ //first safe block
|
||||
$allowed = [];
|
||||
for($y = 0; $y < 128; ++$y){
|
||||
if($this->level->level->getBlock($x, $y, $z)[0] === AIR){
|
||||
return $y; //TODO checking aabb
|
||||
$b = $this->level->getBlockWithoutVector($x, $y, $z);
|
||||
$b1 = $this->level->getBlockWithoutVector($x, $y - 1, $z);
|
||||
if(!$b->isSolid && ($b1->isSolid && ($grassOnly ? $b1->getID() === GRASS : true))){
|
||||
$allowed[] = $y;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return empty($allowed) ? -1 : $allowed[mt_rand(0, count($allowed) - 1)];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue