Minecraft Blogs / Tutorial

mc forge modding: part 1 the base class

  • 421 views, 1 today
  • 2
  • 0
meanman2288's Avatar meanman2288
Level 5 : Apprentice Engineer
3
If youve decided you want to make a mod then youve come to the right place as im going to teach you the basics of forge modding step by step so you can learn how to make your own mod.



In this tutorial i am going to teach you how to make the base class of your mod

requirements

a knowlage of java is not needed but it is recomended that you try to learn a few things

mcp (minecraft coder pack)

minecraft

The latest minecraft forge

since its hard to explain how to set up in text i shal direct you to a video by wuppygaming

http://www.youtube.com/watch?v=eoghY5Gb-lc&feature=youtu.be



Once you have every thing working its time to get started.



The first thing you should do is make a new package in common. Do this by right clicking on the common folder and clicking new Package, next a window will pop up that asks you for the package name. The name could be anything, but but i advise that you use a name like this [yourmodname].common
The first word should be the name of your mod. The second one has to be common.
next we need to make our first class. right click your new package and this time click new Class, a window will pop up again telling you that you need to name your class. The file you are creating now is the base mod file. It will contain the most important information about your mod. It will contain recipes, blocks, items and much more. It is highly recomended that you give this file the name of your mod.

When you create the file it should look something like this.

____________________________________________________________________________________________

package Tutorial.common;

public class Tutorial

{

}

_______________________________________________________________________________________________

(all red text is example code)

(whatever i use blue text for should be changed to the name of your mod)

the first thing we add to our new class must be above the "public class tutorial" line. it should look somthing like this:

@Mod(modid = "your_mc_name_tutorial", name = "tutorial", version = "1.0")

now if you are new to java or modding you are probably wondering what all this means so let me explain.

The first thing inside of the quotation marks is the mod id of your mod. This has to be unique from any other mod or it will crash Minecraft. I suggest giving it the format of your user name_ your mod name.

The second thing inside of the brackets is the mod name. This will show up inside of the Minecraft client when you click on the mods button.

The third and last thing is the version number. This one will as well show up inside of the Minecraft client.
You will probably get some errors right now under @Mod. To fix this press Ctrl, Shift, O. It should add this line to your file just below the line with the package. but if it dosen't don't worry you can put it in manualy.

import cpw.mods.fml.common.Mod;

The next line that you need to add goes right between the @Mod line and the public class line, It should look identical to this one.

@NetworkMod(clientSideRequired = true, serverSideRequired = false)

this line tells the game that it can join vannilla servers with the mod installed but it can not join a server that has the mod if the client dosent have the mod installed. this stops crashes when you try to join with somthing missing.

you will get another error under @NetworkMod. Again you have to press Ctrl, Shift, O. And if that still doesn't work you have to add this line inside of your file.

import cpw.mods.fml.common.network.NetworkMod;

next we add this

@init

public void load(FMLInitializationEvent event)

{



}

This has to be added inside of the brackets below the public class Tutorial line. The public void load() is the first method in your mod. A method is a piece of the code that can be called from outside. The @Init above makes sure that forge will call it during the Init phase of start-up.
Inside of this method will be most of the code for your mod. It is a very important method and it will become very big.
You might get errors under @Init and inside of the load brackets. Fix it by pressing Crtl, Shift, O or by adding these 2 lines.


import cpw.mods.fml.init;
import cpw.mods.fml.common.event.FMLInitializationEvent;

congratulations you have now made the minimum code to alow minecraft forge to recognise your mod

this is what it should all look like now



package Tutorial.common;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid = "Your_mc_Name_Tutorial", name = "Tutorial", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial
{
@Init
public void load(FMLInitializationEvent event)
{

}
}

thank you for reading if it was helpfull a diamond could be nice and there will be more tutorials each week (or earlier if i get chance)
Tags

Create an account or sign in to comment.

Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome