Solved Clearing crafting slots/item on cursor to prevent inventory exploit

Sophed

New member
Jul 21, 2023
2
0
1
How can I clear the player's crafting slots and item on cursor to prevent them from having specific items in places they shouldn't?

In the example below I use a common hack called 'Inventory Tweaks' (sometimes known as extra carry or inventory) which allows you to store items in your crafting slots/cursor and have them persist through closing your inventory. This is a huge issue as it is simple to create a mod with this feature and it would allow players to use items from multiple kits, unbalancing gameplay.

I have looked into replacing the inventory slots but I can't seem to find a method of achieving this as the crafting slots have IDs 1-4, the same as the player's regular inventory. player.inventory.clear() doesn't seem to clear the crafting slots or cursor, only the main inventory and armor slots.

 

Nacio

Paper Triage
Staff member
Jul 11, 2022
4
0
1
18
Lublin, Poland
As far as the server is concerned the player always has their inventory open.
I guess try clearing those slots after the PlayerMoveEvent (not sure if that wouldn't also clear them when the player is moved by e.g. water).
 

Sophed

New member
Jul 21, 2023
2
0
1
Updating this because I had to solve this same issue again recently

Java:
public static void clearCraftingGrid(Player player) {
    if (player.getOpenInventory().getTopInventory().getType() != InventoryType.CRAFTING) return;
    if (player.getOpenInventory().getTopInventory().getSize() > 5) return;
    player.getOpenInventory().getTopInventory().clear();
}