Search in sources :

Example 1 with GuiLogisticsCraftingTable

use of logisticspipes.gui.GuiLogisticsCraftingTable in project LogisticsPipes by RS485.

the class LogisticsCraftingOverlayHandler method overlayRecipe.

@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
    TileEntity tile;
    LogisticsBaseGuiScreen gui;
    if (firstGui instanceof GuiLogisticsCraftingTable) {
        tile = ((GuiLogisticsCraftingTable) firstGui)._crafter;
        gui = (GuiLogisticsCraftingTable) firstGui;
    } else if (firstGui instanceof GuiRequestTable) {
        tile = ((GuiRequestTable) firstGui)._table.container;
        gui = (GuiRequestTable) firstGui;
    } else {
        return;
    }
    ItemStack[] stack = new ItemStack[9];
    ItemStack[][] stacks = new ItemStack[9][];
    boolean hasCanidates = false;
    NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
    for (PositionedStack ps : recipe.getIngredientStacks(recipeIndex)) {
        int x = (ps.relx - 25) / 18;
        int y = (ps.rely - 6) / 18;
        int slot = x + y * 3;
        if (x < 0 || x > 2 || y < 0 || y > 2 || slot < 0 || slot > 8) {
            FMLClientHandler.instance().getClient().thePlayer.sendChatMessage("Internal Error. This button is broken.");
            return;
        }
        if (slot < 9) {
            stack[slot] = ps.items[0];
            List<ItemStack> list = new ArrayList<>(Arrays.asList(ps.items));
            Iterator<ItemStack> iter = list.iterator();
            while (iter.hasNext()) {
                ItemStack wildCardCheckStack = iter.next();
                if (wildCardCheckStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
                    iter.remove();
                    wildCardCheckStack.getItem().getSubItems(wildCardCheckStack.getItem(), wildCardCheckStack.getItem().getCreativeTab(), list);
                    iter = list.iterator();
                }
            }
            stacks[slot] = list.toArray(new ItemStack[0]);
            if (stacks[slot].length > 1) {
                hasCanidates = true;
            } else if (stacks[slot].length == 1) {
                stack[slot] = stacks[slot][0];
            }
        }
    }
    if (hasCanidates) {
        gui.setSubGui(new GuiRecipeImport(tile, stacks));
    } else {
        MainProxy.sendPacketToServer(packet.setContent(stack).setPosX(tile.xCoord).setPosY(tile.yCoord).setPosZ(tile.zCoord));
    }
}
Also used : GuiRecipeImport(logisticspipes.gui.popup.GuiRecipeImport) GuiLogisticsCraftingTable(logisticspipes.gui.GuiLogisticsCraftingTable) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) PositionedStack(codechicken.nei.PositionedStack) ArrayList(java.util.ArrayList) TileEntity(net.minecraft.tileentity.TileEntity) GuiRequestTable(logisticspipes.gui.orderer.GuiRequestTable) NEISetCraftingRecipe(logisticspipes.network.packets.NEISetCraftingRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 2 with GuiLogisticsCraftingTable

use of logisticspipes.gui.GuiLogisticsCraftingTable in project LogisticsPipes by RS485.

the class AutoCraftingGui method getClientGui.

@Override
public Object getClientGui(EntityPlayer player) {
    LogisticsCraftingTableTileEntity tile = getTileAs(player.world, LogisticsCraftingTableTileEntity.class);
    if (tile.isFuzzy()) {
        tile.fuzzyFlags.replaceWith(fuzzyFlags);
    }
    tile.targetType = targetType;
    return new GuiLogisticsCraftingTable(player, tile);
}
Also used : GuiLogisticsCraftingTable(logisticspipes.gui.GuiLogisticsCraftingTable) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)

Example 3 with GuiLogisticsCraftingTable

use of logisticspipes.gui.GuiLogisticsCraftingTable in project LogisticsPipes by RS485.

the class MostLikelyRecipeComponentsResponse method processPacket.

@Override
@ClientSideOnlyMethodContent
public void processPacket(EntityPlayer player) {
    GuiScreen firstGui = Minecraft.getMinecraft().currentScreen;
    LogisticsBaseGuiScreen gui;
    if (firstGui instanceof GuiLogisticsCraftingTable) {
        gui = (GuiLogisticsCraftingTable) firstGui;
    } else if (firstGui instanceof GuiRequestTable) {
        gui = (GuiRequestTable) firstGui;
    } else {
        return;
    }
    GuiRecipeImport importGui = null;
    SubGuiScreen sub = gui.getSubGui();
    while (sub != null) {
        if (sub instanceof GuiRecipeImport) {
            importGui = (GuiRecipeImport) sub;
            break;
        }
        sub = sub.getSubGui();
    }
    if (importGui == null)
        return;
    importGui.handleProposePacket(response);
}
Also used : GuiRecipeImport(logisticspipes.gui.popup.GuiRecipeImport) GuiRequestTable(logisticspipes.gui.orderer.GuiRequestTable) GuiLogisticsCraftingTable(logisticspipes.gui.GuiLogisticsCraftingTable) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) SubGuiScreen(logisticspipes.utils.gui.SubGuiScreen) GuiScreen(net.minecraft.client.gui.GuiScreen) SubGuiScreen(logisticspipes.utils.gui.SubGuiScreen) ClientSideOnlyMethodContent(logisticspipes.asm.ClientSideOnlyMethodContent)

Example 4 with GuiLogisticsCraftingTable

use of logisticspipes.gui.GuiLogisticsCraftingTable in project LogisticsPipes by RS485.

the class RecipeTransferHandler method transferRecipe.

@Nullable
@Override
public IRecipeTransferError transferRecipe(@Nonnull DummyContainer container, @Nonnull IRecipeLayout recipeLayout, @Nonnull EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
    LogisticsBaseGuiScreen gui = container.guiHolderForJEI;
    if (gui instanceof GuiLogisticsCraftingTable || gui instanceof GuiRequestTable) {
        TileEntity tile;
        if (gui instanceof GuiLogisticsCraftingTable) {
            tile = ((GuiLogisticsCraftingTable) gui)._crafter;
        } else {
            tile = ((GuiRequestTable) gui)._table.container;
        }
        if (tile == null) {
            return recipeTransferHandlerHelper.createInternalError();
        }
        if (!recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING)) {
            return recipeTransferHandlerHelper.createInternalError();
        }
        NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
        NonNullList<ItemStack> stackList = packet.getStackList();
        ItemStack[][] stacks = new ItemStack[9][];
        boolean hasCanidates = false;
        IGuiItemStackGroup guiItemStackGroup = recipeLayout.getItemStacks();
        Map<Integer, ? extends IGuiIngredient<ItemStack>> guiIngredients = guiItemStackGroup.getGuiIngredients();
        if (doTransfer) {
            for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> ps : guiIngredients.entrySet()) {
                if (!ps.getValue().isInput())
                    continue;
                int slot = ps.getKey() - 1;
                if (slot < 9) {
                    final ItemStack displayedIngredient = ps.getValue().getDisplayedIngredient();
                    stackList.set(slot, displayedIngredient == null ? ItemStack.EMPTY : displayedIngredient);
                    NonNullList<ItemStack> itemCandidateList = NonNullList.create();
                    // add all non-null non-empty ingredients to the itemCandidateList
                    ps.getValue().getAllIngredients().stream().filter(itemStack -> Objects.nonNull(itemStack) && !itemStack.isEmpty()).forEach(itemCandidateList::add);
                    if (!itemCandidateList.isEmpty()) {
                        Iterator<ItemStack> iter = itemCandidateList.iterator();
                        while (iter.hasNext()) {
                            ItemStack wildCardCheckStack = iter.next();
                            if (wildCardCheckStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
                                iter.remove();
                                final CreativeTabs creativeTab = wildCardCheckStack.getItem().getCreativeTab();
                                if (creativeTab != null) {
                                    NonNullList<ItemStack> secondList = NonNullList.create();
                                    wildCardCheckStack.getItem().getSubItems(creativeTab, secondList);
                                    itemCandidateList.addAll(secondList);
                                }
                                iter = itemCandidateList.iterator();
                            }
                        }
                        stacks[slot] = itemCandidateList.toArray(new ItemStack[0]);
                        if (stacks[slot].length > 1) {
                            hasCanidates = true;
                        } else if (stacks[slot].length == 1) {
                            stackList.set(slot, stacks[slot][0]);
                        }
                    }
                }
            }
            if (hasCanidates) {
                gui.setSubGui(new GuiRecipeImport(tile, stacks));
            } else {
                MainProxy.sendPacketToServer(packet.setTilePos(tile));
            }
        }
        return null;
    }
    return recipeTransferHandlerHelper.createInternalError();
}
Also used : DummyContainer(logisticspipes.utils.gui.DummyContainer) NEISetCraftingRecipe(logisticspipes.network.packets.NEISetCraftingRecipe) GuiRecipeImport(logisticspipes.gui.popup.GuiRecipeImport) MainProxy(logisticspipes.proxy.MainProxy) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) ItemStack(net.minecraft.item.ItemStack) OreDictionary(net.minecraftforge.oredict.OreDictionary) Map(java.util.Map) IGuiIngredient(mezz.jei.api.gui.IGuiIngredient) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) IRecipeTransferHandlerHelper(mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper) Nonnull(javax.annotation.Nonnull) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) Nullable(javax.annotation.Nullable) IRecipeTransferError(mezz.jei.api.recipe.transfer.IRecipeTransferError) Iterator(java.util.Iterator) GuiRequestTable(logisticspipes.gui.orderer.GuiRequestTable) PacketHandler(logisticspipes.network.PacketHandler) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) GuiLogisticsCraftingTable(logisticspipes.gui.GuiLogisticsCraftingTable) Objects(java.util.Objects) Stream(java.util.stream.Stream) VanillaRecipeCategoryUid(mezz.jei.api.recipe.VanillaRecipeCategoryUid) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) IRecipeTransferHandler(mezz.jei.api.recipe.transfer.IRecipeTransferHandler) GuiRecipeImport(logisticspipes.gui.popup.GuiRecipeImport) GuiLogisticsCraftingTable(logisticspipes.gui.GuiLogisticsCraftingTable) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) CreativeTabs(net.minecraft.creativetab.CreativeTabs) TileEntity(net.minecraft.tileentity.TileEntity) GuiRequestTable(logisticspipes.gui.orderer.GuiRequestTable) NEISetCraftingRecipe(logisticspipes.network.packets.NEISetCraftingRecipe) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) Nullable(javax.annotation.Nullable)

Aggregations

GuiLogisticsCraftingTable (logisticspipes.gui.GuiLogisticsCraftingTable)4 GuiRequestTable (logisticspipes.gui.orderer.GuiRequestTable)3 GuiRecipeImport (logisticspipes.gui.popup.GuiRecipeImport)3 LogisticsBaseGuiScreen (logisticspipes.utils.gui.LogisticsBaseGuiScreen)3 NEISetCraftingRecipe (logisticspipes.network.packets.NEISetCraftingRecipe)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 PositionedStack (codechicken.nei.PositionedStack)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Stream (java.util.stream.Stream)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ClientSideOnlyMethodContent (logisticspipes.asm.ClientSideOnlyMethodContent)1 LogisticsCraftingTableTileEntity (logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)1 PacketHandler (logisticspipes.network.PacketHandler)1 MainProxy (logisticspipes.proxy.MainProxy)1 DummyContainer (logisticspipes.utils.gui.DummyContainer)1