Fix Hanging When No Valid Spawn Point Exists

This commit is contained in:
TheBrokenRail 2024-12-18 02:44:51 -05:00
parent 71946d2087
commit b71c089fb3
4 changed files with 36 additions and 0 deletions

View File

@ -57,6 +57,7 @@
* `Text Rendering Fixes` (Enabled By Default) * `Text Rendering Fixes` (Enabled By Default)
* `Close Editor When Sign Is Destroyed` (Enabled By Default) * `Close Editor When Sign Is Destroyed` (Enabled By Default)
* `Remove Chest Placement Restrictions` (Enabled By Default) * `Remove Chest Placement Restrictions` (Enabled By Default)
* `Fix Hanging When No Valid Spawn Point Exists` (Enabled By Default)
* Existing Functionality (All Enabled By Default) * Existing Functionality (All Enabled By Default)
* `Fix Screen Rendering When Hiding HUD` * `Fix Screen Rendering When Hiding HUD`
* `Sanitize Usernames` * `Sanitize Usernames`

View File

@ -135,6 +135,7 @@ CATEGORY Bug Fixes
TRUE Close Current Screen On Death TRUE Close Current Screen On Death
TRUE Fix Reloading Textures On Resize TRUE Fix Reloading Textures On Resize
TRUE Fix options.txt Loading/Saving TRUE Fix options.txt Loading/Saving
TRUE Fix Hanging When No Valid Spawn Point Exists
CATEGORY Logging CATEGORY Logging
FALSE Log FPS FALSE Log FPS
TRUE Log Chat Messages TRUE Log Chat Messages

View File

@ -468,6 +468,31 @@ static SignTileEntity *SignTileEntity_destructor_injection(SignTileEntity_destru
return original(self); return original(self);
} }
// Fix Spawn Point Hanging
static constexpr int allowed_spawn_point_tries = 10000;
static constexpr int not_finding_spawn_point = -1;
static int spawn_point_tries = not_finding_spawn_point;
static void Level_setInitialSpawn_or_validateSpawn_injection(Level_setInitialSpawn_t original, Level *self) {
spawn_point_tries = allowed_spawn_point_tries;
original(self);
spawn_point_tries = not_finding_spawn_point;
}
static int Level_getTopTile_injection(Level_getTopTile_t original, Level *self, int x, int z) {
bool actually_check = true;
if (spawn_point_tries == 0) {
// Give Up Searching
actually_check = false;
} else if (spawn_point_tries > 0) {
// Count Down
spawn_point_tries--;
}
if (actually_check) {
return original(self, x, z);
} else {
return Tile::bedrock->id;
}
}
// Init // Init
void init_misc() { void init_misc() {
// Sanitize Username // Sanitize Username
@ -636,6 +661,13 @@ void init_misc() {
overwrite_calls(SignTileEntity_destructor_complete, SignTileEntity_destructor_injection); overwrite_calls(SignTileEntity_destructor_complete, SignTileEntity_destructor_injection);
} }
// Fix Hanging When Spawning
if (feature_has("Fix Hanging When No Valid Spawn Point Exists", server_enabled)) {
overwrite_calls(Level_setInitialSpawn, Level_setInitialSpawn_or_validateSpawn_injection);
overwrite_calls(Level_validateSpawn, Level_setInitialSpawn_or_validateSpawn_injection);
overwrite_calls(Level_getTopTile, Level_getTopTile_injection);
}
// Disable overwrite_calls() After Minecraft::init // Disable overwrite_calls() After Minecraft::init
misc_run_on_init([](__attribute__((unused)) Minecraft *minecraft) { misc_run_on_init([](__attribute__((unused)) Minecraft *minecraft) {
thunk_enabler = [](__attribute__((unused)) void *a, __attribute__((unused)) void *b) -> void * { thunk_enabler = [](__attribute__((unused)) void *a, __attribute__((unused)) void *b) -> void * {

View File

@ -51,6 +51,8 @@ method bool canSeeSky(int x, int y, int z) = 0xa39b8;
method bool isDay() = 0xa3d9c; method bool isDay() = 0xa3d9c;
method int getTopTile(int x, int z) = 0xa2cc8; method int getTopTile(int x, int z) = 0xa2cc8;
method BiomeSource *getBiomeSource() = 0xa3c64; method BiomeSource *getBiomeSource() = 0xa3c64;
method void setInitialSpawn() = 0xa2bf4;
method void validateSpawn() = 0xa2d2c;
virtual-method void tick() = 0x28; virtual-method void tick() = 0x28;
virtual-method void updateSleepingPlayerList() = 0x2c; virtual-method void updateSleepingPlayerList() = 0x2c;