#include #include #include #include #include #include #include #include "misc-internal.h" // Heart Food Overlay static int heal_amount = 0, heal_amount_drawing = 0; static void Gui_renderHearts_injection(Gui_renderHearts_t original, Gui *gui) { // Get heal_amount heal_amount = heal_amount_drawing = 0; Inventory *inventory = gui->minecraft->player->inventory; const ItemInstance *held_ii = inventory->getSelected(); if (held_ii) { Item *held = Item::items[held_ii->id]; if (held->isFood() && held_ii->id) { const int nutrition = ((FoodItem *) held)->nutrition; const int cur_health = gui->minecraft->player->health; const int heal_num = std::min(cur_health + nutrition, 20) - cur_health; heal_amount = heal_amount_drawing = heal_num; } } // Call original original(gui); } #define PINK_HEART_FULL 70 #define PINK_HEART_HALF 79 static void Gui_renderHearts_GuiComponent_blit_overlay_empty_injection(Gui *gui, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t w1, int32_t h1, int32_t w2, int32_t h2) { // Call Original Method get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, x2, y2, w1, h1, w2, h2); // Render The Overlay if (heal_amount_drawing == 1) { // Half Heart get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, PINK_HEART_HALF, 0, w1, h1, w2, h2); heal_amount_drawing = 0; } else if (heal_amount_drawing > 0) { // Full Heart get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, PINK_HEART_FULL, 0, w1, h1, w2, h2); heal_amount_drawing -= 2; } } static void Gui_renderHearts_GuiComponent_blit_overlay_hearts_injection(Gui *gui, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t w1, int32_t h1, int32_t w2, int32_t h2) { // Offset the overlay if (x2 == 52) { heal_amount_drawing += 2; } else if (x2 == 61 && heal_amount) { // Half heart, flipped get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, PINK_HEART_FULL, 0, w1, h1, w2, h2); heal_amount_drawing += 1; } // Call Original Method get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, x2, y2, w1, h1, w2, h2); heal_amount_drawing = std::min(heal_amount_drawing, heal_amount); } // Additional GUI Rendering static bool hide_chat_messages = false; bool is_in_chat = false; static bool render_selected_item_text = false; static void Gui_renderChatMessages_injection(Gui_renderChatMessages_t original, Gui *gui, int32_t y_offset, const uint32_t max_messages, const bool disable_fading, Font *font) { // Handle Classic HUD y_offset -= get_classic_hud_y_offset(gui->minecraft); // Call Original Method if (!hide_chat_messages && (!is_in_chat || disable_fading)) { original(gui, y_offset, max_messages, disable_fading, font); } // Render Selected Item Text if (render_selected_item_text && !disable_fading) { // Fix GL Mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Calculate Selected Item Text Scale const Minecraft *minecraft = gui->minecraft; const int32_t screen_width = minecraft->screen_width; const float scale = float(screen_width) * Gui::InvGuiScale; // Render Selected Item Text gui->renderOnSelectItemNameText((int32_t) scale, font, y_offset - 0x13); } } // Reset Selected Item Text Timer On Slot Select static bool reset_selected_item_text_timer = false; static void Gui_tick_injection(Gui_tick_t original, Gui *gui) { // Call Original Method original(gui); // Handle Reset if (render_selected_item_text && reset_selected_item_text_timer) { // Reset gui->selected_item_text_timer = 0; reset_selected_item_text_timer = false; } } // Trigger Reset Selected Item Text Timer On Slot Select static void Inventory_selectSlot_injection(Inventory_selectSlot_t original, Inventory *inventory, int32_t slot) { // Call Original Method original(inventory, slot); // Trigger Reset Selected Item Text Timer if (render_selected_item_text) { reset_selected_item_text_timer = true; } } // Translucent Toolbar static void Gui_renderToolBar_injection(Gui_renderToolBar_t original, Gui *gui, const float param_1, const int32_t param_2, const int32_t param_3) { // Call Original Method glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); original(gui, param_1, param_2, param_3); glDisable(GL_BLEND); } static void Gui_renderToolBar_glColor4f_injection(const GLfloat red, const GLfloat green, const GLfloat blue, __attribute__((unused)) GLfloat alpha) { // Fix Alpha glColor4f(red, green, blue, 1.0f); } // Fix Screen Rendering When GUI is Hidden static void Screen_render_injection(Screen_render_t original, Screen *screen, const int32_t param_1, const int32_t param_2, const float param_3) { // Fix glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Call Original Method original(screen, param_1, param_2, param_3); } // Close Current Screen On Death To Prevent Bugs static void LocalPlayer_die_injection(LocalPlayer_die_t original, LocalPlayer *entity, Entity *cause) { // Close Screen Minecraft *minecraft = entity->minecraft; minecraft->setScreen(nullptr); // Call Original Method original(entity, cause); } // Custom Cursor Rendering // // The default behavior for Touch GUI is to only render the cursor when the mouse is clicking, this fixes that. // This also makes the cursor always render if the mouse is unlocked, instead of just when there is a Screen showing. static void GameRenderer_render_injection(GameRenderer_render_t original, GameRenderer *game_renderer, const float param_1) { // Call Original Method original(game_renderer, param_1); // Check If Cursor Should Render if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { // Fix GL Mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Get X And Y float x = Mouse::getX() * Gui::InvGuiScale; float y = Mouse::getY() * Gui::InvGuiScale; // Render Cursor Minecraft *minecraft = game_renderer->minecraft; Common::renderCursor(x, y, minecraft); } } // Fix Furnace Visual Bug static int FurnaceTileEntity_getLitProgress_injection(FurnaceTileEntity_getLitProgress_t original, FurnaceTileEntity *furnace, const int max) { // Call Original Method int ret = original(furnace, max); // Fix Bug if (ret > max) { ret = max; } // Return return ret; } // Add Missing Buttons To Pause Menu static void PauseScreen_init_injection(PauseScreen_init_t original, PauseScreen *screen) { // Call Original Method original(screen); // Check If Server const Minecraft *minecraft = screen->minecraft; RakNetInstance *rak_net_instance = minecraft->rak_net_instance; if (rak_net_instance != nullptr) { if (rak_net_instance->isServer()) { // Add Button std::vector