Search in sources :

Example 1 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class LogisticsCraftingTableTileEntity method getOutput.

public ItemStack getOutput(IResource wanted, IRoutedPowerProvider power) {
    boolean isFuzzy = isFuzzy();
    if (cache == null) {
        cacheRecipe();
        if (cache == null) {
            return null;
        }
    }
    int[] toUse = new int[9];
    int[] used = new int[inv.getSizeInventory()];
    outer: for (int i = 0; i < 9; i++) {
        ItemIdentifierStack item = matrix.getIDStackInSlot(i);
        if (item == null) {
            toUse[i] = -1;
            continue;
        }
        ItemIdentifier ident = item.getItem();
        for (int j = 0; j < inv.getSizeInventory(); j++) {
            item = inv.getIDStackInSlot(j);
            if (item == null) {
                continue;
            }
            if (isFuzzy ? (testFuzzy(ident, item, i)) : ident.equalsForCrafting(item.getItem())) {
                if (item.getStackSize() > used[j]) {
                    used[j]++;
                    toUse[i] = j;
                    continue outer;
                }
            }
        }
        //Not enough material
        return null;
    }
    AutoCraftingInventory crafter = new AutoCraftingInventory(placedBy);
    for (int i = 0; i < 9; i++) {
        int j = toUse[i];
        if (j != -1) {
            crafter.setInventorySlotContents(i, inv.getStackInSlot(j));
        }
    }
    IRecipe recipe = cache;
    outputFuzzyFlags.stack = resultInv.getIDStackInSlot(0);
    if (!recipe.matches(crafter, getWorldObj())) {
        if (isFuzzy && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
            recipe = null;
            for (IRecipe r : CraftingUtil.getRecipeList()) {
                if (r.matches(crafter, getWorldObj()) && outputFuzzyFlags.matches(ItemIdentifier.get(r.getRecipeOutput()), IResource.MatchSettings.NORMAL)) {
                    recipe = r;
                    break;
                }
            }
            if (recipe == null) {
                return null;
            }
        } else {
            //Fix MystCraft
            return null;
        }
    }
    ItemStack result = recipe.getCraftingResult(crafter);
    if (result == null) {
        return null;
    }
    if (isFuzzy && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
        if (!outputFuzzyFlags.matches(ItemIdentifier.get(result), IResource.MatchSettings.NORMAL)) {
            return null;
        }
        if (!outputFuzzyFlags.matches(wanted.getAsItem(), IResource.MatchSettings.NORMAL)) {
            return null;
        }
    } else {
        if (!resultInv.getIDStackInSlot(0).getItem().equalsWithoutNBT(ItemIdentifier.get(result))) {
            return null;
        }
        if (!wanted.matches(resultInv.getIDStackInSlot(0).getItem(), IResource.MatchSettings.WITHOUT_NBT)) {
            return null;
        }
    }
    if (!power.useEnergy(Configs.LOGISTICS_CRAFTING_TABLE_POWER_USAGE)) {
        return null;
    }
    crafter = new AutoCraftingInventory(placedBy);
    for (int i = 0; i < 9; i++) {
        int j = toUse[i];
        if (j != -1) {
            crafter.setInventorySlotContents(i, inv.decrStackSize(j, 1));
        }
    }
    result = recipe.getCraftingResult(crafter);
    if (fake == null) {
        fake = MainProxy.getFakePlayer(this);
    }
    result = result.copy();
    SlotCrafting craftingSlot = new SlotCrafting(fake, crafter, resultInv, 0, 0, 0);
    craftingSlot.onPickupFromSlot(fake, result);
    for (int i = 0; i < 9; i++) {
        ItemStack left = crafter.getStackInSlot(i);
        crafter.setInventorySlotContents(i, null);
        if (left != null) {
            left.stackSize = inv.addCompressed(left, false);
            if (left.stackSize > 0) {
                ItemIdentifierInventory.dropItems(worldObj, left, xCoord, yCoord, zCoord);
            }
        }
    }
    for (int i = 0; i < fake.inventory.getSizeInventory(); i++) {
        ItemStack left = fake.inventory.getStackInSlot(i);
        fake.inventory.setInventorySlotContents(i, null);
        if (left != null) {
            left.stackSize = inv.addCompressed(left, false);
            if (left.stackSize > 0) {
                ItemIdentifierInventory.dropItems(worldObj, left, xCoord, yCoord, zCoord);
            }
        }
    }
    return result;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRecipe(net.minecraft.item.crafting.IRecipe) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) SlotCrafting(net.minecraft.inventory.SlotCrafting)

