mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
level properties, moved some settings from server.properties, cmd placeholders
This commit is contained in:
parent
581a6a8fb2
commit
cf4dc73a6c
10 changed files with 165 additions and 30 deletions
|
|
@ -6,6 +6,10 @@ class Level{
|
|||
* @var Config
|
||||
*/
|
||||
public $entities;
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
public $levelProperties;
|
||||
/**
|
||||
* This is an array of entities in this world.
|
||||
* @var Entity[]
|
||||
|
|
@ -27,7 +31,7 @@ class Level{
|
|||
public $queuedBlockUpdates = [];
|
||||
|
||||
public $forceDisableBlockQueue = false;
|
||||
|
||||
|
||||
public static $randomUpdateBlocks = [
|
||||
FIRE => true,
|
||||
FARMLAND => true,
|
||||
|
|
@ -73,6 +77,35 @@ class Level{
|
|||
$this->randInt2 = 0x3C6EF35F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets level property.
|
||||
*
|
||||
* @param string $name - property name
|
||||
* @param mixed $fail=false - return value if the property doesn't exist
|
||||
* @return string|mixed
|
||||
*/
|
||||
public function getProperty(string $name, $fail = false){
|
||||
return $this->levelProperties->exists($name) ? $this->levelProperties->get($name) : $this->server->api->level->getDefaultProperty($name, $fail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets level property
|
||||
*
|
||||
* @param string $name - property name
|
||||
* @param mixed $value - new property value
|
||||
*
|
||||
* @return boolean true if sucess, false if failed
|
||||
*/
|
||||
public function setProperty(string $name, $value){
|
||||
$c = $this->server->api->dhandle("level.property.change", ["level" => $this, "name" => $name, "value" => $value]);
|
||||
if($c === false) return false;
|
||||
|
||||
$this->levelProperties->set($name, $value);
|
||||
$this->levelProperties->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function close(){
|
||||
if(isset($this->level)){
|
||||
$this->save(true, true, true, true);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
<?php
|
||||
|
||||
class MobSpawner{
|
||||
public static $spawnAnimals = false, $spawnMobs = false, $maxMobsNearPlayerAtOnce = 10;
|
||||
public static $maxMobsNearPlayerAtOnce = 10;
|
||||
private $server;
|
||||
public $level;
|
||||
public $totalMobsPerPlayer;
|
||||
public $playerAffectedEIDS = [];
|
||||
public $entityAffectedPlayers = [];
|
||||
public static $MOB_LIMIT = 50;
|
||||
|
||||
public function __construct(Level $level){
|
||||
$this->server = ServerAPI::request();
|
||||
|
|
@ -42,11 +41,13 @@ class MobSpawner{
|
|||
}
|
||||
|
||||
public function handle(){
|
||||
if($this->countEntities() > self::$MOB_LIMIT || count($this->level->players) <= 0){
|
||||
$limit = $this->level->getProperty("mobs-amount");
|
||||
|
||||
if($this->countEntities() > $limit || count($this->level->players) <= 0){
|
||||
return false; //not spawning
|
||||
}
|
||||
$svd = $this->totalMobsPerPlayer;
|
||||
$this->totalMobsPerPlayer = min(ceil(self::$MOB_LIMIT / count($this->level->players)), self::$maxMobsNearPlayerAtOnce);
|
||||
$this->totalMobsPerPlayer = min(ceil($limit / count($this->level->players)), self::$maxMobsNearPlayerAtOnce);
|
||||
if($svd != $this->totalMobsPerPlayer) ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}.");
|
||||
|
||||
return $this->spawnMobs();
|
||||
|
|
@ -54,11 +55,11 @@ class MobSpawner{
|
|||
|
||||
public function spawnMobs(){
|
||||
$phase = $this->server->api->time->getPhase($this->level);
|
||||
if(self::$spawnAnimals && ($phase == "day" || $phase == "sunrise")){ //Animal
|
||||
if($this->level->getProperty("spawn-animals") && ($phase == "day" || $phase == "sunrise")){ //Animal
|
||||
$type = mt_rand(10, 13);
|
||||
$baby = false;
|
||||
$grassOnly = true;
|
||||
}elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset") && $this->server->difficulty > 0){ //Monster, true night
|
||||
}elseif($this->level->getProperty("spawn-monsters") && ($phase == "night" || $phase == "sunset") && $this->server->difficulty > 0){ //Monster, true night
|
||||
$type = mt_rand(32, 35);
|
||||
$grassOnly = false;
|
||||
$baby = 2;
|
||||
|
|
@ -145,5 +146,15 @@ class MobSpawner{
|
|||
|
||||
return empty($allowed) ? -1 : $allowed[mt_rand(0, count($allowed) - 1)];
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* use $level->getProperty("mobs-amount")
|
||||
*/
|
||||
public static $MOB_LIMIT = 50;
|
||||
/**
|
||||
* @deprecated
|
||||
* use $level->getProperty("spawn-animals") and $level->getProperty("spawn-monsters")
|
||||
*/
|
||||
public static $spawnAnimals = true, $spawnMobs = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue