Tutorials Navigation

Tutorials :: New :: Popular :: Top Rated

Tutorials: 18,357 Categories: 12

Total Tutorial Views: 42,395,041

How to make Minecraft Mods [Modloader][Blocks][Items]+ MORE!

Tutorial Name: How to make Minecraft Mods [Modloader][Blocks][Items]+ MORE!  

Category: PC Tutorials

Submitted By: Odin

Date Added:

Comments: 1

Views: 25,286

Related Forum: PC Building Forum

Share:

Modding tutorials for Minecraft 1.0.0

Requirements:
Java Development Kit (JDK) - [ Register or Signin to view external links. ]
Java Runtime Environments (JRE) - [ Register or Signin to view external links. ]
Eclipse (not required but helps so much) - [ Register or Signin to view external links. ] [choose the first link]
Minecraft Coder Pack (MCP) - [ Register or Signin to view external links. ]
Modloader - [ Register or Signin to view external links. ]

Basic Mod Template


package net.minecraft.src;

import java.util.Random;

public class mod_MythiCraft extends BaseMod
{

    public mod_Example()
    {
        //Registering Blocks:
        ModLoader.RegisterBlock(LC_block);

        //Adding Names:
        ModLoader.AddName(blockExample, "Example Block");

        ModLoader.AddName(itemExample, "Example Item");

        //Texturing:
        blockExample.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/example/blocks/block.png");

        itemExample.iconIndex = ModLoader.addOverride("/gui/items.png", "/example/items/item.png");

        //Crafting Recipes:
        ModLoader.AddRecipe(new ItemStack(blockExample, 1), new Object[]{
        "XX", "XX", Character.valueOf('X'), item
        });
        ModLoader.AddRecipe(new ItemStack(itemExample, 4), new Object[]{
        "X", Character.valueOf('X'), block
        });

        //Furnace Recipes:
        ModLoader.AddSmelting(blockExample.blockID, new ItemStack(itemExample));
    }

    public String getVersion()
    {
        return ("1.0.0");
    }

    //Item Properties:
    public static final Item itemExample = (new Item(10000)).setItemName("itemExample");
    //Highest Item ID used: 10000

    //Block Properties:
    public static final Block blockExample = (new Block(255, 0)).setBlockName("blockExample");
    //Highest Block ID used: 255
}



What each color means

green = a piece of code (in help sections)
brown = Help: filename
blue = a modding tutorial


Creating Your First Block

Using the template helps a lot

BlockNamehere.java

package net.minecraft.src;

import java.util.Random;

public class BlockNamehere extends Block
{

    public BlockNamehere(int i, int j)
    {
        super(i, j, Material.ground);           
    }
    public int idDropped(int i, Random random)
    {
       return mod_Namehere.Namehere.blockID;
    }
    public int quantityDropped(Random random)
    {
            return 3;
    }
}


mod_Namehere.java

package net.minecraft.src;

public class mod_Namehere extends BaseMod
{
   public static Block Namehere = new BlockNamehere(190, 0).setHardness(1.0F).setResistance(6000.0F).setLightValue(1.0F).setBlockN
ame("Namehere");
   
   public String Version()
   {
      return "1.8.1";
   }
   
   public mod_Namehere()
   {
      ModLoader.RegisterBlock(Namehere);
      Namehere.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Namehere.png");
      ModLoader.AddName(Namehere, "Namehere");
      ModLoader.AddRecipe(new ItemStack(Namehere, 1), new Object[] {
      "###", "###", "###", Character.valueOf('#'), Item.redstone
      });
   }
}


HELP: BlockNamehere.java

At return mod_Namehere.Namehere.blockID;
This is what the block drops, Change mod_Namehere.Namehere not the .blockID
examples

return Block.grass.blockID;
return Item.clay.shiftedIndex;


HELP: mod_Namehere

