Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Commit

Permalink
Small AutoSpawn Updates
Browse files Browse the repository at this point in the history
This update adds Parrots to the AutoSpawn Task and makes some slight adjustments to how the location for animal spawns are selected.
  • Loading branch information
95CivicSi committed Oct 16, 2017
1 parent 7d32778 commit b64cb8e
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions PureEntitiesX/src/revivalpmmp/pureentities/task/AutoSpawnTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use revivalpmmp\pureentities\PluginConfiguration;
use revivalpmmp\pureentities\task\spawners\animal\ChickenSpawner;
use revivalpmmp\pureentities\task\spawners\animal\CowSpawner;
use revivalpmmp\pureentities\task\spawners\animal\ParrotSpawner;
use revivalpmmp\pureentities\task\spawners\monster\BlazeSpawner;
use revivalpmmp\pureentities\task\spawners\monster\CaveSpiderSpawner;
use revivalpmmp\pureentities\task\spawners\monster\CreeperSpawner;
Expand Down Expand Up @@ -70,18 +71,25 @@ public function onRun(int $currentTick) {
if (count($level->getPlayers()) > 0) {
foreach ($level->getPlayers() as $player) {
foreach ($this->spawnerClasses as $spawnerClass) {

$x = $player->x + mt_rand(-20, 20);
$z = $player->z + mt_rand(-20, 20);
$y = $player->y;

// search up- and downwards the current player's y-coordinate to find a valid block!
$correctedPosition = PureEntities::getSuitableHeightPosition($x, $y, $z, $level);
if ($correctedPosition !== null) {
$pos = new Position($correctedPosition->x, $correctedPosition->y - 1, $correctedPosition->z, $level);
$spawnerClass->spawn($pos, $player);
} else {
PureEntities::logOutput("AutoSpawnTask: cannot find a suitable spawn coordinate [search.x:$x] [search.y:$y] [search.z:$z]", PureEntities::WARN);
$locationValid = false;
$pass = 1;
while (!$locationValid) {

// Random method used to get 8 block difference from player to entity spawn)
$x = $player->x + (random_int(8, 20) * (random_int(0, 1) === 0 ? 1 : -1));
$z = $player->z + (random_int(8, 20) * (random_int(0, 1) === 0 ? 1 : -1));
$y = $player->y;

// search up- and downwards the current player's y-coordinate to find a valid block!
$correctedPosition = PureEntities::getSuitableHeightPosition($x, $y, $z, $level);
if ($correctedPosition !== null) {
$pos = new Position($correctedPosition->x, $correctedPosition->y - 1, $correctedPosition->z, $level);
$spawnerClass->spawn($pos, $player);
$locationValid = true;
} else {
PureEntities::logOutput("AutoSpawnTask: suitable spawn coordinate not found [search.x:$x] [search.y:$y] [search.z:$z] [pass:$pass]", PureEntities::WARN);
$pass++;
}
}
}
}
Expand All @@ -95,6 +103,7 @@ private function prepareSpawnerClasses() {
$this->spawnerClasses[] = new CowSpawner();
$this->spawnerClasses[] = new HorseSpawner();
$this->spawnerClasses[] = new OcelotSpawner();
// $this->spawnerClasses[] = new ParrotSpawner();
$this->spawnerClasses[] = new PigSpawner();
$this->spawnerClasses[] = new RabbitSpawner();
$this->spawnerClasses[] = new SheepSpawner();
Expand Down

0 comments on commit b64cb8e

Please sign in to comment.