2021-06-30 19:41:18 -04:00
|
|
|
#include <GLES/gl.h>
|
|
|
|
|
|
|
|
#include <libreborn/libreborn.h>
|
2021-09-11 23:18:12 -04:00
|
|
|
#include <symbols/minecraft.h>
|
2021-06-30 19:41:18 -04:00
|
|
|
|
2022-06-25 17:30:08 -04:00
|
|
|
#include <mods/feature/feature.h>
|
|
|
|
#include <mods/init/init.h>
|
2021-06-30 19:41:18 -04:00
|
|
|
|
|
|
|
// Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled
|
2024-04-03 03:19:12 -04:00
|
|
|
static void ItemRenderer_renderGuiItemCorrect_injection(ItemRenderer_renderGuiItemCorrect_t original, Font *font, Textures *textures, ItemInstance *item_instance, int32_t param_1, int32_t param_2) {
|
2024-01-07 02:59:04 -05:00
|
|
|
int32_t leaves_id = Tile_leaves->id;
|
|
|
|
int32_t grass_id = Tile_grass->id;
|
2021-06-30 19:41:18 -04:00
|
|
|
// Replace Rendered Item With Carried Variant
|
2021-07-04 19:02:45 -04:00
|
|
|
ItemInstance carried_item_instance;
|
|
|
|
bool use_carried = false;
|
2024-04-02 19:22:01 -04:00
|
|
|
if (item_instance != nullptr) {
|
2021-07-04 19:02:45 -04:00
|
|
|
if (item_instance->id == leaves_id) {
|
2024-05-15 05:02:19 -04:00
|
|
|
carried_item_instance.constructor_tile_extra(Tile_leaves_carried, item_instance->count, item_instance->auxiliary);
|
2021-07-04 19:02:45 -04:00
|
|
|
use_carried = true;
|
|
|
|
} else if (item_instance->id == grass_id) {
|
2024-05-15 05:02:19 -04:00
|
|
|
carried_item_instance.constructor_tile_extra(Tile_grass_carried, item_instance->count, item_instance->auxiliary);
|
2021-07-04 19:02:45 -04:00
|
|
|
use_carried = true;
|
2021-06-30 19:41:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix Toolbar Rendering
|
|
|
|
GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
// Call Original Method
|
2024-04-03 03:19:12 -04:00
|
|
|
original(font, textures, use_carried ? &carried_item_instance : item_instance, param_1, param_2);
|
2021-06-30 19:41:18 -04:00
|
|
|
|
|
|
|
// Revert GL State Changes
|
|
|
|
if (depth_test_was_enabled) {
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix Translucent Preview Items In Furnace UI Being Fully Opaque When The gui_blocks Atlas Is Disabled
|
2022-01-01 19:04:58 -05:00
|
|
|
static int item_color_fix_mode = 0;
|
2022-06-26 22:01:31 -04:00
|
|
|
#define POTENTIAL_FURNACE_ITEM_TRANSPARENCY 0x33
|
|
|
|
#define INVALID_FURNACE_ITEM_MULTIPLIER 0.25f
|
2024-04-03 03:19:12 -04:00
|
|
|
static void Tesselator_color_injection(Tesselator_color_t original, Tesselator *tesselator, int32_t r, int32_t g, int32_t b, int32_t a) {
|
2021-06-30 19:41:18 -04:00
|
|
|
// Fix Furnace UI
|
2022-01-01 19:04:58 -05:00
|
|
|
if (item_color_fix_mode != 0) {
|
2021-06-30 19:41:18 -04:00
|
|
|
// Force Translucent
|
2022-01-01 19:04:58 -05:00
|
|
|
if (item_color_fix_mode == 1) {
|
2022-06-26 22:01:31 -04:00
|
|
|
a = POTENTIAL_FURNACE_ITEM_TRANSPARENCY;
|
2022-01-01 19:04:58 -05:00
|
|
|
} else {
|
2022-06-26 22:01:31 -04:00
|
|
|
static double multiplier = INVALID_FURNACE_ITEM_MULTIPLIER;
|
|
|
|
b *= multiplier;
|
|
|
|
g *= multiplier;
|
|
|
|
r *= multiplier;
|
2022-01-01 19:04:58 -05:00
|
|
|
}
|
2021-06-30 19:41:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call Original Method
|
2024-04-03 03:19:12 -04:00
|
|
|
original(tesselator, r, g, b, a);
|
2021-06-30 19:41:18 -04:00
|
|
|
}
|
2024-04-03 03:19:12 -04:00
|
|
|
static void Tesselator_begin_injection(Tesselator_begin_t original, Tesselator *tesselator, int32_t mode) {
|
2021-06-30 19:41:18 -04:00
|
|
|
// Call Original Method
|
2024-04-03 03:19:12 -04:00
|
|
|
original(tesselator, mode);
|
2021-06-30 19:41:18 -04:00
|
|
|
|
|
|
|
// Fix Furnace UI
|
2022-01-01 19:04:58 -05:00
|
|
|
if (item_color_fix_mode != 0) {
|
2021-06-30 19:41:18 -04:00
|
|
|
// Implict Translucent
|
2024-05-15 05:02:19 -04:00
|
|
|
tesselator->color(0xff, 0xff, 0xff, 0xff);
|
2021-06-30 19:41:18 -04:00
|
|
|
}
|
|
|
|
}
|
2024-01-06 06:30:23 -05:00
|
|
|
static void InventoryPane_renderBatch_Tesselator_color_injection(Tesselator *tesselator, int32_t r, int32_t g, int32_t b) {
|
2022-01-01 19:04:58 -05:00
|
|
|
// Call Original Method
|
2024-05-15 05:02:19 -04:00
|
|
|
tesselator->color(r, g, b, 0xff);
|
2021-06-30 19:41:18 -04:00
|
|
|
|
2022-01-01 19:04:58 -05:00
|
|
|
// Enable Item Color Fix
|
|
|
|
item_color_fix_mode = 2;
|
|
|
|
}
|
2024-04-03 03:19:12 -04:00
|
|
|
static void ItemRenderer_renderGuiItem_two_injection(ItemRenderer_renderGuiItem_two_t original, Font *font, Textures *textures, ItemInstance *item_instance, float param_1, float param_2, float param_3, float param_4, bool param_5) {
|
2021-06-30 19:41:18 -04:00
|
|
|
// Call Original Method
|
2024-04-03 03:19:12 -04:00
|
|
|
original(font, textures, item_instance, param_1, param_2, param_3, param_4, param_5);
|
2021-06-30 19:41:18 -04:00
|
|
|
|
2022-01-01 19:04:58 -05:00
|
|
|
// Disable Item Color Fix
|
|
|
|
item_color_fix_mode = 0;
|
|
|
|
}
|
2024-01-06 06:30:23 -05:00
|
|
|
static void FurnaceScreen_render_ItemRenderer_renderGuiItem_one_injection(Font *font, Textures *textures, ItemInstance *item_instance, float param_1, float param_2, bool param_3) {
|
2022-01-01 19:04:58 -05:00
|
|
|
// Enable Item Color Fix
|
|
|
|
item_color_fix_mode = 1;
|
2021-06-30 19:41:18 -04:00
|
|
|
|
2022-01-01 19:04:58 -05:00
|
|
|
// Call Original Method
|
2024-05-15 05:02:19 -04:00
|
|
|
ItemRenderer::renderGuiItem_one(font, textures, item_instance, param_1, param_2, param_3);
|
2021-06-30 19:41:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init
|
|
|
|
void init_atlas() {
|
2024-04-02 19:22:01 -04:00
|
|
|
// Add Better nullptr-Check (And More UI Fixes When The gui_blocks Atlas Is Disabled)
|
2024-04-03 03:19:12 -04:00
|
|
|
overwrite_calls(ItemRenderer_renderGuiItem_two, ItemRenderer_renderGuiItem_two_injection);
|
2022-01-01 19:04:58 -05:00
|
|
|
|
2021-06-30 19:41:18 -04:00
|
|
|
// Disable The gui_blocks Atlas Which Contains Pre-Rendered Textures For Blocks In The Inventory
|
2022-04-09 20:01:16 -04:00
|
|
|
if (feature_has("Disable \"gui_blocks\" Atlas", server_disabled)) {
|
2021-06-30 19:41:18 -04:00
|
|
|
unsigned char disable_gui_blocks_atlas_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
|
|
|
patch((void *) 0x63c2c, disable_gui_blocks_atlas_patch);
|
|
|
|
// Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled
|
2024-04-03 03:19:12 -04:00
|
|
|
overwrite_calls(ItemRenderer_renderGuiItemCorrect, ItemRenderer_renderGuiItemCorrect_injection);
|
2021-06-30 19:41:18 -04:00
|
|
|
// Fix Furnace UI
|
2024-04-03 03:19:12 -04:00
|
|
|
overwrite_calls(Tesselator_begin, Tesselator_begin_injection);
|
|
|
|
overwrite_calls(Tesselator_color, Tesselator_color_injection);
|
2022-01-01 19:04:58 -05:00
|
|
|
overwrite_call((void *) 0x32324, (void *) FurnaceScreen_render_ItemRenderer_renderGuiItem_one_injection);
|
|
|
|
overwrite_call((void *) 0x1e21c, (void *) InventoryPane_renderBatch_Tesselator_color_injection);
|
2021-06-30 19:41:18 -04:00
|
|
|
}
|
|
|
|
}
|