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

The following examples show how to use net.minecraft.inventory.Slot#putStack() . 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: ContainerTFCrasher.java    From TofuCraftReload with MIT License 5 votes vote down vote up
/**
 * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = inventorySlots.get(slotIndex);

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

        switch (slotIndex) {
            case 0:
                if (!this.mergeItemStack(itemstack1, 1, 37, true))
                    return ItemStack.EMPTY;
            default:
                if (!this.mergeItemStack(itemstack1, 0, 0, false)) {
                    return ItemStack.EMPTY;
                }

                slot.onSlotChange(itemstack1, itemstack);
        }


        if (itemstack1.getCount() == 0)
            slot.putStack(ItemStack.EMPTY);
        else
            slot.onSlotChanged();
        if (itemstack1.getCount() == itemstack.getCount())
            return ItemStack.EMPTY;

        slot.onTake(player, itemstack1);
    }
    return itemstack;
}
 
Example 2
Source File: ContainerSpaceLaser.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
	ItemStack stack = null;
	Slot slotObject = (Slot) 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 = stackInSlot.copy();

		//merges the item into player inventory since its in the tileEntity
		if (slot == 0) {
			if (!this.mergeItemStack(stackInSlot, 1, 35, true)) {
				return null;
			}
		}
		//placing it into the tileEntity is possible since its in the player inventory
		//check to make sure it's valid for the slot
		else if (!laserTile.isItemValidForSlot(0, stack) || !this.mergeItemStack(stackInSlot, 0, 1, false)) {
			return null;
		}

		if (stackInSlot.getCount() == 0) {
			slotObject.putStack(null);
		} else {
			slotObject.onSlotChanged();
		}

		if (stackInSlot.getCount() == stack.getCount()) {
			return null;
		}
		slotObject.onTake(player, stackInSlot);
	}

	return stack;
}
 
Example 3
Source File: ContainerArcanePackager.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(slotIndex);

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

        int size = packagerInv.getSizeInventory();
        if (slotIndex < size) {
            if (!this.mergeItemStack(itemstack1, size, this.inventorySlots.size(), true)) {
                return null;
            }
        } else {
            int specialSlot = itemstack1.getItem() == Items.leather ? 9 : itemstack1.getItem() == Items.string ? 10 : -1;
            if(specialSlot != -1 && (packagerInv.getStackInSlot(specialSlot) == null || packagerInv.getStackInSlot(specialSlot).stackSize < 64)) {
                this.mergeItemStack(itemstack1, specialSlot, specialSlot + 1, false);

                if(itemstack1.stackSize == 0) {
                    slot.putStack(null);
                }

                return null;
            } else if (!this.mergeItemStack(itemstack1, 0, size - 3, false)) {
                return null;
            }
        }

        if (itemstack1.stackSize == 0) {
            slot.putStack(null);
        } else {
            slot.onSlotChanged();
        }
    }

    return itemstack;
}
 
Example 4
Source File: ContainerGasLift.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param itemStack
 *            ItemStack to merge into inventory
 * @param start
 *            minimum slot to attempt fill
 * @param end
 *            maximum slot to attempt fill
 * @param backwards
 *            go backwards
 * @return true if stacks merged successfully public boolean
 *         mergeItemStack(itemStack, start, end, backwards)
 */

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){

    ItemStack var3 = null;
    Slot var4 = (Slot)inventorySlots.get(par2);

    if(var4 != null && var4.getHasStack()) {
        ItemStack var5 = var4.getStack();
        var3 = var5.copy();

        if(par2 < 5) {
            if(!mergeItemStack(var5, 5, 41, false)) return null;

            var4.onSlotChange(var5, var3);
        } else {

            if(var5.getItem() == Itemss.machineUpgrade) {
                if(!mergeItemStack(var5, 0, 4, false)) return null;
            }
            if(((Slot)inventorySlots.get(4)).isItemValid(var5)) {
                if(!mergeItemStack(var5, 4, 5, false)) return null;
            }
            var4.onSlotChange(var5, var3);
        }

        if(var5.stackSize == 0) {
            var4.putStack((ItemStack)null);
        } else {
            var4.onSlotChanged();
        }

        if(var5.stackSize == var3.stackSize) return null;

        var4.onPickupFromSlot(par1EntityPlayer, var5);
    }

    return var3;
}
 
Example 5
Source File: ContainerPresent.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {

	ItemStack itemstack = null;
	Slot slot = (Slot) this.inventorySlots.get(p_82846_2_);

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

		if (p_82846_2_ < rows * 9)
		{
			if (!this.mergeItemStack(itemstack1, rows * 9, inventorySlots.size(), true))
			{
				return null;
			}
		}
		else if (!this.mergeItemStack(itemstack1, 0, rows * 9, false))
		{
			return null;
		}

		if (itemstack1.stackSize == 0)
		{
			slot.putStack((ItemStack) null);
		}
		else
		{
			slot.onSlotChanged();
		}
	}

	return itemstack;
}
 
Example 6
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void deleteAllItems(EntityPlayerMP player) {
    for (Slot slot : (List<Slot>) player.openContainer.inventorySlots)
        slot.putStack(null);

    player.updateCraftingInventory(player.openContainer, player.openContainer.getInventory());
}
 
Example 7
Source File: ContainerAirCompressor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param itemStack
 *            ItemStack to merge into inventory
 * @param start
 *            minimum slot to attempt fill
 * @param end
 *            maximum slot to attempt fill
 * @param backwards
 *            go backwards
 * @return true if stacks merged successfully public boolean
 *         mergeItemStack(itemStack, start, end, backwards)
 */

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){

    ItemStack var3 = null;
    Slot var4 = (Slot)inventorySlots.get(par2);

    if(var4 != null && var4.getHasStack()) {
        ItemStack var5 = var4.getStack();
        var3 = var5.copy();

        if(par2 < 5) {
            if(!mergeItemStack(var5, 5, 41, false)) return null;

            var4.onSlotChange(var5, var3);
        } else {
            if(var5.getItem() == Itemss.machineUpgrade) {
                if(!mergeItemStack(var5, 1, 5, false)) return null;
            } else if(TileEntityFurnace.isItemFuel(var5) && !mergeItemStack(var5, 0, 1, false)) return null;
            var4.onSlotChange(var5, var3);
        }

        if(var5.stackSize == 0) {
            var4.putStack((ItemStack)null);
        } else {
            var4.onSlotChanged();
        }

        if(var5.stackSize == var3.stackSize) return null;

        var4.onPickupFromSlot(par1EntityPlayer, var5);
    }

    return var3;
}
 
Example 8
Source File: ContainerHardMEDrive.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer p, int i)
{
	ItemStack itemstack = null;
	Slot slot = (Slot) inventorySlots.get(i);
	if (slot != null && slot.getHasStack())
	{
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();
		if (appeng.api.Util.getCellRegistry().isCellHandled(itemstack))
		{
			if (i < 3)
			{
				if (!mergeItemStack(itemstack1, 3, 38, false))
				{
					return null;
				}
			} else if (!mergeItemStack(itemstack1, 0, 3, false))
			{
				return null;
			}
			if (itemstack1.stackSize == 0)
			{
				slot.putStack(null);
			} else
			{
				slot.onSlotChanged();
			}
		}
	}
	return itemstack;
}
 
Example 9
Source File: NEIClientUtils.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static void deleteItemsOfType(ItemStack type) {
    Container c = getGuiContainer().inventorySlots;
    for (int i = 0; i < c.inventorySlots.size(); i++) {
        Slot slot = c.getSlot(i);
        if (slot == null) {
            continue;
        }

        ItemStack stack = slot.getStack();
        if (!stack.isEmpty() && stack.getItem() == type.getItem() && stack.getItemDamage() == type.getItemDamage()) {
            setSlotContents(i, ItemStack.EMPTY, true);
            slot.putStack(ItemStack.EMPTY);
        }
    }
}
 
Example 10
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@SuppressWarnings ("unchecked")
public static void deleteAllItems(EntityPlayerMP player) {
    for (Slot slot : player.openContainer.inventorySlots) {
        slot.putStack(ItemStack.EMPTY);
    }

    player.sendAllContents(player.openContainer, player.openContainer.getInventory());
}
 
Example 11
Source File: ContainerInfusionClaw.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
    if(((TileInfusionClaw)clawInv).isRunning()) {
        return null;
    }

    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(slotIndex);

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

        if (slotIndex == 0) {
            if (!this.mergeItemStack(itemstack1, 1, this.inventorySlots.size(), true)) {
                return null;
            }
        } else {
            if(!((Slot)inventorySlots.get(0)).isItemValid(itemstack1)) {
                return null;
            }

            if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
                return null;
            }
        }

        if (itemstack1.stackSize == 0) {
            slot.putStack(null);
        } else {
            slot.onSlotChanged();
        }
    }
    return itemstack;
}
 
Example 12
Source File: ContainerBase.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
protected void fillPhantomSlot(Slot slot, ItemStack stackHeld, int mouseButton, int modifier){

        if(!((IPhantomSlot)slot).canAdjust()) {
            return;
        }
        int stackSize = mouseButton == 0 ? stackHeld.getCount() : 1;
        if(stackSize > slot.getSlotStackLimit()) {
            stackSize = slot.getSlotStackLimit();
        }
        ItemStack phantomStack = stackHeld.copy();
        phantomStack.setCount(stackSize);

        slot.putStack(phantomStack);
    }
 
