In this tutorial we'll be creating an Ore, creating an Ingot out of our new Ore, setting up the world to generate our Ore, and adding a smelting recipe, so we can smelt that Ore into an Ingot.
This tutorial is written in the context of Minecraft 1.3.2, Minecraft Forge 4.1.2.265, and MCP 7.2. I may not be able to offer support on earlier versions, but on later versions, the process should remain fairly similar, so any questions are welcome
I will be going off the premise that you know how to create Forge mods as of Minecraft Forge 4.x, but if you don't, check out my tutorial here on Forge's Infinite Sprite Index. It explains Forge's new annotation system, and how to use Forge's texturing system to your advantage.
Let's just dive right into it!
OreTutorial.java
This is our main mod class, so it contains everything that dictates how our blocks are added into the game's code, including creating our Ore and Ingot, adding recipes, and setting up Ore generation.
Here's the whole code, with an explanation of pertinent stuff to follow:
package tutorials;
import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
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;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = "ore_tutorial", name = "Ore Tutorial", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class OreTutorial {
public static Block ourOre = new TutorialOre(200, 0);
public static Item ourIngot = new TutorialIngot(450, 0);
@PreInit
public void preInit(FMLPreInitializationEvent event) {
//loads before your mod
}
@Init
public void init(FMLInitializationEvent event) {
GameRegistry.registerBlock(ourOre);
GameRegistry.addSmelting(ourOre.blockID, new ItemStack(ourIngot), 1.0F);
GameRegistry.registerWorldGenerator(new TutorialWorldGenerator());
LanguageRegistry.addName(ourOre, "Tutorial Ore");
LanguageRegistry.addName(ourIngot, "Tutorial Ingot");
MinecraftForgeClient.preloadTexture("/tutorials/terrain.png");
MinecraftForgeClient.preloadTexture("/tutorials/items.png");
}
@PostInit
public void postInit(FMLPostInitializationEvent event) {
//loads after your mod
}
}
Most everything here is something you should understand if you followed my previous tutorial, except for the second and third GameRegistry calls.
GameRegistry.addSmelting(ourOre.blockID, new ItemStack(ourIngot), 1.0F);
This is actually adding the smelting recipe It's very simple and basically says that if you smelt "ourOre", it will produce a stack (of one, but still a stack) of ourIngot, and give you 1.0 experience.
And this is registering our custom class TutorialWorldGenerator with the game, and that class is
going to tak charge of generating our Ore in the world.
That's it for this class. Simple stuff, huh? Like I said, if you don't understand this, follow my
previous tutorial, and it should make sense.
If you want to use the same textures I did (even though they are simple hue shifts of Redstone Ore
and Gold) they're here:
terrain.png
items.png
TutorialOre.java
This is the code for our Ore, and is pretty simple as well.
package tutorials;
import java.util.Random;
import net.minecraft.src.BlockOre;
import net.minecraft.src.CreativeTabs;
public class TutorialOre extends BlockOre {
public TutorialOre(int blockID, int spriteIndex) {
super(blockID, spriteIndex);
this.setResistance(3.0F);
this.setHardness(5.0F);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setBlockName("oreTutorial");
}
@Override
public int idDropped(int i, Random r, int j) {
return OreTutorial.ourOre.blockID;
}
@Override
public int quantityDropped(Random r) {
return 1;
}
@Override
public String getTextureFile() {
return "/tutorials/terrain.png";
}
}
There are a couple key differences from my previous tutorial here. First of all, we have:
public class TutorialOre extends BlockOre {
Which says that our block inherits all the characteristics of a BlockOre, which is also where the vanilla Ores get their characteristics from. It also causes our constructor not to define which Material this block is:
super(blockID, spriteIndex);
Since all Ores begin as Material.iron, according to the constructor for BlockOre, this is fine.
That's it for our Ore, now on to the Ingot!
TutorialIngot.java
This class is also incredibly simple, and is exactly the same as my previous tutorial, except for the method to set which tab our Item displays on in the Creative inventory.
package tutorials;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Item;
public class TutorialIngot extends Item {
public TutorialIngot(int id, int spriteIndex) {
super(id);
this.setIconIndex(spriteIndex);
this.setItemName("ingotTutorial");
this.setCreativeTab(CreativeTabs.tabMaterials);
}
@Override
public String getTextureFile() {
return "/tutorials/items.png";
}
}
In my previous tutorial, it was
this.setTabToDisplayOn(CreativeTab.tabMaterials);
Now it is the same as the method for Blocks, which is:
this.setCreativeTab(CreativeTab.tabMaterials);
And you can obviously change which CreativeTab you dislay it on
That's it here. The next class is where the real fun happens!
TutorialWorldGenerator.java
This class is where all of our Ore generation happens, so it's really the most important class here. You could say I saved the best for last
package tutorials;
import java.util.Random;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.World;
import net.minecraft.src.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
public class TutorialWorldGenerator implements IWorldGenerator {
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider
chunkGenerator, IChunkProvider chunkProvider) {
switch(world.provider.dimensionId) {
case -1:
generateNether();
break;
case 0:
generateSurface(world, random, chunkX*16, chunkZ*16);
break;
case 1:
generateEnd();
break;
}
}
public void generateNether() {
//we're not doing ore ore in the nether
}
public void generateSurface(World world, Random rand, int chunkX, int chunkZ) {
for (int i = 0; i < 30; i++) {
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(64);
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(OreTutorial.ourOre.blockID, 10)).generate(world, rand,
randPosX, randPosY, randPosZ);
}
}
public void generateEnd() {
//we're not going to generate in the end either
}
}
There are a few things happening here. First of all, we have our package declaration, our imports, and then this:
public class TutorialWorldGenerator implements IWorldGenerator {
This is a new one to anyone just starting out, even if you followed my last tutorial, because we never covered the "implements" keyword there. This is a way to tell Java that you want your class to have to use all the methods that any other IWorldGenerator does.
Basically, it means that our WorldGenerator class is forced to "implement" this method defined
inside:
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider
chunkGenerator, IChunkProvider chunkProvider) {
This method takes a cornucopia of parameters, but basically what it gets when the game calls it is
a reference to which chunk is being generated.
Inside of this method we have this:
switch(world.provider.dimensionId) {
case -1:
generateNether();
break;
case 0:
generateSurface(world, random, chunkX*16, chunkZ*16);
break;
case 1:
generateEnd();
break;
}
This asks the world which type of dimension it is, and returns it as an integer. By default, in Minecraft, The Nether is -1, The Overworld is 0, and The End is 1. Now, our Ore is only going to generate in The Overworld, so inside "case 0", we call a new method; our generateSurface().
That method multiplies chunkX and chunkZ by 16, and honestly, I really don't know why, but you have to
do it, or your Ore won't generate correctly
public void generateSurface(World world, Random rand, int chunkX, int chunkZ) {
for (int i = 0; i < 30; i++) {
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(64);
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(OreTutorial.ourOre.blockID, 10)).generate(world, rand,
randPosX, randPosY, randPosZ);
}
}
This is where it all happens!
First we make a "for" loop, which says that we want to generate 30 veins of our Ore per chunk.
Next we have this:
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(64);
int randPosZ = chunkZ + rand.nextInt(16);
This takes the chunk that is being generated, and says that somewhere within its 16x16 area, and up to layer 64 (just below surface level), it will generate our Ore. The very last line in this method generates our Ore!
(new WorldGenMinable(OreTutorial.ourOre.blockID, 10)).generate(world, rand, randPosX, randPosY,
randPosZ);
This creates a new vein, using a class called WorldGenMinable (basically a block that gets generated, and can be mined), that is made up of our new Ore, and there are 10 blocks per vein. It then generates it in the random position we determined earlier in the method.
That's all of it!
Finishing up:
You can package this up and use it as a working mod (a fairly boring one so far) if you want, using the same method described in my previous tutorial
This tutorial doesn't cover Forge's Ore Dictionary, but hopefully some tutorials on that will sprout up soon
If there are any questions, suggestions, or anything that is unclear, please don't hesitate to post below
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
I followed what you said and I read some java. Your tutorial helped ALOT, and thanks. I just have one problem. My texture isn't appearing right, as it looks like clay. And my ingot/gem isn't coming up on the creative menu, and when I try to do /give, it says there is no item with the ID of 201. Thanks!
I followed what you said and I read some java. Your tutorial helped ALOT, and thanks. I just have one problem. My texture isn't appearing right, as it looks like clay. And my ingot/gem isn't coming up on the creative menu, and when I try to do /give, it says there is no item with the ID of 201. Thanks!
Did you follow my other tutorial too? That should be letting your textures work... Can you post a screenshot? Or your code? Or both?
As to the item ID, I realized that in this tutorial I used 450 instead, so try changing that. It should show up; are you sure it's not there in the inventory? It might be hiding with the others, not necessarily at the end. Also, try "/giving" 450 instead.
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
Did you follow my other tutorial too? That should be letting your textures work... Can you post a screenshot? Or your code? Or both?
As to the item ID, I realized that in this tutorial I used 450 instead, so try changing that. It should show up; are you sure it's not there in the inventory? It might be hiding with the others, not necessarily at the end. Also, try "/giving" 450 instead.
I fixed it. Thanks to you, I have 4 ores done, and 4 gems done. Once the mod is complete, I will post a link to your profile on the forums. I hope other people see this post! It would help a lot if you made a tutorial on how to make a tool set or armor set.
I fixed it. Thanks to you, I have 4 ores done, and 4 gems done. Once the mod is complete, I will post a link to your profile on the forums. I hope other people see this post! It would help a lot if you made a tutorial on how to make a tool set or armor set.
Thank you When I figure it out, I probably will. For the time being, Borderlands 2 is taking up the vast majority of my free time, however
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
I'm not sure if you meant to link me to MultiMC, but if you truly "didnt everything [I] said", then something is obviously very wrong. You should probably post your code, or an error log, or something, because without seeing what is actually wrong, I can't help at all.
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
The music discs "13" and "cat" are found in 8% of dungeon chests. All music discs except "11" can be obtained by getting a creeper to be killed by a skeleton's arrow.
Is that what you meant?
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
The music discs "13" and "cat" are found in 8% of dungeon chests. All music discs except "11" can be obtained by getting a creeper to be killed by a skeleton's arrow.
I don't actually know how to do that, so a tutorial is unlikely. However, on the same page I quoted before, on the Minecraft Wiki, it says if you replace an .ogg file, that's all it takes. Also, that type of thing probably isn't Forge specific, so any tutorial should work.
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
can you use generation like this with flowers? I tried changing worldgenminable to worldgenflowers and fixing the parameters, but when trying to make a new world minecraft would crash
can you use generation like this with flowers? I tried changing worldgenminable to worldgenflowers and fixing the parameters, but when trying to make a new world minecraft would crash
That has something to do with decorators and Biomes, I think... I don't know about that :/
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
That has something to do with decorators and Biomes, I think... I don't know about that :/
hey do you know how to render things? im currently making a gun but when i shoot it its invisible so people told me that it was because i havent created the renderbullet class
hey do you know how to render things? im currently making a gun but when i shoot it its invisible so people told me that it was because i havent created the renderbullet class
No, I don't... Sorry Everyone keeps asking me for things I don't know
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
In this tutorial we'll be creating an Ore, creating an Ingot out of our new Ore, setting up the world to generate our Ore, and adding a smelting recipe, so we can smelt that Ore into an Ingot.
This tutorial is written in the context of Minecraft 1.3.2, Minecraft Forge 4.1.2.265, and MCP 7.2. I may not be able to offer support on earlier versions, but on later versions, the process should remain fairly similar, so any questions are welcome
I will be going off the premise that you know how to create Forge mods as of Minecraft Forge 4.x, but if you don't, check out my tutorial here on Forge's Infinite Sprite Index. It explains Forge's new annotation system, and how to use Forge's texturing system to your advantage.
Let's just dive right into it!
OreTutorial.java
This is our main mod class, so it contains everything that dictates how our blocks are added into the game's code, including creating our Ore and Ingot, adding recipes, and setting up Ore generation.
Here's the whole code, with an explanation of pertinent stuff to follow:
Most everything here is something you should understand if you followed my previous tutorial, except for the second and third GameRegistry calls.
This is actually adding the smelting recipe It's very simple and basically says that if you smelt "ourOre", it will produce a stack (of one, but still a stack) of ourIngot, and give you 1.0 experience.
And this is registering our custom class TutorialWorldGenerator with the game, and that class is
going to tak charge of generating our Ore in the world.
That's it for this class. Simple stuff, huh? Like I said, if you don't understand this, follow my
previous tutorial, and it should make sense.
If you want to use the same textures I did (even though they are simple hue shifts of Redstone Ore
and Gold) they're here:
terrain.png
items.png
TutorialOre.java
This is the code for our Ore, and is pretty simple as well.
There are a couple key differences from my previous tutorial here. First of all, we have:
Which says that our block inherits all the characteristics of a BlockOre, which is also where the vanilla Ores get their characteristics from. It also causes our constructor not to define which Material this block is:
Since all Ores begin as Material.iron, according to the constructor for BlockOre, this is fine.
That's it for our Ore, now on to the Ingot!
TutorialIngot.java
This class is also incredibly simple, and is exactly the same as my previous tutorial, except for the method to set which tab our Item displays on in the Creative inventory.
In my previous tutorial, it was
Now it is the same as the method for Blocks, which is:
And you can obviously change which CreativeTab you dislay it on
That's it here. The next class is where the real fun happens!
This class is where all of our Ore generation happens, so it's really the most important class here. You could say I saved the best for last
There are a few things happening here. First of all, we have our package declaration, our imports, and then this:
This is a new one to anyone just starting out, even if you followed my last tutorial, because we never covered the "implements" keyword there. This is a way to tell Java that you want your class to have to use all the methods that any other IWorldGenerator does.
Basically, it means that our WorldGenerator class is forced to "implement" this method defined
inside:
This method takes a cornucopia of parameters, but basically what it gets when the game calls it is
a reference to which chunk is being generated.
Inside of this method we have this:
This asks the world which type of dimension it is, and returns it as an integer. By default, in Minecraft, The Nether is -1, The Overworld is 0, and The End is 1. Now, our Ore is only going to generate in The Overworld, so inside "case 0", we call a new method; our generateSurface().
That method multiplies chunkX and chunkZ by 16, and honestly, I really don't know why, but you have to
do it, or your Ore won't generate correctly
This is where it all happens!
First we make a "for" loop, which says that we want to generate 30 veins of our Ore per chunk.
Next we have this:
This takes the chunk that is being generated, and says that somewhere within its 16x16 area, and up to layer 64 (just below surface level), it will generate our Ore. The very last line in this method generates our Ore!
This creates a new vein, using a class called WorldGenMinable (basically a block that gets generated, and can be mined), that is made up of our new Ore, and there are 10 blocks per vein. It then generates it in the random position we determined earlier in the method.
That's all of it!
You can package this up and use it as a working mod (a fairly boring one so far) if you want, using the same method described in my previous tutorial
This tutorial doesn't cover Forge's Ore Dictionary, but hopefully some tutorials on that will sprout up soon
If there are any questions, suggestions, or anything that is unclear, please don't hesitate to post below
This.
Did you follow my other tutorial too? That should be letting your textures work... Can you post a screenshot? Or your code? Or both?
As to the item ID, I realized that in this tutorial I used 450 instead, so try changing that. It should show up; are you sure it's not there in the inventory? It might be hiding with the others, not necessarily at the end. Also, try "/giving" 450 instead.
I fixed it. Thanks to you, I have 4 ores done, and 4 gems done. Once the mod is complete, I will post a link to your profile on the forums. I hope other people see this post! It would help a lot if you made a tutorial on how to make a tool set or armor set.
Thank you When I figure it out, I probably will. For the time being, Borderlands 2 is taking up the vast majority of my free time, however
(dimensionId cannot be resolved or is not a field)
http://forkk.net/MultiMC4
I'm not sure if you meant to link me to MultiMC, but if you truly "didnt everything [I] said", then something is obviously very wrong. You should probably post your code, or an error log, or something, because without seeing what is actually wrong, I can't help at all.
From the Minecraft Wiki:
The music discs "13" and "cat" are found in 8% of dungeon chests. All music discs except "11" can be obtained by getting a creeper to be killed by a skeleton's arrow.
no i mean like make a custom one
That has something to do with decorators and Biomes, I think... I don't know about that :/
hey do you know how to render things? im currently making a gun but when i shoot it its invisible so people told me that it was because i havent created the renderbullet class
No, I don't... Sorry Everyone keeps asking me for things I don't know