Java Code Examples for net.minecraft.inventory.Slot

The following examples show how to use net.minecraft.inventory.Slot. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Chisel-2   Source File: GuiChisel.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void drawGuiContainerBackgroundLayer(float f, int mx, int my) {
	drawDefaultBackground();
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

	int i = width - xSize >> 1;
	int j = height - ySize >> 1;

	String texture = "chisel:textures/chisel2Gui.png";

	GeneralClient.bind(texture);
	drawTexturedModalRect(i, j, 0, 0, xSize, ySize);

	int x = (width - xSize) / 2;
	int y = (height - ySize) / 2;

	Slot main = (Slot) container.inventorySlots.get(InventoryChiselSelection.normalSlots);
	if (main.getStack() == null) {
		GuiAutoChisel.drawSlotOverlay(this, x + 14, y + 14, main, 0, ySize, 60);
	}
}
 
Example 2
Source Project: TofuCraftReload   Source File: ContainerTFAggregator.java    License: MIT License 6 votes vote down vote up
public ContainerTFAggregator(InventoryPlayer playerInventory, IInventory machineInventory) {
    this.tileMachine = machineInventory;

    this.addSlotToContainer(new Slot(machineInventory, 0, 45, 32));
    this.addSlotToContainer(new Slot(machineInventory, 1, 115, 32){
        @Override
        public boolean isItemValid(ItemStack stack) {
            return false;
        }
    });


    for (int var3 = 0; var3 < 3; var3++) {
        for (int var4 = 0; var4 < 9; var4++) {
            this.addSlotToContainer(new Slot(playerInventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
        }
    }

    for (int var3 = 0; var3 < 9; var3++) {
        this.addSlotToContainer(new Slot(playerInventory, var3, 8 + var3 * 18, 142));
    }
}
 
Example 3
/**
 * Fired when a control is clicked. This is the equivalent of
 * ActionListener.actionPerformed(ActionEvent e).
 */

@Override
public void actionPerformed(IGuiWidget widget){
    if(widget.getID() == 1) {
        if(filterStat != null) {
            filterStat.closeWindow();
            if(te.filterMode == TileEntityPressureChamberInterface.EnumFilterMode.ITEM) {
                for(int i = 5; i < 14; i++) {
                    ((Slot)inventorySlots.inventorySlots.get(i)).xDisplayPosition += 1000;
                }
            } else if(te.filterMode.ordinal() == TileEntityPressureChamberInterface.EnumFilterMode.values().length - 1) {
                for(int i = 5; i < 14; i++) {
                    ((Slot)inventorySlots.inventorySlots.get(i)).xDisplayPosition -= 1000;
                }
            }
        }
    }
    super.actionPerformed(widget);
}
 
Example 4
Source Project: NotEnoughItems   Source File: NEIController.java    License: MIT License 6 votes vote down vote up
@Override
public boolean mouseScrolled(GuiScreen gui, int mouseX, int mouseY, int scrolled) {
    if (gui instanceof GuiContainer) {
        GuiContainer container = (GuiContainer) gui;
        if (!NEIClientConfig.isEnabled() || GuiInfo.hasCustomSlots(container) || !NEIClientConfig.isMouseScrollTransferEnabled()) {
            return false;
        }

        Point mousePos = getMousePosition();
        Slot mouseover = container.getSlotAtPosition(mousePos.x, mousePos.y);
        if (mouseover != null && mouseover.getHasStack() && !ItemInfo.fastTransferContainerExemptions.contains(container.getClass())) {
            if(NEIClientConfig.shouldInvertMouseScrollTransfer()) {
                scrolled = -scrolled;
            }
            if (scrolled > 0) {
                fastTransferManager.transferItem(container, mouseover.slotNumber);
            } else {
                fastTransferManager.retrieveItem(container, mouseover.slotNumber);
            }
            return true;
        }
    }
    return false;
}
 
Example 5
@Override
protected int getMaxStackSizeFromSlotAndStack(Slot slot, ItemStack stack)
{
    // Our main item inventory or the furnace inventory
    if (slot instanceof SlotItemHandler)
    {
        SlotItemHandler slotItemHandler = (SlotItemHandler) slot;

        if (slotItemHandler.getItemHandler() == this.inventory ||
            slotItemHandler.getItemHandler() == this.tecs.getFurnaceInventory())
        {
            return slotItemHandler.getItemStackLimit(stack);
        }
    }

    // Player inventory, module slots or crafting slots
    return super.getMaxStackSizeFromSlotAndStack(slot, stack);
}
 
Example 6
Source Project: Thermos   Source File: CraftContainer.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void setupWorkbench(net.minecraft.inventory.IInventory top, net.minecraft.inventory.IInventory bottom) {
    // This code copied from ContainerWorkbench
    this.addSlotToContainer(new net.minecraft.inventory.Slot(top, 0, 124, 35));

    int row;
    int col;

    for (row = 0; row < 3; ++row) {
        for (col = 0; col < 3; ++col) {
            this.addSlotToContainer(new net.minecraft.inventory.Slot(top, 1 + col + row * 3, 30 + col * 18, 17 + row * 18));
        }
    }

    for (row = 0; row < 3; ++row) {
        for (col = 0; col < 9; ++col) {
            this.addSlotToContainer(new net.minecraft.inventory.Slot(bottom, col + row * 9 + 9, 8 + col * 18, 84 + row * 18));
        }
    }

    for (col = 0; col < 9; ++col) {
        this.addSlotToContainer(new net.minecraft.inventory.Slot(bottom, col, 8 + col * 18, 142));
    }
    // End copy from ContainerWorkbench
}
 
Example 7
Source Project: CodeChickenCore   Source File: ContainerExtended.java    License: MIT License 6 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotIndex) {
    ItemStack transferredStack = null;
    Slot slot = (Slot) inventorySlots.get(slotIndex);

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

        if (!doMergeStackAreas(slotIndex, stack))
            return null;

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

    return transferredStack;
}
 
Example 8
Source Project: NotEnoughItems   Source File: ContainerCreativeInv.java    License: MIT License 6 votes vote down vote up
public ContainerCreativeInv(EntityPlayer player, ExtendedCreativeInv extraInv) {
    this.player = player;
    InventoryPlayer invPlayer = player.inventory;
    for (int row = 0; row < 6; row++) {
        for (int col = 0; col < 9; col++) {
            addSlotToContainer(new Slot(extraInv, col + row * 9, 8 + col * 18, 5 + row * 18));
        }
    }

    for (int row = 0; row < 3; ++row) {
        for (int col = 0; col < 9; ++col) {
            addSlotToContainer(new Slot(invPlayer, col + row * 9 + 9, 8 + col * 18, 118 + row * 18));
        }
    }

    for (int col = 0; col < 9; ++col) {
        addSlotToContainer(new Slot(invPlayer, col, 8 + col * 18, 176));
    }
    for (int i = 0; i < 4; i++) {
        EntityEquipmentSlot entityEquipmentSlot = VALID_EQUIPMENT_SLOTS[i];
        addSlotToContainer(new SlotArmor(invPlayer, 36 + (3 - i), -15, 23 + i * 18, entityEquipmentSlot));
    }
    addSlotToContainer(new SlotArmor(invPlayer, 40, -15, 23 + 4 * 18, VALID_EQUIPMENT_SLOTS[4], 64));
}
 
Example 9
Source Project: Chisel-2   Source File: ContainerPresent.java    License: GNU General Public License v2.0 6 votes vote down vote up
public ContainerPresent(IInventory player, IInventory chest) {
	lower = chest;
	rows = chest.getSizeInventory() / 9;
	chest.openInventory();
	int a = (rows - 4) * 18;

	for (int d = 0; d < rows; d++) {
		for (int e = 0; e < 9; e++) {
			addSlotToContainer(new Slot(chest, e + d * 9, 8 + e * 18, 18 + d * 18));
		}
	}

	for (int d = 0; d < 3; d++) {
		for (int e = 0; e < 9; e++) {
			addSlotToContainer(new Slot(player, e + d * 9 + 9, 8 + e * 18, 103 + d * 18 + a));
		}
	}

	for (int d = 0; d < 9; d++) {
		addSlotToContainer(new Slot(player, d, 8 + d * 18, 161 + a));
	}
}
 
Example 10
Source Project: bartworks   Source File: BW_Container_HeatedWaterPump.java    License: MIT License 6 votes vote down vote up
public BW_Container_HeatedWaterPump(BW_TileEntity_HeatedWaterPump TILE, EntityPlayer INVENTORY) {
    this.TILE = TILE;
    this.INVENTORY = INVENTORY.inventory;

    this.addSlotToContainer(new BW_FuelSlot(TILE, 0, 56, 53));
    this.addSlotToContainer(new GT_Slot_Render(TILE, 1, 86, 33));
    int i;

    for (i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlotToContainer(new Slot(this.INVENTORY, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
        }
    }

    for (i = 0; i < 9; ++i) {
        this.addSlotToContainer(new Slot(this.INVENTORY, i, 8 + i * 18, 142));
    }
}
 
Example 11
@Override
public List<Slot> getInventorySlots(ContainerCreationStation container)
{
    List<Slot> slots = new ArrayList<Slot>();
    SlotRange playerInventorySlots = container.getPlayerMainInventorySlotRange();
    SlotRange customInventorySlots = container.getCustomInventorySlotRange();

    for (int slotNum = customInventorySlots.first; slotNum < customInventorySlots.lastExc; slotNum++)
    {
        slots.add(container.getSlot(slotNum));
    }

    for (int slotNum = playerInventorySlots.first; slotNum < playerInventorySlots.lastExc; slotNum++)
    {
        slots.add(container.getSlot(slotNum));
    }

    return slots;
}
 
Example 12
Source Project: NotEnoughItems   Source File: FastTransferManager.java    License: MIT License 6 votes vote down vote up
public void throwAll(GuiContainer window, int pickedUpFromSlot) {
    ItemStack held = NEIClientUtils.getHeldItem();
    if (held == null)
        return;

    clickSlot(window, -999);

    generateSlotMap(window.inventorySlots, held);
    Integer zone = slotZoneMap.get(pickedUpFromSlot);
    if(zone == null) //something went wrong and we can't work out where the item was picked up from
        return;

    for (int slotIndex : slotZones.get(zone)) {
        Slot slot = window.inventorySlots.getSlot(slotIndex);
        if (areStacksSameType(held, slot.getStack())) {
            clickSlot(window, slotIndex);
            clickSlot(window, -999);
        }
    }
}
 
Example 13
Source Project: GardenCollection   Source File: ContainerBloomeryFurnace.java    License: MIT License 6 votes vote down vote up
public ContainerBloomeryFurnace (InventoryPlayer inventory, TileEntityBloomeryFurnace tile) {
    tileFurnace = tile;

    primarySlot = addSlotToContainer(new Slot(tile, 0, 56, 17));
    secondarySlot = addSlotToContainer(new Slot(tile, 1, 35, 17));
    fuelSlot = addSlotToContainer(new Slot(tile, 2, 56, 53));

    outputSlot = addSlotToContainer(new SlotBloomeryOutput(inventory.player, tile, 3, 116, 35));

    playerSlots = new ArrayList<Slot>();
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 9; j++)
            playerSlots.add(addSlotToContainer(new Slot(inventory, j + i * 9 + 9, InventoryX + j * 18, InventoryY + i * 18)));
    }

    hotbarSlots = new ArrayList<Slot>();
    for (int i = 0; i < 9; i++)
        hotbarSlots.add(addSlotToContainer(new Slot(inventory, i, InventoryX + i * 18, HotbarY)));
}
 
Example 14
Source Project: ehacks-pro   Source File: ShowContainer.java    License: GNU General Public License v3.0 6 votes vote down vote up
public ShowContainerContainer(ItemStack[] inventory, String containerName) {
    this.containerName = containerName;
    this.inventory = inventory;
    int x = 0;
    int y = 0;
    int page = 0;
    for (int i = 0; i < inventory.length; i++) {
        if (slots.size() == page) {
            slots.add(new ArrayList<>());
        }
        Slot slot = new ShowContainerSlot(inventory[i], i, page == currentPage ? 12 + x * 18 : -2000, page == currentPage ? 18 + y * 18 : -2000);
        slots.get(page).add(slot);
        this.addSlotToContainer(slot);
        this.putStackInSlot(i, inventory[i]);
        x++;
        y += x / 13;
        x %= 13;
        page += y / 11;
        y %= 11;
    }
    if (slots.isEmpty()) {
        slots.add(new ArrayList<>());
    }
}
 
Example 15
Source Project: NotEnoughItems   Source File: NEIController.java    License: MIT License 6 votes vote down vote up
@Override
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
    if (!NEIClientConfig.isEnabled() ||
            GuiInfo.hasCustomSlots(gui) ||
            isSpreading(gui))
        return false;

    Slot slot = GuiContainerManager.getSlotMouseOver(gui);
    if (slot == null)
        return false;

    int slotIndex = slot.slotNumber;

    if (keyCode == Minecraft.getMinecraft().gameSettings.keyBindDrop.getKeyCode() && NEIClientUtils.shiftKey()) {
        FastTransferManager.clickSlot(gui, slotIndex);
        fastTransferManager.throwAll(gui, slotIndex);
        FastTransferManager.clickSlot(gui, slotIndex);

        return true;
    }

    return false;
}
 
