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

The following examples show how to use net.minecraft.inventory.Slot#getItemStackLimit() . 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: GuiContainer.java    From NotEnoughItems with MIT License 6 votes vote down vote up
private void updateActivePotionEffects() {
    ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();

    if (itemstack != null && this.dragSplitting) {
        this.dragSplittingRemnant = itemstack.stackSize;

        for (Slot slot : this.dragSplittingSlots) {
            ItemStack itemstack1 = itemstack.copy();
            int i = slot.getStack() == null ? 0 : slot.getStack().stackSize;
            Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i);

            if (itemstack1.stackSize > itemstack1.getMaxStackSize()) {
                itemstack1.stackSize = itemstack1.getMaxStackSize();
            }

            if (itemstack1.stackSize > slot.getItemStackLimit(itemstack1)) {
                itemstack1.stackSize = slot.getItemStackLimit(itemstack1);
            }

            this.dragSplittingRemnant -= itemstack1.stackSize - i;
        }
    }
}
 
Example 2
Source File: GuiContainer.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private void updateDragSplitting()
{
    ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();

    if (itemstack != null && this.dragSplitting)
    {
        this.dragSplittingRemnant = itemstack.stackSize;
        ItemStack itemstack1;
        int i;

        for (Iterator iterator = this.dragSplittingSlots.iterator(); iterator.hasNext(); this.dragSplittingRemnant -= itemstack1.stackSize - i)
        {
            Slot slot = (Slot)iterator.next();
            itemstack1 = itemstack.copy();
            i = slot.getStack() == null ? 0 : slot.getStack().stackSize;
            Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i);

            if (itemstack1.stackSize > itemstack1.getMaxStackSize())
            {
                itemstack1.stackSize = itemstack1.getMaxStackSize();
            }

            if (itemstack1.stackSize > slot.getItemStackLimit(itemstack1))
            {
                itemstack1.stackSize = slot.getItemStackLimit(itemstack1);
            }
        }
    }
}
 
Example 3
Source File: ContainerLargeStacks.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected int getMaxStackSizeFromSlotAndStack(Slot slot, ItemStack stack)
{
    // Our inventory
    if (slot instanceof SlotItemHandler && ((SlotItemHandler) slot).getItemHandler() == this.inventory)
    {
        return slot.getItemStackLimit(stack);
    }

    // Player inventory
    return super.getMaxStackSizeFromSlotAndStack(slot, stack);
}
 
Example 4
Source File: GuiContainer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
/**
 * Draws the given slot: any item in it, the slot's background, the hovered highlight, etc.
 *
 * @param slotIn The slot to draw
 */
private void drawSlot(Slot slotIn) {
    int i = slotIn.xDisplayPosition;
    int j = slotIn.yDisplayPosition;
    ItemStack itemstack = slotIn.getStack();
    boolean flag = false;
    boolean flag1 = slotIn == this.clickedSlot && this.draggedStack != null && !this.isRightMouseClick;
    ItemStack itemstack1 = this.mc.thePlayer.inventory.getItemStack();
    String s = null;

    if (slotIn == this.clickedSlot && this.draggedStack != null && this.isRightMouseClick && itemstack != null) {
        itemstack = itemstack.copy();
        itemstack.stackSize /= 2;
    } else if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && itemstack1 != null) {
        if (this.dragSplittingSlots.size() == 1) {
            return;
        }

        if (Container.canAddItemToSlot(slotIn, itemstack1, true) && this.inventorySlots.canDragIntoSlot(slotIn)) {
            itemstack = itemstack1.copy();
            flag = true;
            Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack, slotIn.getStack() == null ? 0 : slotIn.getStack().stackSize);

            if (itemstack.stackSize > itemstack.getMaxStackSize()) {
                s = TextFormatting.YELLOW + "" + itemstack.getMaxStackSize();
                itemstack.stackSize = itemstack.getMaxStackSize();
            }

            if (itemstack.stackSize > slotIn.getItemStackLimit(itemstack)) {
                s = TextFormatting.YELLOW + "" + slotIn.getItemStackLimit(itemstack);
                itemstack.stackSize = slotIn.getItemStackLimit(itemstack);
            }
        } else {
            this.dragSplittingSlots.remove(slotIn);
            this.updateActivePotionEffects();
        }
    }

    this.zLevel = 100.0F;
    this.itemRender.zLevel = 100.0F;

    if (itemstack == null && slotIn.canBeHovered()) {
        TextureAtlasSprite textureatlassprite = slotIn.getBackgroundSprite();

        if (textureatlassprite != null) {
            GlStateManager.disableLighting();
            this.mc.getTextureManager().bindTexture(slotIn.getBackgroundLocation());
            this.drawTexturedModalRect(i, j, textureatlassprite, 16, 16);
            GlStateManager.enableLighting();
            flag1 = true;
        }
    }

    if (!flag1) {
        if (flag) {
            drawRect(i, j, i + 16, j + 16, -2130706433);
        }

        GlStateManager.enableDepth();
        manager.renderSlotUnderlay(slotIn);
        manager.drawSlotItem(slotIn, itemstack, i, j, s);
        manager.renderSlotOverlay(slotIn);
        //this.itemRender.renderItemAndEffectIntoGUI(this.mc.thePlayer, itemstack, i, j);
        //this.itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, itemstack, i, j, s);
    }

    this.itemRender.zLevel = 0.0F;
    this.zLevel = 0.0F;
}
 
