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

The following examples show how to use net.minecraft.inventory.Slot#onPickupFromSlot() . 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: ContainerGarden.java    From GardenCollection with MIT License 5 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 stacks within inventory and hotbar spaces
        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;
}
 
Example 2
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 3
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 4
Source File: ContainerPneumaticGenerator.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 5
Source File: ContainerElectricCompressor.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 || PneumaticCraftUtils.isIC2Upgrade(var3.getItem())) {
            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: ContainerSecurityStationInventory.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 < 39) {
            if(!mergeItemStack(var5, 39, 74, false)) return null;
            var4.onSlotChange(var5, var3);
        } else {
            if(var3.getItem() == Itemss.machineUpgrade) {
                if(!mergeItemStack(var5, 35, 39, false)) return null;
            } else if(var3.getItem() == Itemss.networkComponent) {
                if(!mergeItemStack(var5, 0, 35, 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 7
Source File: ContainerVacuumPump.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 8
Source File: ContainerAirCannon.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 < 6) {
            if(!mergeItemStack(var5, 6, 41, false)) return null;
            var4.onSlotChange(var5, var3);
        } else {
            if(var3.getItem() == Itemss.GPSTool) {
                if(!mergeItemStack(var5, 1, 2, false)) return null;
            } else if(var3.getItem() == Itemss.machineUpgrade) {
                if(!mergeItemStack(var5, 2, 6, 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 9
Source File: ContainerProgrammer.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 == 0) {
            if(!mergeItemStack(var5, 1, 36, false)) return null;
            var4.onSlotChange(var5, var3);
        } else if(isProgrammableItem(var3)) {
            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 10
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 11
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 12
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 13
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 14
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;
}
 
Example 15
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;
}
 
Example 16
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 17
Source File: ContainerCyaniteReprocessor.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 = _entity.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 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: ContainerEnchantment.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
/**
 * Take a stack from the specified inventory slot.
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
	ItemStack var3 = null;
	Slot var4 = (Slot) inventorySlots.get(index);

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

		if (index == 0) {
			if (!mergeItemStack(var5, 2, 38, true))
				return null;
		} else if (index == 1) {
			if (!mergeItemStack(var5, 2, 38, true))
				return null;
		} else if (var5.getItem() == Items.dye && var5.getItemDamage() == 4) {
			if (!mergeItemStack(var5, 1, 2, true))
				return null;
		} else {
			if (((Slot) inventorySlots.get(0)).getHasStack() || !((Slot) inventorySlots.get(0)).isItemValid(var5))
				return null;

			if (var5.hasTagCompound() && var5.stackSize == 1) {
				((Slot) inventorySlots.get(0)).putStack(var5.copy());
				var5.stackSize = 0;
			} else if (var5.stackSize >= 1) {
				((Slot) inventorySlots.get(0)).putStack(new ItemStack(var5.getItem(), 1, var5.getItemDamage()));
				--var5.stackSize;
			}
		}

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

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

		var4.onPickupFromSlot(playerIn, var5);
	}

	return var3;
}
 
Example 20
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;
}