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

The following examples show how to use net.minecraft.inventory.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: ContainerBackpack.java    From WearableBackpacks with MIT License 6 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
	Slot slot = inventorySlots.get(index);
	if (slot == null) return null;
	ItemStack stack = slot.getStack();
	if (stack.isEmpty()) return ItemStack.EMPTY;
	ItemStack result = stack.copy();
	
	if (index < items.getSlots()) {
		if (!mergeItemStack(stack, items.getSlots(), inventorySlots.size(), true))
			return ItemStack.EMPTY;
	} else if (!mergeItemStack(stack, 0, items.getSlots(), false))
		return ItemStack.EMPTY;
	
	if (stack.isEmpty()) slot.putStack(ItemStack.EMPTY);
	else slot.onSlotChanged();
	
	return result;
}
 
Example 2
Source File: ContainerPressureChamber.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) {
            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 3
Source File: ContainerBlueprintArchive.java    From Cyberware with MIT License 5 votes vote down vote up
/**
 * Take a stack from the specified inventory slot.
 */
@Nullable
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
	ItemStack itemstack = null;
	Slot slot = (Slot)this.inventorySlots.get(index);

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

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

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

	return itemstack;
}
 
Example 4
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 5
Source File: ContainerProgrammableController.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@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, 40, false)) return null;
            var4.onSlotChange(var5, var3);
        } else if(te.isItemValidForSlot(0, var3)) {
            if(!mergeItemStack(var5, 0, 1, false)) return null;
            var4.onSlotChange(var5, var3);
        } else if(var3.getItem() == Itemss.machineUpgrade) {
            if(!mergeItemStack(var5, 1, 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 6
Source File: ContainerCreativeInv.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotIndex) {
    ItemStack transferredStack = ItemStack.EMPTY;
    Slot slot = inventorySlots.get(slotIndex);

    if (slot != null && slot.getHasStack()) {
        ItemStack stack = slot.getStack();
        transferredStack = stack.copy();

        if (stack.getItem() instanceof ItemArmor) {
            ItemArmor armor = (ItemArmor) stack.getItem();
            if (!getSlot(90 + armor.armorType.getIndex()).getHasStack()) {
                getSlot(90 + armor.armorType.getIndex()).putStack(transferredStack);
                slot.putStack(ItemStack.EMPTY);
                return transferredStack;
            }
        }

        if (slotIndex < 54) {
            if (!this.mergeItemStack(stack, 54, 90, true)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.mergeItemStack(stack, 0, 54, false)) {
            return ItemStack.EMPTY;
        }

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

    return transferredStack;
}
 
Example 7
Source File: ContainerBabyChest.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer pPlayer, int pSlot)
{
    ItemStack tStack = null;
    Slot tSlotObject = (Slot) inventorySlots.get(pSlot);

    //null checks and checks if the item can be stacked (maxStackSize > 1)
    if (tSlotObject != null && tSlotObject.getHasStack()) 
    {
        ItemStack tStackInSlot = tSlotObject.getStack();
        tStack = tStackInSlot.copy();

        //merges the item into player inventory since its in the tileEntity
        if (pSlot < _mTileEntity.getSizeInventory())
        {
            if (!mergeItemStack(tStackInSlot, _mTileEntity.getSizeInventory(), 36 + _mTileEntity.getSizeInventory(), true)) {
                return null;
            }
        }
        //places it into the tileEntity is possible since its in the player inventory
        else if (!mergeItemStack(tStackInSlot, 0, _mTileEntity.getSizeInventory(), false)) {
            return null;
        }

        if (tStackInSlot.stackSize == 0) {
            tSlotObject.putStack(null);
        } else {
            tSlotObject.onSlotChanged();
        }


        if (tStackInSlot.stackSize == tStack.stackSize) {
            return null;
        }

        tSlotObject.onPickupFromSlot(pPlayer, tStackInSlot);
    }
    return tStack;
}
 
Example 8
Source File: ContainerThermopneumaticProcessingPlant.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;
            } else {
                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 9
Source File: ContainerBusFluidExport.java    From ExtraCells1 with MIT License 5 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 && slotnumber <= 7)
			{
				shiftItemStack(itemstack, 8, 43);
				return null;
			} else if (slotnumber >= 8 && slotnumber <= 43)
			{
				shiftItemStack(itemstack, 0, 7);
				return null;
			}
			if (itemstack1.stackSize == 0)
			{
				slot.putStack(null);
			} else
			{
				slot.onSlotChanged();
			}
		} else
		{
			return null;
		}
	}
	return itemstack;
}
 
