From 8f720231fa2b03cbc1f9eebe67cb6102dded985b Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sun, 3 Sep 2023 08:47:39 +0300 Subject: [PATCH] extra.properties cleanup, fixed fire/water/lava collisions --- src/API/ServerAPI.php | 2 ++ src/Player.php | 2 +- src/PocketMinecraftServer.php | 15 +++------------ src/entity/Entity.php | 10 +++++----- src/material/block/nonfull/RailBaseBlock.php | 6 ++---- src/material/block/nonfull/RailBlock.php | 2 -- src/utils/Utils.php | 6 +++--- src/world/Level.php | 4 ++-- src/world/MobSpawner.php | 4 ++-- 9 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 654a3d1c..8f660d0a 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -137,10 +137,12 @@ class ServerAPI{ "enable-rcon" => false, "rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10), "auto-save" => true, + "enable-mob-ai" => true, ]); $this->parseProperties(); MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50); + Entity::$allowedAI = $this->getProperty("enable-mob-ai", true); //Load advanced properties define("DEBUG", $this->getProperty("debug", 1)); define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); diff --git a/src/Player.php b/src/Player.php index 4798b9f4..152bd7ed 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1482,7 +1482,7 @@ class Player{ $this->server->api->entity->spawnAll($this); $this->server->api->entity->spawnToAll($this->entity); - $this->server->schedule(5, [$this->entity, "update"], [], true); + //$this->server->schedule(5, [$this->entity, "update"], [], true); $this->server->schedule(2, [$this->entity, "updateMovement"], [], true); $this->sendArmor(); $array = explode("@n", (string)$this->server->motd); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index b2751195..03ca736e 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -77,11 +77,8 @@ class PocketMinecraftServer{ console("[INFO] Loading extra.properties..."); $this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [ "version" => "5", - "experemental-mob-features" => true, - "enable-mob-ai" => false, "enable-nether-reactor" => true, "enable-explosions" => true, - "enable-rail-connection" => true, "save-player-data" => true, "save-console-data" => true, "query-plugins" => false, @@ -91,20 +88,15 @@ class PocketMinecraftServer{ "discord-bot-name" => "NostalgiaCore Logger", "despawn-mobs" => true, "mob-despawn-ticks" => 18000, - "16x16x16_chunk_sending" => false - + "16x16x16_chunk_sending" => false, + "experimental-mob-ai" => false, ]); Player::$smallChunks = $this->extraprops->get("16x16x16_chunk_sending"); Living::$despawnMobs = $this->extraprops->get("despawn-mobs"); Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks"); - Entity::$allowedAI = $this->extraprops->get("enable-mob-ai"); - Entity::$updateOnTick = $this->extraprops->get("experemental-mob-features"); PocketMinecraftServer::$SAVE_PLAYER_DATA = $this->extraprops->get("save-player-data"); - if(Entity::$updateOnTick){ - console("[WARNING] Experemental mob features are enabled. Unpredictable behavior."); - } + MobController::$ADVANCED = $this->extraprops->get("experimental-mob-ai"); Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); - RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor"); if($this->extraprops->get("discord-msg") == true){ if($this->extraprops->get("discord-webhook-url") !== "none"){ @@ -223,7 +215,6 @@ class PocketMinecraftServer{ $t->stop = true; $t->notify(); }, $this->asyncThread); - //@$this->asyncThread->stop = true; } } } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 8b73974a..71446a86 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -333,7 +333,7 @@ class Entity extends Position public function environmentUpdate() { - $hasUpdate = Entity::$updateOnTick ? $this->class === ENTITY_MOB : false; // force true for mobs + $hasUpdate = $this->class === ENTITY_MOB; // force true for mobs $time = microtime(true); if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true && ! $this->dead){ foreach($this->server->api->entity->getRadius($this, 2, ENTITY_ITEM) as $item){ //TODO vanilla method of searching/radius @@ -429,7 +429,7 @@ class Entity extends Position switch ($id) { case WATER: case STILL_WATER: // Drowing - if ($this->fire > 0 and $this->inBlockNonVector($x, $y, $z)) { + if ($this->fire > 0 and $this->inBlock(new Vector3($x, $y, $z))) { $this->fire = 0; $this->updateMetadata(); } @@ -446,7 +446,7 @@ class Entity extends Position break; case LAVA: // Lava damage case STILL_LAVA: - if ((!$this->isPlayer() && StaticBlock::getBoundingBoxForBlockCoords($id, $x, $y, $z)->intersectsWith($this->boundingBox)) || ($this->isPlayer() && $this->inBlockNonVector($x, $y, $z))) { + if ($this->inBlock(new Vector3($x, $y, $z))) { $this->harm(5, "lava"); $this->fire = 300; $this->updateMetadata(); @@ -454,7 +454,7 @@ class Entity extends Position } break; case FIRE: // Fire block damage - if ((!$this->isPlayer() && StaticBlock::getBoundingBoxForBlockCoords($id, $x, $y, $z)->intersectsWith($this->boundingBox)) || ($this->isPlayer() && $this->inBlockNonVector($x, $y, $z))) { + if ($this->inBlock(new Vector3($x, $y, $z))) { $this->harm(1, "fire"); $this->fire = 300; $this->updateMetadata(); @@ -468,7 +468,7 @@ class Entity extends Position } break; default: - if($this->inBlockNonVector($x, $y, $z, 0.7) && $y == $endY and !StaticBlock::getIsTransparent($id) && ($this->class === ENTITY_MOB || $this->class === ENTITY_PLAYER)){ + if($this->inBlock(new Vector3($x, $y, $z), 0.7) && $y == $endY and !StaticBlock::getIsTransparent($id) && ($this->class === ENTITY_MOB || $this->class === ENTITY_PLAYER)){ }elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){ $this->air = 200; diff --git a/src/material/block/nonfull/RailBaseBlock.php b/src/material/block/nonfull/RailBaseBlock.php index fda95e51..3c813139 100644 --- a/src/material/block/nonfull/RailBaseBlock.php +++ b/src/material/block/nonfull/RailBaseBlock.php @@ -12,10 +12,8 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here if($down->getID() !== AIR and $down instanceof SolidBlock){ $this->level->setBlock($block, $this, true, false, true); - if(RailBlock::$shouldconnectrails){ - $logic = new RailLogic($this); - $logic->place(false, true); - } + $logic = new RailLogic($this); + $logic->place(false, true); return true; } return false; diff --git a/src/material/block/nonfull/RailBlock.php b/src/material/block/nonfull/RailBlock.php index 93a7be6a..4fdc41a7 100644 --- a/src/material/block/nonfull/RailBlock.php +++ b/src/material/block/nonfull/RailBlock.php @@ -8,8 +8,6 @@ class RailBlock extends RailBaseBlock{ $this->isSolid = false; } - public static $shouldconnectrails = true; - public function updateState(){ //$logic = (new RailLogic($this)); //if($logic->countPotentialConnections() == 3){ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index d9851a2d..2b7e14e5 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -753,7 +753,7 @@ class Utils{ public static function readLong($x, $signed = true){ $value = "0"; if($signed === true){ - $negative = ((ord($x[0]) & 0x80) === 0x80) ? true : false; + $negative = ((ord($x[0]) & 0x80) === 0x80); if($negative){ $x = ~$x; } @@ -763,9 +763,9 @@ class Utils{ for($i = 0; $i < 8; $i += 4){ $value = bcmul($value, "4294967296", 0); //4294967296 == 2^32 - $value = bcadd($value, 0x1000000 * ord(@$x[$i]) + ((ord(@$x[$i + 1]) << 16) | (ord(@$x[$i + 2]) << 8) | ord(@$x[$i + 3])), 0); + $value = bcadd($value, 0x1000000 * ord($x[$i] ?? 0) + ((ord($x[$i + 1] ?? 0) << 16) | (ord($x[$i + 2] ?? 0) << 8) | ord($x[$i + 3] ?? 0)), 0); } - return ($negative === true ? "-" . $value : $value); + return ($negative ? "-$value" : $value); } public static function writeLLong($value){ diff --git a/src/world/Level.php b/src/world/Level.php index 89242c3e..a5de2b47 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -356,11 +356,11 @@ class Level{ if($e->class === ENTITY_MOB && !$e->isPlayer()){ ++$this->totalMobsAmount; } - if($e->needsUpdate){ + if($e->isPlayer() || $e->needsUpdate){ $e->update(); } } - if(Entity::$updateOnTick && $server->ticks % 40 === 0){ //40 ticks delay + if($server->ticks % 40 === 0){ //40 ticks delay $this->mobSpawner->handle(); } } diff --git a/src/world/MobSpawner.php b/src/world/MobSpawner.php index 2161cd5c..f2ba92e3 100644 --- a/src/world/MobSpawner.php +++ b/src/world/MobSpawner.php @@ -23,11 +23,11 @@ class MobSpawner{ public function spawnMobs(){ $phase = $this->server->api->time->getPhase($this->level); - if(self::$spawnAnimals && $phase == "day"){ //Animal + if(self::$spawnAnimals && ($phase == "day" || $phase == "sunrise")){ //Animal $type = mt_rand(10, 13); $baby = false; //TODO baby $grassOnly = true; - }elseif(self::$spawnMobs && $phase == "night"){ //Monster, true night + }elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset")){ //Monster, true night $type = mt_rand(32, 35); $grassOnly = false; $baby = 2;