diff --git a/build.gradle b/build.gradle index 8d3f536..1f62c05 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { apply plugin: 'net.minecraftforge.gradle' group = 'com.buuz135' -version = '1.18.2-1.0.2' +version = '1.18.2-1.0.3' java { archivesBaseName = 'functionalstorage' 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 74ddced..86c194f 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/ControllableDrawerTile.java @@ -263,12 +263,30 @@ public abstract class ControllableDrawerTile 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 (!stack.isEmpty() && stack.getItem() instanceof UpgradeItem upgradeItem) { + if (upgradeItem instanceof StorageUpgradeItem storageUpgradeItem) { + InventoryComponent component = storageUpgrades; + for (int i = 0; i < component.getSlots(); i++) { + if (component.getStackInSlot(i).isEmpty()) { + playerIn.setItemInHand(hand, component.insertItem(i, stack, false)); + return InteractionResult.SUCCESS; + } + } + for (int i = 0; i < component.getSlots(); i++) { + if (!component.getStackInSlot(i).isEmpty() && component.getStackInSlot(i).getItem() instanceof StorageUpgradeItem instertedUpgrade && instertedUpgrade.getStorageMultiplier() < storageUpgradeItem.getStorageMultiplier()) { + ItemHandlerHelper.giveItemToPlayer(playerIn, component.getStackInSlot(i).copy()); + component.setStackInSlot(i, ItemStack.EMPTY); + playerIn.setItemInHand(hand, component.insertItem(i, stack, false)); + return InteractionResult.SUCCESS; + } + } + } else { + InventoryComponent component = 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; + } } } }