Example 2 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class LogisticsCraftingTableTileEntity method cacheRecipe.

public void cacheRecipe() {
    ItemIdentifier oldTargetType = targetType;
    cache = null;
    resultInv.clearInventorySlotContents(0);
    AutoCraftingInventory craftInv = new AutoCraftingInventory(placedBy);
    for (int i = 0; i < 9; i++) {
        craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
    }
    List<IRecipe> list = new ArrayList<>();
    for (IRecipe r : CraftingUtil.getRecipeList()) {
        if (r.matches(craftInv, getWorldObj())) {
            list.add(r);
        }
    }
    if (list.size() == 1) {
        cache = list.get(0);
        resultInv.setInventorySlotContents(0, cache.getCraftingResult(craftInv));
        targetType = null;
    } else if (list.size() > 1) {
        if (targetType != null) {
            for (IRecipe recipe : list) {
                craftInv = new AutoCraftingInventory(placedBy);
                for (int i = 0; i < 9; i++) {
                    craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
                }
                ItemStack result = recipe.getCraftingResult(craftInv);
                if (result != null && targetType.equals(ItemIdentifier.get(result))) {
                    resultInv.setInventorySlotContents(0, result);
                    cache = recipe;
                    break;
                }
            }
        }
        if (cache == null) {
            for (IRecipe r : list) {
                ItemStack result = r.getCraftingResult(craftInv);
                if (result != null) {
                    cache = r;
                    resultInv.setInventorySlotContents(0, result);
                    targetType = ItemIdentifier.get(result);
                    break;
                }
            }
        }
    } else {
        targetType = null;
    }
    outputFuzzyFlags.stack = resultInv.getIDStackInSlot(0);
    if (((targetType == null && oldTargetType != null) || (targetType != null && !targetType.equals(oldTargetType))) && !guiWatcher.isEmpty() && getWorldObj() != null && MainProxy.isServer(getWorldObj())) {
        MainProxy.sendToPlayerList(PacketHandler.getPacket(CraftingSetType.class).setTargetType(targetType).setTilePos(this), guiWatcher);
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) CraftingSetType(logisticspipes.network.packets.block.CraftingSetType) IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class GuiRequestTable method actionPerformed.

@Override
protected void actionPerformed(GuiButton guibutton) {
    if (guibutton.id == 0 && itemDisplay.getSelectedItem() != null) {
        MainProxy.sendPacketToServer(PacketHandler.getPacket(RequestSubmitPacket.class).setDimension(dimension).setStack(itemDisplay.getSelectedItem().getItem().makeStack(itemDisplay.getRequestCount())).setTilePos(_table.container));
        refreshItems();
    } else if (guibutton.id == 1) {
        itemDisplay.nextPage();
    } else if (guibutton.id == 2) {
        itemDisplay.prevPage();
    } else if (guibutton.id == 3) {
        refreshItems();
    } else if (guibutton.id == 10) {
        itemDisplay.sub(3);
    } else if (guibutton.id == 4) {
        itemDisplay.sub(2);
    } else if (guibutton.id == 5) {
        itemDisplay.sub(1);
    } else if (guibutton.id == 6) {
        itemDisplay.add(1);
    } else if (guibutton.id == 7) {
        itemDisplay.add(2);
    } else if (guibutton.id == 11) {
        itemDisplay.add(3);
    } else if (guibutton.id == 8) {
        GuiCheckBox button = (GuiCheckBox) guibutton;
        Configs.DISPLAY_POPUP = button.change();
        Configs.savePopupState();
    } else if (guibutton.id == 13 && itemDisplay.getSelectedItem() != null) {
        MainProxy.sendPacketToServer(PacketHandler.getPacket(RequestComponentPacket.class).setDimension(dimension).setStack(itemDisplay.getSelectedItem().getItem().makeStack(itemDisplay.getRequestCount())).setTilePos(_table.container));
    } else if (guibutton.id == 9) {
        String displayString = "";
        switch(displayOptions) {
            case Both:
                displayOptions = DisplayOptions.CraftOnly;
                displayString = "Craft";
                break;
            case CraftOnly:
                displayOptions = DisplayOptions.SupplyOnly;
                displayString = "Supply";
                break;
            case SupplyOnly:
                displayOptions = DisplayOptions.Both;
                displayString = "Both";
                break;
        }
        guibutton.displayString = displayString;
        refreshItems();
    } else if (guibutton.id == 14) {
        requestMatrix(1);
    } else if (guibutton.id == 15) {
        requestMatrix(10);
    } else if (guibutton.id == 16) {
        requestMatrix(64);
    } else if (guibutton.id == 17) {
        //hideShowButton
        // moveWhileSmall
        showRequest = !showRequest;
        if (showRequest) {
            xSize = startXSize;
            guiLeft = startLeft;
            for (GuiButton button : moveWhileSmall) {
                button.xPosition -= 105;
            }
            hideShowButton.xPosition -= 90;
        } else {
            xSize = startXSize - 210;
            guiLeft = startLeft + 105;
            for (GuiButton button : moveWhileSmall) {
                button.xPosition += 105;
            }
            hideShowButton.xPosition += 90;
        }
        hideShowButton.displayString = showRequest ? "Hide" : "Show";
        for (GuiButton button : hideWhileSmall) {
            button.visible = showRequest;
        }
        Macrobutton.visible = showRequest;
        orderIdForButton = -1;
    } else if (guibutton.id == 100) {
        extentionControllerLeft.retract();
        setSubGui(new RequestMonitorPopup(_table, orderIdForButton));
    } else if (guibutton.id == 18) {
        MainProxy.sendPacketToServer(PacketHandler.getPacket(DiskRequestConectPacket.class).setPosX(_table.getX()).setPosY(_table.getY()).setPosZ(_table.getZ()));
        setSubGui(new GuiDiskPopup(this));
    } else if (guibutton.id == 20) {
        itemDisplay.cycle();
    } else if (guibutton.id == 21 || guibutton.id == 22) {
        MainProxy.sendPacketToServer(PacketHandler.getPacket(CraftingCycleRecipe.class).setDown(guibutton.id == 22).setTilePos(_table.container));
    } else if (guibutton.id == 30) {
        MainProxy.sendPacketToServer(PacketHandler.getPacket(ClearCraftingGridPacket.class).setTilePos(_table.container));
        _table.cacheRecipe();
    } else if (guibutton.id == 31) {
        ArrayList<ItemIdentifierStack> list = new ArrayList<>(9);
        list.addAll(_table.matrix.getItemsAndCount().entrySet().stream().map(e -> e.getKey().makeStack(e.getValue())).collect(Collectors.toList()));
        for (Pair<ItemStack, Integer> entry : _table.inv) {
            if (entry.getValue1() == null)
                continue;
            int size = entry.getValue1().stackSize;
            ItemIdentifier ident = ItemIdentifier.get(entry.getValue1());
            for (ItemIdentifierStack stack : list) {
                if (!stack.getItem().equals(ident))
                    continue;
                int toUse = Math.min(size, stack.getStackSize());
                stack.lowerStackSize(toUse);
                size -= toUse;
            }
        }
        Iterator<ItemIdentifierStack> iter = list.iterator();
        while (iter.hasNext()) {
            if (iter.next().getStackSize() <= 0) {
                iter.remove();
            }
        }
        if (!list.isEmpty()) {
            MainProxy.sendPacketToServer(PacketHandler.getPacket(RequestSubmitListPacket.class).setIdentList(list).setTilePos(_table.container));
            refreshItems();
        }
    }
}
Also used : GuiDiskPopup(logisticspipes.gui.popup.GuiDiskPopup) ChainAddArrayList(logisticspipes.utils.ChainAddArrayList) ArrayList(java.util.ArrayList) CraftingCycleRecipe(logisticspipes.network.packets.block.CraftingCycleRecipe) ClearCraftingGridPacket(logisticspipes.network.packets.block.ClearCraftingGridPacket) RequestMonitorPopup(logisticspipes.gui.popup.RequestMonitorPopup) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) RequestSubmitListPacket(logisticspipes.network.packets.orderer.RequestSubmitListPacket) SmallGuiButton(logisticspipes.utils.gui.SmallGuiButton) GuiButton(net.minecraft.client.gui.GuiButton) RequestComponentPacket(logisticspipes.network.packets.orderer.RequestComponentPacket) GuiCheckBox(logisticspipes.utils.gui.GuiCheckBox) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class GuiAddMacro method loadMacroItems.

