Search in sources :

Example 1 with InventoryContainerSlot

use of mekanism.common.inventory.container.slot.InventoryContainerSlot in project Mekanism by mekanism.

the class QIOItemViewerContainer method quickMoveStack.

@Nonnull
@Override
public ItemStack quickMoveStack(@Nonnull PlayerEntity player, int slotID) {
    Slot currentSlot = slots.get(slotID);
    if (currentSlot == null) {
        return ItemStack.EMPTY;
    }
    if (currentSlot instanceof VirtualCraftingOutputSlot) {
        // If we are clicking an output crafting slot, allow the slot itself to handle the transferring
        return ((VirtualCraftingOutputSlot) currentSlot).shiftClickSlot(player, hotBarSlots, mainInventorySlots);
    } else if (currentSlot instanceof InventoryContainerSlot) {
        // use our normal handling to attempt and transfer the contents to the player's inventory
        return super.quickMoveStack(player, slotID);
    }
    // special handling for shift-clicking into GUI
    if (!player.level.isClientSide()) {
        ItemStack slotStack = currentSlot.getItem();
        byte selectedCraftingGrid = getSelectedCraftingGrid(player.getUUID());
        if (selectedCraftingGrid != -1) {
            // If the player has a crafting window open
            QIOCraftingWindow craftingWindow = getCraftingWindow(selectedCraftingGrid);
            if (!craftingWindow.isOutput(slotStack)) {
                // and the stack we are trying to transfer was not the output from the crafting window
                // as then shift clicking should be sending it into the QIO, then try transferring it
                // into the crafting window before transferring into the frequency
                ItemStack stackToInsert = slotStack;
                List<InventoryContainerSlot> craftingGridSlots = getCraftingGridSlots(selectedCraftingGrid);
                SelectedWindowData windowData = craftingWindow.getWindowData();
                // Start by trying to stack it with other things and if that fails try to insert it into empty slots
                stackToInsert = insertItem(craftingGridSlots, stackToInsert, windowData);
                if (stackToInsert.getCount() != slotStack.getCount()) {
                    // and return it as a new stack for what is now in the slot
                    return transferSuccess(currentSlot, player, slotStack, stackToInsert);
                }
            // Otherwise, if nothing changed, try to transfer into the QIO Frequency
            }
        }
        QIOFrequency frequency = getFrequency();
        if (frequency != null) {
            if (currentSlot.hasItem()) {
                // Make sure that we copy it so that we aren't just pointing to the reference of it
                slotStack = slotStack.copy();
                ItemStack ret = frequency.addItem(slotStack);
                if (slotStack.getCount() == ret.getCount()) {
                    return ItemStack.EMPTY;
                }
                setTransferTracker(slotStack, slotID);
                return updateSlot(player, currentSlot, ret);
            } else {
                if (slotID == lastSlot && !lastStack.isEmpty()) {
                    doDoubleClickTransfer(player);
                }
                resetTransferTracker();
                return ItemStack.EMPTY;
            }
        }
    }
    return ItemStack.EMPTY;
}
Also used : QIOCraftingWindow(mekanism.common.content.qio.QIOCraftingWindow) Slot(net.minecraft.inventory.container.Slot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) VirtualInventoryContainerSlot(mekanism.common.inventory.container.slot.VirtualInventoryContainerSlot) CraftingWindowInventorySlot(mekanism.common.inventory.slot.CraftingWindowInventorySlot) VirtualCraftingOutputSlot(mekanism.common.inventory.container.slot.VirtualCraftingOutputSlot) VirtualCraftingOutputSlot(mekanism.common.inventory.container.slot.VirtualCraftingOutputSlot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) VirtualInventoryContainerSlot(mekanism.common.inventory.container.slot.VirtualInventoryContainerSlot) ItemStack(net.minecraft.item.ItemStack) QIOFrequency(mekanism.common.content.qio.QIOFrequency) Nonnull(javax.annotation.Nonnull)

Example 2 with InventoryContainerSlot

use of mekanism.common.inventory.container.slot.InventoryContainerSlot in project Mekanism by mekanism.

the class MekanismContainer method quickMoveStack.

/**
 * {@inheritDoc}
 *
 * @return The contents in this slot AFTER transferring items away.
 */
@Nonnull
@Override
public ItemStack quickMoveStack(@Nonnull PlayerEntity player, int slotID) {
    Slot currentSlot = slots.get(slotID);
    if (currentSlot == null || !currentSlot.hasItem()) {
        return ItemStack.EMPTY;
    }
    SelectedWindowData selectedWindow = player.level.isClientSide ? getSelectedWindow() : getSelectedWindow(player.getUUID());
    if (currentSlot instanceof IInsertableSlot && !((IInsertableSlot) currentSlot).exists(selectedWindow)) {
        return ItemStack.EMPTY;
    }
    ItemStack slotStack = currentSlot.getItem();
    ItemStack stackToInsert = slotStack;
    if (currentSlot instanceof InventoryContainerSlot) {
        // Insert into stacks that already contain an item in the order hot bar -> main inventory
        stackToInsert = insertItem(armorSlots, stackToInsert, true, selectedWindow);
        stackToInsert = insertItem(hotBarSlots, stackToInsert, true, selectedWindow);
        stackToInsert = insertItem(mainInventorySlots, stackToInsert, true, selectedWindow);
        // If we still have any left then input into the empty stacks in the order of main inventory -> hot bar
        // Note: Even though we are doing the main inventory, we still need to do both, ignoring empty then not instead of
        // just directly inserting into the main inventory, in case there are empty slots before the one we can stack with
        stackToInsert = insertItem(armorSlots, stackToInsert, false, selectedWindow);
        stackToInsert = insertItem(hotBarSlots, stackToInsert, false, selectedWindow);
        stackToInsert = insertItem(mainInventorySlots, stackToInsert, false, selectedWindow);
    } else {
        // We are in the main inventory or the hot bar
        // Start by trying to insert it into the tile's inventory slots, first attempting to stack with other items
        stackToInsert = insertItem(inventoryContainerSlots, stackToInsert, true, selectedWindow);
        if (slotStack.getCount() == stackToInsert.getCount()) {
            // Then as long as if we still have the same number of items (failed to insert), try to insert it into the tile's inventory slots allowing for empty items
            stackToInsert = insertItem(inventoryContainerSlots, stackToInsert, false, selectedWindow);
            if (slotStack.getCount() == stackToInsert.getCount()) {
                // Else if we failed to do that also, try transferring to armor inventory, main inventory or the hot bar, depending on which one we currently are in
                if (currentSlot instanceof ArmorSlot || currentSlot instanceof OffhandSlot) {
                    stackToInsert = insertItem(hotBarSlots, stackToInsert, true, selectedWindow);
                    stackToInsert = insertItem(mainInventorySlots, stackToInsert, true, selectedWindow);
                    stackToInsert = insertItem(hotBarSlots, stackToInsert, false, selectedWindow);
                    stackToInsert = insertItem(mainInventorySlots, stackToInsert, false, selectedWindow);
                } else if (currentSlot instanceof MainInventorySlot) {
                    stackToInsert = insertItem(armorSlots, stackToInsert, false, selectedWindow);
                    stackToInsert = insertItem(hotBarSlots, stackToInsert, selectedWindow);
                } else if (currentSlot instanceof HotBarSlot) {
                    stackToInsert = insertItem(armorSlots, stackToInsert, false, selectedWindow);
                    stackToInsert = insertItem(mainInventorySlots, stackToInsert, selectedWindow);
                } else {
                // TODO: Should we add a warning message so we can find out if we ever end up here. (Given we should never end up here anyways)
                }
            }
        }
    }
    if (stackToInsert.getCount() == slotStack.getCount()) {
        // If nothing changed then return that fact
        return ItemStack.EMPTY;
    }
    // Otherwise, decrease the stack by the amount we inserted, and return it as a new stack for what is now in the slot
    return transferSuccess(currentSlot, player, slotStack, stackToInsert);
}
Also used : OffhandSlot(mekanism.common.inventory.container.slot.OffhandSlot) ArmorSlot(mekanism.common.inventory.container.slot.ArmorSlot) OffhandSlot(mekanism.common.inventory.container.slot.OffhandSlot) ArmorSlot(mekanism.common.inventory.container.slot.ArmorSlot) MainInventorySlot(mekanism.common.inventory.container.slot.MainInventorySlot) HotBarSlot(mekanism.common.inventory.container.slot.HotBarSlot) Slot(net.minecraft.inventory.container.Slot) IInsertableSlot(mekanism.common.inventory.container.slot.IInsertableSlot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) IInsertableSlot(mekanism.common.inventory.container.slot.IInsertableSlot) MainInventorySlot(mekanism.common.inventory.container.slot.MainInventorySlot) ItemStack(net.minecraft.item.ItemStack) SyncableItemStack(mekanism.common.inventory.container.sync.SyncableItemStack) HotBarSlot(mekanism.common.inventory.container.slot.HotBarSlot) Nonnull(javax.annotation.Nonnull)

Example 3 with InventoryContainerSlot

use of mekanism.common.inventory.container.slot.InventoryContainerSlot in project Mekanism by mekanism.

the class GuiMekanism method addSlots.

