extra.properties cleanup, fixed fire/water/lava collisions

This commit is contained in:
GameHerobrine 2023-09-03 08:47:39 +03:00
parent 86e32a1620
commit 8f720231fa
9 changed files with 20 additions and 31 deletions

View file

@ -137,10 +137,12 @@ class ServerAPI{
"enable-rcon" => false, "enable-rcon" => false,
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10), "rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
"auto-save" => true, "auto-save" => true,
"enable-mob-ai" => true,
]); ]);
$this->parseProperties(); $this->parseProperties();
MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50); MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50);
Entity::$allowedAI = $this->getProperty("enable-mob-ai", true);
//Load advanced properties //Load advanced properties
define("DEBUG", $this->getProperty("debug", 1)); define("DEBUG", $this->getProperty("debug", 1));
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));

View file

@ -1482,7 +1482,7 @@ class Player{
$this->server->api->entity->spawnAll($this); $this->server->api->entity->spawnAll($this);
$this->server->api->entity->spawnToAll($this->entity); $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->server->schedule(2, [$this->entity, "updateMovement"], [], true);
$this->sendArmor(); $this->sendArmor();
$array = explode("@n", (string)$this->server->motd); $array = explode("@n", (string)$this->server->motd);

View file

@ -77,11 +77,8 @@ class PocketMinecraftServer{
console("[INFO] Loading extra.properties..."); console("[INFO] Loading extra.properties...");
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [ $this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [
"version" => "5", "version" => "5",
"experemental-mob-features" => true,
"enable-mob-ai" => false,
"enable-nether-reactor" => true, "enable-nether-reactor" => true,
"enable-explosions" => true, "enable-explosions" => true,
"enable-rail-connection" => true,
"save-player-data" => true, "save-player-data" => true,
"save-console-data" => true, "save-console-data" => true,
"query-plugins" => false, "query-plugins" => false,
@ -91,20 +88,15 @@ class PocketMinecraftServer{
"discord-bot-name" => "NostalgiaCore Logger", "discord-bot-name" => "NostalgiaCore Logger",
"despawn-mobs" => true, "despawn-mobs" => true,
"mob-despawn-ticks" => 18000, "mob-despawn-ticks" => 18000,
"16x16x16_chunk_sending" => false "16x16x16_chunk_sending" => false,
"experimental-mob-ai" => false,
]); ]);
Player::$smallChunks = $this->extraprops->get("16x16x16_chunk_sending"); Player::$smallChunks = $this->extraprops->get("16x16x16_chunk_sending");
Living::$despawnMobs = $this->extraprops->get("despawn-mobs"); Living::$despawnMobs = $this->extraprops->get("despawn-mobs");
Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks"); 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"); PocketMinecraftServer::$SAVE_PLAYER_DATA = $this->extraprops->get("save-player-data");
if(Entity::$updateOnTick){ MobController::$ADVANCED = $this->extraprops->get("experimental-mob-ai");
console("[WARNING] Experemental mob features are enabled. Unpredictable behavior.");
}
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); 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"); NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor");
if($this->extraprops->get("discord-msg") == true){ if($this->extraprops->get("discord-msg") == true){
if($this->extraprops->get("discord-webhook-url") !== "none"){ if($this->extraprops->get("discord-webhook-url") !== "none"){
@ -223,7 +215,6 @@ class PocketMinecraftServer{
$t->stop = true; $t->stop = true;
$t->notify(); $t->notify();
}, $this->asyncThread); }, $this->asyncThread);
//@$this->asyncThread->stop = true;
} }
} }
} }

View file

@ -333,7 +333,7 @@ class Entity extends Position
public function environmentUpdate() 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); $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){ 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 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) { switch ($id) {
case WATER: case WATER:
case STILL_WATER: // Drowing 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->fire = 0;
$this->updateMetadata(); $this->updateMetadata();
} }
@ -446,7 +446,7 @@ class Entity extends Position
break; break;
case LAVA: // Lava damage case LAVA: // Lava damage
case STILL_LAVA: 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->harm(5, "lava");
$this->fire = 300; $this->fire = 300;
$this->updateMetadata(); $this->updateMetadata();
@ -454,7 +454,7 @@ class Entity extends Position
} }
break; break;
case FIRE: // Fire block damage 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->harm(1, "fire");
$this->fire = 300; $this->fire = 300;
$this->updateMetadata(); $this->updateMetadata();
@ -468,7 +468,7 @@ class Entity extends Position
} }
break; break;
default: 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)){ }elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){
$this->air = 200; $this->air = 200;

View file

@ -12,10 +12,8 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here
if($down->getID() !== AIR and $down instanceof SolidBlock){ if($down->getID() !== AIR and $down instanceof SolidBlock){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
if(RailBlock::$shouldconnectrails){ $logic = new RailLogic($this);
$logic = new RailLogic($this); $logic->place(false, true);
$logic->place(false, true);
}
return true; return true;
} }
return false; return false;

View file

@ -8,8 +8,6 @@ class RailBlock extends RailBaseBlock{
$this->isSolid = false; $this->isSolid = false;
} }
public static $shouldconnectrails = true;
public function updateState(){ public function updateState(){
//$logic = (new RailLogic($this)); //$logic = (new RailLogic($this));
//if($logic->countPotentialConnections() == 3){ //if($logic->countPotentialConnections() == 3){

View file

@ -753,7 +753,7 @@ class Utils{
public static function readLong($x, $signed = true){ public static function readLong($x, $signed = true){
$value = "0"; $value = "0";
if($signed === true){ if($signed === true){
$negative = ((ord($x[0]) & 0x80) === 0x80) ? true : false; $negative = ((ord($x[0]) & 0x80) === 0x80);
if($negative){ if($negative){
$x = ~$x; $x = ~$x;
} }
@ -763,9 +763,9 @@ class Utils{
for($i = 0; $i < 8; $i += 4){ for($i = 0; $i < 8; $i += 4){
$value = bcmul($value, "4294967296", 0); //4294967296 == 2^32 $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){ public static function writeLLong($value){

View file

@ -356,11 +356,11 @@ class Level{
if($e->class === ENTITY_MOB && !$e->isPlayer()){ if($e->class === ENTITY_MOB && !$e->isPlayer()){
++$this->totalMobsAmount; ++$this->totalMobsAmount;
} }
if($e->needsUpdate){ if($e->isPlayer() || $e->needsUpdate){
$e->update(); $e->update();
} }
} }
if(Entity::$updateOnTick && $server->ticks % 40 === 0){ //40 ticks delay if($server->ticks % 40 === 0){ //40 ticks delay
$this->mobSpawner->handle(); $this->mobSpawner->handle();
} }
} }

View file

@ -23,11 +23,11 @@ class MobSpawner{
public function spawnMobs(){ public function spawnMobs(){
$phase = $this->server->api->time->getPhase($this->level); $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); $type = mt_rand(10, 13);
$baby = false; //TODO baby $baby = false; //TODO baby
$grassOnly = true; $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); $type = mt_rand(32, 35);
$grassOnly = false; $grassOnly = false;
$baby = 2; $baby = 2;