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;
}
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);
}
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));
}
}
}
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;
}
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;
}
Aggregations