Jump to content

  • Curse Sites
Become a Premium Member! Help
Latest News Article

[Creating Mods] Modding tutorials [21/5/11]


  • Please log in to reply
5201 replies to this topic

#1

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 11 December 2010 - 12:07 AM

*
POPULAR

Modding Tutorials

In these tutorials I will explain how to create basic mods. I am willing to help people learn how to mod and I will take requests on how to mod certain things. The aim of this thread is to create a central location for all tutorials.

Below is a tutorial list which has details about each mod. Note that no matter how old the tutorial is, what you should learn in the tutorial is how to go about modding that particular aspect of the game.

Note: MCP only works for the version of Minecraft it is released with. You CANNOT use MCP with a newer or older version of minecraft. For example: MCP 2.6 ONLY works with Minecraft 1.1_02.

Tutorial List (Game Mods):
Create a new Block type
Difficulty/Time: 2/10
Last Update: 21/Feb/2011
Minecraft Version: Alpha 1.2.6 - Beta 1.5_01
MCP Version: 2.7-3.1
Author: simo_415


Create a new Recipe
Difficulty/Time: 1/10
Last Update: 12/Dec/2010
Minecraft Version: Alpha 1.2.6 - Beta 1.5_01
MCP Version: 2.5 - 3.1
Author: simo_415


Create a new Item type
Difficulty/Time: 2/10
Last Update: 12/Dec/2010
Minecraft Version: Alpha 1.2.6 - Beta 1.5_01
MCP Version: 2.5 - 3.1
Author: simo_415


Create a new Block for the Furnace
Difficulty/Time: 2/10
Last Update: 14/Dec/2010
Minecraft Version: 1.2.6 - ?
MCP Version: 2.5 - ?
Author: Marcus101RR


Customising a block class
Difficulty/Time: 3/10
Last Update: 17/Dec/2010
Minecraft Version: Alpha 1.2.6 - Beta 1.5_01
MCP Version: 2.5 - 3.1
Author: simo_415


Create a new NPC
Difficulty/Time: 6/10
Last Update: 17/Dec/2010
Minecraft Version: Beta 1.5_01
MCP Version: 2.7-3.1
Author: simo_415


Controlling NPC movement
Difficulty/Time: 6/10
Last Update: 20/Jan/2011
Minecraft Version: 1.1_02
MCP Version: 2.6
Author: OgreSean


Create custom world generation
Difficulty/Time: 5/10
Last Update: 17/Dec/2010
Minecraft Version: Alpha 1.2.6 - Beta 1.5_01
MCP Version: 2.5 - 3.1
Author: simo_415


Making an Item with ModLoader
Difficulty/Time: 3/10
Last Update: 20/Feb/2011
Minecraft Version: Beta 1.2_02
MCP Version: 2.7
Author: Gidding


Custom WorldGeneration (ModLoader)
Difficulty/Time: 5/10
Last Update: 20/Feb/2011
Minecraft Version: Beta 1.2_02
MCP Version: 2.7
Author: Club559


Creating a weapon (ModLoader)
Difficulty/Time: 3/10
Last Update: 18/Mar/2011
Minecraft Version: Beta 1.3_01
MCP Version: 2.9
Author: blahthing


Creating a pickaxe/shovel (ModLoader)
Difficulty/Time: 3/10
Last Update: 18/Mar/2011
Minecraft Version: Beta 1.3_01
MCP Version: 2.9
Author: blahthing


Create a Custom Block with Modloader
Difficulty/Time: 2/10
Last Update: 17/Jun/2011
Minecraft Version: Beta 1.6.6
MCP Version: 3.3
Author: BuilderJ3rk


Tutorial List (Other):
Making your mod compatible with the ModLoader
Difficulty/Time: 4/10
Last Update: 9/Jan/2011
Author: Club559


How to make a simple person mob (with ModLoader)
Difficulty/Time: 5/10
Last Update: 9/Jan/2011
Author: Club559


How to update a mod to the latest version of MC (without MCP)
Difficulty/Time: 8/10
Last Update: 28/Dec/2010
Author: simo_415


How to mod on a MAC
Difficulty/Time: 4/10
Last Update: 12/Jan/2011
Author: BHCS


Thorough guide to beginning Minecraft modding
Difficulty/Time: 1-3/10
Author: birjolaxew


Complete beginners guide to modding
Difficulty/Time: 1-3/10
Author: Mr. Hobo


Fixing common compile and runtime errors
Difficulty/Time: 1/10
Last Update: 21/May/2011
Author: simo_415


SMP Modding:
How to mod a SMP server
Difficulty/Time: Varies
Author: Mzaq

