Search in sources :

Example 1 with GUIPacket

use of logisticspipes.network.packets.gui.GUIPacket 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)1 GUIPacket (logisticspipes.network.packets.gui.GUIPacket)1 GuiContainer (net.minecraft.client.gui.inventory.GuiContainer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 Container (net.minecraft.inventory.Container)1