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
|
|
|
|
2022-06-25 21:30:08 +00:00
|
|
|
#include "input-internal.h"
|
|
|
|
#include <mods/input/input.h>
|
|
|
|
#include <mods/feature/feature.h>
|
|
|
|
#include <mods/creative/creative.h>
|
2022-07-10 14:37:19 +00:00
|
|
|
#include <mods/misc/misc.h>
|
2021-07-04 23:02:45 +00:00
|
|
|
|
|
|
|
// Enable Item Dropping
|
|
|
|
static int enable_drop = 0;
|
|
|
|
|
|
|
|
// Store Drop Item Presses
|
|
|
|
static int drop_item_presses = 0;
|
|
|
|
static bool drop_slot_pressed = false;
|
|
|
|
void input_drop(int drop_slot) {
|
|
|
|
if (enable_drop) {
|
|
|
|
if (drop_slot) {
|
|
|
|
drop_slot_pressed = true;
|
|
|
|
} else {
|
|
|
|
drop_item_presses++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Drop Item Presses
|
2024-01-06 11:30:23 +00:00
|
|
|
static void _handle_drop(Minecraft *minecraft) {
|
2024-04-02 23:22:01 +00:00
|
|
|
if ((minecraft->screen == nullptr) && (!creative_is_restricted() || !Minecraft_isCreativeMode(minecraft)) && (drop_item_presses > 0 || drop_slot_pressed)) {
|
2021-07-04 23:02:45 +00:00
|
|
|
// Get Player
|
2024-01-06 11:30:23 +00:00
|
|
|
LocalPlayer *player = minecraft->player;
|
2024-04-02 23:22:01 +00:00
|
|
|
if (player != nullptr) {
|
2021-07-04 23:02:45 +00:00
|
|
|
// Get Selected Slot
|
2024-01-06 11:30:23 +00:00
|
|
|
int32_t selected_slot = misc_get_real_selected_slot((Player *) player);
|
|
|
|
Inventory *inventory = player->inventory;
|
2021-07-04 23:02:45 +00:00
|
|
|
|
|
|
|
// Get Item
|
2024-01-06 11:30:23 +00:00
|
|
|
ItemInstance *inventory_item = inventory->vtable->getItem(inventory, selected_slot);
|
2021-07-04 23:02:45 +00:00
|
|
|
// Check
|
2024-04-02 23:22:01 +00:00
|
|
|
if (inventory_item != nullptr && inventory_item->count > 0) {
|
2021-07-04 23:02:45 +00:00
|
|
|
// Copy
|
|
|
|
ItemInstance *dropped_item = new ItemInstance;
|
2021-12-01 02:54:43 +00:00
|
|
|
ALLOC_CHECK(dropped_item);
|
2021-07-04 23:02:45 +00:00
|
|
|
*dropped_item = *inventory_item;
|
|
|
|
|
|
|
|
// Update Inventory
|
|
|
|
if (drop_slot_pressed) {
|
|
|
|
// Drop Slot
|
|
|
|
|
|
|
|
// Empty Slot
|
|
|
|
inventory_item->count = 0;
|
|
|
|
} else {
|
|
|
|
// Drop Item
|
|
|
|
|
|
|
|
// Set Item Drop Count
|
|
|
|
int drop_count = drop_item_presses < inventory_item->count ? drop_item_presses : inventory_item->count;
|
|
|
|
dropped_item->count = drop_count;
|
|
|
|
inventory_item->count -= drop_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Empty Slot If Needed
|
|
|
|
if (inventory_item->count < 1) {
|
2024-01-07 08:23:43 +00:00
|
|
|
Inventory_release(inventory, selected_slot);
|
|
|
|
Inventory_compressLinkedSlotList(inventory, selected_slot);
|
2021-07-04 23:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Drop
|
2024-01-06 11:30:23 +00:00
|
|
|
player->vtable->drop(player, dropped_item, false);
|
2021-07-04 23:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Reset
|
|
|
|
drop_item_presses = 0;
|
|
|
|
drop_slot_pressed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init
|
|
|
|
void _init_drop() {
|
2022-04-10 00:01:16 +00:00
|
|
|
enable_drop = feature_has("Bind \"Q\" Key To Item Dropping", server_disabled);
|
2021-10-04 23:42:55 +00:00
|
|
|
input_run_on_tick(_handle_drop);
|
2021-07-04 23:02:45 +00:00
|
|
|
}
|