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

The following examples show how to use net.minecraft.inventory.Slot#getHasStack() . 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: ContainerLevelEmitterFluid.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotnumber)
{
	ItemStack itemstack = null;
	Slot slot = (Slot) inventorySlots.get(slotnumber);
	if (slot != null && slot.getHasStack())
	{
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();
		itemstack.stackSize = 1;
		if (tileentity.isItemValidForSlot(0, itemstack1))
		{
			if (slotnumber == 0)
			{
				((Slot) inventorySlots.get(0)).putStack(null);
				return null;
			} else if (slotnumber >= 1 && slotnumber <= 36)
			{
				((Slot) inventorySlots.get(0)).putStack(itemstack);
				return null;
			}
		}
	}
	return null;
}
 
Example 2
Source File: ContainerRoutiduct.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
@Nonnull
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
	Slot slot = inventorySlots.get(index);
	ItemStack stack = slot.getStack().copy();

	if (slot.getHasStack()) {
		int containerSlots = tile.protocol.stacks;
		if (index >= containerSlots) {
			if (!mergeItemStack(stack, 0, containerSlots, false))
				return ItemStack.EMPTY; // Inventory -> Slot
		} else if (!mergeItemStack(stack, containerSlots, containerSlots + 36, true))
			return ItemStack.EMPTY; // Slot -> Inventory
		slot.onSlotChanged();
		if (stack.isEmpty())
			slot.putStack(ItemStack.EMPTY);
		slot.onTake(player, stack);
		return stack;
	}
	return ItemStack.EMPTY;
}
 
Example 3
Source File: ContainerAutoChisel.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
	ItemStack itemStack = null;
	Slot slot = (Slot) this.inventorySlots.get(slotNumber);

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

		// if we are in the auto chisel
		if (slotNumber <= 7) {
			if (!this.mergeItemStack(itemStack1, 8, 42, false)) {
				return null;
			}
			// otherwise just put it in one of the machine slots
		} else if (!this.mergeItemStack(itemStack1, 0, 8, false)) {
			return null;
		}

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

		if (itemStack1.stackSize == itemStack.stackSize) {
			return null;
		}

		slot.onPickupFromSlot(player, itemStack1);
	}

	return itemStack;
}
 
Example 4
Source File: GuiMSU.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onTooltipEvent(ItemTooltipEvent event)
{
    if (Minecraft.getMinecraft().currentScreen instanceof GuiMSU && event.getEntityPlayer() != null &&
        event.getEntityPlayer().openContainer instanceof ContainerMSU)
    {
        ContainerMSU container = (ContainerMSU) event.getEntityPlayer().openContainer;
        GuiMSU gui = (GuiMSU) Minecraft.getMinecraft().currentScreen;
        Slot slot = gui.getSlotUnderMouse();

        if (slot != null && slot.getHasStack() && container.getCustomInventorySlotRange().contains(slot.slotNumber))
        {
            String size = EUStringUtils.formatNumberWithKSeparators(slot.getStack().getCount());
            event.getToolTip().add(size + " " + I18n.format("enderutilities.tooltip.item.items"));
        }
    }
}
 
