From 72a1a932834679d5328b032103d26445eaaadc4c Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 2 Jul 2024 21:13:11 +0300 Subject: [PATCH] changed how mobs spawn a bit --- src/world/Level.php | 2 +- src/world/MobSpawner.php | 47 +++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/world/Level.php b/src/world/Level.php index 56ffdee2..e5d29992 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -598,7 +598,7 @@ class Level{ $this->checkSleep(); - if($server->ticks % 10 === 0){ + if($server->ticks % 100 === 0){ $this->mobSpawner->handle(); } diff --git a/src/world/MobSpawner.php b/src/world/MobSpawner.php index 768db8e5..45f6125d 100644 --- a/src/world/MobSpawner.php +++ b/src/world/MobSpawner.php @@ -80,26 +80,37 @@ class MobSpawner{ continue; } - $y = $this->getSafeY($x, $z, $grassOnly, $type >= 32 && $type <= 36 && $type != 35); - if(!$y || $y < 0){ - continue; - } - $data = $this->genPosData($x, $y + 0.5, $z); - if($baby != 2) $data["IsBaby"] = $baby; + $cnt = mt_rand(1, 3); - $e = $this->server->api->entity->add($this->level, 2, $type, $data); - - if($e instanceof Entity){ - $this->server->api->entity->spawnToAll($e); - //ConsoleAPI::debug("$type spawned at $x, $y, $z"); + for($i = 0; $i < $cnt; ++$i){ + + $xMob = $x + mt_rand(-3, 3); + $zMob = $z + mt_rand(-3, 3); + + + $y = $this->getSafeY($xMob, $zMob, $grassOnly, $type >= 32 && $type <= 36 && $type != 35); + if(!$y || $y < 0){ + continue; + } + + $data = $this->genPosData($xMob, $y + 0.5, $zMob); + if($baby != 2) $data["IsBaby"] = $baby; + + $e = $this->server->api->entity->add($this->level, 2, $type, $data); + + if($e instanceof Entity){ + $this->server->api->entity->spawnToAll($e); + ConsoleAPI::debug("$type spawned at $xMob, $y, $zMob"); + } + if(!isset($this->playerAffectedEIDS[$player->entity->eid])){ + $this->playerAffectedEIDS[$player->entity->eid] = [$e->eid => true]; + }else{ + $this->playerAffectedEIDS[$player->entity->eid][$e->eid] = true; + } + + $this->entityAffectedPlayers[$e->eid] = $player->entity->eid; + } - if(!isset($this->playerAffectedEIDS[$player->entity->eid])){ - $this->playerAffectedEIDS[$player->entity->eid] = [$e->eid => true]; - }else{ - $this->playerAffectedEIDS[$player->entity->eid][$e->eid] = true; - } - - $this->entityAffectedPlayers[$e->eid] = $player->entity->eid; }