From 869b8b111a43f2436919d13ebce3b3a87065fb4c Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 15 Feb 2024 02:55:02 +0300 Subject: [PATCH] force load all chunks on load, check is entity correct or not --- src/API/LevelAPI.php | 7 +++++++ src/constants/EntityIDs.php | 32 +++++++++++++++++++++++++++++- src/world/Level.php | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 8fcb2ff6..dac35c6c 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -40,6 +40,12 @@ class LevelAPI{ console("[ERROR] Could not load level \"" . $name . "\""); return false; } + for($X = 0; $X < 16; ++$X){ + for($Z = 0; $Z < 16; ++$Z){ + $level->loadChunk($X, $Z); + } + } + $entities = new Config($path . "entities.yml", CONFIG_YAML); if(file_exists($path . "tileEntities.yml")){ @rename($path . "tileEntities.yml", $path . "tiles.yml"); @@ -94,6 +100,7 @@ class LevelAPI{ foreach($blockUpdates->getAll() as $bupdate){ if($bupdate["type"] !== BLOCK_UPDATE_RANDOM) $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"], (int) $bupdate["y"], (int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]); } + return true; } /** diff --git a/src/constants/EntityIDs.php b/src/constants/EntityIDs.php index 8fe38eb2..dacf8e95 100644 --- a/src/constants/EntityIDs.php +++ b/src/constants/EntityIDs.php @@ -34,4 +34,34 @@ define("TILE_SIGN", "Sign"); define("TILE_CHEST", "Chest"); define("CHEST_SLOTS", 27); define("TILE_FURNACE", "Furnace"); - define("FURNACE_SLOTS", 3); \ No newline at end of file + define("FURNACE_SLOTS", 3); + +const CORRECT_ENTITY_CLASSES = [ + ENTITY_PLAYER => true, + ENTITY_MOB => [ + MOB_CHICKEN => true, + MOB_COW => true, + MOB_PIG => true, + MOB_SHEEP => true, + + MOB_ZOMBIE => true, + MOB_SKELETON => true, + MOB_SPIDER => true, + MOB_CREEPER => true, + MOB_PIGMAN => true + ], + ENTITY_OBJECT => [ + OBJECT_TRIPOD_CAMERA => true, + OBJECT_PRIMEDTNT => true, + OBJECT_ARROW => true, + OBJECT_SNOWBALL => true, + OBJECT_EGG => true, + OBJECT_PAINTING => true, + OBJECT_MINECART => true, + ], + ENTITY_ITEM => true, + ENTITY_FALLING => [ + FALLING_SAND => true + ] + +]; diff --git a/src/world/Level.php b/src/world/Level.php index 3e7ec3cf..5e2e2859 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -401,8 +401,47 @@ class Level{ } $this->totalMobsAmount = 0; $post = []; + //console("ELP {$this->getName()}"); + //var_dump($this->entityListPositioned); foreach($this->entityList as $k => $e){ + if(!isset(CORRECT_ENTITY_CLASSES[$e->class])){ + ConsoleAPI::warn("Entity $k has invalid class type! {$e->class}"); + $e->close(); + unset($this->entityList[$k]); + unset($this->server->entities[$k]); + + $curChunkX = (int)$e->x >> 4; + $curChunkZ = (int)$e->z >> 4; + $index = "$curChunkX $curChunkZ"; + + if(isset($this->entityListPositioned[$index]) && isset($this->entityListPositioned[$index][$k])){ + unset($this->entityListPositioned[$index][$k]); + } + + continue; + } + $dd = CORRECT_ENTITY_CLASSES[$e->class]; + if($dd !== true && !isset($dd[$e->type])){ + ConsoleAPI::warn("Entity $k has invalid entity type! {$e->class} {$e->type}"); + $e->close(); + + unset($this->entityList[$k]); + unset($this->server->entities[$k]); + + $curChunkX = (int)$e->x >> 4; + $curChunkZ = (int)$e->z >> 4; + $index = "$curChunkX $curChunkZ"; + + if(isset($this->entityListPositioned[$index]) && isset($this->entityListPositioned[$index][$k])){ + unset($this->entityListPositioned[$index][$k]); + } + + continue; + } + + + if(!($e instanceof Entity)){ unset($this->entityList[$k]); unset($this->server->entities[$k]);