From cd2cb379804ac1df926907a10c4d1c2a707fedd3 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 28 Feb 2025 18:41:16 -0500 Subject: [PATCH] Fix Eggs Spawning Abnormally Healthy Chickens --- docs/CHANGELOG.md | 3 ++- .../util/env/flags/available-feature-flags | 1 + mods/include/mods/misc/misc.h | 2 ++ mods/src/misc/misc.cpp | 24 ++++++++++++++++--- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0c442860..1e24ce55 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -64,7 +64,8 @@ * `Implement RaspberryJuice API` (Enabled By Default) * `Fix HUD When Spectating Other Players` (Enabled By Default) * `Fix Crash When Spectated Entity Is Removed` (Enabled By Default) - * `Fix Torch Placement` (Enabled) + * `Fix Torch Placement` (Enabled By Default) + * `Fix Eggs Spawning Abnormally Healthy Chickens` (Enabled By Default) * Existing Functionality (All Enabled By Default) * `Fix Screen Rendering When Hiding HUD` * `Sanitize Usernames` diff --git a/libreborn/src/util/env/flags/available-feature-flags b/libreborn/src/util/env/flags/available-feature-flags index 284dbdd9..925990e6 100644 --- a/libreborn/src/util/env/flags/available-feature-flags +++ b/libreborn/src/util/env/flags/available-feature-flags @@ -132,6 +132,7 @@ CATEGORY Bug Fixes TRUE Fix Sunlight Not Properly Setting Mobs On Fire TRUE Fix Transferring Durability When Using Items TRUE Fix Torch Placement + TRUE Fix Eggs Spawning Abnormally Healthy Chickens CATEGORY Crashes TRUE Fix Crash When Generating Certain Seeds TRUE Close Editor When Sign Is Destroyed diff --git a/mods/include/mods/misc/misc.h b/mods/include/mods/misc/misc.h index 5d6a2e3a..d9b0bcd0 100644 --- a/mods/include/mods/misc/misc.h +++ b/mods/include/mods/misc/misc.h @@ -15,6 +15,8 @@ typedef RakNet_RakString *(*RakNet_RakString_constructor_2_t)(RakNet_RakString * extern RakNet_RakString_constructor_2_t RakNet_RakString_constructor_2; } +void misc_set_on_fire(Mob *mob, int seconds); + void misc_run_on_init(const std::function &func); void misc_run_on_update(const std::function &func); void misc_run_on_tick(const std::function &func); diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index a30da434..cb534214 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -398,7 +398,7 @@ static void ServerSideNetworkHandler_handle_PlayerActionPacket_injection(ServerS } // Make Mobs Actually Catch On Fire -static void set_on_fire(Mob *mob, const int seconds) { +void misc_set_on_fire(Mob *mob, const int seconds) { const int value = seconds * 20; if (value > mob->fire_timer) { mob->fire_timer = value; @@ -413,7 +413,7 @@ static void Monster_aiStep_injection(__attribute__((unused)) const std::function if (brightness > 0.5f) { Random *random = &self->random; if (level->canSeeSky(Mth::floor(self->x), Mth::floor(self->y), Mth::floor(self->z)) && random->nextFloat() * 3.5f < (brightness - 0.4f)) { - set_on_fire((Mob *) self, 8); + misc_set_on_fire((Mob *) self, 8); } } } @@ -499,13 +499,26 @@ static int Level_getTopTile_injection(Level_getTopTile_t original, Level *self, // Fix Torch Placement static bool TileItem_useOn_Level_setTileAndData_injection(Level *self, const int x, const int y, const int z, const int tile, const int data) { + // Call Original Method const bool ret = self->setTileAndData(x, y, z, tile, data); - if (tile == Tile::torch->id) { + // Force Correct Data + if (ret && tile == Tile::torch->id) { self->setData(x, y, z, data); } + // Return return ret; } +// Fix Egg Behavior +static void ThrownEgg_onHit_Chicken_moveTo_injection(Chicken *self, const float x, const float y, const float z, const float yaw, const float pitch) { + // Call Original Method + self->moveTo(x, y, z, yaw, pitch); + // Fix Health + self->health = self->getMaxHealth(); + // Fix Age + self->setAge(-24000); +} + // Init void init_misc() { // Sanitize Username @@ -687,6 +700,11 @@ void init_misc() { overwrite_call((void *) 0xcb784, Level_setTileAndData, TileItem_useOn_Level_setTileAndData_injection); } + // Fix Egg Behavior + if (feature_has("Fix Eggs Spawning Abnormally Healthy Chickens", server_enabled)) { + overwrite_call((void *) 0x7de0c, Chicken_moveTo, ThrownEgg_onHit_Chicken_moveTo_injection); + } + // Disable overwrite_calls() After Minecraft::init misc_run_on_init([](__attribute__((unused)) Minecraft *minecraft) { thunk_enabler = [](__attribute__((unused)) void *a, __attribute__((unused)) void *b) -> void * {