Search in sources :

Example 1 with PacketOpenGui

use of ivorius.reccomplex.network.PacketOpenGui in project RecurrentComplex by Ivorforce.

the class IvGuiRegistry method openGui.

// From FMLNetworkHandler.openGui
public void openGui(EntityPlayer entityPlayer, String modid, int modGuiId, ByteBuf data) {
    IvGuiHandler handler = handlers.get(modid);
    if (handler == null)
        return;
    if (entityPlayer instanceof EntityPlayerMP && !(entityPlayer instanceof FakePlayer)) {
        EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entityPlayer;
        ByteBuf dataCopy = data.copy();
        Container remoteGuiContainer = handler.getServerGuiElement(modGuiId, entityPlayerMP, data);
        entityPlayerMP.getNextWindowId();
        entityPlayerMP.closeContainer();
        int windowId = entityPlayerMP.currentWindowId;
        RecurrentComplex.network.sendTo(new PacketOpenGui(windowId, modid, modGuiId, dataCopy), entityPlayerMP);
        if (// If null, it's client only
        remoteGuiContainer != null) {
            entityPlayerMP.openContainer = remoteGuiContainer;
            entityPlayerMP.openContainer.windowId = windowId;
            entityPlayerMP.openContainer.addListener(entityPlayerMP);
        }
    } else if (entityPlayer instanceof FakePlayer) {
    // NO OP - I won't even log a message!
    } else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT)) {
        RecurrentComplex.network.sendToServer(new PacketOpenGui(0, modid, modGuiId, data));
    } else {
        FMLLog.fine("Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUI ID: %s,%d", modid, modGuiId);
    }
}
Also used : Container(net.minecraft.inventory.Container) PacketOpenGui(ivorius.reccomplex.network.PacketOpenGui) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ByteBuf(io.netty.buffer.ByteBuf) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 PacketOpenGui (ivorius.reccomplex.network.PacketOpenGui)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 Container (net.minecraft.inventory.Container)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1