Allow picking ingredients in the Auto Crafter recipe window #36

Merged
unimatrix merged 1 commit from feat/dunechest-planets-recipe-cursor into main 2026-11-30 18:59:30 +01:00
6 changed files with 32 additions and 3 deletions

View file

@ -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/")

View file

@ -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;

View file

@ -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<String> 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); }
}

View file

@ -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]

View file

@ -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<Material, Integer>();
counts.put(Material.DIRT, 50); counts.put(Material.STONE, 40);

View file

@ -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')