Search in sources :

Example 1 with Slot

use of net.minecraft.inventory.container.Slot in project Overloaded by CJ-MC-Mods.

the class ContainerUtil method transferStackInSlot.

@Nonnull
public static ItemStack transferStackInSlot(final PlayerEntity player, final int index, final Container container) {
    ItemStack itemstack = ItemStack.EMPTY;
    final Slot slot = container.slots.get(index);
    if ((slot != null) && slot.hasItem()) {
        final ItemStack itemStack1 = slot.getItem();
        itemstack = itemStack1.copy();
        final int containerSlots = container.slots.size() - player.inventory.items.size();
        if (index < containerSlots) {
            if (!mergeItemStack(itemStack1, containerSlots, container.slots.size(), true, container)) {
                return ItemStack.EMPTY;
            }
        } else if (!mergeItemStack(itemStack1, 0, containerSlots, false, container)) {
            return ItemStack.EMPTY;
        }
        if (itemStack1.getCount() == 0) {
            slot.set(ItemStack.EMPTY);
        } else {
            slot.setChanged();
        }
        if (itemStack1.getCount() == itemstack.getCount()) {
            return ItemStack.EMPTY;
        }
        slot.onTake(player, itemStack1);
    }
    return itemstack;
}
Also used : Slot(net.minecraft.inventory.container.Slot) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 2 with Slot

use of net.minecraft.inventory.container.Slot in project Overloaded by CJ-MC-Mods.

the class ContainerUtil method mergeItemStack.

