zombies/skeletons/creepers should not spawn in blocks if only one block is free, mob limit is changeable in server.properties, small tweaks to entity hitboxes

This commit is contained in:
GameHerobrine 2023-01-17 20:01:15 +03:00
parent 9677196135
commit c2e069ef08
5 changed files with 15 additions and 12 deletions

View file

@ -120,6 +120,7 @@ class ServerAPI{
"allow-flight" => false,
"spawn-animals" => true,
"spawn-mobs" => true,
"mobs-amount" => 50,
"gamemode" => SURVIVAL,
"hardcore" => false,
"pvp" => true,
@ -135,7 +136,7 @@ class ServerAPI{
]);
$this->parseProperties();
MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50);
//Load advanced properties
define("DEBUG", $this->getProperty("debug", 1));
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));

View file

@ -574,9 +574,9 @@ class Entity extends Position
$y1 = $y1 > 128 ? 128 : $y1;
$z1 = $z1 > 256 ? 256 : $z1;
$waterDone = false;
for($x = $x0; $x < $x1; ++$x){
for($x = $x0; $x <= $x1; ++$x){
for($y = $y0; $y < $y1; ++$y){
for($z = $z0; $z < $z1; ++$z){
for($z = $z0; $z <= $z1; ++$z){
$pos = new Vector3($x, $y, $z);
$b = $this->level->getBlock($pos);
switch($b->getID()) {
@ -1531,7 +1531,8 @@ class Entity extends Position
{
throw new Exception("Use getHeightOf or getWidthOf method instead of this.");
}
/**
*
* @deprecated Use {@link getHeight} or {@link getWidth} instead

View file

@ -5,7 +5,7 @@ class Chicken extends Animal{
public $timeUntilEgg;
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
$this->setSize($this->isBaby() ? 0.2 : 0.3, $this->isBaby() ? 0.35 : 0.4);
$this->setSize($this->isBaby() ? 0.2 : 0.4, $this->isBaby() ? 0.35 : 0.7);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
$this->setName('Chicken');

View file

@ -28,7 +28,7 @@ class BucketItem extends Item{
if($block->getID() === AIR || ( $block instanceof WaterBlock && ($block->getMetadata() & 0x07) != 0x00 ) ){
$water = new WaterBlock();
$level->setBlock($block, $water, true, false, true);
$water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz);
$water->place($this, $player, $block, $target, $face, $fx, $fy, $fz);
if(($player->gamemode & 0x01) === 0){
$this->meta = 0;
}

View file

@ -4,7 +4,7 @@ class MobSpawner{
public static $spawnAnimals = false, $spawnMobs = false;
private $server;
public $level;
const MOB_LIMIT = 50; //constant for now
public static $MOB_LIMIT = 50;
public function __construct(Level $level){
$this->server = ServerAPI::request();
$this->level = $level;
@ -19,7 +19,7 @@ class MobSpawner{
}
public function handle(){
if($this->countEntities() > self::MOB_LIMIT || count($this->level->players) <= 0){
if($this->countEntities() > self::$MOB_LIMIT || count($this->level->players) <= 0){
return false; //not spawning
}
return $this->spawnMobs();
@ -40,11 +40,11 @@ class MobSpawner{
}
$x = mt_rand(0,255);
$z = mt_rand(0,255);
$y = $this->getSafeY($x, $z, $grassOnly);
$y = $this->getSafeY($x, $z, $grassOnly, $type >= 32 && $type <= 36 && $type != 35);
if(!$y || $y < 0){
return false;
}
$data = $this->genPosData($x, $y + 1, $z);
$data = $this->genPosData($x, $y + 0.5, $z);
if($baby != 2) $data["IsBaby"] = $baby;
$e = $this->server->api->entity->add($this->level, 2, $type, $data);
@ -64,12 +64,13 @@ class MobSpawner{
];
}
protected function getSafeY($x, $z, $grassOnly = false){ //first safe block
protected function getSafeY($x, $z, $grassOnly = false, $highMob = false){ //first safe block //TODO check boundingbox
$allowed = [];
for($y = 0; $y < 128; ++$y){
$b = $this->level->getBlockWithoutVector($x, $y, $z);
$b2 = $this->level->getBlockWithoutVector($x, $y + 1, $z);
$b1 = $this->level->getBlockWithoutVector($x, $y - 1, $z);
if(!$b->isSolid && ($b1->isSolid && ($grassOnly ? $b1->getID() === GRASS : true))){
if(!$b->isSolid && !$b->isLiquid && ($b1->isSolid && ($grassOnly ? $b1->getID() === GRASS : true) && ($highMob ? !$b2->isSolid && !$b2->isLiquid : true))){
$allowed[] = $y;
}
}