I am creating my custom GUI for a quiz mod and have run into some trouble.
When I right click my block to open up the quiz GUI, it opens nicely.
However when I try to open it using a command, it does not work.
After some googling, I have found that it is required to send a packet from the server to the client to inform it to open the GUI.
As such, I have implemented a SimpleNetworkWrapper as found in this tutorial.
I initialize my network wrapper within the FMLPreInitializationEvent with:
network = NetworkRegistry.INSTANCE.newSimpleChannel("GUIChannel");
network.registerMessage(MyMessage.Handler.class, MyMessage.class, 0, Side.SERVER);
Then from my command, I send the packet:
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
Main.network.sendTo(new MyMessage("ASDF"), (EntityPlayerMP) sender);
My Handler class attempts to open the gui:
public static class Handler implements IMessageHandler<MyMessage, IMessage> {
@Override
public IMessage onMessage(MyMessage message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().playerEntity;
player.openGui(Main.INSTANCE, GUIHandler.TUTGUID, player.getEntityWorld(), player.getPosition().getX(),
player.getPosition().getY(), player.getPosition().getZ());
return null;
}
}
This does not seem to open the GUI and I'm not quite sure what I'm doing wrong.
How do I modify this to make it functional via a command? Thanks.