Example 16
public ContainerElevator(InventoryPlayer inventoryPlayer, TileEntityElevatorBase te){
    super(te);

    // add the upgrade slots
    addSlotToContainer(new SlotUpgrade(te, 0, 23, 29));
    addSlotToContainer(new SlotUpgrade(te, 1, 41, 29));
    addSlotToContainer(new SlotUpgrade(te, 2, 23, 47));
    addSlotToContainer(new SlotUpgrade(te, 3, 41, 47));

    // Add the camo slots.
    addSlotToContainer(new Slot(te, 4, 77, 36));
    addSlotToContainer(new Slot(te, 5, 77, 55));

    // Add the player's inventory slots to the container
    for(int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) {
        for(int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex) {
            addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 84 + inventoryRowIndex * 18));
        }
    }

    // Add the player's action bar slots to the container
    for(int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex) {
        addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 142));
    }
}
 
Example 17
Source Project: SkyblockAddons   Source File: ItemDropChecker.java    License: MIT License 5 votes vote down vote up
/**
 * Checks if this item can be dropped or sold.
 *
 * @param slot the inventory slot to check
 * @return {@code true} if this item can be dropped or sold, {@code false} otherwise
 */
public boolean canDropItem(Slot slot) {
    if (slot != null && slot.getHasStack()) {
        return canDropItem(slot.getStack());
    }
    else {
        return true;
    }
}
 
