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

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

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

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

                slot.onSlotChange(itemstack1, itemstack);
        }


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

        slot.onTake(player, itemstack1);
    }
    return itemstack;
}
 
Example 3
Source File: ContainerSpaceLaser.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
	ItemStack stack = null;
	Slot slotObject = (Slot) inventorySlots.get(slot);
	//null checks and checks if the item can be stacked (maxStackSize > 1)
	if (slotObject != null && slotObject.getHasStack()) {

		ItemStack stackInSlot = slotObject.getStack();
		stack = stackInSlot.copy();

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

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

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

	return stack;
}
 
Example 4
Source File: ContainerBase.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){

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

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

        if(par2 < playerSlotsStart) {
            if(!mergeItemStack(var5, playerSlotsStart, playerSlotsStart + 36, false)) return ItemStack.EMPTY;

            var4.onSlotChange(var5, var3);
        } else {
            if(!mergeItemStack(var5, 0, playerSlotsStart, false)) return ItemStack.EMPTY;
            var4.onSlotChange(var5, var3);
        }

        if(var5.isEmpty()) {
            var4.putStack(ItemStack.EMPTY);
        } else {
            var4.onSlotChanged();
        }

        if(var5.getCount() == var3.getCount()) return ItemStack.EMPTY;

        var4.onTake(par1EntityPlayer, var5);
    }

    return var3;
}
 
Example 5
Source File: ContainerCart.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();

		// From pile to inventory
		if (slotNum < 36)
		{
			if (!this.mergeItemStack(slotStack, 36, inventorySlots.size(), true))
				return ItemStack.EMPTY;
		}
		else
		{
			if (!this.mergeItemStack(slotStack, 0, 36, false))
				return ItemStack.EMPTY;
		}

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

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

		slot.onTake(player, slotStack);
	}

	return origStack;
}
 
Example 6
Source File: ContainerMinecoprocessor.java    From Minecoprocessors with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
  ItemStack previous = ItemStack.EMPTY;
  Slot slot = this.inventorySlots.get(fromSlot);

  if (slot != null && slot.getHasStack()) {
    ItemStack current = slot.getStack();
    previous = current.copy();

    if (fromSlot == 0) {
      if (!this.mergeItemStack(current, 1, 37, true)) {
        return ItemStack.EMPTY;
      }
    } else {
      if (!this.mergeItemStack(current, 0, 1, true)) {
        return ItemStack.EMPTY;
      }
    }

    slot.onSlotChange(current, previous);

    if (current.isEmpty()) {
      slot.putStack(ItemStack.EMPTY);
    } else {
      slot.onSlotChanged();
    }

    if (current.getCount() == previous.getCount()) {
      return ItemStack.EMPTY;
    }

    slot.onTake(playerIn, current);
  }

  return previous;
}
 
Example 7
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 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: ContainerSeedAnalyzer.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
public final ItemStack transferStackInSlot(EntityPlayer player, int clickedSlot) {

    // Get the clicked Slot.
    Slot slot = this.inventorySlots.get(clickedSlot);

    // There is nothing to move!
    if (!hasItem(slot)) {
        return ItemStack.EMPTY;
    }

    // Fetch the itemstack and a copy.
    ItemStack slotStack = slot.getStack();
    final ItemStack itemstack = slotStack.copy();

    // Determine Slot Range
    final int start;
    final int stop;

    if (clickedSlot == SEED_SLOT_ID || clickedSlot == JOURNAL_SLOT_ID) {
        //try to move item from the analyzer into the player's inventory
        start = 0;
        stop = inventorySlots.size() - 2;
    } else {
        //try to move item from the player's inventory into the analyzer
        start = SEED_SLOT_ID;
        stop = JOURNAL_SLOT_ID + 1;
    }

    if (this.mergeItemStack(slotStack, start, stop, false)) {
        if (slotStack.getCount() == 0) {
            slot.putStack(ItemStack.EMPTY);
        }
        slot.onSlotChanged();
        slot.onTake(player, slotStack);
        return itemstack;
    }

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

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

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

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

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

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

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

        slot.onTake(par1EntityPlayer, itemStack1);
    }

    return itemStack;
}
 