If you would like another tutorial added to this list please PM me the link to the thread/post and if it is a legitimate modding tutorial I will add it to this list.

Requirements

1. Java Development Kit 6 (JDK6)
2. Minecraft Coder Pack (latest)
3. EditPlus/Notepad++/Eclipse/Netbeans (text editor with syntax highlighting)
4. Programming knowledge, preferably Java

To begin with

1. Setup the minecraft coder pack (MCP)
   1.1 Extract the ZIP to a directory on your computer, for this example; C:/MCP
   1.2 Copy the whole .minecraft/bin and .minecraft/resources directories to C:/MCP/jars/
   1.3 Run decompile.bat

2. Open two Windows, one to C:/MCP/sources/minecraft/net/minecraft/src the other to C:/MCP/

Running your mods
To run your mods you first need to compile, debug, and test.
1. To compile run 'recompile.bat' this will generate all the class files for minecraft.
2. Go to C:/MCP/logs/minecraft_compile.log and search for ^ if this character is not found, there are no compile errors. If there is you will need to fix your code where the errors are and try compiling again.
3. If there is no errors, run 'test_game.bat'.
4. This will bring up an alternate version of minecraft with your mod installed - test your mod.

Once satisfied that the mod is complete you need to obfuscate it so that it can be added to minecraft.jar

Using Eclipse
You can use Eclipse to write your mod in, debug your code, compile your code, run your code - it will save you a lot of time in the long run if you use it.


Obfuscating the Code
Obfuscating the code allows your mod to work in minecraft.jar for anyone
1. Open C:/MCP/conf/client_conf.txt
2. Remove all the lines in the file.
3. Add the classes you changed, for example:
BlockExample
Block
CraftingManager
4. Run 'reobf.bat'
5. All the classes contained within C:/MCP/final_out/minecraft/ are the mod classes. Add these to minecraft.jar to add your mod to the game.

Any questions about this feel free to ask. Please refer people who are posting on how to add a block/crafting recipe to this post. I will probably add a few more tutorials on how to do simple things. Any feedback is appreciated.

Register or log in to remove.

#2

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 11 December 2010 - 04:07 AM

In this tutorial I will explain how to create a new block in Minecraft and how to make it craftable. This tutorial makes a standard block like stone.

Creating a new block

1. You need to make a new file called BlockExample.java in the src directory.
2. The basic structure of this file is this:
package net.minecraft.src;

import java.util.Random;

public class BlockExample extends Block
{
	public BlockExample(int i, int j)
	{
		super(i, j, Material.rock);
	}

	public int idDropped(int i, Random random)
	{
		return 0;
	}
}
3. You now need to add this block to minecraft so that it knows about it. To do this open up Block.java
4. You should see a whole bunch of variable declarations towards the bottom of the file, add a new one:
public static final Block example;
5. Below the declarations you should see initialisation of these instance variables, initialise your block.
example = (new BlockExample(92, 1)).setHardness(1.5F).setResistance(10F).setStepSound(soundStoneFootstep);
Like mentioned before this example block is creating a new 'stone' block.
new BlockExample(92, 1) creates the new block, the first number is the block id - THIS HAS TO BE UNIQUE, the second number is the graphic of the block, in this case the same as stone.
setHardness(1.5F) is the same as stone, this is how long it takes to destroy a block.
setResistance(10F) is the same as stone, this is how strong the block is against explosions.
setStepSound(soundStoneFootstep) is the same as stone, this is the sound it makes when you walk on it.

You have now successfully created a new block class. To use this block you need to generate it, this can be done using the Single Player Commands mod using this command: "/give 92".

Continue on reading if you want to add a recipe to the crafting table to make this block.

Creating a new recipe
1. Open up CraftingManager.java
2. You should immediately see the constructor for the class and within it recipes being added using the addRecipe function.
3. Scroll to the bottom of this list of recipes and add in a new one:
addRecipe(new ItemStack(Block.example, 1), new Object[] {"##", "##", Character.valueOf('#'), Block.dirt});
This will add a recipe in which when you craft four dirt is a square share will give you your new block.
new ItemStack(Block.example, 1) - this specifies what item is going to be generated and the quantity.
new Object[] {"##", "##", Character.valueOf('#'), Block.dirt} - this specifies how it is created.

This should allow you to now craft a very basic new block using four dirt like so:
:P  :soil:
:soil:  :soil:

#3

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 11 December 2010 - 01:13 PM

Creating a new Item type

1. You need to create a new file called ItemExample.java in the src directory.
2. The basic structure of the file is this:
package net.minecraft.src;