Example 5
Source File: GuiContainer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private void drawSlot(Slot slotIn)
{
    int i = slotIn.xDisplayPosition;
    int j = slotIn.yDisplayPosition;
    ItemStack itemstack = slotIn.getStack();
    boolean flag = false;
    boolean flag1 = slotIn == this.clickedSlot && this.draggedStack != null && !this.isRightMouseClick;
    ItemStack itemstack1 = this.mc.thePlayer.inventory.getItemStack();
    String s = null;

    if (slotIn == this.clickedSlot && this.draggedStack != null && this.isRightMouseClick && itemstack != null)
    {
        itemstack = itemstack.copy();
        itemstack.stackSize /= 2;
    }
    else if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && itemstack1 != null)
    {
        if (this.dragSplittingSlots.size() == 1)
        {
            return;
        }

        if (Container.canAddItemToSlot(slotIn, itemstack1, true) && this.inventorySlots.canDragIntoSlot(slotIn))
        {
            itemstack = itemstack1.copy();
            flag = true;
            Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack, slotIn.getStack() == null ? 0 : slotIn.getStack().stackSize);

            if (itemstack.stackSize > itemstack.getMaxStackSize())
            {
                s = EnumChatFormatting.YELLOW + "" + itemstack.getMaxStackSize();
                itemstack.stackSize = itemstack.getMaxStackSize();
            }

            if (itemstack.stackSize > slotIn.getItemStackLimit(itemstack))
            {
                s = EnumChatFormatting.YELLOW + "" + slotIn.getItemStackLimit(itemstack);
                itemstack.stackSize = slotIn.getItemStackLimit(itemstack);
            }
        }
        else
        {
            this.dragSplittingSlots.remove(slotIn);
            this.updateDragSplitting();
        }
    }

    this.zLevel = 100.0F;
    this.itemRender.zLevel = 100.0F;

    if (itemstack == null)
    {
        TextureAtlasSprite textureatlassprite = slotIn.getBackgroundSprite();

        if (textureatlassprite != null)
        {
            GlStateManager.disableLighting();
            this.mc.getTextureManager().bindTexture(slotIn.getBackgroundLocation());
            this.drawTexturedModalRect(i, j, textureatlassprite, 16, 16);
            GlStateManager.enableLighting();
            flag1 = true;
        }
    }

    if (!flag1)
    {
        if (flag)
        {
            drawRect(i, j, i + 16, j + 16, -2130706433);
        }

        GlStateManager.enableDepth();
        manager.renderSlotUnderlay(slotIn);
        manager.drawSlotItem(slotIn, itemstack, i, j, s);
        manager.renderSlotOverlay(slotIn);
    }

    this.itemRender.zLevel = 0.0F;
    this.zLevel = 0.0F;
}
 
Example 6
Source File: ContainerTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
/**
 * Handles slot click.
 *  
 * @param mode 0 = basic click, 1 = shift click, 2 = hotbar, 3 = pick block, 4 = drop, 5 = ?, 6 = double click
 */