Example 15
Source File: 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 16
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 17
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 18
Source File: ContainerTFAdvancedAggregator.java    From TofuCraftReload 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 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, 5, 41, true)) 
            return ItemStack.EMPTY;
case 1:
            if (!this.mergeItemStack(itemstack1, 5, 41, true)) 
            return ItemStack.EMPTY;
case 2:
            if (!this.mergeItemStack(itemstack1, 5, 41, true)) 
            return ItemStack.EMPTY;
case 3:
            if (!this.mergeItemStack(itemstack1, 5, 41, true)) 
            return ItemStack.EMPTY;
case 4:
            if (!this.mergeItemStack(itemstack1, 5, 41, true)) 
            return ItemStack.EMPTY;
case 5:
            if (!this.mergeItemStack(itemstack1, 5, 41, true)) 
            return ItemStack.EMPTY;
default:
            if (!this.mergeItemStack(itemstack1, 0, 4, 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 19
Source File: ContainerPhysicsInfuser.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int slotIndex) {
    ItemStack itemStack1 = ItemStack.EMPTY;
    Slot slot = inventorySlots.get(slotIndex);

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

        if (slotIndex >= SIZE_INVENTORY) {
            // check if we clicked on the player inventory
            if (slotIndex < SIZE_INVENTORY + 27) {
                // We clicked a player inventory slot
                // First try putting the itemstack into the physics infuser
                if (!mergeItemStack(itemStack2, 0, SIZE_INVENTORY, false)) {
                    // If that failed try putting it into the hotbar
                    if (!mergeItemStack(itemStack2, SIZE_INVENTORY + 27, SIZE_INVENTORY + 35,
                        false)) {
                        // If that failed then we are a failure
                        return ItemStack.EMPTY;
                    }
                }
            } else if (slotIndex < SIZE_INVENTORY + 36
                && !mergeItemStack(itemStack2, 0, SIZE_INVENTORY, false)
                && !mergeItemStack(itemStack2, SIZE_INVENTORY + 1,
                SIZE_INVENTORY + 27, false)) {
                // hotbar slots
                return ItemStack.EMPTY;
            }
        } else if (!mergeItemStack(itemStack2, SIZE_INVENTORY,
            SIZE_INVENTORY + 36, false)) {
            return ItemStack.EMPTY;
        }

        if (itemStack2.stackSize == 0) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }

        if (itemStack2.stackSize == itemStack1.stackSize) {
            return ItemStack.EMPTY;
        }

        slot.onTake(playerIn, itemStack2);
    }

    return itemStack1;
}
 
Example 20
Source File: ContainerBase.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Source: Buildcraft
 */
/* @Override
 public ItemStack slotClick(int slotNum, int modifier, int mouseButton, EntityPlayer player){

     Slot slot = slotNum < 0 ? null : (Slot)inventorySlots.get(slotNum);
     if(slot instanceof IPhantomSlot) {
         return slotClickPhantom(slot, modifier, mouseButton, player);
     }
     return super.slotClick(slotNum, modifier, mouseButton, player);
 }
*/
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player){

    ItemStack stack = ItemStack.EMPTY;

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

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

        if(stackSlot.isEmpty()) {
            if(!stackHeld.isEmpty() && slot.isItemValid(stackHeld)) {
                fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
            }
        } else if(stackHeld.isEmpty()) {
            adjustPhantomSlot(slot, mouseButton, modifier);
            slot.onTake(player, playerInv.getItemStack());
        } else if(slot.isItemValid(stackHeld)) {
            if(canStacksMerge(stackSlot, stackHeld)) {
                adjustPhantomSlot(slot, mouseButton, modifier);
            } else {
                fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
            }
        }
    }
    return stack;
}