There are tons of forge modding tutorials out there, so why make another one you may ask. That is because this will be a more in-depth learn as you go tutorials. The more java you know the better, although this set of tutorials, ranging from beginner to advanced, will be designed so you can the as you mod. Remember to leave a comment if you need help and if you want to suggest tutorials for me to make.
Once you have eclipse ready, open the project explorer(if it is not already open) and navigate to the minecraft then src. Then, go to file, new, other. Then search package. The package states where the mod files are located in folders. Create two packages. Ex:
limeyin.tutorial.common
limeyin.tutorial.client
you can change anything except the client and common part have to be the last part of the packages. Once you do that, right click the client package and click new class. Name it ClientProxyYourMod and make sure the package is the limeyin.tutorial.client or whatever you called the package.
Then, in the common package, create YourMod class.
First, add this
@Mod(modid="KnK", name="KnK", version="4.0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
Make sure this is before this line of code: [code]public class YourMod
The "ModID" is the id of your mod. It can be anything you want, although something to do with your mod works best. "YourModName" is just the name of the mod and the "Alpha 1.0" is the version. The next line states that you must install the client side of the mod but the server side is not required.
Then add the instance, which will be used later:
@Instance ("limeyin")
public static YourMod instance;
This should be after this line of code:
public class YourMod
Then, after the instance, add this code:
@PreInit
public void preInit(FMLPreInitializationEvent evt) {
}
@Init
public void load(FMLInitializationEvent event) {
}
@PostInit
public void postInit(FMLPostInitializationEvent evt) {
}
This is what the mod class should look like:
package limeyin.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.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 = "ModID", name = "ModName", version = "Alpha 1.0.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial {
@Instance ("yourinstance")
public static YourMod instance;
@PreInit
public void preInit(FMLPreInitializationEvent evt) {
}
@Init
public void load(FMLInitializationEvent evt) {
}
@PostInit
public void postInit(FMLPostInitializationEvent evt) {
}
}
Proxies:
Put this code into the ClientProxyYourMod class:
package limeyin.tutorial.client;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.main.common.CommonProxyKnK;
import net.minecraftforge.client.MinecraftForgeClient;
public class ClientProxyYourMod extends CommonProxyYourMod {
@Override
public void registerRenders() {
MinecraftForgeClient.preloadTexture("/KnK/main/KnKTextures.png");
}
}
@Override
public void registerRenders() {
MinecraftForgeClient.preloadTexture("/KnK/main/KnKTextures.png");
}
This shows where the sprite sheet is located. The sprite sheet adds the textures to the game. We will get onto the sprite sheet in the block tutorial.
Now make the CommonProxyYourMod. Make sure the commonproxy is in the common package. After that class, the main mod file will be made. Here is the code to add to the CommonProxyYourMod class:
package net.main.common;
public class CommonProxyKnK {
public void registerRenders(){
}
}
@PreInit
public void preInit(FMLPreInitializationEvent evt) {
proxy.registerRenderThings();
}
@Init
public void load(FMLInitializationEvent evt) {
}
@PostInit
public void postInit(FMLPostInitializationEvent evt) {
}
}
Blocks
Basic Blocks
First you should add this line of code into the main mod file. I have it added in between the @Init and the @PreInit annotations.
int yourblockID = 500;
Then you also should add, in the same area
public static Block yourblock;
Then, in the @Init area:
yourblock = new Blockyourblock(yourblockID , 0, Material.iron).setBlockName("youblock").setLightValue(0F).setResistance(15F).setHardness(4F);
The light value is the amount of light it gives. A torch is about 0.87F and glowstone is 1F. Hardness and resistance are the resistance against explosions and how long it takes to mine. I can't remember which is which, so if you find out leave a comment. The .setBlockName doesn't name the block, it is just like a second block id. Every block name needs to be different, just like the block id's. 0 is referring to the location on the custom sprite sheet you create. After the block is finished, I will show you the sprite sheet tutorial. I haven't really experimented with the material.iron part, but I think it shows what tool is good at harvesting it. This would make a pickaxe be able to mine it.
Create the BlockYourBlock class in the common package. Here is the code:
This is the base of the BlockYourBlock class that is required:
package limeyin.tutorial.common;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.world.World;
public class BlockYourBlock extends Block{
public BlockYourBlock(int id, int texture, Material net) {
super(id, texture, net);
setCreativeTab(KnK.KNK);
}
public String getTextureFile(){
return "/KnK/main/KnKTextures.png";
}
}
Add this code if you want the block to drop exp:
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) {
this.dropXpOnBlockBreak(world, x, y, z, 10);
}
Is if you want your block to drop exp. Do not change anything except the 10. The 10 is how much exp drops. You will gain 1 level from breaking this block.
Add this is you want to have the block drop a different block or an item:
public int idDropped(int par1, Random rend, int par2){
return YourMod.YourItem.itemID;
}
public int quantityDropped(Random rend) {
return 1;
}
You could also do to have blocks.
public int idDropped(int par1, Random rend, int par2){
return YourMod.YourBlock.blockID;
You can change YourMod to either Item or Block to have it drop vanilla items. Use either itemID or blockID, depending if you want a block or an item dropped.
This is the final class:
package limeyin.tutorial.common;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.world.World;
public class BlockYourBlock extends Block{
public BlockYourBlock(int id, int texture, Material net) {
super(id, texture, net);
setCreativeTab(KnK.KNK);
}
public String getTextureFile(){
return "/KnK/main/KnKTextures.png";
}
public int idDropped(int par1, Random rend, int par2){
return YourModClass.YourItem.itemID;
}
public int quantityDropped(Random rend) {
return 1;
}
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) {
this.dropXpOnBlockBreak(world, x, y, z, 15);
}
}
Multi-Textured Block
Will come soon
Sprite Sheets
Recommended you have a legit Minecraft account first.
First, I recommend to download GIMP and winrar/7-zip. Open up gimp and get the create a new sheet screen and make sure the dimensions of it is 256x256 pixels and then open up advanced options. Make sure the background it set to transparency. Then, if you are running windows, go to start. Type in %appdata% in the search bar and hit enter. Go to the roaming and then .minecraft folder. Go to bin and open the minecraft.jar with winrar/7-zip. There will be a terrain.png file in it. Drag it to your desktop or a folder dedicated to modding. Open the terrain.png with gimp and you can easily copy and paste a block into your sprite sheet and change the colors. It may take a little bit to get used to GIMP, but it's definitely worth it. Once you are done with the textures, export the file as a .png file. Then create a new package in eclipse called: limeyin.tutorial.textures and put your .png file there. Then, in the proxy classes and any block or item classes, make the .png path to where ever the .png is located. Ex: limeyin.tutorial.textures.ModTextures.png
Entities
Hostile Mobs
First, add this to your main mod file
int YourMobID = 24;
That just gives your entity an id.
Also add this:
static int startEntityId = 300;
Then make a new method called EntityRegisters();
Then add this inside the entityregisters method
This registers the entity and lets it spawn in the biomes listed. The EntityYourMob class hasn't been added yet, but will be after we finish in the main mod class. Change the EnumCreatureType if you want a non hostile mob. There is creature, waterCreature, and monster.
Add this code too:
You should have and know what language registry is. The 0xC7C5D4, 0x787682 stands for the colors for the eggs. Those are color codes. Make sure the 0x is always in front of the actual color code. Go here to find color codes: http://www.colorpicker.com/
Now create the EntityYourMob class. Put this inside it::
super(par1World);
this.texture = "path/mobtexture.png";
this.moveSpeed = 0.25F;
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIBreakDoor(this));
this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, this.moveSpeed, false));
this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
this.tasks.addTask(4, new EntityAIWander(this, this.moveSpeed));
this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 16.0F, 0, true));
}
This adds the entity AI. Change what you wish, or you can add some new ones too.
Also, add this code: If you made a non hostile mob, delete some of this code that is for a hostile mob.
public int getTotalArmorValue() {
return 6;
}
protected boolean isAIEnabled() {
return true;
}
public int getMaxHealth() {
return 16;
}
public int getAttackStrngth(Entity par1Entity) {
return 4;
}
public EnumCreatureAttribute getCreatureAttribute() {
return EnumCreatureAttribute.UNDEFINED;
}
protected String getLivingSound() {
return "mob.zombie.say";
}
protected String getHurtSound() {
return "mob.zombie.hurt";
}
protected String getDeathSound() {
return "mob.endermen.death";
}
protected void playStepSound(int par1, int par2, int par3, int par4) {
this.worldObj.playSoundAtEntity(this, "mob.zombie.metal", 0.15F, 1.0F);
}
protected int getDroppedItemID() {
return Block.cake.blockID;
}
protected void dropRareDrop(int par1) {
switch(this.rand.nextInt(2)) {
case 0:
this.dropItem(Item.flintAndSteel.itemID, 1);
}
}
protected void dropFewItems(boolean par1, int par2) {
if(this.rand.nextInt(4) == 0) {
this.dropItem(Item.appleRed.itemID, 1);
}
}
This gets how much armor the mob has, if the AI is on, the health, strength, sounds, and dropped items.
I made the proxies and mod setup tutorials. If there are any bugs, leave a comment and I will fix them. I will try and release one tutorial every other day or so, depending of the difficulty of the tutorial.
Finished Tutorials
Mod Setup
Proxies
Blocks
Hostile Mobs
Planned Tutorials
NPC's
Items
Crafting Table
Furnace
Configs
Achievements
Biomes
Dimensions
Any Suggestions
Setup
Mod File Setup
Once you have eclipse ready, open the project explorer(if it is not already open) and navigate to the minecraft then src. Then, go to file, new, other. Then search package. The package states where the mod files are located in folders. Create two packages. Ex:
you can change anything except the client and common part have to be the last part of the packages. Once you do that, right click the client package and click new class. Name it ClientProxyYourMod and make sure the package is the limeyin.tutorial.client or whatever you called the package.
Then, in the common package, create YourMod class.
First, add this
The "ModID" is the id of your mod. It can be anything you want, although something to do with your mod works best. "YourModName" is just the name of the mod and the "Alpha 1.0" is the version. The next line states that you must install the client side of the mod but the server side is not required.
Then add the instance, which will be used later:
This should be after this line of code:
Then, after the instance, add this code:
This is what the mod class should look like:
Proxies:
Put this code into the ClientProxyYourMod class:
This shows where the sprite sheet is located. The sprite sheet adds the textures to the game. We will get onto the sprite sheet in the block tutorial.
Now make the CommonProxyYourMod. Make sure the commonproxy is in the common package. After that class, the main mod file will be made. Here is the code to add to the CommonProxyYourMod class:
This should be YourMod class
package limeyin.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 = "ModID", name = "Name", version = "1.0.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial {
@Instance ("TheInstance")
public static YourMod instance;
@SidedProxy (clientSide = "limeyin.tutorial.common.ClientProxyYourMod", serverSide = "limeyin.tutorial.common.CommonProxyYourMod")
public static CommonProxy proxy;
@PreInit
public void preInit(FMLPreInitializationEvent evt) {
proxy.registerRenderThings();
}
@Init
public void load(FMLInitializationEvent evt) {
}
@PostInit
public void postInit(FMLPostInitializationEvent evt) {
}
}
Blocks
Basic Blocks
First you should add this line of code into the main mod file. I have it added in between the @Init and the @PreInit annotations.
Then you also should add, in the same area
Then, in the @Init area:
The light value is the amount of light it gives. A torch is about 0.87F and glowstone is 1F. Hardness and resistance are the resistance against explosions and how long it takes to mine. I can't remember which is which, so if you find out leave a comment. The .setBlockName doesn't name the block, it is just like a second block id. Every block name needs to be different, just like the block id's. 0 is referring to the location on the custom sprite sheet you create. After the block is finished, I will show you the sprite sheet tutorial. I haven't really experimented with the material.iron part, but I think it shows what tool is good at harvesting it. This would make a pickaxe be able to mine it.
Create the BlockYourBlock class in the common package. Here is the code:
This is the base of the BlockYourBlock class that is required:
Add this code if you want the block to drop exp:
Is if you want your block to drop exp. Do not change anything except the 10. The 10 is how much exp drops. You will gain 1 level from breaking this block.
Add this is you want to have the block drop a different block or an item:
You could also do to have blocks.
You can change YourMod to either Item or Block to have it drop vanilla items. Use either itemID or blockID, depending if you want a block or an item dropped.
This is the final class:
Will come soon
Sprite Sheets
Recommended you have a legit Minecraft account first.
First, I recommend to download GIMP and winrar/7-zip. Open up gimp and get the create a new sheet screen and make sure the dimensions of it is 256x256 pixels and then open up advanced options. Make sure the background it set to transparency. Then, if you are running windows, go to start. Type in %appdata% in the search bar and hit enter. Go to the roaming and then .minecraft folder. Go to bin and open the minecraft.jar with winrar/7-zip. There will be a terrain.png file in it. Drag it to your desktop or a folder dedicated to modding. Open the terrain.png with gimp and you can easily copy and paste a block into your sprite sheet and change the colors. It may take a little bit to get used to GIMP, but it's definitely worth it. Once you are done with the textures, export the file as a .png file. Then create a new package in eclipse called: limeyin.tutorial.textures and put your .png file there. Then, in the proxy classes and any block or item classes, make the .png path to where ever the .png is located. Ex: limeyin.tutorial.textures.ModTextures.png
Entities
Hostile Mobs
First, add this to your main mod file
That just gives your entity an id.
Also add this:
Then make a new method called EntityRegisters();
Then add this inside the entityregisters method
This registers the entity and lets it spawn in the biomes listed. The EntityYourMob class hasn't been added yet, but will be after we finish in the main mod class. Change the EnumCreatureType if you want a non hostile mob. There is creature, waterCreature, and monster.
Add this code too:
You should have and know what language registry is. The 0xC7C5D4, 0x787682 stands for the colors for the eggs. Those are color codes. Make sure the 0x is always in front of the actual color code. Go here to find color codes: http://www.colorpicker.com/
Now create the EntityYourMob class. Put this inside it::
This adds the entity AI. Change what you wish, or you can add some new ones too.
Also, add this code: If you made a non hostile mob, delete some of this code that is for a hostile mob.
This gets how much armor the mob has, if the AI is on, the health, strength, sounds, and dropped items.
Import this:
This is what the EntityYourMob class should look like: