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

The following examples show how to use net.minecraft.inventory.Slot#onSlotChange() . 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: 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 2
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 3
Source File: ContainerLiquidHopper.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, 40, false)) return null;

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

            if(var5.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 4
Source File: ContainerKeroseneLamp.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 < 2) {
            if(!mergeItemStack(var5, 2, 38, false)) return null;

            var4.onSlotChange(var5, var3);
        } else {
            if(te.isItemValidForSlot(0, var5) && !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 5
Source File: ContainerUVLightBox.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.emptyPCB && !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 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: 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 8
Source File: ContainerOmnidirectionalHopper.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 {

            if(var5.getItem() == Itemss.machineUpgrade) {
                if(!mergeItemStack(var5, 5, 9, false)) return null;
            } else if(!mergeItemStack(var5, 0, 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: 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 10
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 11
Source File: ContainerTFBattery.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 12
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 13
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 14
Source File: ContainerGasLift.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;
            }
            if(((Slot)inventorySlots.get(4)).isItemValid(var5)) {
                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 15
Source File: ContainerMapleCauldron.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: Contain inventory
    // 1-27: Player inventory
    // 28-36: 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){
            if (!this.mergeItemStack(itemStack1, 1, 37, true))
            {
                return ItemStack.EMPTY;
            }

            slot.onSlotChange(itemStack1, itemStack);
        }
        else if (index >= 1){
        	if (index >= 1 && index < 28){
                if (!this.mergeItemStack(itemStack1, 28, 37, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (index >= 28 && index < 37 && !this.mergeItemStack(itemStack1, 1, 28, false))
            {
                return ItemStack.EMPTY;
            }
        }
        else if (!this.mergeItemStack(itemStack1, 1, 37, 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: 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 17
Source File: ContainerNewBrewingStand.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@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();

		if ((slotIndex < 0 || slotIndex > 2) && slotIndex != 3) {
			if (!ingredientSlot.getHasStack() && ingredientSlot.isItemValid(itemstack1)) {
				if (!mergeItemStack(itemstack1, 3, 4, false))
					return null;
			} else if (PotionSlot.canHoldPotion(itemstack)) {
				if (!mergeItemStack(itemstack1, 0, 3, false))
					return null;
			} else if (slotIndex >= 4 && slotIndex < 31) {
				if (!mergeItemStack(itemstack1, 31, 40, false))
					return null;
			} else if (slotIndex >= 31 && slotIndex < 40) {
				if (!mergeItemStack(itemstack1, 4, 31, false))
					return null;
			} else if (!mergeItemStack(itemstack1, 4, 40, false))
				return null;
		} else {
			if (!mergeItemStack(itemstack1, 4, 40, true))
				return null;

			slot.onSlotChange(itemstack1, itemstack);
		}

		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: 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 19
Source File: ContainerBloomeryFurnace.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) {
            boolean merged = false;
            if (TileEntityBloomeryFurnace.isItemFuel(slotStack))
                merged = mergeItemStack(slotStack, fuelSlot.slotNumber, fuelSlot.slotNumber + 1, false);
            else if (TileEntityBloomeryFurnace.isItemPrimaryInput(slotStack))
                merged = mergeItemStack(slotStack, primarySlot.slotNumber, primarySlot.slotNumber + 1, false);
            else if (TileEntityBloomeryFurnace.isItemSecondaryInput(slotStack))
                merged = mergeItemStack(slotStack, secondarySlot.slotNumber, secondarySlot.slotNumber + 1, false);

            if (!merged) {
                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 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;
}