Example 5
Source File: ContainerUniversalSensor.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 < 4) {
            if(!mergeItemStack(var5, 4, 39, false)) return null;
            var4.onSlotChange(var5, var3);
        } else if(var3.getItem() == Itemss.machineUpgrade || var3.getItem() == Itemss.GPSTool) {
            if(!mergeItemStack(var5, 0, 4, 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 6
Source File: ContainerSeedStorageBase.java    From AgriCraft with MIT License 5 votes vote down vote up
/**
 * Handles shift clicking in the inventory, return the stack that was transferred
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int clickedSlot) {
    ItemStack originalStackInSlot = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(clickedSlot);
    if (slot != null && slot.getHasStack()) {
        ItemStack notMergedStack = slot.getStack();
        originalStackInSlot = notMergedStack.copy();
        //try to move item from the player's inventory into the container
        AgriSeed seed = AgriApi.getSeedRegistry().valueOf(notMergedStack).orElse(null);
        if (seed != null && seed.getStat().isAnalyzed()) {
            ISeedStorageControllable controllable = this.getControllable(notMergedStack).orElse(null);
            if (controllable != null && controllable.hasLockedSeed()) {
                ItemStack locked = controllable.getLockedSeed().map(AgriSeed::toStack).orElse(ItemStack.EMPTY);
                if (notMergedStack.getItem() != locked.getItem() || notMergedStack.getItemDamage() != locked.getItemDamage()) {
                    return ItemStack.EMPTY;
                }
            }
            if (this.addSeedToStorage(notMergedStack)) {
                notMergedStack.setCount(0);
            } else {
                return ItemStack.EMPTY;
            }
        }
        if (notMergedStack.getCount() == 0) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }
        if (notMergedStack.getCount() == originalStackInSlot.getCount()) {
            return ItemStack.EMPTY;
        }
        slot.onTake(player, notMergedStack);
    }
    return originalStackInSlot;
}
 
Example 7
Source File: ContainerTFOven.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 8
Source File: ContainerCookingPot.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called to transfer a stack from one inventory to the other eg. when shift clicking.
 */
@Override
public ItemStack transferStackInSlotTFC(EntityPlayer player, int slotNum)
{
	ItemStack origStack = ItemStack.EMPTY;
	Slot slot = (Slot)this.inventorySlots.get(slotNum);

	if (slot != null && slot.getHasStack())
	{
		ItemStack slotStack = slot.getStack();
		origStack = slotStack.copy();

		if (slotNum < 36)
		{
			if (!this.mergeItemStack(slotStack, 36, inventorySlots.size()-1, false))
				return ItemStack.EMPTY;
		}
		else
		{
			if (!this.mergeItemStack(slotStack, 0, 36, false))
				return ItemStack.EMPTY;
		}

		if (slotStack.getMaxStackSize() <= 0)
			slot.putStack(ItemStack.EMPTY);
		else
			slot.onSlotChanged();

		if (slotStack.getMaxStackSize() == origStack.getMaxStackSize())
			return ItemStack.EMPTY;

		slot.onTake(player, slotStack);
	}

	return origStack;
}
 
Example 9
Source File: ContainerSentryTurret.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 < 8) {
            if(!mergeItemStack(var5, 8, 44, false)) return null;

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

            if(var5.getItem() == Itemss.machineUpgrade) {
                if(!mergeItemStack(var5, 4, 8, false)) return null;
            } else if(var5.getItem() == Itemss.gunAmmo) {
                if(!mergeItemStack(var5, 0, 4, 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 10
Source File: ContainerAssemblyController.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(var5.getItem() == Itemss.assemblyProgram && !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 11
Source File: DefaultOverlayHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean clearIngredients(GuiContainer gui, List<PositionedStack> ingreds) {
    for(PositionedStack pstack : ingreds)
        for(Slot slot : (List<Slot>)gui.inventorySlots.inventorySlots)
            if(slot.xDisplayPosition == pstack.relx+offsetx && slot.yDisplayPosition == pstack.rely+offsety) {
                if(!slot.getHasStack())
                    continue;
                
                FastTransferManager.clickSlot(gui, slot.slotNumber, 0, 1);
                if(slot.getHasStack())
                    return false;
            }
    
    return true;
}
 
Example 12
Source File: ItemDropChecker.java    From SkyblockAddons with MIT License 5 votes vote down vote up
/**
 * Checks if this item can be dropped or sold.
 *
 * @param slot the inventory slot to check
 * @return {@code true} if this item can be dropped or sold, {@code false} otherwise
 */
public boolean canDropItem(Slot slot) {
    if (slot != null && slot.getHasStack()) {
        return canDropItem(slot.getStack());
    }
    else {
        return true;
    }
}
 
Example 13
Source File: GuiWiki.java    From IGW-mod with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void handleMouseClick(Slot slot, int slotId, int mouseButton, ClickType type){
    if(slot != null && slot.getHasStack()) {
        setCurrentFile(slot.getStack());
    }
}
 
Example 14
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 15
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 16
Source File: ContainerScanner.java    From Cyberware with MIT License 4 votes vote down vote up
@Nullable
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
	ItemStack itemstack = null;
	Slot slot = (Slot)this.inventorySlots.get(index);
	boolean doUpdate = false;
	if (slot != null && slot.getHasStack())
	{
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();

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

			//slot.onSlotChange(itemstack1, itemstack);
			//engineering.updateRecipe();
		}
		else if (index > 2)
		{
			if (scanner.slots.isItemValidForSlot(1, itemstack1))
			{
				if (!this.mergeItemStack(itemstack1, 1, 2, false))
				{
					return null;
				}
			}
			else if (scanner.slots.isItemValidForSlot(0, itemstack1))
			{
				if (!this.mergeItemStack(itemstack1, 0, 1, false))
				{
					return null;
				}
			}
			else if (index >= 3 && index < 30)
			{
				if (!this.mergeItemStack(itemstack1, 30, 39, false))
				{
					return null;
				}
			}
			else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
			{
				return null;
			}
		}
		else if (!this.mergeItemStack(itemstack1, 3, 39, false))
		{
			return null;
		}

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

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

		slot.onPickupFromSlot(playerIn, itemstack1);
	}
	
	return itemstack;
}
 
Example 17
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 18
Source File: ContainerAnvil.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Called to transfer a stack from one inventory to the other eg. when shift clicking.
 */
@Override
public ItemStack transferStackInSlotTFC(EntityPlayer player, int slotNum)
{
	ItemStack origStack = ItemStack.EMPTY;
	Slot slot = (Slot)this.inventorySlots.get(slotNum);

	if (slot != null && slot.getHasStack())
	{
		ItemStack slotStack = slot.getStack();
		origStack = slotStack.copy();

		// From pile to inventory
		if (slotNum >= 9 && slotNum < 27)
		{
			if (!this.mergeItemStack(slotStack, 27, inventorySlots.size(), true))
				return ItemStack.EMPTY;
		}
		else if (slotNum < 9)
		{
			if (!this.mergeItemStack(slotStack, 9, 27, true))
				return ItemStack.EMPTY;
		}
		else
		{
			if (!this.mergeItemStack(slotStack, 9, 27, false))
				return ItemStack.EMPTY;
		}

		if (slotStack.getMaxStackSize() <= 0)
			slot.putStack(ItemStack.EMPTY);
		else
			slot.onSlotChanged();

		if (slotStack.getMaxStackSize() == origStack.getMaxStackSize())
			return ItemStack.EMPTY;

		slot.onTake(player, slotStack);
	}

	return origStack;
}
 
Example 19
Source File: ContainerSeedAnalyzer.java    From AgriCraft with MIT License 4 votes vote down vote up
public final boolean hasItem(Slot slot) {
    return slot != null && slot.getHasStack();
}
 
Example 20
Source File: ContainerPotteryTable.java    From GardenCollection with MIT License 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot (EntityPlayer player, int slotIndex) {
    ItemStack itemStack = null;
    Slot slot = (Slot) inventorySlots.get(slotIndex);

    // Assume inventory and hotbar slot IDs are contiguous
    int inventoryStart = playerSlots.get(0).slotNumber;
    int hotbarStart = hotbarSlots.get(0).slotNumber;
    int hotbarEnd = hotbarSlots.get(hotbarSlots.size() - 1).slotNumber + 1;

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

        // Try merge output into inventory and signal change
        if (slotIndex == outputSlot.slotNumber) {
            if (!mergeItemStack(slotStack, inventoryStart, hotbarEnd, true))
                return null;
            slot.onSlotChange(slotStack, itemStack);
        }
        // Try merge stacks within inventory and hotbar spaces
        else if (slotIndex >= inventoryStart && slotIndex < hotbarEnd) {
            if (slotIndex >= inventoryStart && slotIndex < hotbarStart) {
                if (!mergeItemStack(slotStack, hotbarStart, hotbarEnd, false))
                    return null;
            }
            else if (slotIndex >= hotbarStart && slotIndex < hotbarEnd && !this.mergeItemStack(slotStack, inventoryStart, hotbarStart, false))
                return null;
        }
        // Try merge stack into inventory
        else if (!mergeItemStack(slotStack, inventoryStart, hotbarEnd, false))
            return null;

        if (slotStack.stackSize == 0)
            slot.putStack(null);
        else
            slot.onSlotChanged();

        if (slotStack.stackSize == itemStack.stackSize)
            return null;

        slot.onPickupFromSlot(player, slotStack);
    }

    return itemStack;
}