Example 13
Source File: ContainerBarrel.java    From Sakura_mod with MIT License 4 votes vote down vote up
/**
 * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int index)
{
    // 0-4: Contain inventory
    // 5-31: Player inventory
    // 32-41: Hot bar in the player inventory

    ItemStack itemStack = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(index);

    if (slot != null && slot.getHasStack())
    {
        ItemStack itemStack1 = slot.getStack();
        itemStack = itemStack1.copy();

        if (index >= 0 && index <= 4){
            if (!this.mergeItemStack(itemStack1, 5, 41, true))
            {
                return ItemStack.EMPTY;
            }

            slot.onSlotChange(itemStack1, itemStack);
        }
        else if (index >= 5){
        	if (index >= 5 && index < 32){
                if (!this.mergeItemStack(itemStack1, 32, 41, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (index >= 32 && index < 41 && !this.mergeItemStack(itemStack1, 5, 32, false))
            {
                return ItemStack.EMPTY;
            }
        }
        else if (!this.mergeItemStack(itemStack1, 5, 41, false))
        {
            return ItemStack.EMPTY;
        }

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

        if (itemStack1.getCount() == itemStack.getCount())
        {
            return ItemStack.EMPTY;
        }

        slot.onTake(par1EntityPlayer, itemStack1);
    }

    return itemStack;
}
 
Example 14
Source File: ContainerCampfirePot.java    From Sakura_mod with MIT License 4 votes vote down vote up
/**
 * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int index)
{
    // 0-9: Contain inventory
    // 10-36: Player inventory
    // 37-46: Hot bar in the player inventory

    ItemStack itemStack = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(index);

    if (slot != null && slot.getHasStack())
    {
        ItemStack itemStack1 = slot.getStack();
        itemStack = itemStack1.copy();

        if (index >= 0 && index <= 9){
            if (!this.mergeItemStack(itemStack1, 10, 46, true))
            {
                return ItemStack.EMPTY;
            }

            slot.onSlotChange(itemStack1, itemStack);
        }
        else if (index >= 10){
        	if (index >= 10 && index < 37){
                if (!this.mergeItemStack(itemStack1, 37, 46, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (index >= 37 && index < 46 && !this.mergeItemStack(itemStack1, 10, 37, false))
            {
                return ItemStack.EMPTY;
            }
        }
        else if (!this.mergeItemStack(itemStack1, 10, 46, false))
        {
            return ItemStack.EMPTY;
        }

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

        if (itemStack1.getCount() == itemStack.getCount())
        {
            return ItemStack.EMPTY;
        }

        slot.onTake(par1EntityPlayer, itemStack1);
    }

    return itemStack;
}
 
Example 15
Source File: ContainerHelper.java    From AgriCraft with MIT License 4 votes vote down vote up
/**
 * Attempts to merge the given ItemStack into the given slot.
 *
 * @param slot
 * @param stack
 * @return the remainder of the stack, or the empty stack.
 */
public static final ItemStack attemptMergeIntoSlot(@Nonnull Slot slot, @Nonnull ItemStack stack) {
    // Validate the input parameters.
    Preconditions.checkNotNull(slot);
    Preconditions.checkNotNull(stack);

    // If stack is empty, then return.
    if (stack.isEmpty()) {
        return stack;
    }

    // If the slot is not valid for the stack then fail.
    if (!isSlotValidFor(slot, stack)) {
        return stack;
    }

    // The slot max amount.
    final int slotMax = slot.getItemStackLimit(stack);

    // The amount in the slot.
    final int slotAmount;

    // If the slot is not empty get the amount, else set amount to zero.
    if (slot.getHasStack()) {
        slotAmount = slot.getStack().getCount();
    } else {
        slotAmount = 0;
    }

    // Clear out the slot.
    slot.putStack(ItemStack.EMPTY);

    // The total amount we have.
    final int totalAmount = slotAmount + stack.getCount();

    // Calculate the new amounts.
    final int newSlotAmount = Math.min(totalAmount, slotMax);
    final int newStackAmount = totalAmount - newSlotAmount;

    // Create the new slot stack.
    final ItemStack newSlotStack = stack.copy();
    newSlotStack.setCount(newSlotAmount);

    // If the amounts have changed, then do an update.
    stack.setCount(newStackAmount);
    slot.putStack(newSlotStack);
    slot.onSlotChanged();

    // Return the stack.
    return stack;
}
 
