minecraft-pi-reborn/mods/src/input/bow.c

37 lines
1.3 KiB
C
Raw Normal View History

2021-07-04 23:02:45 +00:00
#include <libreborn/libreborn.h>
2021-09-12 03:18:12 +00:00
#include <symbols/minecraft.h>
2021-07-04 23:02:45 +00:00
#include "../feature/feature.h"
#include "input.h"
// Store Right-Click Status
static int is_right_click = 0;
void input_set_is_right_click(int val) {
is_right_click = val;
}
// Enable Bow & Arrow Fix
static int fix_bow = 0;
// Handle Bow & Arrow
2021-10-04 23:42:55 +00:00
static void _handle_bow(unsigned char *minecraft) {
2021-07-04 23:02:45 +00:00
if (fix_bow && !is_right_click) {
// GameMode Is Offset From minecraft By 0x160
// Player Is Offset From minecraft By 0x18c
unsigned char *game_mode = *(unsigned char **) (minecraft + Minecraft_game_mode_property_offset);
unsigned char *player = *(unsigned char **) (minecraft + Minecraft_player_property_offset);
if (player != NULL && game_mode != NULL && (*Player_isUsingItem)(player)) {
unsigned char *game_mode_vtable = *(unsigned char **) game_mode;
GameMode_releaseUsingItem_t GameMode_releaseUsingItem = *(GameMode_releaseUsingItem_t *) (game_mode_vtable + GameMode_releaseUsingItem_vtable_offset);
(*GameMode_releaseUsingItem)(game_mode, player);
}
}
}
// Init
void _init_bow() {
// Enable Bow & Arrow Fix
2022-04-10 00:01:16 +00:00
fix_bow = feature_has("Fix Bow & Arrow", server_disabled);
2021-10-04 23:42:55 +00:00
input_run_on_tick(_handle_bow);
2021-07-04 23:02:45 +00:00
}