Example 10
Source File: ContainerFirepit.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, 38, true))
				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 11
Source File: ContainerRefinery.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 < 27) {
            if(!mergeItemStack(var5, 27, 36, false)) return null;
            var4.onSlotChange(var5, var3);
        } else {
            if(!mergeItemStack(var5, 0, 27, 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 12
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 13
Source File: ContainerPlasticMixer.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 < 9) {
            if(!mergeItemStack(var5, 9, 45, false)) return null;

            var4.onSlotChange(var5, var3);
        } else {
            for(int i = 0; i < 9; i++) {
                Slot slot = (Slot)inventorySlots.get(i);
                if(slot.isItemValid(var5)) {
                    if(!mergeItemStack(var5, i, i + 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 14
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 15
Source File: ContainerIndustrialWandRecharge.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(par2);

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

        if (par2 == 1) {
            if (!this.mergeItemStack(itemstack1, 2, 38, true)) {
                return null;
            }

            slot.onSlotChange(itemstack1, itemstack);
        } else if (par2 != 0) {
            if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null) {
                if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
                    return null;
                }
            } else if (par2 >= 2 && par2 < 29) {
                if (!this.mergeItemStack(itemstack1, 29, 38, false)) {
                    return null;
                }
            } else if (par2 >= 29 && par2 < 38 && !this.mergeItemStack(itemstack1, 2, 29, false)) {
                return null;
            }
        } else if (!this.mergeItemStack(itemstack1, 2, 38, false)) {
            return null;
        }

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

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

        slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
    }

    return itemstack;
}
 
Example 16
Source File: ContainerSurgery.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);

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

		if (!(slot instanceof SlotSurgery))
		{
		
			
			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;
			}
		}
	

		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: ContainerStoneMortar.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-5: Contain inventory
    // 6-32: Player inventory
    // 33-42: 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 <= 5){
            if (!this.mergeItemStack(itemStack1, 6, 42, true))
            {
                return ItemStack.EMPTY;
            }

            slot.onSlotChange(itemStack1, itemStack);
        }
        else if (index >= 6){
        	if (index >= 6 && index < 33){
                if (!this.mergeItemStack(itemStack1, 33, 42, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (index >= 33 && index < 42 && !this.mergeItemStack(itemStack1, 6, 32, false))
            {
                return ItemStack.EMPTY;
            }
        }
        else if (!this.mergeItemStack(itemStack1, 6, 42, 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 18
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 19
Source File: ContainerChargingStation.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 < 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)){
             * 
             * if(par2 < 28){ if (!this.mergeItemStack(var5, 33, 41, false))
             * return null; }else{ if (!this.mergeItemStack(var5, 5, 33,
             * false)) return null; } }
             */
            else if(!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 20
Source File: ContainerEtheralMacerator.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(par2);

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

        if (par2 == 1) {
            if (!this.mergeItemStack(itemstack1, 2, 38, true)) {
                return null;
            }

            slot.onSlotChange(itemstack1, itemstack);
        } else if (par2 != 0) {
            if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null) {
                if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
                    return null;
                }
            } else if (par2 >= 2 && par2 < 29) {
                if (!this.mergeItemStack(itemstack1, 29, 38, false)) {
                    return null;
                }
            } else if (par2 >= 29 && par2 < 38 && !this.mergeItemStack(itemstack1, 2, 29, false)) {
                return null;
            }
        } else if (!this.mergeItemStack(itemstack1, 3, 38, false)) {
            return null;
        }

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

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

        slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
    }

    return itemstack;
}