Search in sources :

Example 1 with SlotDefinition

use of crazypants.enderio.base.machine.baselegacy.SlotDefinition in project EnderIO by SleepyTrousers.

the class AbstractMachineContainer method transferStackInSlot.

@Override
@Nonnull
public ItemStack transferStackInSlot(@Nonnull EntityPlayer entityPlayer, int slotNumber) {
    hasAlreadyJustSuccessfullyTransferedAStack = false;
    SlotDefinition slotDef = te.getSlotDefinition();
    ItemStack copystack = Prep.getEmpty();
    Slot slot = inventorySlots.get(slotNumber);
    if (slot != null && slot.getHasStack()) {
        ItemStack origStack = slot.getStack();
        if (Prep.isValid(origStack)) {
            copystack = origStack.copy();
            boolean merged = false;
            for (SlotRange range : getTargetSlotsForTransfer(slotNumber, slot)) {
                if (mergeItemStack(origStack, range.getStart(), range.getEnd(), range.reverse)) {
                    while (mergeItemStack(origStack, range.getStart(), range.getEnd(), range.reverse)) {
                    }
                    merged = true;
                    break;
                }
            }
            if (!merged) {
                return Prep.getEmpty();
            }
            if (slotDef.isOutputSlot(slot.getSlotIndex())) {
                slot.onSlotChange(origStack, copystack);
            }
            if (Prep.isInvalid(origStack)) {
                slot.putStack(Prep.getEmpty());
            } else {
                slot.onSlotChanged();
            }
            if (origStack.getCount() == copystack.getCount()) {
                return Prep.getEmpty();
            }
            slot.onTake(entityPlayer, origStack);
        }
    }
    hasAlreadyJustSuccessfullyTransferedAStack = true;
    return copystack;
}
Also used : SlotDefinition(crazypants.enderio.base.machine.baselegacy.SlotDefinition) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 2 with SlotDefinition

use of crazypants.enderio.base.machine.baselegacy.SlotDefinition in project EnderIO by SleepyTrousers.

the class LegacyMachineWrapper method computeSlotMappings.

protected void computeSlotMappings() {
    final IoMode ioMode = machine.getIoMode(side);
    if (ioMode != lastIoMode) {
        slots.clear();
        final SlotDefinition slotDefinition = machine.getSlotDefinition();
        for (int i = 0; i < slotDefinition.getNumSlots(); i++) {
            if ((ioMode.canRecieveInput() && slotDefinition.isInputSlot(i)) || ((ioMode.canOutput() && slotDefinition.isOutputSlot(i)))) {
                slots.add(i);
            }
        }
        lastIoMode = ioMode;
    }
}
Also used : SlotDefinition(crazypants.enderio.base.machine.baselegacy.SlotDefinition) IoMode(crazypants.enderio.base.machine.modes.IoMode)

Aggregations

SlotDefinition (crazypants.enderio.base.machine.baselegacy.SlotDefinition)2 IoMode (crazypants.enderio.base.machine.modes.IoMode)1 Nonnull (javax.annotation.Nonnull)1 Slot (net.minecraft.inventory.Slot)1 ItemStack (net.minecraft.item.ItemStack)1