At new BlockNamehere(190,
change 190, that is the block ID be careful not to use the same ID again

At .setHardness(1.0F)
change the 1.0, dirt is 0.5; stone is 1.5; 10 is unbreakable

At .setResistance(2500.0F)
this is how resistant the block is to Explosives
change the 2500.0, obsidian is 2000.0F all other blocks are 5.0F

At .setLightValue(1.0F)
this is how bright your block is
1.0F is as high as it goes, Torches are 0.9375F and redstone is 0.5F

At ModLoader.AddName(Namehere, "Nameingamehere");
this is the ingame name, so change Namehere to the block name (in mod_Namehere) and change Nameingamehere to whatever you want it to say ingame

At Namehere.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Namehere.png");
this is the texture, change the Namehere.blockIndexInTexture and in the () change "/Namehere.png" ex. "/Mod/Fireblock.png" the /Mod/ is a folder and the Fireblock.png is the image file



Creating your First Item

Again use the template to your advantage

ItemNamehere.java

package net.minecraft.src;

import java.util.Random;

public class ItemNamehere extends Item
{

        public ItemNamehere (int i)
        {
                super(i);
                maxStackSize = 64;
        }
}


mod_Namehere.java

package net.minecraft.src;

public class mod_Namehere extends BaseMod
{
   public static final Item Namehere = new Item(30000).setItemName("Namehere");

public mod_Namehere()
{
   Namehere.iconIndex = ModLoader.addOverride("/gui/items.png", "/Namehere.png");
   ModLoader.AddName(Namehere, "Namehere");
   ModLoader.AddRecipe(new ItemStack(Namehere, 1), new Object[] {
    "XPX", "PSP", "XPX", Character.valueOf('P'), Item.porkCooked, Character.valueOf('X'), Item.redstone, Character.valueOf('S'), Item.swordStone
    });
}

public String Version()
{
   return "1.7.3";
}
       
}


HELP: mod_Namehere.java

At setItemName
this is the coding name not the ingame name

At



Creating a Food

This is the same as the item tutorial with some small tweaks

mod_Namehere

package net.minecraft.src;

public class mod_Namehere extends BaseMod
{
  public static Item Namehere = (new ItemFood(28000, 4, 1F, false)).setItemName("Namehere");

  public mod_Namehere()
  {
         Namehere.iconIndex = ModLoader.addOverride("/gui/items.png", "/Namehere.png");
         ModLoader.AddName(Namehere, "Namehere");
  }

  public String Version()
  {
     return "1.8.1";
  } 
}


HELP:
At new ItemFood(28000, 4, 1F,
1F stands for half a heart so 5F is 2.5 hearts



An Item That Spawns a Mob!


ItemNamehere

package net.minecraft.src;

import java.util.*;

public class ItemNamehere extends Item
{
    private World worldObj;
       
        public ItemNamehere (int i)
        {
                super(i);
                maxStackSize = 1;
        }
        public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l)
    {
        if(!world.multiplayerWorld)
        {
                    ModLoader.getMinecraftInstance().thePlayer.addChatMessage("A pig has Spawned!");
            EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Pig", entityplayer.worldObj);
                       
                        entityliving.setLocationAndAngles(i, j + 1, k, 0F, 0F);
            entityplayer.worldObj.entityJoinedWorld(entityliving);
                        entityplayer.swingItem();
        }
        return true;
    }
}


mod_Namehere

package net.minecraft.src;

public class mod_Namehere extends BaseMod
{
   public static Item Namehere = (new ItemNamehere(30439)).setItemName("Namehere");

  public mod_Namehere()
  {
     Namehere.iconIndex = ModLoader.addOverride("/gui/items.png", "/Namehere.png");
     ModLoader.AddName(Namehere, "Namehere");
  }

   public String Version()
   {
     return "1.8.1";
   } 
}


NOTE** The mod_Namehere is different then the Item tutorial only the ItemNamehere.java file is being altered

HELP: ItemNamehere.java

At ModLoader.getMinecraftInstance().thePlayer.addChatMessage("A pig has Spawned!")
this is the function that makes a message pop up on the screen


Making the Block more Advanced!

This tutorial edits the BlockNamehere.java file

slipperiness = 1.5F;

it would go under
super(i, j, Material.ground);

Makes you run faster as long as your on that specific block, great for long distance travel

A Bouncy Block
public void onEntityWalking(World world, int x, int y, int z, Entity entity)
    {
            entity.motionY += 2.0;
    }


goes here
public int idDropped(int i, Random random)
    {
       return mod_Namehere.Namehere.blockID;
    }
        public void onEntityWalking(World world, int x, int y, int z, Entity entity)
    {
            entity.motionY += 2.0;
    }
    public int quantityDropped(Random random)
    {
            return 1;
    }
}




Creating Armor


package net.minecraft.src;

import net.minecraft.client.Minecraft;

public class mod_Namehere extends BaseMod
{

    public mod_Namehere()
    {
        NamehereHelmet.iconIndex = ModLoader.addOverride("/gui/items.png", "/Nameherehelmet.png");
        ModLoader.AddName(NamehereHelmet, "Namehere Helmet");
        ModLoader.AddRecipe(new ItemStack(NamehereHelmet, 1), new Object[] {
            "rrr", "r r", "   ", Character.valueOf('r'), Item.redstone
        });
        NamehereBody.iconIndex = ModLoader.addOverride("/gui/items.png", "/Nameherebody.png");
        ModLoader.AddName(NamehereBody, "Namehere Chestplate");
        ModLoader.AddRecipe(new ItemStack(NamehereBody, 1), new Object[] {
            "r r", "rrr", "rrr", Character.valueOf('r'), Item.redstone
        });
        NamehereLegs.iconIndex = ModLoader.addOverride("/gui/items.png", "/Nameherelegs.png");
        ModLoader.AddName(NamehereLegs, "Namehere Leggings");
        ModLoader.AddRecipe(new ItemStack(NamehereLegs, 1), new Object[] {
            "rrr", "r r", "r r", Character.valueOf('r'), Item.redstone
        });
        NamehereBoots.iconIndex = ModLoader.addOverride("/gui/items.png", "/Namehereboots.png");
        ModLoader.AddName(NamehereBoots, "Namehere Boots");
        ModLoader.AddRecipe(new ItemStack(NamehereBoots, 1), new Object[] {
            "   ", "r r", "r r", Character.valueOf('r'), Item.redstone
        });
    }

    public String Version()
    {
        return "1.7.3";
    }

    public static Item NamehereHelmet = (new ItemArmor(2612, 3, ModLoader.AddArmor("NamehereArmor"), 0)).setItemName("NamehereHelmet");
    public static Item NamehereBody = (new ItemArmor(2613, 3, ModLoader.AddArmor("NamehereArmor"), 1)).setItemName("NamehereBody");
    public static Item NamehereLegs = (new ItemArmor(2614, 3, ModLoader.AddArmor("NamehereArmor"), 2)).setItemName("NamehereLegs");
    public static Item NamehereBoots = (new ItemArmor(2615, 3, ModLoader.AddArmor("NamehereArmor"), 3)).setItemName("NamehereBoots");

}


HELP:
At ("NamehereArmor"), 0))
the 0 is the type of armor

types 0-Helmet 1-Body 2-Legs 3-Boots



Adding Armor effects

put
ModLoader.SetInGameHook(this, true, false);
under all your recipes

add
public boolean OnTickInGame(Minecraft minecraft)
    {
        ItemStack boots = minecraft.thePlayer.inventory.armorInventory[0];
        ItemStack legs = minecraft.thePlayer.inventory.armorInventory[1];
        ItemStack chest = minecraft.thePlayer.inventory.armorInventory[2];
        ItemStack helm = minecraft.thePlayer.inventory.armorInventory[3];

        if(boots == null || legs == null || chest == null || helm == null)
        {
            return true;
        }
        if(boots.itemID == NamehereBoots.shiftedIndex && legs.itemID == NamehereLegs.shiftedIndex && chest.itemID == NamehereBody.shiftedIndex && helm.itemID == NamehereHelmet.shiftedIndex)
        {
           minecraft.thePlayer.air = minecraft.thePlayer.maxAir;
        }
                return true;
    }

into

ModLoader.AddRecipe(new ItemStack(NamehereBoots, 1), new Object[] {
            "   ", "r r", "r r", Character.valueOf('r'), Item.redstone
        });
                ModLoader.SetInGameHook(this, true, false);
    }
       
        public boolean OnTickInGame(Minecraft minecraft)
    {
        ItemStack boots = minecraft.thePlayer.inventory.armorInventory[0];
        ItemStack legs = minecraft.thePlayer.inventory.armorInventory[1];
        ItemStack chest = minecraft.thePlayer.inventory.armorInventory[2];
        ItemStack helm = minecraft.thePlayer.inventory.armorInventory[3];

        if(boots == null || legs == null || chest == null || helm == null)
        {
            return true;
        }
        if(boots.itemID == NamehereBoots.shiftedIndex && legs.itemID == NamehereLegs.shiftedIndex && chest.itemID == NamehereBody.shiftedIndex && helm.itemID == NamehereHelmet.shiftedIndex)
        {
           minecraft.thePlayer.air = minecraft.thePlayer.maxAir;
        }
                return true;
    }


at the bottom where it says minecraft.thePlayer.air = minecraft.thePlayer.maxAir;
you can change it to minecraft.thePlayer.isImmuneToFire = true;



Growing Plant (like sugar canes)

mod_Namehere

package net.minecraft.src;

import java.util.Random;

public class mod_Namehere extends BaseMod
{

