Search in sources :

Example 1 with GuiProvider

use of logisticspipes.network.abstractguis.GuiProvider in project LogisticsPipes by RS485.

the class NewGuiHandler method initialize.

@SuppressWarnings("unchecked")
@SneakyThrows({ IOException.class, InvocationTargetException.class, IllegalAccessException.class, InstantiationException.class })
public static final // Suppression+sneakiness because these shouldn't ever fail, and if they do, it needs to fail.
void initialize() {
    final List<ClassInfo> classes = new ArrayList<>(ClassPath.from(NewGuiHandler.class.getClassLoader()).getTopLevelClassesRecursive("logisticspipes.network.guis"));
    Collections.sort(classes, (o1, o2) -> o1.getSimpleName().compareTo(o2.getSimpleName()));
    NewGuiHandler.guilist = new ArrayList<>(classes.size());
    NewGuiHandler.guimap = new HashMap<>(classes.size());
    int currentid = 0;
    for (ClassInfo c : classes) {
        final Class<?> cls = c.load();
        final GuiProvider instance = (GuiProvider) cls.getConstructors()[0].newInstance(currentid);
        NewGuiHandler.guilist.add(instance);
        NewGuiHandler.guimap.put((Class<? extends GuiProvider>) cls, instance);
        currentid++;
    }
}
Also used : GuiProvider(logisticspipes.network.abstractguis.GuiProvider) PopupGuiProvider(logisticspipes.network.abstractguis.PopupGuiProvider) ArrayList(java.util.ArrayList) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo) SneakyThrows(lombok.SneakyThrows)

Example 2 with GuiProvider

use of logisticspipes.network.abstractguis.GuiProvider 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)

Aggregations

GuiProvider (logisticspipes.network.abstractguis.GuiProvider)2 PopupGuiProvider (logisticspipes.network.abstractguis.PopupGuiProvider)2 ClassInfo (com.google.common.reflect.ClassPath.ClassInfo)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 TargetNotFoundException (logisticspipes.network.exception.TargetNotFoundException)1 LogisticsBaseGuiScreen (logisticspipes.utils.gui.LogisticsBaseGuiScreen)1 SubGuiScreen (logisticspipes.utils.gui.SubGuiScreen)1 SneakyThrows (lombok.SneakyThrows)1 GuiContainer (net.minecraft.client.gui.inventory.GuiContainer)1