Example 16
Source File: ContainerCamoMine.java    From AdvancedMod with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex){
    ItemStack itemstack = null;
    Slot slot = (Slot)inventorySlots.get(slotIndex);

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

        //From here change accordingly...
        if(slotIndex < 6) {
            if(!mergeItemStack(itemstack1, 6, 42, true)) {
                return null;
            }
        } else {
            //Shift click single items only.
            if(itemstack1.stackSize == 1) {
                for(int i = 0; i < 6; i++) {
                    Slot shiftedInSlot = (Slot)inventorySlots.get(i);
                    if(!shiftedInSlot.getHasStack() && shiftedInSlot.isItemValid(itemstack1)) mergeItemStack(itemstack1, i, i + 1, false);
                }
            }
        }
        //...till here.

        if(itemstack1.stackSize == 0) {
            slot.putStack((ItemStack)null);
        } else {
            slot.onSlotChanged();
        }

        if(itemstack1.stackSize == itemstack.stackSize) {
            return null;
        }

        slot.onPickupFromSlot(player, itemstack1);
    }

    return itemstack;
}
 
Example 17
Source File: ECContainer.java    From ExtraCells1 with MIT License 4 votes vote down vote up
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player)
{
	ItemStack stack = null;

	if (mouseButton == 2)
	{
		if (((SlotFake) slot).canAdjust())
		{
			slot.putStack(null);
		}
	} else if (mouseButton == 0 || mouseButton == 1)
	{
		InventoryPlayer playerInv = player.inventory;
		slot.onSlotChanged();
		ItemStack stackSlot = slot.getStack();
		ItemStack stackHeld = playerInv.getItemStack();

		if (stackSlot != null)
		{
			stack = stackSlot.copy();
		}

		if (stackSlot == null)
		{
			if (stackHeld != null && slot.isItemValid(stackHeld))
			{
				fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
			}
		} else if (stackHeld == null)
		{
			adjustPhantomSlot(slot, mouseButton, modifier);
			slot.onPickupFromSlot(player, playerInv.getItemStack());
		} else if (slot.isItemValid(stackHeld))
		{
			if (canStacksMerge(stackSlot, stackHeld))
			{
				adjustPhantomSlot(slot, mouseButton, modifier);
			} else
			{
				fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
			}
		}
	}
	return stack;
}
 
Example 18
Source File: ContainerReactorAccessPort.java    From BigReactors with MIT License 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
	ItemStack stack = null;
	Slot slotObject = (Slot) inventorySlots.get(slot);
	int numSlots = _port.getSizeInventory();

	if(slotObject != null && slotObject.getHasStack())
	{
		ItemStack stackInSlot = slotObject.getStack();
		stack = stackInSlot.copy();

		if(slot < numSlots)
		{
			if(!mergeItemStack(stackInSlot, numSlots, inventorySlots.size(), true))
			{
				return null;
			}
		}
		else if(!mergeItemStack(stackInSlot, 0, numSlots, false))
		{
			return null;
		}

		if(stackInSlot.stackSize == 0)
		{
			slotObject.putStack(null);
		}
		else
		{
			slotObject.onSlotChanged();
		}

		if(stackInSlot.stackSize == stack.stackSize)
		{
			return null;
		}

		slotObject.onPickupFromSlot(player, stackInSlot);
	}

	return stack;
}
 
Example 19
Source File: GT_Container_Item_Destructopack.java    From bartworks with MIT License 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int aSlotIndex) {
    Slot slotObject = (Slot) this.inventorySlots.get(aSlotIndex);
    slotObject.putStack(null);
    return null;
}
 
Example 20
Source File: ContainerPressureChamberInterface.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param itemStack
 *            ItemStack to merge into inventory
 * @param start
 *            minimum slot to attempt fill
 * @param end
 *            maximum slot to attempt fill
 * @param backwards
 *            go backwards
 * @return true if stacks merged successfully public boolean
 *         mergeItemStack(itemStack, start, end, backwards)
 */

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){

    ItemStack var3 = null;
    Slot var4 = (Slot)inventorySlots.get(par2);

    if(var4 != null && var4.getHasStack()) {
        ItemStack var5 = var4.getStack();
        var3 = var5.copy();

        if(par2 < 14) {
            if(!mergeItemStack(var5, 14, 50, false)) return null;
            var4.onSlotChange(var5, var3);
        } else {
            if(var3.getItem() == Itemss.machineUpgrade) {
                if(!mergeItemStack(var5, 1, 5, false)) return null;
            } else {
                if(par2 < 41) {
                    if(!mergeItemStack(var5, 41, 50, false)) return null;
                } else {
                    if(!mergeItemStack(var5, 14, 41, false)) return null;
                }
            }
            var4.onSlotChange(var5, var3);
        }

        if(var5.stackSize == 0) {
            var4.putStack((ItemStack)null);
        } else {
            var4.onSlotChanged();
        }

        if(var5.stackSize == var3.stackSize) return null;

        var4.onPickupFromSlot(par1EntityPlayer, var5);
    }

    return var3;
}