Are you constantly getting "Mod tried to open GUI on server without being a network mod!" when you try to open those GUI's that you created? Well, I had them too, trust me, they were annoying as hell. I found a fix that worked for me, and may just work for you!
Lets get started, I will split this into the different classes.
BASE MOD CLASS:
First off, make sure you setup EVERYTHING correctly.Proxies, annotations, variables, everything.
Next, where you have your mod instance, make sure it is set up like this:
@Instance("~MOD ID~")
public static BaseModClass instance = new BaseModClass();
Next, create another class instance like this:
public static GuiHandler guiHandler = new GuiHandler();
Finally create a new integer variable called "whateverGuiID" and set it equal to "0". For each GUI, make a new variable and raise that number by 1.
That's it for this class! Two more to go!
GUIHANDLER
This should be a new class, and it should be in your client package, in this class place this:
package jcm2606.industrize.client.handlers;
import jcm2606.industrize.client.gui.GUIAnvil;
import jcm2606.industrize.common.containers.ContainerAnvil;
import jcm2606.industrize.common.tiles.TileEntityAnvil;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandler implements IGuiHandler{
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z){
TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
if(tile_entity instanceof TileEntityWhatever){
return new ContainerWhatever(PARAMS);
}
return null;
}
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z){
TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
if(tile_entity instanceof TileEntityWhatever){
return new GuiWhatever(PARAMS);
}
return null;
}
}
Thats it for GuiHandler.
CALLING THE GUI
To call the gui use this:
variableEntityPlayer.openGui(BaseModClass.instance, BaseModClass.whateverGuiID, x, y, z);
That should be it, if this does not work, reply saying so with your code and I will see whether I can see any errors. Thanks for reading, hope everything goes well with modding.
Rollback Post to RevisionRollBack
Author of the Clarity, Serenity, Sapphire & Halcyon shader packs for Minecraft: Java Edition.
Lets get started, I will split this into the different classes.
BASE MOD CLASS:
First off, make sure you setup EVERYTHING correctly.Proxies, annotations, variables, everything.
Next, where you have your mod instance, make sure it is set up like this:
Next, create another class instance like this:
Next, in your @Init method, place this:
Finally create a new integer variable called "whateverGuiID" and set it equal to "0". For each GUI, make a new variable and raise that number by 1.
That's it for this class! Two more to go!
GUIHANDLER
This should be a new class, and it should be in your client package, in this class place this:
Thats it for GuiHandler.
CALLING THE GUI
To call the gui use this:
That should be it, if this does not work, reply saying so with your code and I will see whether I can see any errors. Thanks for reading, hope everything goes well with modding.
Author of the Clarity, Serenity, Sapphire & Halcyon shader packs for Minecraft: Java Edition.
My Github page.
The entire Minecraft shader development community now has its own Discord server! Feel free to join and chat with all the developers!