Search in sources :

Example 1 with ItemIdentifierStack

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

the class LogisticsSolderingTileEntity method tryCraft.

private boolean tryCraft() {
    ItemIdentifierStack content = inv.getIDStackInSlot(10);
    ICraftingResultHandler handler = getHandlerForRecipe();
    ItemStack toAdd = getTagetForRecipe(false);
    if (handler != null) {
        handler.handleCrafting(toAdd);
    }
    if (content != null) {
        if (!content.getItem().equals(toAdd)) {
            return false;
        }
        if (content.getStackSize() + toAdd.stackSize > content.getItem().getMaxStackSize()) {
            return false;
        }
        toAdd.stackSize += content.getStackSize();
    }
    //dummy
    getTagetForRecipe(true);
    inv.setInventorySlotContents(10, toAdd);
    inv.decrStackSize(9, 1);
    inv.markDirty();
    super.markDirty();
    updateInventory();
    return true;
}
Also used : ICraftingResultHandler(logisticspipes.interfaces.ICraftingResultHandler) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemIdentifierStack

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

the class LogisticsSolderingTileEntity method getRecipeForTagetAsItemIdentifierStackList.

public List<ItemIdentifierStack> getRecipeForTagetAsItemIdentifierStackList() {
    LinkedList<ItemIdentifierStack> list = new LinkedList<>();
    ItemStack[] array = getRecipeForTaget();
    if (array != null) {
        for (ItemStack stack : array) {
            if (stack != null) {
                list.addLast(ItemIdentifier.get(stack).makeStack(1));
            } else {
                list.addLast(null);
            }
        }
    }
    return list;
}
Also used : ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Example 3 with ItemIdentifierStack

use of logisticspipes.utils.item.ItemIdentifierStack 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 4 with ItemIdentifierStack

use of logisticspipes.utils.item.ItemIdentifierStack 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 5 with ItemIdentifierStack

use of logisticspipes.utils.item.ItemIdentifierStack 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)

Aggregations

ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)58 ItemStack (net.minecraft.item.ItemStack)21 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)18 ArrayList (java.util.ArrayList)9 Pair (logisticspipes.utils.tuples.Pair)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 LinkedList (java.util.LinkedList)5 NBTTagList (net.minecraft.nbt.NBTTagList)5 List (java.util.List)4 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)4 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)4 DictResource (logisticspipes.request.resources.DictResource)4 IResource (logisticspipes.request.resources.IResource)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)3 LogisticsCraftingTableTileEntity (logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)3 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)3 ItemResource (logisticspipes.request.resources.ItemResource)3 IRouter (logisticspipes.routing.IRouter)3