Allow Opening Crafting With Controller

This commit is contained in:
TheBrokenRail 2022-10-07 00:06:50 -04:00
parent 5d65b4092f
commit f3dc145d4a
10 changed files with 59 additions and 4 deletions

View File

@ -29,10 +29,11 @@
| Action | Function |
| --- | --- |
| A | Jump |
| D-Pad Down | Drop Item |
| Y | Open Inventory |
| D-Pad Up | Change Perspective |
| B | Sneak[^1] |
| X | Open Crafting |
| D-Pad Up | Change Perspective |
| D-Pad Down | Drop Item |
| D-Pad Right | Open Chat |
| Left/Right Bumper | Cycle Selected Item In Toolbar |
| Left Trigger | Attack/Destroy |

View File

@ -60,6 +60,7 @@ static void character_event(char c) {
}
// Convert GLFW Key To SDL Key
#define IMAGINARY_GLFW_CRAFTING_KEY GLFW_KEY_LAST
static SDLKey glfw_key_to_sdl_key(int key) {
switch (key) {
// Movement
@ -136,6 +137,9 @@ static SDLKey glfw_key_to_sdl_key(int key) {
// Chat
case GLFW_KEY_T:
return SDLK_t;
// Crafting
case IMAGINARY_GLFW_CRAFTING_KEY:
return SDLK_WORLD_0;
// Unknown
default:
return SDLK_UNKNOWN;
@ -293,6 +297,9 @@ static SDLKey glfw_controller_button_to_key(int button) {
case GLFW_GAMEPAD_BUTTON_START:
case GLFW_GAMEPAD_BUTTON_BACK:
return GLFW_KEY_ESCAPE;
// Crafting
case GLFW_GAMEPAD_BUTTON_X:
return IMAGINARY_GLFW_CRAFTING_KEY;
// Unknown
default:
return GLFW_KEY_UNKNOWN;

View File

@ -38,7 +38,8 @@ typedef enum {
SDLK_F11 = 292,
SDLK_F12 = 293,
SDLK_RSHIFT = 303,
SDLK_LSHIFT = 304
SDLK_LSHIFT = 304,
SDLK_WORLD_0 = 160 // Used For Controller Crafting Button
} SDLKey;
typedef enum {

View File

@ -62,7 +62,7 @@ else()
target_link_libraries(camera screenshot)
endif()
add_library(input SHARED src/input/input.cpp src/input/bow.c src/input/attack.c src/input/toggle.c src/input/misc.c src/input/drop.cpp)
add_library(input SHARED src/input/input.cpp src/input/bow.c src/input/attack.c src/input/toggle.c src/input/misc.c src/input/drop.cpp src/input/crafting.cpp)
target_link_libraries(input mods-headers reborn-patch symbols creative feature misc media-layer-core)
add_library(sign SHARED src/sign/sign.cpp)

View File

@ -12,6 +12,7 @@ void input_hide_gui();
void input_third_person();
int input_back();
void input_drop(int drop_slot);
void input_open_crafting();
void input_set_is_left_click(int val);

View File

@ -84,6 +84,10 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) {
// Drop Item
input_drop((event->key.keysym.mod & KMOD_CTRL) != 0);
handled = 1;
} else if (event->key.keysym.sym == SDLK_WORLD_0) {
// Crafting
input_open_crafting();
handled = 1;
}
break;
}

View File

@ -0,0 +1,30 @@
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
#include "input-internal.h"
#include <mods/input/input.h>
#include <mods/creative/creative.h>
// Store Should Open Crafting Menu
static int should_open_crafting = 0;
void input_open_crafting() {
should_open_crafting = 1;
}
static void _handle_open_crafting(unsigned char *minecraft) {
if (should_open_crafting) {
should_open_crafting = 0;
// Set Screen
if (!creative_is_restricted() || !(*Minecraft_isCreativeMode)(minecraft)) {
unsigned char *screen = (unsigned char *) ::operator new(WORKBENCH_SCREEN_SIZE);
ALLOC_CHECK(screen);
screen = (*WorkbenchScreen)(screen, 0);
(*Minecraft_setScreen)(minecraft, screen);
}
}
}
// Init
void _init_crafting() {
input_run_on_tick(_handle_open_crafting);
}

View File

@ -9,6 +9,7 @@ __attribute__((visibility("internal"))) void _init_bow();
__attribute__((visibility("internal"))) void _init_misc();
__attribute__((visibility("internal"))) void _init_toggle();
__attribute__((visibility("internal"))) void _init_drop();
__attribute__((visibility("internal"))) void _init_crafting();
#ifdef __cplusplus
}

View File

@ -49,6 +49,9 @@ void init_input() {
// Allow Attacking Mobs
_init_attack();
// Allow Opening Crafting With Controller
_init_crafting();
// Disable Raw Mouse Motion
if (feature_has("Disable Raw Mouse Motion (Not Recommended)", server_disabled)) {
media_set_raw_mouse_motion_enabled(0);

View File

@ -854,6 +854,13 @@ static uint32_t HumanoidModel_is_sneaking_property_offset = 0x236; // bool
static void *PlayerRenderer_render_vtable_addr = (void *) 0x107f08;
// WorkbenchScreen
#define WORKBENCH_SCREEN_SIZE 0x180
typedef unsigned char *(*WorkbenchScreen_t)(unsigned char *screen, int32_t param_1);
static WorkbenchScreen_t WorkbenchScreen = (WorkbenchScreen_t) 0x301cc;
// Method That Require C++ Types
#ifdef __cplusplus