Java Code Examples for net.minecraft.inventory.container.Slot#onSlotChanged()

The following examples show how to use net.minecraft.inventory.container.Slot#onSlotChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerEnderItemStorage.java    From EnderStorage with MIT License 6 votes vote down vote up
@Override
public ItemStack transferStackInSlot(PlayerEntity par1EntityPlayer, int i) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = inventorySlots.get(i);

    if (slot != null && slot.getHasStack()) {
        ItemStack itemstack1 = slot.getStack();
        itemstack = itemstack1.copy();

        int chestSlots = EnderItemStorage.sizes[chestInv.getSize()];
        if (i < chestSlots) {
            if (!mergeItemStack(itemstack1, chestSlots, inventorySlots.size(), true)) {
                return ItemStack.EMPTY;
            }
        } else if (!mergeItemStack(itemstack1, 0, chestSlots, false)) {
            return ItemStack.EMPTY;
        }
        if (itemstack1.getCount() == 0) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }
    }
    return itemstack;
}
 
Example 2
Source File: DryingRackContainer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex)
{
    boolean transferred = false;
    for (int i = startIndex; i < endIndex; i++)
    {
        Slot slot = this.inventorySlots.get(i);
        ItemStack existing = slot.getStack();

        if (existing.getCount() <= 0 && slot.isItemValid(stack))
        {
            slot.putStack(copyWithSize(stack, 1));
            slot.onSlotChanged();
            stack.grow(-1);
            transferred = true;
            if (stack.getCount() <= 0)
                break;
        }
    }
    return transferred;
}
 
Example 3
Source File: ModificationTableContainer.java    From MiningGadgets with MIT License 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(index);
    if (slot != null && slot.getHasStack()) {
        ItemStack stack = slot.getStack();
        itemstack = stack.copy();
        if (index == 0) {
            if (!this.mergeItemStack(stack, 1, this.getInventory().size(), true)) {
                return ItemStack.EMPTY;
            }
            slot.onSlotChange(stack, itemstack);
        } else {
            if (stack.getItem() instanceof MiningGadget) {
                if (!this.mergeItemStack(stack, 0, 1, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (stack.getItem() instanceof UpgradeCard) {
                // Push the item right into the modification table.
                if( ModificationTableCommands.insertButton(this, stack) ) {
                    int maxSize = Math.min(slot.getSlotStackLimit(), stack.getMaxStackSize());
                    int remove = maxSize - itemstack.getCount();
                    stack.shrink(remove == 0 ? 1 : remove);
                    updateUpgradeCache(0);
                }
                else
                    return ItemStack.EMPTY;
            } else if (index < 29) {
                if (!this.mergeItemStack(stack, 29, 38, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (index < 38 && !this.mergeItemStack(stack, 1, 29, false)) {
                return ItemStack.EMPTY;
            }
        }

        if (stack.isEmpty()) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }

        if (stack.getCount() == itemstack.getCount()) {
            return ItemStack.EMPTY;
        }

        slot.onTake(playerIn, stack);
    }

    return itemstack;
}
 
Example 4
Source File: SawmillContainer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index)
{
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(index);

    if (slot != null && slot.getHasStack())
    {
        ItemStack itemstack1 = slot.getStack();
        itemstack = itemstack1.copy();

        if (index == 2)
        {
            if (!this.mergeItemStack(itemstack1, 3, 39, true))
            {
                return ItemStack.EMPTY;
            }

            slot.onSlotChange(itemstack1, itemstack);
        }
        else if (index != 1 && index != 0)
        {
            if (ChoppingRecipe.getRecipe(playerIn.world, itemstack1)
                    .isPresent())
            {
                if (!this.mergeItemStack(itemstack1, 0, 1, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (AbstractFurnaceTileEntity.isFuel(itemstack1))
            {
                if (!this.mergeItemStack(itemstack1, 1, 2, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (index >= 3 && index < 30)
            {
                if (!this.mergeItemStack(itemstack1, 30, 39, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
            {
                return ItemStack.EMPTY;
            }
        }
        else if (!this.mergeItemStack(itemstack1, 3, 39, false))
        {
            return ItemStack.EMPTY;
        }

        if (itemstack1.isEmpty())
        {
            slot.putStack(ItemStack.EMPTY);
        }
        else
        {
            slot.onSlotChanged();
        }

        if (itemstack1.getCount() == itemstack.getCount())
        {
            return ItemStack.EMPTY;
        }

        slot.onTake(playerIn, itemstack1);
    }

    return itemstack;
}
 
Example 5
Source File: DryingRackContainer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex)
{
    Slot slot = this.inventorySlots.get(slotIndex);
    if (slot == null || !slot.getHasStack())
    {
        return ItemStack.EMPTY;
    }

    ItemStack stack = slot.getStack();
    ItemStack stackCopy = stack.copy();

    int startIndex;
    int endIndex;

    if (slotIndex < 4)
    {
        startIndex = 4;
        endIndex = startIndex + 4 * 9;

        if (!mergeItemStack(stack, startIndex, endIndex, false))
        {
            return ItemStack.EMPTY;
        }
    }
    else
    {
        startIndex = 0;
        endIndex = startIndex + 4;

        if (!mergeItemStack(stack, startIndex, endIndex))
        {
            return ItemStack.EMPTY;
        }
    }

    if (stack.getCount() == 0)
    {
        slot.putStack(ItemStack.EMPTY);
    }
    else
    {
        slot.onSlotChanged();
    }

    if (stack.getCount() == stackCopy.getCount())
    {
        return ItemStack.EMPTY;
    }

    slot.onTake(player, stack);
    return stackCopy;
}