public class ItemExample extends Item
{
	public ItemFood(int i)
	{
		super(i);
		maxStackSize = 64;
	}

	public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
	{
	}
}
3. You now need to add this item to minecraft so that it knows about it. To do this open up Item.java
4. Towards the bottom of the file there should be a whole heap of instance variables, add a new one:
public static Item example = (new ItemExample(95)).setIconIndex(42);
This will create a new item which is item id 256 + 95 and uses icon 42. Therefore it should look like a sign. Currently it has no properties, and you cannot craft it. But after you compile and run the mod it will add the new item to minecraft.

#4

Flapman
    Flapman

    Zombie Killer

  • Members
  • 190 posts

Posted 11 December 2010 - 01:29 PM

Thx for this tutorial, but Im stuck at "recompile.bat" because when I run it, it says:

Finding javac.exe... if you want to speed this up, add it to your PATH
'C:\Users\Hypothawits\minecraft' is not recognized as an internal or external command
,
operable program or batch file.
Path set.
Unable to locate javac.exe. Please verify that it is in the PATH.
If you don't know where to get it, please visit http://www.oracle.com/technetwor
k/java/javase/downloads/index.html and download a JDK.
Press any key to continue . . .

Yes I have JDK, but how can I change the PATH?

#5

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 11 December 2010 - 01:37 PM

Flapman said:

Thx for this tutorial, but Im stuck at "recompile.bat" because when I run it, it says:

Finding javac.exe... if you want to speed this up, add it to your PATH
'C:\Users\Hypothawits\minecraft' is not recognized as an internal or external command
,
operable program or batch file.
Path set.
Unable to locate javac.exe. Please verify that it is in the PATH.
If you don't know where to get it, please visit http://www.oracle.com/technetwor
k/java/javase/downloads/index.html and download a JDK.
Press any key to continue . . .

Yes I have JDK, but how can I change the PATH?

I gather you have no knowledge of Java in this case, I hope you have programming knowledge... Basically you need to add javac to the PATH there are ample guides on how to do this if you search google.

For example... here is one: http://www.phoons.co.../aboutpath.html

You can test if it is set by opening up a shell/command prompt and typing 'javac' if it is found then it is configured correctly.

#6

ManxAndrew
  • Location: Isle of Man

Posted 11 December 2010 - 01:43 PM

Okay I'm still stuck with making my spear. This is what I've tried.

package net.minecraft.src;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 


public class ItemSpear extends Item
{

	public ItemSpear(int i, int j)
	{
		super(i);
		maxStackSize = 1;
		maxDamage = 44 << j;
		if(j == 3)
		{
			maxDamage *= 4;
		}
		weaponDamage = 4 + j * 2;
	}

	public float getStrVsBlock(ItemStack itemstack, Block block)
	{
		return 1.5F;
	}

	public void hitEntity(ItemStack itemstack, EntityLiving entityliving)
	{
		itemstack.damageItem(1);
	}

	public void hitBlock(ItemStack itemstack, int i, int j, int k, int l)
	{
		itemstack.damageItem(4);
	}

	public int getDamageVsEntity(Entity entity)
	{
		return weaponDamage;
	}

	public boolean isFull3D()
	{
		return true;
	}

	private int weaponDamage;
}

In a file called ItemSpear.java

then added
craftingmanager.addRecipe(new ItemStack(Item.spear, 1), new Object[] {
		"  X", " # ", "#  ", Character.valueOf('X'), Item.flint, Character.valueOf('#'), Item.sticks
	});
underneath the two recipes for a bow and arrows in RecipesWeapons.java

and lastly added

public static Item spear (new ItemSpear(101, 0)).setIconIndex(53);

to Item.java It should look like a stick. So what's wrong? I've recompiled, tested and it didn't work. So I reobfuscated and put the new class files into my minecraft.jar and it didn't work there either.

Any help?

#7

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 11 December 2010 - 01:53 PM

Have you checked your compile logs? Read my first post about it.

I copied your code and compiled it and found that there was a compile error "Item.sticks" not found. I changed it to Item.stick and this is what I got:

Posted Image

Also I gather you are using the ModLoader due to craftingmanager.addRecipe(...) I haven't used this and I am not sure the level of support that there is for MCP as well, if there is any other problem with your code it would be to do with that... The rest of it is perfect.

#8

ManxAndrew
  • Location: Isle of Man

Posted 11 December 2010 - 01:55 PM

haha, Thanks, I'll go fix that now. Never realised.

/me feels retarded O.o

#9

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 11 December 2010 - 01:56 PM

ManxAndrew said:

haha, Thanks, I'll go fix that now. Never realised.