protected void addSlots() {
    int size = menu.slots.size();
    for (int i = 0; i < size; i++) {
        Slot slot = menu.slots.get(i);
        if (slot instanceof InventoryContainerSlot) {
            InventoryContainerSlot containerSlot = (InventoryContainerSlot) slot;
            ContainerSlotType slotType = containerSlot.getSlotType();
            DataType dataType = findDataType(containerSlot);
            // Shift the slots by one as the elements include the border of the slot
            SlotType type;
            if (dataType != null) {
                type = SlotType.get(dataType);
            } else if (slotType == ContainerSlotType.INPUT || slotType == ContainerSlotType.OUTPUT || slotType == ContainerSlotType.EXTRA) {
                type = SlotType.NORMAL;
            } else if (slotType == ContainerSlotType.POWER) {
                type = SlotType.POWER;
            } else if (slotType == ContainerSlotType.NORMAL || slotType == ContainerSlotType.VALIDITY) {
                type = SlotType.NORMAL;
            } else {
                // slotType == ContainerSlotType.IGNORED: don't do anything
                continue;
            }
            GuiSlot guiSlot = new GuiSlot(type, this, slot.x - 1, slot.y - 1);
            SlotOverlay slotOverlay = containerSlot.getSlotOverlay();
            if (slotOverlay != null) {
                guiSlot.with(slotOverlay);
            }
            if (slotType == ContainerSlotType.VALIDITY) {
                int index = i;
                guiSlot.validity(() -> checkValidity(index));
            }
            addButton(guiSlot);
        } else {
            addButton(new GuiSlot(SlotType.NORMAL, this, slot.x - 1, slot.y - 1));
        }
    }
}
Also used : SlotOverlay(mekanism.common.inventory.container.slot.SlotOverlay) ContainerSlotType(mekanism.common.inventory.container.slot.ContainerSlotType) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) IVirtualSlot(mekanism.common.inventory.container.slot.IVirtualSlot) Slot(net.minecraft.inventory.container.Slot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) GuiVirtualSlot(mekanism.client.gui.element.slot.GuiVirtualSlot) DataType(mekanism.common.tile.component.config.DataType) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) SlotType(mekanism.client.gui.element.slot.SlotType) ContainerSlotType(mekanism.common.inventory.container.slot.ContainerSlotType)

Example 4 with InventoryContainerSlot

use of mekanism.common.inventory.container.slot.InventoryContainerSlot in project Mekanism by mekanism.

the class GuiMekanismTile method getFromSlot.

private DataType getFromSlot(Slot slot) {
    if (slot.index < tile.getSlots() && slot instanceof InventoryContainerSlot) {
        ISideConfiguration config = (ISideConfiguration) tile;
        ConfigInfo info = config.getConfig().getConfig(TransmissionType.ITEM);
        if (info != null) {
            Set<DataType> supportedDataTypes = info.getSupportedDataTypes();
            IInventorySlot inventorySlot = ((InventoryContainerSlot) slot).getInventorySlot();
            for (DataType type : supportedDataTypes) {
                ISlotInfo slotInfo = info.getSlotInfo(type);
                if (slotInfo instanceof InventorySlotInfo && ((InventorySlotInfo) slotInfo).hasSlot(inventorySlot)) {
                    return type;
                }
            }
        }
    }
    return null;
}
Also used : IInventorySlot(mekanism.api.inventory.IInventorySlot) ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) DataType(mekanism.common.tile.component.config.DataType) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Example 5 with InventoryContainerSlot

use of mekanism.common.inventory.container.slot.InventoryContainerSlot in project Mekanism by mekanism.

the class FormulaicRecipeTransferInfo method getInventorySlots.

@Override
public List<Slot> getInventorySlots(FormulaicAssemblicatorContainer container) {
    List<Slot> slots = new ArrayList<>();
    slots.addAll(container.getMainInventorySlots());
    slots.addAll(container.getHotBarSlots());
    for (InventoryContainerSlot slot : container.getInventoryContainerSlots()) {
        if (slot.getInventorySlot() instanceof InputInventorySlot) {
            slots.add(slot);
        }
    }
    return slots;
}
Also used : InputInventorySlot(mekanism.common.inventory.slot.InputInventorySlot) ArrayList(java.util.ArrayList) FormulaicCraftingSlot(mekanism.common.inventory.slot.FormulaicCraftingSlot) InputInventorySlot(mekanism.common.inventory.slot.InputInventorySlot) Slot(net.minecraft.inventory.container.Slot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot)

Aggregations

InventoryContainerSlot (mekanism.common.inventory.container.slot.InventoryContainerSlot)5 Slot (net.minecraft.inventory.container.Slot)4 Nonnull (javax.annotation.Nonnull)2 DataType (mekanism.common.tile.component.config.DataType)2 ItemStack (net.minecraft.item.ItemStack)2 ArrayList (java.util.ArrayList)1 IInventorySlot (mekanism.api.inventory.IInventorySlot)1 GuiSlot (mekanism.client.gui.element.slot.GuiSlot)1 GuiVirtualSlot (mekanism.client.gui.element.slot.GuiVirtualSlot)1 SlotType (mekanism.client.gui.element.slot.SlotType)1 QIOCraftingWindow (mekanism.common.content.qio.QIOCraftingWindow)1 QIOFrequency (mekanism.common.content.qio.QIOFrequency)1 ArmorSlot (mekanism.common.inventory.container.slot.ArmorSlot)1 ContainerSlotType (mekanism.common.inventory.container.slot.ContainerSlotType)1 HotBarSlot (mekanism.common.inventory.container.slot.HotBarSlot)1 IInsertableSlot (mekanism.common.inventory.container.slot.IInsertableSlot)1 IVirtualSlot (mekanism.common.inventory.container.slot.IVirtualSlot)1 MainInventorySlot (mekanism.common.inventory.container.slot.MainInventorySlot)1 OffhandSlot (mekanism.common.inventory.container.slot.OffhandSlot)1 SlotOverlay (mekanism.common.inventory.container.slot.SlotOverlay)1