    public mod_Namehere()
    {
        ModLoader.RegisterBlock(Namehere);
        ModLoader.AddName(Namehere, "Namehere");
        ModLoader.AddRecipe(new ItemStack(Item.redstone, 3), new Object[] {
            "#", Character.valueOf('#'), Namehere
        });
    }

    public void GenerateSurface(World world, Random random, int i, int j)
    {
        if(random.nextInt(20) == 0)
        {
            for(int k = 0; k < 16; k++)
            {
                for(int l = 0; l < 16; l++)
                {
                    int i1 = random.nextInt(200);
                    if(world.getBlockId(i + l, i1, j + k) != Block.grass.blockID || !world.isAirBlock(i + l, i1 + 1, j + k))
                    {
                        continue;
                    }
                    int j1 = random.nextInt(2);
                    if(j1 == 0)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                    }
                    if(j1 == 1)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
                    }
                    if(j1 == 2)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 3, j + k, Namehere.blockID);
                    }
                                        if(j1 == 3)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 3, j + k, Namehere.blockID);
                                                world.setBlock(i + l, i1 + 4, j + k, Namehere.blockID);
                    }
                }

            }

        }
    }

    public String Version()
    {
        return "1.7.3";
    }

    public static Block Namehere = (new BlockNamehere(124, ModLoader.addOverride("/terrain.png", "/Namehere.png"))).setHardness(0.0F).setResistance(0.0F).setBlo
ckName("Namehere");

}


BlockNamehere

package net.minecraft.src;

import java.util.Random;

public class BlockNamehere extends Block
{

    protected BlockNamehere(int i, int j)
    {
        super(i, Material.plants);
        blockIndexInTexture = j;
        float f = 0.375F;
        setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 1.0F, 0.5F + f);
        setTickOnLoad(true);
    }

    public void updateTick(World world, int i, int j, int k, Random random)
    {
        if(world.isAirBlock(i, j + 1, k))
        {
            int l;
            for(l = 1; world.getBlockId(i, j - l, k) == blockID; l++) { }
            if(l < 3)
            {
                int i1 = world.getBlockMetadata(i, j, k);
                if(i1 == 15)
                {
                    world.setBlockWithNotify(i, j + 1, k, blockID);
                    world.setBlockMetadataWithNotify(i, j, k, 0);
                } else
                {
                    world.setBlockMetadataWithNotify(i, j, k, i1 + 1);
                }
            }
        }
    }

    public boolean canPlaceBlockAt(World world, int i, int j, int k)
    {
        int l = world.getBlockId(i, j - 1, k);
        if(l == blockID)
        {
            return true;
        }
        return l == Block.grass.blockID || l == Block.dirt.blockID;
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        checkBlockCoordValid(world, i, j, k);
    }

    protected final void checkBlockCoordValid(World world, int i, int j, int k)
    {
        if(!canBlockStay(world, i, j, k))
        {
            dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k));
            world.setBlockWithNotify(i, j, k, 0);
        }
    }

    public boolean canBlockStay(World world, int i, int j, int k)
    {
        return canPlaceBlockAt(world, i, j, k);
    }

    public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
    {
        return null;
    }

    public int idDropped(int i, Random random)
    {
        return mod_Namehere.Namehere.blockID;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

    public int getRenderType()
    {
        return 1;
    }
}


HELP: mod_Namehere

At if(j1 == 1)
{
world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
}

