Search in sources :

Example 1 with PopupGuiProvider

use of logisticspipes.network.abstractguis.PopupGuiProvider 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 2 with PopupGuiProvider

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

the class NewGuiHandler method openGui.

public static void openGui(GuiProvider guiProvider, EntityPlayer oPlayer) {
    if (!(oPlayer instanceof EntityPlayerMP)) {
        throw new UnsupportedOperationException("Gui can only be opened on the server side");
    }
    EntityPlayerMP player = (EntityPlayerMP) oPlayer;
    Container container = guiProvider.getContainer(player);
    if (container == null) {
        if (guiProvider instanceof PopupGuiProvider) {
            GUIPacket packet = PacketHandler.getPacket(GUIPacket.class);
            packet.setGuiID(guiProvider.getId());
            packet.setWindowID(-2);
            packet.setGuiData(LPDataIOWrapper.collectData(guiProvider::writeData));
            MainProxy.sendPacketToPlayer(packet, player);
        }
        return;
    }
    player.getNextWindowId();
    player.closeContainer();
    int windowId = player.currentWindowId;
    GUIPacket packet = PacketHandler.getPacket(GUIPacket.class);
    packet.setGuiID(guiProvider.getId());
    packet.setWindowID(windowId);
    packet.setGuiData(LPDataIOWrapper.collectData(guiProvider::writeData));
    MainProxy.sendPacketToPlayer(packet, player);
    player.openContainer = container;
    player.openContainer.windowId = windowId;
    player.openContainer.addCraftingToCrafters(player);
}
Also used : GuiContainer(net.minecraft.client.gui.inventory.GuiContainer) Container(net.minecraft.inventory.Container) PopupGuiProvider(logisticspipes.network.abstractguis.PopupGuiProvider) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) GUIPacket(logisticspipes.network.packets.gui.GUIPacket)

Aggregations

PopupGuiProvider (logisticspipes.network.abstractguis.PopupGuiProvider)2 GuiContainer (net.minecraft.client.gui.inventory.GuiContainer)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 GuiProvider (logisticspipes.network.abstractguis.GuiProvider)1 TargetNotFoundException (logisticspipes.network.exception.TargetNotFoundException)1 GUIPacket (logisticspipes.network.packets.gui.GUIPacket)1 LogisticsBaseGuiScreen (logisticspipes.utils.gui.LogisticsBaseGuiScreen)1 SubGuiScreen (logisticspipes.utils.gui.SubGuiScreen)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 Container (net.minecraft.inventory.Container)1