minecraft-pi-reborn/mods/src/misc/api.cpp

68 lines
2.3 KiB
C++
Raw Permalink Normal View History

2024-04-03 07:19:12 +00:00
#include <utility>
2022-06-27 18:47:55 +00:00
#include <vector>
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
2024-05-12 02:06:37 +00:00
#ifndef MCPI_HEADLESS_MODE
2024-05-10 23:50:28 +00:00
#include <GLES/gl.h>
2024-05-12 02:06:37 +00:00
#endif
2022-06-27 18:47:55 +00:00
#include <mods/misc/misc.h>
#include "misc-internal.h"
2022-07-10 14:37:19 +00:00
// Callbacks
2024-02-03 03:25:22 +00:00
#define STORE_CALLBACK(name, type) \
static std::vector<misc_update_function_##type##_t> &get_misc_##name##_functions() { \
2024-01-06 11:30:23 +00:00
static std::vector<misc_update_function_##type##_t> functions; \
2022-07-10 14:37:19 +00:00
return functions; \
} \
2024-02-03 03:25:22 +00:00
void misc_run_on_##name(misc_update_function_##type##_t function) { \
get_misc_##name##_functions().push_back(function); \
}
#define SETUP_CALLBACK(name, type) \
STORE_CALLBACK(name, type) \
2024-01-06 11:30:23 +00:00
static void handle_misc_##name(type *obj) { \
for (misc_update_function_##type##_t function : get_misc_##name##_functions()) { \
2024-01-07 08:23:43 +00:00
function(obj); \
2022-07-10 14:37:19 +00:00
} \
}
// Run Functions On Creative Inventory Setup
2024-01-06 11:30:23 +00:00
SETUP_CALLBACK(creative_inventory_setup, FillingContainer);
2022-07-10 14:37:19 +00:00
// Handle Custom Creative Inventory Setup Behavior
2024-01-06 11:30:23 +00:00
static void Inventory_setupDefault_FillingContainer_addItem_call_injection(FillingContainer *filling_container, ItemInstance *item_instance) {
2022-07-10 14:37:19 +00:00
// Call Original Method
2024-05-15 09:02:19 +00:00
filling_container->addItem(item_instance);
2022-07-10 14:37:19 +00:00
// Run Functions
handle_misc_creative_inventory_setup(filling_container);
}
2024-05-10 23:50:28 +00:00
// Render Fancy Background
void misc_render_background(int color, Minecraft *minecraft, int x, int y, int width, int height) {
// https://github.com/ReMinecraftPE/mcpe/blob/f0d65eaecec1b3fe9c2f2b251e114a890c54ab77/source/client/gui/components/RolledSelectionList.cpp#L169-L179
2024-05-12 02:06:37 +00:00
#ifndef MCPI_HEADLESS_MODE
2024-05-10 23:50:28 +00:00
glColor4f(1, 1, 1, 1);
2024-05-12 02:06:37 +00:00
#endif
2024-05-10 23:50:28 +00:00
std::string texture = "gui/background.png";
minecraft->textures->loadAndBindTexture(&texture);
2024-05-17 06:52:55 +00:00
Tesselator *t = &Tesselator::instance;
2024-05-10 23:50:28 +00:00
t->begin(7);
t->color(color, color, color, 255);
float x1 = x;
float x2 = x + width;
float y1 = y;
float y2 = y + height;
t->vertexUV(x1, y2, 0.0f, x1 / 32.0f, y2 / 32.0f);
t->vertexUV(x2, y2, 0.0f, x2 / 32.0f, y2 / 32.0f);
t->vertexUV(x2, y1, 0.0f, x2 / 32.0f, y1 / 32.0f);
t->vertexUV(x1, y1, 0.0f, x1 / 32.0f, y1 / 32.0f);
t->draw();
}
2022-06-27 18:47:55 +00:00
// Init
void _init_misc_api() {
2022-07-10 14:37:19 +00:00
// Handle Custom Creative Inventory Setup Behavior
overwrite_call((void *) 0x8e0fc, (void *) Inventory_setupDefault_FillingContainer_addItem_call_injection);
2022-06-27 18:47:55 +00:00
}