add a world.setBlock(i + l, i1 + #HERE, j + k, Namehere.blockID); just change the #HERE to the next highest number

HELP: BlockNamehere

At public boolean canPlaceBlockAt(World world, int i, int j, int k)
{
int l = world.getBlockId(i, j - 1, k);
if(l == blockID)
{
return true;
}
return l == Block.grass.blockID || l == Block.dirt.blockID;


at the bottom where it says return l == Block.grass.blockID || 1 == Block.dirt.blockID;
add || 1 == Block.Namehere.blockID



Making Tools!

mod_Namehere

package net.minecraft.src;

import net.minecraft.client.Minecraft;

public class mod_Namehere extends BaseMod
{

    public mod_Namehere()
    {
        NameherePickaxe.iconIndex = ModLoader.addOverride("/gui/items.png", "/Tools/Nameherepick.png");
        NamehereShovel.iconIndex = ModLoader.addOverride("/gui/items.png", "/Tools/Nameherespade.png");
        NamehereAxe.iconIndex = ModLoader.addOverride("/gui/items.png", "/Tools/Namehereaxe.png");
        NamehereHoe.iconIndex = ModLoader.addOverride("/gui/items.png", "/Tools/Nameherehoe.png");
        NamehereSword.iconIndex = ModLoader.addOverride("/gui/items.png", "/Tools/Nameheresword.png");
       
        ModLoader.AddName(NameherePickaxe, "Namehere Pickaxe");
        ModLoader.AddName(NamehereShovel, "Namehere Shovel");
        ModLoader.AddName(NamehereAxe, "Namehere Axe");
        ModLoader.AddName(NamehereHoe, "Namehere Hoe");
        ModLoader.AddName(NamehereSword, "Namehere Sword");
       
        ModLoader.AddRecipe(new ItemStack(NameherePickaxe, 1), new Object[] {"sss", " | ", " | ", Character.valueOf('s'), Item.seeds, Character.valueOf('|'), Item.stick});
        ModLoader.AddRecipe(new ItemStack(NamehereShovel, 1), new Object[] {" s ", " | ", " | ", Character.valueOf('s'), Item.seeds, Character.valueOf('|'), Item.stick});
        ModLoader.AddRecipe(new ItemStack(NamehereAxe, 1), new Object[] {"ss ", "s| ", " | ", Character.valueOf('s'), Item.seeds, Character.valueOf('|'), Item.stick});
        ModLoader.AddRecipe(new ItemStack(NamehereHoe, 1), new Object[] {"ss ", " | ", " | ", Character.valueOf('s'), Item.seeds, Character.valueOf('|'), Item.stick});
        ModLoader.AddRecipe(new ItemStack(NamehereSword, 1), new Object[] {" s ", " s ", " | ", Character.valueOf('s'), Item.seeds, Character.valueOf('|'), Item.stick});
        }
    static
    {
        new ItemPickaxe(1000, EnumToolMaterial.EMERALD).setItemName("1");
        new ItemSpade(1001, EnumToolMaterial.EMERALD).setItemName("2");
        new ItemAxe(1002, EnumToolMaterial.EMERALD).setItemName("3");
        new ItemHoe(1003, EnumToolMaterial.EMERALD).setItemName("4");
        new ItemSword(1004, EnumToolMaterial.EMERALD).setItemName("5");
    }

    public String Version()
    {
        return "1.0.0 - Frogbite99 Tutorials";
    }

    public static Item NameherePickaxe;
    public static Item NamehereShovel;
    public static Item NamehereAxe;
    public static Item NamehereHoe;
    public static Item NamehereSword;

}

This is just like making an item except you dont need to make ItemNamehere.java files!

now for the only difficult part. find EnumToolMaterial.java file and open it up

at the top where it says
WOOD("WOOD", 0, 0, 59, 2.0F, 0, 15),
STONE("STONE", 1, 1, 131, 4F, 1, 5),
IRON("IRON", 2, 2, 250, 6F, 2, 14),
EMERALD("EMERALD", 3, 3, 1561, 8F, 3, 10),
GOLD("GOLD", 4, 0, 32, 12F, 0, 22);


delete the ; after the Gold line and put a comma there

for a new material
Namehere("NAMEHERE", 5, #, ##, #F, #, ###);
# = 0 means it can only mine stone/coal, 1 means iron, 2 means gold/diamond/redstone/lupis, 3 means obsidian
## = how many uses
#F = How strong it is against ores
### = not sure XD put the same number as emerald (aka diamond)


Making a Sword Catch Mobs on Fire!
Add
public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1)
    {
        entityliving.fire=300;
          return false;
    }

to you ItemNamehere.java file


Making an Ore Generate

mod_Namehere
public void GenerateSurface(World world, Random rand, int chunkX, int chunkZ)
    {
        for(int i = 0; i < 5; i++)
        {
            int randPosX = chunkX + rand.nextInt(16);
            int randPosY = rand.nextInt(25);
            int randPosZ = chunkZ + rand.nextInt(16);
            (new WorldGenMinable(mod_Namehere.NamehereOre.blockID, 5)).generate(world, rand, randPosX, randPosY, randPosZ);
        }
    }

goes in after
public String Version()
{
return "1.0.0";
}





Check out my Forum post to stay up-to-date with your modding needs! Forum Post is here

Ratings

Current rating: 4.01 by 240 users
Please take one second and rate this tutorial...

Not a Chance
1
2
3
4
5
6
7
8
9
10
Absolutely

Comments

"How to make Minecraft Mods [Modloader][Blocks][Items]+ MORE!" :: Login/Create an Account :: 1 comment

If you would like to post a comment please signin to your account or register for an account.

OdinPosted:

these are out of date i updated all of them in my forum post