/me feels retarded O.o

Hehe it's ok

#10

Flapman
    Flapman

    Zombie Killer

  • Members
  • 190 posts

Posted 11 December 2010 - 02:12 PM

Thank you so much :P, I made my first ever minecraft block! <3

#11

ManxAndrew
  • Location: Isle of Man

Posted 11 December 2010 - 02:25 PM

Another thing, I went into the jar folder and drew a spear sprite and put it in the slot that should be setIconIndex(255)

I tried that and the spear just returned no sprite. I also edited the item.png in the bin.minecraft jar to be the same, so how do I set up new sprites?

#12

dcrew
    dcrew

    Zombie Killer

  • Members
  • 217 posts

Posted 11 December 2010 - 03:49 PM

I get a all errors on imports from Minecraft.java
I'll list a few:
[parsing started sources\minecraft\net\minecraft\client\Minecraft.java]
sources\minecraft\net\minecraft\client\Minecraft.java:7: '.' expected
import AxisAlignedBB;
					^
sources\minecraft\net\minecraft\client\Minecraft.java:7: ';' expected
import AxisAlignedBB;
					 ^
sources\minecraft\net\minecraft\client\Minecraft.java:8: class, interface, or enum expected
import Block;
	   ^
sources\minecraft\net\minecraft\client\Minecraft.java:9: '.' expected
import BlockGrass;
				 ^
sources\minecraft\net\minecraft\client\Minecraft.java:9: ';' expected
import BlockGrass;
				  ^
sources\minecraft\net\minecraft\client\Minecraft.java:10: class, interface, or enum expected
import EffectRenderer;
	   ^
sources\minecraft\net\minecraft\client\Minecraft.java:11: '.' expected
import EntityPlayer;
				   ^

Here's what I've done:

ItemThrowingknives.java :
package net.minecraft.src;

public class ItemThrowingknives extends Item
{
	public ItemThrowingknives(int i)
	{
		super(i);
		maxStackSize = 64;
	}

	public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
	{
		if(entityplayer.inventory.consumeInventoryItem(Item.throwingknives.shiftedIndex))
		{
			world.playSoundAtEntity(entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
			if(!world.multiplayerWorld)
			{
				world.entityJoinedWorld(new EntityArrow(world, entityplayer));
			}
		}
		return itemstack;
	}
}

Item.java :
	public static Item throwingknives = (new ItemThrowingknives(101, 0)).setIconIndex(37);

RecipesWeapons.java :

Under :
		craftingmanager.addRecipe(new ItemStack(Item.bow, 1), new Object[] {
			" #X", "# X", " #X", Character.valueOf('X'), Item.silk, Character.valueOf('#'), Item.stick
		});
		craftingmanager.addRecipe(new ItemStack(Item.arrow, 4), new Object[] {
			"X", "#", "Y", Character.valueOf('Y'), Item.feather, Character.valueOf('X'), Item.flint, Character.valueOf('#'), Item.stick
		});

Added :
		craftingmanager.addRecipe(new ItemStack(Item.throwingknives, 8), new Object[] {
			"X  ", "#  ", "   ", Character.valueOf('X'), Item.flint, Character.valueOf('#'), Item.stick
		});

Minecraft 2D - www.minecraftforum.net/topic/1131475-minecraft-2d-in-dev-community-build/

Posted Image

#13

gameman
    gameman

    404: Member Not Found

  • Members
  • 404 posts
  • Location: Holland as known as the Netherlands
  • Minecraft: gameman

Posted 11 December 2010 - 06:28 PM

I`ve made a new block (just the example one). and I want to test the game,I haven`t any bugs in my scripts but it will not run. please helpme fast.

gameman
Have a nice day!

#14

Hoppip
    Hoppip

    Out of the Water

