mod_Main, CommonProxy and ClientProxy
Updated for 1.8
Now that you have eclipse open, there should be a tab called package explorer to the left of the screen. There should be a folder called Minecraft there. Extend it, and then extend the src folder inside of it. This is where all of the code for Minecraft is located.
Your first step is to left click on src and select new and then package. Package names tend to be a website or email address. An example of a package name is com.blfngl.common, com for the extension of my site (that doesn't exit ), blfngl for the domain name, and common because it's the main section of my mod. For a website use one that you own, if you don't own one, don't do something like com.google.common or net.minecraft.common.
After you create your package, the next thing you want to do is create your main mod file. Left click on your package and create a new class. The class can be named many things. Most users like their main file to be mod_ModNameHere or ModNameHereMain. You can name it whatever you want, but try to keep your code organized. Mine will be called TutorialMain.
Inside your main file, you should paste this code.
TutorialMain:
package tutorial.common;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
@Mod(modid="tutorial", name="Tutorial Mod", version="1.8")
public class TutorialMain
{
// The instance of your mod that Forge uses, in my case tutorial.
@Instance("tutorial")
public static TutorialMain instance;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
// Stub Method
}
@EventHandler
public void init(FMLInitializationEvent event)
{
proxy.registerRenderers();
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
// Stub Method
}
}
The first section:
@Mod(modid="tutorial", name="Tutorial Mod", version="1.8")
public class TutorialMain{
modid is what your mod will be named in the code, not it's title. Keep it short and sweet, if you're doing something like Alabaster mod name it alabaster.
name is the mod's display name. Now you can name it Alabaster Mod.
version is pretty obvious.
The next section:
// The instance of your mod that Forge uses, in my case tutorial.
@Instance("tutorial")
public static TutorialMain instance;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
// Stub Method
}
@EventHandler
public void init(FMLInitializationEvent event)
{
proxy.registerRenderers();
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
// Stub Method
}
Instance should be the same as modid. If not, you can't run your mod and Minecraft will crash.
public static TutorialMain instance; should be the name of your mod's main class, this one is TutorialMain.
PreInit loads sounds and other things.
Init is where most registries occur, like names and recipes.
PostInit isn't used in this tutorial.
Now we want to go and make the two proxy classes. Make a new class in your mod.common package named TutorialCommonProxy. This is mainly for preloading textures.
TutorialCommonProxy
package tutorial.common;
public class TutorialCommonProxy
{
// Client stuff
public void registerRenderers()
{
// Nothing here as the server doesn't render graphics!
}
}
Texture loading used to go here, but now not many mods need this to function. However, that method is mandatory. To add texture files will be covered later. Now we move onto the client proxy. Make a new class called TutorialClientProxy in your tutorial.client package. This is where the textures are notified for the server and mob registering takes place.
TutorialClientProxy:
package tutorial.client;
public class TutorialClientProxy extends TutorialCommonProxy
{
@Override
public void registerRenderers()
{
}
}
This needs to extend you common proxy to get the texture files for the server. Now we can move on to our first item.
Now that you have eclipse open, there should be a tab called package explorer to the left of the screen. There should be a folder called Minecraft there. Extend it, and then extend the src folder inside of it. This is where all of the code for Minecraft is located.
Your first step is to left click on src and select new and then package. Package names tend to be a website or email address. An example of a package name is com.blfngl.common, com for the extension of my site (that doesn't exit ), blfngl for the domain name, and common because it's the main section of my mod. For a website use one that you own, if you don't own one, don't do something like com.google.common or net.minecraft.common.
After you create your package, the next thing you want to do is create your main mod file. Left click on your package and create a new class. The class can be named many things. Most users like their main file to be mod_ModNameHere or ModNameHereMain. You can name it whatever you want, but try to keep your code organized. Mine will be called TutorialMain.
Inside your main file, you should paste this code.
TutorialMain:
package tutorial.common;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
@Mod(modid="tutorial", name="Tutorial Mod", version="1.8")
public class TutorialMain
{
// The instance of your mod that Forge uses, in my case tutorial.
@Instance("tutorial")
public static TutorialMain instance;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
// Stub Method
}
@EventHandler
public void init(FMLInitializationEvent event)
{
proxy.registerRenderers();
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
// Stub Method
}
}
The first section:
@Mod(modid="tutorial", name="Tutorial Mod", version="1.8")
public class TutorialMain{
modid is what your mod will be named in the code, not it's title. Keep it short and sweet, if you're doing something like Alabaster mod name it alabaster.
name is the mod's display name. Now you can name it Alabaster Mod.
version is pretty obvious.
The next section:
// The instance of your mod that Forge uses, in my case tutorial.
@Instance("tutorial")
public static TutorialMain instance;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
// Stub Method
}
@EventHandler
public void init(FMLInitializationEvent event)
{
proxy.registerRenderers();
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
// Stub Method
}
Instance should be the same as modid. If not, you can't run your mod and Minecraft will crash.
public static TutorialMain instance; should be the name of your mod's main class, this one is TutorialMain.
PreInit loads sounds and other things.
Init is where most registries occur, like names and recipes.
PostInit isn't used in this tutorial.
Now we want to go and make the two proxy classes. Make a new class in your mod.common package named TutorialCommonProxy. This is mainly for preloading textures.
TutorialCommonProxy
package tutorial.common;
public class TutorialCommonProxy
{
// Client stuff
public void registerRenderers()
{
// Nothing here as the server doesn't render graphics!
}
}
Texture loading used to go here, but now not many mods need this to function. However, that method is mandatory. To add texture files will be covered later. Now we move onto the client proxy. Make a new class called TutorialClientProxy in your tutorial.client package. This is where the textures are notified for the server and mob registering takes place.
TutorialClientProxy:
package tutorial.client;
public class TutorialClientProxy extends TutorialCommonProxy
{
@Override
public void registerRenderers()
{
}
}
This needs to extend you common proxy to get the texture files for the server. Now we can move on to our first item.