public ItemStack slotClick(int slotID, int dragType, ClickType clickTypeIn, EntityPlayer p)
{
	if (slotID >= 0 && slotID < this.inventorySlots.size())
	{
		Slot sourceSlot = (Slot) this.inventorySlots.get(slotID);
		ItemStack slotStack = sourceSlot.getStack();

		//This section is for merging foods with differing expirations.
		if(clickTypeIn == ClickType.SWAP && slotStack != null && p.inventory.getItemStack() != null)
		{
			ItemStack itemstack4 = p.inventory.getItemStack();
			if (slotStack.getItem() == itemstack4.getItem() && slotStack.getMetadata() == itemstack4.getMetadata() && ContainerTFC.areCompoundsEqual(slotStack, itemstack4))
			{
				if(slotStack.getItem() instanceof IFood && itemstack4.getItem() instanceof IFood)
				{
					long ex1 = Food.getDecayTimer(slotStack);
					long ex2 = Food.getDecayTimer(itemstack4);
					if(ex2 < ex1)
						Food.setDecayTimer(slotStack, ex2);
				}

				//int l1 = clickedButton == 0 ? itemstack4.getMaxStackSize() : 1;
				int l1 = itemstack4.getMaxStackSize();

				if (l1 > sourceSlot.getItemStackLimit(itemstack4) - slotStack.getMaxStackSize())
				{
					l1 = sourceSlot.getItemStackLimit(itemstack4) - slotStack.getMaxStackSize();
				}

				if (l1 > itemstack4.getMaxStackSize() - slotStack.getMaxStackSize())
				{
					l1 = itemstack4.getMaxStackSize() - slotStack.getMaxStackSize();
				}

				itemstack4.splitStack(l1);

				if (itemstack4.getMaxStackSize() == 0)
				{
					p.inventory.setItemStack(ItemStack.EMPTY);
				}

				slotStack.grow(l1);
				return ItemStack.EMPTY;
			}
			else if (itemstack4.getMaxStackSize() <= sourceSlot.getItemStackLimit(itemstack4))
			{
				sourceSlot.putStack(itemstack4);
				p.inventory.setItemStack(slotStack);
			}
		}

		// Hotbar press to remove from crafting output
		if (clickTypeIn == ClickType.QUICK_MOVE && slotID == 0 && slotStack != null)
		{
			//Removed During Port
			//CraftingHandler.preCraft(p, slotStack, craftMatrix);
		}
		// S and D hotkeys for trimming/combining food
		/*else if (mode == 7 && slotID >= 9 && slotID < 45)
		{
			if (sourceSlot.canTakeStack(p))
			{
				Slot destSlot = (Slot) this.inventorySlots.get(clickedButton);
				destSlot.putStack(slotStack);
				sourceSlot.putStack(null);
				return null;
			}
		}*/
	}

	ItemStack is = super.slotClick(slotID, dragType, clickTypeIn, p);
	//saveContents(is);
	return is;
}
 
Example 7
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 8
Source File: GuiContainerLargeStacks.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void drawSlot(Slot slotIn)
{
    int slotPosX = slotIn.xPos;
    int slotPosY = slotIn.yPos;
    ItemStack stack = slotIn.getStack();
    boolean flag = false;
    boolean flag1 = slotIn == this.clickedSlot && this.draggedStack.isEmpty() == false && this.isRightMouseClick == false;
    ItemStack stackCursor = this.mc.player.inventory.getItemStack();
    String str = null;

    if (slotIn == this.clickedSlot && this.draggedStack.isEmpty() == false && this.isRightMouseClick && stack.isEmpty() == false)
    {
        stack = stack.copy();
        stack.setCount(stack.getCount() / 2);
    }
    else if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && stackCursor.isEmpty() == false)
    {
        if (this.dragSplittingSlots.size() == 1)
        {
            return;
        }

        if (Container.canAddItemToSlot(slotIn, stackCursor, true) && this.inventorySlots.canDragIntoSlot(slotIn))
        {
            stack = stackCursor.copy();
            flag = true;
            Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, stack, slotIn.getStack().getCount());

            if (stack.getCount() > stack.getMaxStackSize())
            {
                str = TextFormatting.YELLOW + "" + stack.getMaxStackSize();
                stack.setCount(stack.getMaxStackSize());
            }

            if (stack.getCount() > slotIn.getItemStackLimit(stack))
            {
                str = TextFormatting.YELLOW + "" + slotIn.getItemStackLimit(stack);
                stack.setCount(slotIn.getItemStackLimit(stack));
            }
        }
        else
        {
            this.dragSplittingSlots.remove(slotIn);
            this.updateDragSplitting();
        }
    }

    this.zLevel = 100.0F;
    this.itemRender.zLevel = 100.0F;

    if (stack.isEmpty())
    {
        TextureAtlasSprite textureatlassprite = slotIn.getBackgroundSprite();

        if (textureatlassprite != null)
        {
            GlStateManager.disableLighting();
            this.mc.getTextureManager().bindTexture(slotIn.getBackgroundLocation());
            this.drawTexturedModalRect(slotPosX, slotPosY, textureatlassprite, 16, 16);
            GlStateManager.enableLighting();
            flag1 = true;
        }
    }

    if (flag1 == false)
    {
        if (flag)
        {
            drawRect(slotPosX, slotPosY, slotPosX + 16, slotPosY + 16, -2130706433);
        }

        GlStateManager.enableDepth();
        this.itemRender.renderItemAndEffectIntoGUI(stack, slotPosX, slotPosY);

        // This slot belongs to a "large stacks" type inventory, render the stack size text scaled to 0.5x
        if (slotIn instanceof SlotItemHandler && this.scaledStackSizeTextInventories.contains(((SlotItemHandler) slotIn).getItemHandler()))
        {
            this.renderLargeStackItemOverlayIntoGUI(this.fontRenderer, stack, slotPosX, slotPosY);
        }
        else
        {
            this.itemRender.renderItemOverlayIntoGUI(this.fontRenderer, stack, slotPosX, slotPosY, str);
        }
    }

    this.itemRender.zLevel = 0.0F;
    this.zLevel = 0.0F;
}