  • Members
  • 8 posts

Posted 11 December 2010 - 11:00 PM

Thanks man finally got it to work :D
Posted Image

#15

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 12 December 2010 - 01:08 AM

ManxAndrew said:

Another thing, I went into the jar folder and drew a spear sprite and put it in the slot that should be setIconIndex(255)

I tried that and the spear just returned no sprite. I also edited the item.png in the bin.minecraft jar to be the same, so how do I set up new sprites?

You need to edit the /temp/minecraft/gui/item.png file.

#16

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 12 December 2010 - 01:10 AM

dcrew said:

I get a all errors on imports from Minecraft.java
I'll list a few:
[parsing started sources\minecraft\net\minecraft\client\Minecraft.java]
sources\minecraft\net\minecraft\client\Minecraft.java:7: '.' expected
import AxisAlignedBB;
					^
sources\minecraft\net\minecraft\client\Minecraft.java:7: ';' expected
import AxisAlignedBB;
					 ^
sources\minecraft\net\minecraft\client\Minecraft.java:8: class, interface, or enum expected
import Block;
	   ^
sources\minecraft\net\minecraft\client\Minecraft.java:9: '.' expected
import BlockGrass;
				 ^
sources\minecraft\net\minecraft\client\Minecraft.java:9: ';' expected
import BlockGrass;
				  ^
sources\minecraft\net\minecraft\client\Minecraft.java:10: class, interface, or enum expected
import EffectRenderer;
	   ^
sources\minecraft\net\minecraft\client\Minecraft.java:11: '.' expected
import EntityPlayer;
				   ^

Here's what I've done:

ItemThrowingknives.java :
package net.minecraft.src;

public class ItemThrowingknives extends Item
{
	public ItemThrowingknives(int i)
	{
		super(i);
		maxStackSize = 64;
	}

	public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
	{
		if(entityplayer.inventory.consumeInventoryItem(Item.throwingknives.shiftedIndex))
		{
			world.playSoundAtEntity(entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
			if(!world.multiplayerWorld)
			{
				world.entityJoinedWorld(new EntityArrow(world, entityplayer));
			}
		}
		return itemstack;
	}
}

Item.java :
	public static Item throwingknives = (new ItemThrowingknives(101, 0)).setIconIndex(37);

RecipesWeapons.java :

Under :
		craftingmanager.addRecipe(new ItemStack(Item.bow, 1), new Object[] {
			" #X", "# X", " #X", Character.valueOf('X'), Item.silk, Character.valueOf('#'), Item.stick
		});
		craftingmanager.addRecipe(new ItemStack(Item.arrow, 4), new Object[] {
			"X", "#", "Y", Character.valueOf('Y'), Item.feather, Character.valueOf('X'), Item.flint, Character.valueOf('#'), Item.stick
		});

Added :
		craftingmanager.addRecipe(new ItemStack(Item.throwingknives, 8), new Object[] {
			"X  ", "#  ", "   ", Character.valueOf('X'), Item.flint, Character.valueOf('#'), Item.stick
		});

Sounds like the decompile.bat didn't rename all the classes correctly. Try running update_names.bat and try again

#17

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 12 December 2010 - 01:13 AM

gameman said:

I`ve made a new block (just the example one). and I want to test the game,I haven`t any bugs in my scripts but it will not run. please helpme fast.

gameman

Some more information would help I guess. If there are no errors in the compile log and the game won't run this is very unusual. Will the minecraft GUI appear? Does the test_game.bat script print out any errors (put a "pause" at the end of the script to check)?

#18

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 12 December 2010 - 01:15 AM

Hoppip said:

Im trying to make a Bacon block but i keep getting errors while compiling..
Note:I know it already exist but i'm new and i gotta start somewhere

MeatBlock.java
package net.minecraft.src;

import java.util.Random;

public class MeatBlock extends Block
{
	public MeatBlock(int i, int j)
	{
		super(i, j, Material.rock);
	}


	public int idDropped(int i, Random random)
	{
		return 0;
	}
}

Error
MeatBlock.java:5: cannot find symbol
symbol: class Block
public class MeatBlock extends Block
							   ^
MeatBlock.java:5: cannot find symbol
symbol: variable Material
location: class net.minecraft.scr.MeatBlock
				   super(i, j, Material.rock);
2 errors

EDIT: I found it nvm :)
EDIT 2: I lied. When i recompile everything all the "block" classes are missing, "crafting" classes and MeatBlock(my custom block) is missing.. Help please D:

From the two errors I can one obvious problem "net.minecraft.scr.MeatBlock" should be "net.minecraft.src.MeatBlock". The other problem could be the same as the first, check the package name (first line of file) make sure that this is correct, it needs to be the same as all the other files.

#19

ManxAndrew
  • Location: Isle of Man

Posted 12 December 2010 - 01:42 AM

Thanks, now is there a way to do it with a separate sprite sheet? I want to make it compatible with other mods so that if other mods use items.png my spear won't conflict.

#20

simo_415
    simo_415

    Glowstone Miner

  • Members
  • 3046 posts

Posted 12 December 2010 - 02:38 AM

ManxAndrew said:

Thanks, now is there a way to do it with a separate sprite sheet? I want to make it compatible with other mods so that if other mods use items.png my spear won't conflict.

Hmm.. I haven't delved that deeply into the actual sprites, I would assume that it is possible to do by changing RenderItem.java to pick up a new file or create a new Render class. Like I mentioned I haven't really had too good a look into how to do this though.