From deb0e2f161af6e8219f34c5f898a3c4c7cdbe407 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Mon, 30 Nov 2026 18:55:21 +0100 Subject: [PATCH] Allow picking ingredients in the Auto Crafter recipe window --- DuneChest/build.gradle.kts | 2 +- .../java/com/example/dunechest/StorageModule.java | 6 ++++++ .../java/com/example/dunechest/StorageRules.java | 12 ++++++++++++ DuneChest/src/main/resources/plugin.yml | 2 +- .../java/com/example/dunechest/StorageRulesTest.java | 11 +++++++++++ tools/install-plugin-fleet.py | 2 +- 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/DuneChest/build.gradle.kts b/DuneChest/build.gradle.kts index 498c950f..eb69d8a4 100644 --- a/DuneChest/build.gradle.kts +++ b/DuneChest/build.gradle.kts @@ -1,6 +1,6 @@ plugins { java } group = "com.example" -version = "1.0.3" +version = "1.0.4" repositories { mavenCentral() maven("https://repo.papermc.io/repository/maven-public/") diff --git a/DuneChest/src/main/java/com/example/dunechest/StorageModule.java b/DuneChest/src/main/java/com/example/dunechest/StorageModule.java index 62ec60dd..2c441bd6 100644 --- a/DuneChest/src/main/java/com/example/dunechest/StorageModule.java +++ b/DuneChest/src/main/java/com/example/dunechest/StorageModule.java @@ -255,6 +255,12 @@ public final class StorageModule implements Listener, CommandExecutor { var top = e.getView().getTopInventory(); if (top.getHolder() instanceof StorageData.FreqHolder) { data.dirty = true; return; } if (!(top.getHolder() instanceof Menu m)) return; + int rawSlot = e.getRawSlot(); + if (m.recipeBlock != null && rawSlot >= top.getSize() + && e.getClickedInventory() == e.getView().getBottomInventory() + && StorageRules.canUseRecipeCursor(e.getClick(), e.getAction())) { + return; + } e.setCancelled(true); var p = data.blocks.get(m.blockKey); if (p == null || !(e.getWhoClicked() instanceof Player pl)) return; if (e.getClickedInventory() != top) return; diff --git a/DuneChest/src/main/java/com/example/dunechest/StorageRules.java b/DuneChest/src/main/java/com/example/dunechest/StorageRules.java index 943bfcc3..165222e6 100644 --- a/DuneChest/src/main/java/com/example/dunechest/StorageRules.java +++ b/DuneChest/src/main/java/com/example/dunechest/StorageRules.java @@ -4,6 +4,8 @@ import java.util.*; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.inventory.ItemStack; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryAction; /** Pure rules for the custom storage blocks: hopper tiers, filters, ender-chest colour frequencies and pad geometry. */ public final class StorageRules { @@ -91,6 +93,16 @@ public final class StorageRules { return consumption; } + /** Only ordinary cursor moves below the preview may be handled by the server. */ + static boolean canUseRecipeCursor(ClickType click, InventoryAction action) { + if (click != ClickType.LEFT && click != ClickType.RIGHT) return false; + return switch (action) { + case PICKUP_ALL, PICKUP_SOME, PICKUP_HALF, PICKUP_ONE, + PLACE_ALL, PLACE_SOME, PLACE_ONE, SWAP_WITH_CURSOR -> true; + default -> false; + }; + } + static final Set BLOCKED_TARGETS = Set.of("BREWING", "CRAFTER", "JUKEBOX", "LECTERN", "COMPOSTER", "DECORATED_POT", "CHISELED_BOOKSHELF", "BEACON", "ENCHANTING", "ANVIL", "SMITHING"); public static boolean transferable(String inventoryType) { return !BLOCKED_TARGETS.contains(inventoryType); } } diff --git a/DuneChest/src/main/resources/plugin.yml b/DuneChest/src/main/resources/plugin.yml index 26031ec4..ca27c591 100644 --- a/DuneChest/src/main/resources/plugin.yml +++ b/DuneChest/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: DuneChest -version: 1.0.3 +version: 1.0.4 main: com.example.dunechest.DuneChest api-version: '1.21.8' softdepend: [floodgate, DuneMenus, DuneEss] diff --git a/DuneChest/src/test/java/com/example/dunechest/StorageRulesTest.java b/DuneChest/src/test/java/com/example/dunechest/StorageRulesTest.java index 7db79f98..697e6c3f 100644 --- a/DuneChest/src/test/java/com/example/dunechest/StorageRulesTest.java +++ b/DuneChest/src/test/java/com/example/dunechest/StorageRulesTest.java @@ -5,6 +5,8 @@ import java.util.*; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.inventory.ItemStack; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryAction; import org.junit.jupiter.api.Test; class StorageRulesTest { @@ -82,6 +84,15 @@ class StorageRulesTest { } } + @Test void recipeWindowAllowsCursorMovesButBlocksCrossInventoryActions() { + assertTrue(StorageRules.canUseRecipeCursor(ClickType.LEFT, InventoryAction.PICKUP_ALL)); + assertTrue(StorageRules.canUseRecipeCursor(ClickType.RIGHT, InventoryAction.PICKUP_HALF)); + assertTrue(StorageRules.canUseRecipeCursor(ClickType.RIGHT, InventoryAction.PLACE_ONE)); + assertFalse(StorageRules.canUseRecipeCursor(ClickType.SHIFT_LEFT, InventoryAction.MOVE_TO_OTHER_INVENTORY)); + assertFalse(StorageRules.canUseRecipeCursor(ClickType.DOUBLE_CLICK, InventoryAction.COLLECT_TO_CURSOR)); + assertFalse(StorageRules.canUseRecipeCursor(ClickType.NUMBER_KEY, InventoryAction.HOTBAR_SWAP)); + } + @Test void mostCommonItemPicksBiggestTotal() { var counts = new java.util.LinkedHashMap(); counts.put(Material.DIRT, 50); counts.put(Material.STONE, 40); diff --git a/tools/install-plugin-fleet.py b/tools/install-plugin-fleet.py index ef4d48de..26db556e 100644 --- a/tools/install-plugin-fleet.py +++ b/tools/install-plugin-fleet.py @@ -277,7 +277,7 @@ def plan(artifacts, inventory, expected_source): installed=existing_paths.get('dunechest') approved_dunechest = { chosen[0]['sha256'], - 'a1cd67aeea65d4a9dc98b75b1466fd54a120213e3eef31582c9492d546e484c2', + '49668bc342a4e15edec1a6e38e590378d2783d03c7af049b0b96bc92b210d9e9', } if installed is not None and digest(installed) not in approved_dunechest: raise ValueError('Existing DuneChest differs from the approved release or predecessor') -- 2.53.0