private void loadMacroItems() {
    if ((name1 + name2).equals("")) {
        return;
    }
    NBTTagList inventar = null;
    NBTTagList list = diskProvider.getDisk().getTagCompound().getTagList("macroList", 10);
    for (int i = 0; i < list.tagCount(); i++) {
        NBTTagCompound tag = list.getCompoundTagAt(i);
        String name = tag.getString("name");
        if (name.equals(name1 + name2)) {
            inventar = tag.getTagList("inventar", 10);
            break;
        }
    }
    if (inventar == null) {
        return;
    }
    for (int i = 0; i < inventar.tagCount(); i++) {
        NBTTagCompound itemNBT = inventar.getCompoundTagAt(i);
        int itemID = itemNBT.getInteger("id");
        int itemData = itemNBT.getInteger("data");
        NBTTagCompound tag = null;
        if (itemNBT.hasKey("nbt")) {
            tag = itemNBT.getCompoundTag("nbt");
        }
        ItemIdentifier item = ItemIdentifier.get(Item.getItemById(itemID), itemData, tag);
        int amount = itemNBT.getInteger("amount");
        ItemIdentifierStack stack = new ItemIdentifierStack(item, amount);
        macroItems.add(stack);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 5 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class GuiAddMacro method drawGuiContainerForegroundLayer.

@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
    int panelxSize = 20;
    int panelySize = 20;
    int ppi = 0;
    int column = 0;
    int row = 0;
    int wheel = org.lwjgl.input.Mouse.getDWheel();
    if (wheel != 0) {
        if (wheel < 0) {
            mousebutton = 0;
        } else {
            mousebutton = 1;
        }
        mousePosX = mouseX;
        mousePosY = mouseY;
    }
    tooltip = null;
    for (ItemIdentifierStack itemStack : diskProvider.getItemDisplay()._allItems) {
        ItemIdentifier item = itemStack.getItem();
        if (!itemSearched(item)) {
            continue;
        }
        ppi++;
        if (ppi <= 45 * pageAll) {
            continue;
        }
        if (ppi > 45 * (pageAll + 1)) {
            continue;
        }
        ItemStack st = itemStack.unsafeMakeNormalStack();
        int x = guiLeft + 10 + panelxSize * column;
        int y = guiTop + 18 + panelySize * row;
        if (!super.hasSubGui()) {
            if (mouseX >= x && mouseX < x + panelxSize && mouseY >= y && mouseY < y + panelySize) {
                Gui.drawRect(x - 3, y - 1, x + panelxSize - 3, y + panelySize - 3, Color.getValue(Color.BLACK));
                Gui.drawRect(x - 2, y - 0, x + panelxSize - 4, y + panelySize - 4, Color.getValue(Color.DARKER_GREY));
                tooltip = new Object[] { mouseX + guiLeft, mouseY + guiTop, st, false };
            }
            if (mousePosX != 0 && mousePosY != 0) {
                if ((mousePosX >= x && mousePosX < x + panelxSize && mousePosY >= y && mousePosY < y + panelySize) || (mouseX >= x && mouseX < x + panelxSize && mouseY >= y && mouseY < y + panelySize && (wheeldown != 0 || wheelup != 0))) {
                    boolean handled = false;
                    for (ItemIdentifierStack stack : macroItems) {
                        if (stack.getItem().equals(item)) {
                            if (mousebutton == 0 || wheelup != 0) {
                                stack.setStackSize(stack.getStackSize() + (1 + (wheelup != 0 ? wheelup - 1 : 0)));
                            } else if (mousebutton == 1 || wheeldown != 0) {
                                stack.setStackSize(stack.getStackSize() - (1 + (wheeldown != 0 ? wheeldown - 1 : 0)));
                                if (stack.getStackSize() <= 0) {
                                    macroItems.remove(stack);
                                }
                            }
                            handled = true;
                            break;
                        }
                    }
                    if (!handled) {
                        int i = 0;
                        for (ItemIdentifierStack stack : macroItems) {
                            if (item.equals(stack.getItem()) && item.itemDamage < stack.getItem().itemDamage) {
                                if (mousebutton == 0 || wheelup != 0) {
                                    macroItems.add(i, item.makeStack(1 + (wheelup != 0 ? wheelup - 1 : 0)));
                                } else if (mousebutton == 2) {
                                    macroItems.add(i, item.makeStack(64));
                                }
                                handled = true;
                                break;
                            }
                            if (Item.getIdFromItem(item.item) < Item.getIdFromItem(stack.getItem().item)) {
                                if (mousebutton == 0 || wheelup != 0) {
                                    macroItems.add(i, item.makeStack(1 + (wheelup != 0 ? wheelup - 1 : 0)));
                                } else if (mousebutton == 2) {
                                    macroItems.add(i, item.makeStack(64));
                                }
                                handled = true;
                                break;
                            }
                            i++;
                        }
                        if (!handled) {
                            if (mousebutton == 0 || wheelup != 0) {
                                macroItems.addLast(item.makeStack(1 + (wheelup != 0 ? wheelup - 1 : 0)));
                            } else if (mousebutton == 2) {
                                macroItems.addLast(item.makeStack(64));
                            }
                        }
                    }
                    mousePosX = 0;
                    mousePosY = 0;
                }
            }
        }
        column++;
        if (column == 9) {
            row++;
            column = 0;
        }
    }
    ItemStackRenderer.renderItemIdentifierStackListIntoGui(diskProvider.getItemDisplay()._allItems, this, pageAll, guiLeft + 9, guiTop + 17, 9, 45, panelxSize, panelySize, 100.0F, DisplayAmount.NEVER);
    ppi = 0;
    column = 0;
    row = 0;
    for (ItemIdentifierStack itemStack : macroItems) {
        ItemIdentifier item = itemStack.getItem();
        if (!itemSearched(item)) {
            continue;
        }
        ppi++;
        if (ppi <= 9 * pageMacro) {
            continue;
        }
        if (ppi > 9 * (pageMacro + 1)) {
            continue;
        }
        ItemStack st = itemStack.unsafeMakeNormalStack();
        int x = guiLeft + 10 + panelxSize * column;
        int y = guiTop + 150 + panelySize * row;
        if (!super.hasSubGui()) {
            if (mouseX >= x && mouseX < x + panelxSize && mouseY >= y && mouseY < y + panelySize) {
                tooltip = new Object[] { mouseX + guiLeft, mouseY + guiTop, st };
            }
        }
        column++;
        if (column == 9) {
            row++;
            column = 0;
        }
    }
    ItemStackRenderer.renderItemIdentifierStackListIntoGui(macroItems, this, pageMacro, guiLeft + 10, guiTop + 150, 9, 9, panelxSize, panelySize, 100.0F, DisplayAmount.ALWAYS);
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)69 ItemStack (net.minecraft.item.ItemStack)37 ArrayList (java.util.ArrayList)23 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)23 HashMap (java.util.HashMap)14 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)13 TreeSet (java.util.TreeSet)12 IFilter (logisticspipes.interfaces.routing.IFilter)11 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)11 LinkedList (java.util.LinkedList)10 List (java.util.List)10 Map (java.util.Map)10 SinkReply (logisticspipes.utils.SinkReply)10 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)9 IRouter (logisticspipes.routing.IRouter)9 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 BitSet (java.util.BitSet)8 Entry (java.util.Map.Entry)7 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7