Search in sources :

Example 1 with AddonMetaItem

use of omtteam.openmodularturrets.items.AddonMetaItem in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretBaseContainer method transferStackInSlot.

@SuppressWarnings("ConstantConditions")
@ParametersAreNonnullByDefault
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    ItemStack stack = ItemStackTools.getEmptyStack();
    Slot slotObject = inventorySlots.get(slot);
    // null checks and checks if the item can be stacked (maxStackSize > 1)
    if (slotObject != null && slotObject.getHasStack()) {
        ItemStack stackInSlot = slotObject.getStack();
        stack = ItemStackTools.safeCopy(stackInSlot);
        // Actual slot start index of turret base
        int slotStart = 36;
        int ammoSlotStart = 100, ammoSlotEnd = 0, addonSlotStart = 100, addonSlotEnd = 0, upgSlotStart = 100, upgSlotEnd = 0;
        // Determine the slot range for each type( According to the class constructor )
        for (int i = slotStart; i < this.inventorySlots.size(); i++) {
            Class slotClass = this.getSlot(i).getClass();
            if (slotClass == Slot.class) {
                ammoSlotStart = Math.min(i, ammoSlotStart);
                ammoSlotEnd = Math.max(i + 1, ammoSlotEnd);
            } else if (slotClass == AddonSlot.class) {
                addonSlotStart = Math.min(i, addonSlotStart);
                addonSlotEnd = Math.max(i + 1, addonSlotEnd);
            } else if (slotClass == UpgradeSlot.class) {
                upgSlotStart = Math.min(i, upgSlotStart);
                upgSlotEnd = Math.max(i + 1, upgSlotEnd);
            }
        }
        // Transfer from player inventory
        if (slot < slotStart) {
            // Priority addon and upgrade slot first
            if (stackInSlot.getItem() instanceof AddonMetaItem) {
                if (!mergeItemStackWithStackLimit(stackInSlot, addonSlotStart, addonSlotEnd, false, this)) {
                    return ItemStackTools.getEmptyStack();
                }
            } else if (stackInSlot.getItem() instanceof UpgradeMetaItem) {
                if (!mergeItemStackWithStackLimit(stackInSlot, upgSlotStart, upgSlotEnd, false, this)) {
                    return ItemStackTools.getEmptyStack();
                }
            } else {
                if (!mergeItemStackWithStackLimit(stackInSlot, slotStart, slotStart + 9, false, this)) {
                    return ItemStackTools.getEmptyStack();
                }
            }
        } else // Transfer from turret base inventory
        {
            if (!mergeItemStackWithStackLimit(stackInSlot, 0, slotStart, false, this)) {
                return ItemStackTools.getEmptyStack();
            }
        }
        if (getStackSize(stackInSlot) == 0) {
            slotObject.putStack(ItemStackTools.getEmptyStack());
        } else {
            slotObject.onSlotChanged();
        }
        if (getStackSize(stackInSlot) == getStackSize(stack)) {
            return ItemStackTools.getEmptyStack();
        }
        slotObject.onSlotChanged();
    }
    return stack;
}
Also used : AddonMetaItem(omtteam.openmodularturrets.items.AddonMetaItem) UpgradeSlot(omtteam.openmodularturrets.client.gui.customSlot.UpgradeSlot) AddonSlot(omtteam.openmodularturrets.client.gui.customSlot.AddonSlot) Slot(net.minecraft.inventory.Slot) AddonSlot(omtteam.openmodularturrets.client.gui.customSlot.AddonSlot) ItemStack(net.minecraft.item.ItemStack) UpgradeMetaItem(omtteam.openmodularturrets.items.UpgradeMetaItem) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)1 Slot (net.minecraft.inventory.Slot)1 ItemStack (net.minecraft.item.ItemStack)1 AddonSlot (omtteam.openmodularturrets.client.gui.customSlot.AddonSlot)1 UpgradeSlot (omtteam.openmodularturrets.client.gui.customSlot.UpgradeSlot)1 AddonMetaItem (omtteam.openmodularturrets.items.AddonMetaItem)1 UpgradeMetaItem (omtteam.openmodularturrets.items.UpgradeMetaItem)1