This example shows you how to implement proxy classes for your Minecraft Mod Application, which are used to initialize your mod.
First of all you will need to implement the base CommonProxy.java class which contains the 3 mainly used method:
public class CommonProxy {
public void preInit(FMLPreInitializationEvent e) {}
public void init(FMLInitializationEvent e) {}
public void postInit(FMLPostInitializationEvent e) {}
}
Normally your mod has 2 different packages for Client and Server Code, so you will need in each package a child class of CommonProxy.java like:
public class ClientProxy extends CommonProxy {
@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e);
}
@Override
public void init(FMLInitializationEvent e) {
super.init(e);
}
@Override
public void postInit(FMLPostInitializationEvent e) {
super.postInit(e);
}
}
and for the server:
public class ServerProxy extends CommonProxy {
@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e);
}
@Override
public void init(FMLInitializationEvent e) {
super.init(e);
}
@Override
public void postInit(FMLPostInitializationEvent e) {
super.postInit(e);
}
}
After you have created this classes you are able to extend them by methods which have to run only on client or server side, but can also attach them to both if you call the methods in the 'base' class.
Lastly you have to define which proxy is taken at runtime. You have to extend your main mod class with the @Mod
annotation, by:
private static final String CLIENTPROXY = "com.yourpackage.client.ClientProxy";
private static final String SERVERPROXY = "com.yourpackage.client.ServerProxy";
@SidedProxy(clientSide = CLIENTPROXY, serverSide = SERVERPROXY)
public static CommonProxy PROXY;
This will enable Forge to detect which class should be taken at runtime. In the initialization methods of your Mod you can now use this static PROXY property.
@EventHandler
public void init(FMLInitializationEvent event) {
PROXY.init(event);
}
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
PROXY.preInit(event);
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
PROXY.postInit(event);
}