Example 18
public ContainerBabyChest (InventoryPlayer pInventoryPlayer, TileEntityBabyChest pTileEntity)
{
    _mTileEntity = pTileEntity;
    addSlotToContainer(new Slot(pTileEntity, 0, 12 + 4 * 18, 8 + 2 * 18));
    _mTileEntity.openInventory();

    bindPlayerInventory(pInventoryPlayer, 184, 184);
}
 
Example 19
@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 20
Source Project: NotEnoughItems   Source File: DefaultOverlayHandler.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean clearIngredients(GuiContainer gui, List<PositionedStack> ingreds) {
    for(PositionedStack pstack : ingreds)
        for(Slot slot : (List<Slot>)gui.inventorySlots.inventorySlots)
            if(slot.xDisplayPosition == pstack.relx+offsetx && slot.yDisplayPosition == pstack.rely+offsety) {
                if(!slot.getHasStack())
                    continue;
                
                FastTransferManager.clickSlot(gui, slot.slotNumber, 0, 1);
                if(slot.getHasStack())
                    return false;
            }
    
    return true;
}
 
Example 21
Source Project: Cyberware   Source File: ContainerSurgery.java    License: MIT License 5 votes vote down vote up
public ContainerSurgery(InventoryPlayer playerInventory, TileEntitySurgery surgery)
{
	this.surgery = surgery;
	
	int row = 0;
	int c = 0;
	for (EnumSlot slot : EnumSlot.values())
	{
		for (int n = 0; n < 8; n++)
		{
			this.addSlotToContainer(new SlotSurgery(surgery.slots, surgery.slotsPlayer, c, 9 + 20 * n, 109, slot));
			c++;
		}
		for (int n = 0; n < LibConstants.WARE_PER_SLOT - 8; n++)
		{
			this.addSlotToContainer(new SlotSurgery(surgery.slots, surgery.slotsPlayer, c, Integer.MIN_VALUE, Integer.MIN_VALUE, slot));
			c++;
		}
		row++;
	}

	for (int l = 0; l < 3; ++l)
	{
		for (int j1 = 0; j1 < 9; ++j1)
		{
			this.addSlotToContainer(new Slot(playerInventory, j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + 37));
		}
	}

	for (int i1 = 0; i1 < 9; ++i1)
	{
		this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 161 + 37));
	}
}
 
