Skip to content

Instantly share code, notes, and snippets.

@TheGreyGhost
Last active January 21, 2018 14:47
Show Gist options
  • Save TheGreyGhost/7613416 to your computer and use it in GitHub Desktop.
Save TheGreyGhost/7613416 to your computer and use it in GitHub Desktop.
A basic framework for understanding how Forge starts up your code. See http://greyminecraftcoder.blogspot.com/2013/11/how-forge-starts-up-your-code.html
---TestFrameworkMod.Java---------------------------------------------
package testframework;
/**
* This class is just used to pass control to the appropriate "Proxy" class depending on whether the mod has been installed in a normal Minecraft Client or a Dedicated Server.
*/
@Mod(modid="testframeworkmod", name="Forge Test Framework Mod", version="0.0.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class TestFrameworkMod {
// The instance of your mod that Forge uses.
@Mod.Instance("testframeworkmod")
public static TestFrameworkMod instance;
// the proxy reference will be set to either CombinedClientProxy or DedicatedServerProxy depending on whether this mod is running in a normal Minecraft client or a dedicated server.
// NB this is not the same as client-side vs server-side:
// CombinedClientProxy contains both client-side code and server-side code (used by the integrated server)
// DedicatedServerProxy doesn't contain any client-side code
@SidedProxy(clientSide="testframework.clientonly.CombinedClientProxy", serverSide="testframework.serveronly.DedicatedServerProxy")
public static CommonProxy proxy;
/**
* Run before anything else. Read your config, create blocks, items, etc, and register them with the GameRegistry
*/
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
proxy.preInit();
}
/**
* Do your mod setup. Build whatever data structures you care about. Register recipes,
* send FMLInterModComms messages to other mods.
*/
@EventHandler
public void load(FMLInitializationEvent event) {
proxy.load();
}
/**
* Handle interaction with other mods, complete your setup based on this.
*/
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit();
}
CommonProxy.java ------------------------------------------------------
package testframework.common;
/**
* CommonProxy is used to set up the mod and start it running. It contains all the code that should run on both the
* normal Minecraft client and the dedicated server.
*/
public class CommonProxy {
/**
* Run before anything else. Read your config, create blocks, items, etc, and register them with the GameRegistry
*/
public void preInit()
{
// register my Items, Blocks, Entities, etc
}
/**
* Do your mod setup. Build whatever data structures you care about. Register recipes,
* send FMLInterModComms messages to other mods.
*/
public void load()
{
// register my Recipies
}
/**
* Handle interaction with other mods, complete your setup based on this.
*/
public void postInit()
{
}
}
CombinedClientProxy.java ------------------------------------------------------
package testframework.clientonly;
/**
* CombinedClient is used to set up the mod and start it running when installed on a normal minecraft client.
* It should not contain any code necessary for proper operation on a DedicatedServer. Code required for both
* normal minecraft client and dedicated server should go into CommonProxy
*/
public class CombinedClientProxy extends CommonProxy {
/**
* Run before anything else. Read your config, register renderers
*/
@Override
public void preInit()
{
super.preInit();
// register my renderers
}
/**
* Do your mod setup. Build whatever data structures you care about.
* send FMLInterModComms messages to other mods.
*/
@Override
public void load()
{
super.load();
}
/**
* Handle interaction with other mods, complete your setup based on this.
*/
@Override
public void postInit()
{
super.postInit();
}
}
DedicatedServerProxy.java ------------------------------------------------------
package testframework.serveronly;
/**
* DedicatedServerProxy is used to set up the mod and start it running when installed on a dedicated server.
* It should not contain (or refer to) any client-side code at all, since the dedicated server has no client-side code.
*/
public class DedicatedServerProxy extends CommonProxy {
/**
* Run before anything else. Read your config.
*/
@Override
public void preInit()
{
super.preInit();
}
/**
* Do your mod setup. Build whatever data structures you care about.
* send FMLInterModComms messages to other mods.
*/
@Override
public void load()
{
super.load();
}
/**
* Handle interaction with other mods, complete your setup based on this.
*/
@Override
public void postInit()
{
super.postInit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment