From 9ed28467b9e0f7017dbabca53ff9eafe8aadd44a Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Fri, 24 Dec 2021 11:49:43 +0100 Subject: [PATCH] Upgrades can now be inserted by right clicking and you dont need to shift to use the tools --- .../block/tile/ControllableDrawerTile.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java index f967c40..c4fcb32 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java @@ -137,13 +137,23 @@ public abstract class ControllableDrawerTile } public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) { + ItemStack stack = playerIn.getItemInHand(hand); + if (stack.getItem().equals(FunctionalStorage.CONFIGURATION_TOOL.get()) || stack.getItem().equals(FunctionalStorage.LINKING_TOOL.get())) return InteractionResult.PASS; + if (!stack.isEmpty() && stack.getItem() instanceof UpgradeItem){ + InventoryComponent component = ((UpgradeItem) stack.getItem()).getType() == UpgradeItem.Type.STORAGE ? storageUpgrades : utilityUpgrades; + for (int i = 0; i < component.getSlots(); i++) { + if (component.getStackInSlot(i).isEmpty()){ + playerIn.setItemInHand(hand, component.insertItem(i, stack, false)); + return InteractionResult.SUCCESS; + } + } + } if (super.onActivated(playerIn, hand, facing, hitX, hitY, hitZ) == InteractionResult.SUCCESS) { return InteractionResult.SUCCESS; } if (slot == -1){ openGui(playerIn); } else if (isServer()){ - ItemStack stack = playerIn.getItemInHand(hand); if (!stack.isEmpty() && getStorage().isItemValid(slot, stack)) { playerIn.setItemInHand(hand, getStorage().insertItem(slot, stack, false)); } else if (System.currentTimeMillis() - INTERACTION_LOGGER.getOrDefault(playerIn.getUUID(), System.currentTimeMillis()) < 300) {