Example 22
Source Project: TofuCraftReload   Source File: ContainerTFStorage.java    License: MIT License 5 votes vote down vote up
public ContainerTFStorage(InventoryPlayer playerInventory, IInventory machineInventory) {
    this.tileStorageMachine = machineInventory;

    this.addSlotToContainer(new Slot(machineInventory, 0, 28, 29));

    for (int var3 = 0; var3 < 3; var3++) {
        for (int var4 = 0; var4 < 9; var4++) {
            this.addSlotToContainer(new Slot(playerInventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
        }
    }

    for (int var3 = 0; var3 < 9; var3++) {
        this.addSlotToContainer(new Slot(playerInventory, var3, 8 + var3 * 18, 142));
    }
}
 
Example 23
Source Project: ExtraCells1   Source File: ContainerHardMEDrive.java    License: MIT License 5 votes vote down vote up
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer)
{
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 9; j++)
		{
			addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

	for (int i = 0; i < 9; i++)
	{
		addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
	}
}
 
Example 24
Source Project: TFC2   Source File: PlayerInventory.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void buildInventoryLayout(Container container, InventoryPlayer inventory, int x, int y, boolean freezeSlot, boolean toolBarAfterMainInv)
{
	index = 0;
	if(!toolBarAfterMainInv)
		addToolbarSlots(container, inventory, x, y, freezeSlot);

	for(int i = 0; i < 3; ++i)
	{
		for(int k = 0; k < 9; ++k)
		{
			index =  k + (i+1) * 9;
			addSlotToContainer(container, new Slot(inventory, index, x + k * 18, y + i * 18));
		}
	}

	if(toolBarAfterMainInv)
		addToolbarSlots(container, inventory, x, y, freezeSlot);

	/*ItemStack is = getInventory(inventory.player).extraEquipInventory[0];
	if(is != null)
	{
		if(is.getItem() instanceof ItemQuiver)
		{
			addSlotToContainer(container, new SlotQuiver(containerInv, index++, x + 178, y));
			addSlotToContainer(container, new SlotQuiver(containerInv, index++, x + 178, y+18));
			addSlotToContainer(container, new SlotQuiver(containerInv, index++, x + 178, y+36));
			addSlotToContainer(container, new SlotQuiver(containerInv, index++, x + 178, y+54));
			addSlotToContainer(container, new SlotQuiver(containerInv, index++, x + 196, y));
			addSlotToContainer(container, new SlotQuiver(containerInv, index++, x + 196, y+18));
			addSlotToContainer(container, new SlotQuiver(containerInv, index++, x + 196, y+36));
			addSlotToContainer(container, new SlotQuiver(containerInv, index++, x + 196, y+54));
		}
		loadBagInventory(is, container);
	}*/
}
 
Example 25
private MCCraftingGrid(InventoryCrafting inventory) {
	this.inventory = inventory;
	width = height = (int) Math.sqrt(inventory.getSizeInventory());
	items = new nova.core.item.Item[width * height];
	original = new net.minecraft.item.ItemStack[items.length];
	itemCount = 0;
	update();

	Container container = ReflectionUtil.getCraftingContainer(inventory);
	if (container != null) {
		@SuppressWarnings("unchecked")
		List<Slot> slots = container.inventorySlots;

		EntityPlayer playerOrig = null;
		Optional<Player> player = Optional.empty();

		for (Slot slot : slots) {
			if (slot instanceof SlotCrafting) {
				playerOrig = ReflectionUtil.getCraftingSlotPlayer((SlotCrafting) slot);
				player = WrapUtility.getNovaPlayer(playerOrig);

				if (player.isPresent()) {
					break;
				}
			}
		}

		this.playerOrig = playerOrig;
		this.player = player;
	} else {
		playerOrig = null;
		player = Optional.empty();
	}
}
 
Example 26
Source Project: NotEnoughItems   Source File: NEIController.java    License: MIT License 5 votes vote down vote up
@Override
public void onMouseClickedPost(GuiScreen gui, int mouseX, int mouseY, int button) {
    if (!(gui instanceof GuiContainer) || !NEIClientConfig.isEnabled()) {
        return;
    }
    Slot slot = GuiHelper.getSlotMouseOver(((GuiContainer) gui));
    if (slot != null) {

        ItemStack nowHeld = NEIClientUtils.getHeldItem();

        if (heldTracker != nowHeld) {
            pickedUpFromSlot = slot.slotNumber;
        }
    }
}
 
Example 27
Source Project: NotEnoughItems   Source File: FastTransferManager.java    License: MIT License 5 votes vote down vote up
public void retrieveItem(GuiContainer window, int toSlot) {
    Slot slot = window.inventorySlots.getSlot(toSlot);
    ItemStack slotStack = slot.getStack();
    if (slotStack.isEmpty() || slotStack.getCount() == slot.getSlotStackLimit() || slotStack.getCount() == slotStack.getMaxStackSize()) {
        return;
    }

    generateSlotMap(window.inventorySlots, slotStack);

    Integer destZone = slotZoneMap.get(toSlot);
    if (destZone == null)//slots that don't accept
    {
        return;
    }

    int firstZoneSlot = findShiftClickDestinationSlot(window.inventorySlots, toSlot);
    int firstZone = -1;
    if (firstZoneSlot != -1) {
        Integer integer = slotZoneMap.get(firstZoneSlot);
        if (integer != null) {
            firstZone = integer;
            if (retrieveItemFromZone(window, firstZone, toSlot)) {
                return;
            }
        }
    }

    for (int zone = 0; zone < slotZones.size(); zone++) {
        if (zone == destZone || zone == firstZone) {
            continue;
        }

        if (retrieveItemFromZone(window, zone, toSlot)) {
            return;
        }
    }

    retrieveItemFromZone(window, destZone, toSlot);
}
 
Example 28
Source Project: ForgeHax   Source File: ExtraInventory.java    License: MIT License 5 votes vote down vote up
private static void checkSlotIntegrity(Slot s1, Slot s2) throws ExecutionFailure {
  // compare references (yes i realize im doing ItemStack == ItemStack)
  if (s1 != null
      && s2 != null
      && (s1.inventory != s2.inventory
      || s1.getSlotIndex() != s2.getSlotIndex()
      || s1.slotNumber != s2.slotNumber
      || s1.getStack() != s2.getStack())) {
    fail();
  }
}
 
Example 29
Source Project: TofuCraftReload   Source File: ContainerTFBattery.java    License: 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 30
public ContainerIndustrialWandRecharge(InventoryPlayer invPlayer, TileEntityIndustrialWandRecharge entity) {
    this.charger = entity;

    for (int x = 0; x < 9; x++) {
        this.addSlotToContainer(new Slot(invPlayer, x, 8 + x * 18, 142));
    }

    for (int y = 0; y < 3; y++) {
        for (int x = 0; x < 9; x++) {
            this.addSlotToContainer(new Slot(invPlayer, 9 + x + y * 9, 8 + x * 18, 84 + y * 18));
        }
    }

    this.addSlotToContainer(new Slot(charger, 0, 80, 35));
}