Search in sources :

Example 1 with LogisticsBaseGuiScreen

use of logisticspipes.utils.gui.LogisticsBaseGuiScreen 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 LogisticsBaseGuiScreen

use of logisticspipes.utils.gui.LogisticsBaseGuiScreen in project LogisticsPipes by RS485.

the class NewGuiHandler method openGui.

@SideOnly(Side.CLIENT)
public static void openGui(OpenGUIPacket packet, EntityPlayer player) {
    int guiID = packet.getGuiID();
    GuiProvider provider = NewGuiHandler.guilist.get(guiID).template();
    LPDataIOWrapper.provideData(packet.getGuiData(), provider::readData);
    if (provider instanceof PopupGuiProvider && packet.getWindowID() == -2) {
        if (FMLClientHandler.instance().getClient().currentScreen instanceof LogisticsBaseGuiScreen) {
            LogisticsBaseGuiScreen baseGUI = (LogisticsBaseGuiScreen) FMLClientHandler.instance().getClient().currentScreen;
            SubGuiScreen newSub;
            try {
                newSub = (SubGuiScreen) provider.getClientGui(player);
            } catch (TargetNotFoundException e) {
                throw e;
            } catch (Exception e) {
                LogisticsPipes.log.error(packet.getClass().getName());
                LogisticsPipes.log.error(packet.toString());
                throw new RuntimeException(e);
            }
            if (newSub != null) {
                if (!baseGUI.hasSubGui()) {
                    baseGUI.setSubGui(newSub);
                } else {
                    SubGuiScreen canidate = baseGUI.getSubGui();
                    while (canidate.hasSubGui()) {
                        canidate = canidate.getSubGui();
                    }
                    canidate.setSubGui(newSub);
                }
            }
        }
    } else {
        GuiContainer screen;
        try {
            screen = (GuiContainer) provider.getClientGui(player);
        } catch (TargetNotFoundException e) {
            throw e;
        } catch (Exception e) {
            LogisticsPipes.log.error(packet.getClass().getName());
            LogisticsPipes.log.error(packet.toString());
            throw new RuntimeException(e);
        }
        screen.inventorySlots.windowId = packet.getWindowID();
        FMLCommonHandler.instance().showGuiScreen(screen);
    }
}
Also used : GuiProvider(logisticspipes.network.abstractguis.GuiProvider) PopupGuiProvider(logisticspipes.network.abstractguis.PopupGuiProvider) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) TargetNotFoundException(logisticspipes.network.exception.TargetNotFoundException) PopupGuiProvider(logisticspipes.network.abstractguis.PopupGuiProvider) GuiContainer(net.minecraft.client.gui.inventory.GuiContainer) TargetNotFoundException(logisticspipes.network.exception.TargetNotFoundException) SubGuiScreen(logisticspipes.utils.gui.SubGuiScreen) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with LogisticsBaseGuiScreen

use of logisticspipes.utils.gui.LogisticsBaseGuiScreen in project LogisticsPipes by RS485.

the class GuiPacket method getGui.

@SideOnly(Side.CLIENT)
protected <T> T getGui(Class<T> guiClass) {
    GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
    if (currentScreen == null) {
        return null;
    }
    if (guiClass.isAssignableFrom(currentScreen.getClass())) {
        return (T) currentScreen;
    }
    SubGuiScreen subScreen = null;
    if (currentScreen instanceof LogisticsBaseGuiScreen) {
        subScreen = ((LogisticsBaseGuiScreen) currentScreen).getSubGui();
    }
    while (subScreen != null) {
        if (guiClass.isAssignableFrom(subScreen.getClass())) {
            return (T) subScreen;
        }
        subScreen = subScreen.getSubGui();
    }
    return null;
}
Also used : LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) SubGuiScreen(logisticspipes.utils.gui.SubGuiScreen) GuiScreen(net.minecraft.client.gui.GuiScreen) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) SubGuiScreen(logisticspipes.utils.gui.SubGuiScreen) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with LogisticsBaseGuiScreen

use of logisticspipes.utils.gui.LogisticsBaseGuiScreen in project LogisticsPipes by RS485.

the class NewGuiHandler method openGui.

@SideOnly(Side.CLIENT)
public static void openGui(GUIPacket packet, EntityPlayer player) {
    int guiID = packet.getGuiID();
    GuiProvider provider = NewGuiHandler.guilist.get(guiID).template();
    LPDataIOWrapper.provideData(packet.getGuiData(), provider::readData);
    if (provider instanceof PopupGuiProvider && packet.getWindowID() == -2) {
        if (FMLClientHandler.instance().getClient().currentScreen instanceof LogisticsBaseGuiScreen) {
            LogisticsBaseGuiScreen baseGUI = (LogisticsBaseGuiScreen) FMLClientHandler.instance().getClient().currentScreen;
            SubGuiScreen newSub;
            try {
                newSub = (SubGuiScreen) provider.getClientGui(player);
            } catch (TargetNotFoundException e) {
                throw e;
            } catch (Exception e) {
                LogisticsPipes.log.error(packet.getClass().getName());
                LogisticsPipes.log.error(packet.toString());
                throw new RuntimeException(e);
            }
            if (newSub != null) {
                if (!baseGUI.hasSubGui()) {
                    baseGUI.setSubGui(newSub);
                } else {
                    SubGuiScreen canidate = baseGUI.getSubGui();
                    while (canidate.hasSubGui()) {
                        canidate = canidate.getSubGui();
                    }
                    canidate.setSubGui(newSub);
                }
            }
        }
    } else {
        GuiContainer screen;
        try {
            screen = (GuiContainer) provider.getClientGui(player);
        } catch (TargetNotFoundException e) {
            throw e;
        } catch (Exception e) {
            LogisticsPipes.log.error(packet.getClass().getName());
            LogisticsPipes.log.error(packet.toString());
            throw new RuntimeException(e);
        }
        screen.inventorySlots.windowId = packet.getWindowID();
        FMLCommonHandler.instance().showGuiScreen(screen);
    }
}
Also used : GuiProvider(logisticspipes.network.abstractguis.GuiProvider) PopupGuiProvider(logisticspipes.network.abstractguis.PopupGuiProvider) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) TargetNotFoundException(logisticspipes.network.exception.TargetNotFoundException) PopupGuiProvider(logisticspipes.network.abstractguis.PopupGuiProvider) GuiContainer(net.minecraft.client.gui.inventory.GuiContainer) TargetNotFoundException(logisticspipes.network.exception.TargetNotFoundException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubGuiScreen(logisticspipes.utils.gui.SubGuiScreen) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 5 with LogisticsBaseGuiScreen

use of logisticspipes.utils.gui.LogisticsBaseGuiScreen 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)

Aggregations

LogisticsBaseGuiScreen (logisticspipes.utils.gui.LogisticsBaseGuiScreen)8 SubGuiScreen (logisticspipes.utils.gui.SubGuiScreen)5 GuiLogisticsCraftingTable (logisticspipes.gui.GuiLogisticsCraftingTable)3 GuiRequestTable (logisticspipes.gui.orderer.GuiRequestTable)3 GuiRecipeImport (logisticspipes.gui.popup.GuiRecipeImport)3 ItemStack (net.minecraft.item.ItemStack)3 ArrayList (java.util.ArrayList)2 Stream (java.util.stream.Stream)2 Nonnull (javax.annotation.Nonnull)2 PacketHandler (logisticspipes.network.PacketHandler)2 GuiProvider (logisticspipes.network.abstractguis.GuiProvider)2 PopupGuiProvider (logisticspipes.network.abstractguis.PopupGuiProvider)2 TargetNotFoundException (logisticspipes.network.exception.TargetNotFoundException)2 NEISetCraftingRecipe (logisticspipes.network.packets.NEISetCraftingRecipe)2 MainProxy (logisticspipes.proxy.MainProxy)2 FluidIdentifier (logisticspipes.utils.FluidIdentifier)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 PositionedStack (codechicken.nei.PositionedStack)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 Rectangle (java.awt.Rectangle)1