Search in sources :

Example 1 with SlotCrafter

use of forestry.core.gui.slots.SlotCrafter in project ForestryMC by ForestryMC.

the class SlotUtil method transferStackInSlot.

public static ItemStack transferStackInSlot(List<Slot> inventorySlots, EntityPlayer player, int slotIndex) {
    Slot slot = inventorySlots.get(slotIndex);
    if (slot == null || !slot.getHasStack()) {
        return ItemStack.EMPTY;
    }
    boolean fromCraftingSlot = slot instanceof SlotCrafting || slot instanceof SlotCrafter;
    int numSlots = inventorySlots.size();
    ItemStack stackInSlot = slot.getStack();
    ItemStack originalStack = stackInSlot.copy();
    if (!shiftItemStack(inventorySlots, stackInSlot, slotIndex, numSlots, fromCraftingSlot)) {
        return ItemStack.EMPTY;
    }
    slot.onSlotChange(stackInSlot, originalStack);
    if (stackInSlot.isEmpty()) {
        slot.putStack(ItemStack.EMPTY);
    } else {
        slot.onSlotChanged();
    }
    if (stackInSlot.getCount() == originalStack.getCount()) {
        return ItemStack.EMPTY;
    }
    slot.onTake(player, stackInSlot);
    return originalStack;
}
Also used : SlotCrafter(forestry.core.gui.slots.SlotCrafter) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) SlotCrafting(net.minecraft.inventory.SlotCrafting)

Aggregations

SlotCrafter (forestry.core.gui.slots.SlotCrafter)1 Slot (net.minecraft.inventory.Slot)1 SlotCrafting (net.minecraft.inventory.SlotCrafting)1 ItemStack (net.minecraft.item.ItemStack)1