private static boolean mergeItemStack(final ItemStack stack, final int startIndex, final int endIndex, final boolean reverseDirection, final Container container) {
    boolean flag = false;
    int i = startIndex;
    if (reverseDirection) {
        i = endIndex - 1;
    }
    if (stack.isStackable()) {
        while (!stack.isEmpty()) {
            if (reverseDirection) {
                if (i < startIndex) {
                    break;
                }
            } else if (i >= endIndex) {
                break;
            }
            final Slot slot = container.slots.get(i);
            final ItemStack itemstack = slot.getItem();
            if (slot.mayPlace(stack) && !itemstack.isEmpty() && (itemstack.getItem() == stack.getItem()) && ItemStack.tagMatches(stack, itemstack)) {
                final int j = itemstack.getCount() + stack.getCount();
                final int maxSize = Math.min(slot.getMaxStackSize(), stack.getMaxStackSize());
                if (j <= maxSize) {
                    stack.setCount(0);
                    itemstack.setCount(j);
                    slot.setChanged();
                    flag = true;
                } else if (itemstack.getCount() < maxSize) {
                    stack.shrink(maxSize - itemstack.getCount());
                    itemstack.setCount(maxSize);
                    slot.setChanged();
                    flag = true;
                }
            }
            if (reverseDirection) {
                --i;
            } else {
                ++i;
            }
        }
    }
    if (!stack.isEmpty()) {
        if (reverseDirection) {
            i = endIndex - 1;
        } else {
            i = startIndex;
        }
        while (true) {
            if (reverseDirection) {
                if (i < startIndex) {
                    break;
                }
            } else if (i >= endIndex) {
                break;
            }
            final Slot slot1 = container.slots.get(i);
            final ItemStack itemstack1 = slot1.getItem();
            if (itemstack1.isEmpty() && slot1.mayPlace(stack)) {
                if (stack.getCount() > slot1.getMaxStackSize()) {
                    slot1.set(stack.split(slot1.getMaxStackSize()));
                } else {
                    slot1.set(stack.split(stack.getCount()));
                }
                slot1.setChanged();
                flag = true;
                break;
            }
            if (reverseDirection) {
                --i;
            } else {
                ++i;
            }
        }
    }
    return flag;
}
Also used : Slot(net.minecraft.inventory.container.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Slot

use of net.minecraft.inventory.container.Slot in project BluePower by Qmunity.

the class ContainerProjectTable method clicked.

@Override
public ItemStack clicked(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) {
    boolean clickTypeCrafting = slotId == 0 && slots.get(slotId).hasItem() && (clickTypeIn.equals(ClickType.PICKUP) || clickTypeIn.equals(ClickType.QUICK_MOVE));
    // Save the Matrix State before Crafting
    NonNullList<ItemStack> beforeAction = NonNullList.withSize(9, ItemStack.EMPTY);
    if (clickTypeCrafting) {
        for (int i = 1; i < 10; ++i) {
            Slot matrixSlot = slots.get(i);
            ItemStack matrixStack = matrixSlot.getItem();
            beforeAction.set(i - 1, matrixStack);
        }
    }
    ItemStack itemStack = super.clicked(slotId, dragType, clickTypeIn, player);
    // Try to pull from the Project Table Inventory if the last of an item for a recipe.
    if (clickTypeCrafting) {
        for (int i = 1; i < 10; ++i) {
            ItemStack beforeStack = beforeAction.get(i - 1);
            Slot matrixSlot = slots.get(i);
            ItemStack matrixStack = matrixSlot.getItem();
            if (matrixStack.getCount() == 0 && beforeStack.getCount() != 0) {
                for (int ptSlot = 10; ptSlot < 28; ++ptSlot) {
                    Slot inventorySlot = slots.get(ptSlot);
                    ItemStack ptStack = inventorySlot.getItem();
                    if (ptStack.getItem() == beforeStack.getItem() && ptStack.getTag() == beforeStack.getTag()) {
                        ptStack.setCount(ptStack.getCount() - 1);
                        inventorySlot.set(ptStack);
                        beforeStack.setCount(1);
                        matrixSlot.set(beforeStack);
                        break;
                    }
                }
            }
        }
    }
    return itemStack;
}
Also used : Slot(net.minecraft.inventory.container.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 4 with Slot

use of net.minecraft.inventory.container.Slot in project BluePower by Qmunity.

the class ContainerSeedBag method quickMoveStack.

@Override
public ItemStack quickMoveStack(PlayerEntity par1EntityPlayer, int par2) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = (Slot) this.slots.get(par2);
    if (slot != null && slot.hasItem()) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.copy();
        if (par2 < 9) {
            if (!this.moveItemStackTo(itemstack1, 9, 45, true)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.moveItemStackTo(itemstack1, 0, 9, false)) {
            return ItemStack.EMPTY;
        }
        if (itemstack1.getCount() == 0) {
            slot.set(ItemStack.EMPTY);
        } else {
            slot.setChanged();
        }
        if (itemstack1.getCount() == itemstack.getCount()) {
            return ItemStack.EMPTY;
        }
        slot.onQuickCraft(itemstack, itemstack1);
    }
    return itemstack;
}
Also used : Slot(net.minecraft.inventory.container.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 5 with Slot

use of net.minecraft.inventory.container.Slot in project BluePower by Qmunity.

the class ContainerRelay method quickMoveStack.

@Override
public ItemStack quickMoveStack(PlayerEntity player, int par2) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = (Slot) slots.get(par2);
    if (slot != null && slot.hasItem()) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.copy();
        if (par2 < 9) {
            if (!moveItemStackTo(itemstack1, 9, 45, true))
                return ItemStack.EMPTY;
        } else if (!moveItemStackTo(itemstack1, 0, 9, false)) {
            return ItemStack.EMPTY;
        }
        if (itemstack1.getCount() == 0) {
            slot.set(ItemStack.EMPTY);
        } else {
            slot.setChanged();
        }
        if (itemstack1.getCount() != itemstack.getCount()) {
            slot.onQuickCraft(itemstack, itemstack1);
        } else {
            return ItemStack.EMPTY;
        }
    }
    return itemstack;
}
Also used : Slot(net.minecraft.inventory.container.Slot) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Slot (net.minecraft.inventory.container.Slot)21 ItemStack (net.minecraft.item.ItemStack)21 Nonnull (javax.annotation.Nonnull)2 IAgriJournalItem (com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem)1 IAgriSeedItem (com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem)1