could you please make a tutorial on how to make a block drop an item (example: diamond ore drops diamond)
I have tried copying codes from the Blocks.java file but it doesn't seem to work!
PLEASE HELP!
All you do is change the idDropped
an example, if you wanted to make Iron ore drop diamond, you would write this:
public int idDropped(int x, Random random, int y)
{
return Item.diamond.shiftedIndex;
}
instead of this:
public int idDropped(int x, Random random, int y)
{
return Block.oreIron.blockID;
}
Hello, in this tutorial I will be showing you how to create different mods in Minecraft! I will NOT be showing you how to set up MCP, or Eclipse (USE IT!). I do strongly suggest using Eclipse be cause it will make your life so much easier! Make sure to install ModLoader into MCP before using these tutorials. I do suggest that you write out everything and don't just Copy-and-Paste. You will learn more. Also, I will note one thing; When creating textures, put the texture into the temp/bin/minecraft folder in MCP. Okay, on with the tutorials!
(Make sure to press the button at the bottom right!) +1 +1 +1
Tutorials
--- Basic Block
------ Item
--------- Generating Ores
------------ Armor
--------------- Tools
------------------ Advanced Block
---------------------- Food
------------------------- Smelting your ore
---------------------------- Making your smelted ore food!
================ And more to come!
Helpers
This is for the people that help out if I cannot or am not around. Thanks a lot for whoever does help!
[None yet!]
Help
If you get an error if Minecraft crashes be sure to READ the error. It does come in handy and will usually tell you what is wrong.
Also, you ALWAYS have to add this to every "mod_NameHere":
Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
Actual Tutorials
Block
This tutorial in on a basic block with a recipe, block ID, and the code for the texture!
mod_NameHere
package net.minecraft.src;
import java.util.*;
public class mod_NameHere extends BaseMod
{
public String Version()
{
return "1.0.0";
}
public mod_NameHere()
{
ModLoader.RegisterBlock(NameHere);
Diamonite.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/mod/NameHere.png"); //Make sure to create this texture!
ModLoader.AddName(NameHere, "NameHere");
ModLoader.AddRecipe(new ItemStack(Namehere, 1), new Object[] {
"333", "333", "333", Character.valueOf('3'), Block.dirt
});
}
public static Block NameHere = new BlockNameHere(190,0).setHardness(3.5F).setResistance(2.0F).setBlockName("NameHere");
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
}
BlockNameHere
package net.minecraft.src;
import java.util.Random;
public class BlockNameHere extends Block
{
public BlockNameHere(int i, int j)
{
super(i, j, Material.rock);
}
public int idDropped(int i, Random random)
{
return mod_NameHere.NameHere.blockID;
}
public int quantityDropped(Random random)
{
return 1;
}
}
Item
mod_NameHere
package net.minecraft.src;
public class mod_NameHere extends BaseMod
{
public static final Item NameHere = new Item(31415).setItemName("NameHere");
public String Version()
{
return "1.0.0";
}
public mod_NameHere()
{
NameHere.iconIndex = ModLoader.addOverride("/gui/items.png", "/mod/NameHere.png");
ModLoader.AddName(NameHere, "NameHere");
}
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
}
ItemNameHere
package net.minecraft.src;
import java.util.Random;
public class ItemNameHere extends Item
{
public ItemNameHere (int i)
{
super(i);
maxStackSize = 64;
}
}
Food(Really easy!)
For this tutorial I am just going to use the example "Pie". mod_Pie
package net.minecraft.src;
public class mod_Pie extends BaseMod
{
public String Version()
{
return "1.0.0";
}
public mod_Pie()
{
Pie.iconIndex = ModLoader.addOverride("/gui/items.png", "/mORES/Pie.png");
ModLoader.AddName(Pie, "Pie");
ModLoader.AddRecipe(new ItemStack(Pie, 1), new Object[] {
" ", " ", " 1 ", Character.valueOf('1'), Block.dirt, Character.valueOf('2'), Item.wheat, Character.valueOf('3'), Item.bucketMilk, Character.valueOf('4'), Item.egg
});
}
public static Item Pie = (new ItemFood(31415, 8, 1F, false)).setItemName("Pie");
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
}
Generating Ores(Add this in the block we made)
mod_NameHere
public void GenerateSurface(World world, Random rand, int chunkX, int chunkZ)
{
for(int i = 0; i < 50; i++) //The -50- is how many allowed per chunk.
{
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(128); //Height above Bedrock is allowed to spawn.
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(mod_Silver.Silver.blockID, 60)).generate(world, rand, randPosX, randPosY, randPosZ); // -60- is how many per vain.
}
}
Smelting
I will show you how to smelt your ore into the item. mod_NameHere
public mod_NameHere()
{
ModLoader.RegisterBlock(NameHere);
NameHere.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Folder/NameHere.png");
ModLoader.AddName(NameHere, "NameHere");
ModLoader.AddSmelting(NameHere.blockID, new ItemStack(mod_NameHere.NameHere, 1, 1)); //The last part: new ItemStack(mod_NameHere.NameHere, 1, 1));. That is your item name.
}
Add this in there:
ModLoader.AddSmelting(NameHere.blockID, new ItemStack(mod_NameHere.NameHere, 1, 1));
\
Making your smelted ore food!
Go into your mod_NameHere. This is the item mod_NameHere.
mod_NameHere
Change this:
public static final Item NameHere = new Item(30000).setItemName("NameHere");
To this:
public static final Item NameHere = (new ItemFood(30000, 1, 1F, false)).setItemName("NameHere");
Advanced Block(All these are in the BlockNameHere)
Self building house!
package net.minecraft.src;
import java.util.Random;
public class BlockNameHere extends Block
{
public BlockNameHere(int i, int j)
{
super(i, j, Material.rock);
}
public int idDropped(int i, Random random)
{
return mod_NameHere.NameHere.blockID;
}
public int quantityDropped(Random random)
{
return 1;
}
public void onBlockClicked(World world, int i, int j, int k, EntityPlayer entityplayer)
{
int block = Block.planks.blockID;
int block2 = Block.doorWood.blockID;
int block3 = Block.wood.blockID;
int block4 = Block.glass.blockID;
//Log Pillers
world.setBlockWithNotify(i + 5, j + 0, k, block3);
world.setBlockWithNotify(i + 5, j + 1, k, block3);
world.setBlockWithNotify(i + 5, j + 2, k, block3);
world.setBlockWithNotify(i + 5, j + 3, k, block3);
world.setBlockWithNotify(i, j + 0, k + 5, block3);
world.setBlockWithNotify(i, j + 1, k + 5, block3);
world.setBlockWithNotify(i, j + 2, k + 5, block3);
world.setBlockWithNotify(i, j + 3, k + 5, block3);
world.setBlockWithNotify(i + 5, j + 0, k + 5, block3);
world.setBlockWithNotify(i + 5, j + 1, k + 5, block3);
world.setBlockWithNotify(i + 5, j + 2, k + 5, block3);
world.setBlockWithNotify(i + 5, j + 3, k + 5, block3);
world.setBlockWithNotify(i, j + 0, k, block3);
world.setBlockWithNotify(i, j + 1, k, block3);
world.setBlockWithNotify(i, j + 2, k, block3);
world.setBlockWithNotify(i, j + 3, k, block3);
//Walls (Wood)
world.setBlockWithNotify(i + 4, j + 0, k, block);
world.setBlockWithNotify(i + 4, j + 2, k, block);
world.setBlockWithNotify(i + 4, j + 3, k, block);
world.setBlockWithNotify(i + 1, j + 0, k, block);
world.setBlockWithNotify(i + 1, j + 2, k, block);
world.setBlockWithNotify(i + 1, j + 3, k, block);
world.setBlockWithNotify(i + 2, j + 3, k, block);
world.setBlockWithNotify(i + 2, j + 2, k, block);
world.setBlockWithNotify(i + 3, j + 2, k, block);
world.setBlockWithNotify(i + 3, j + 2, k, block);
world.setBlockWithNotify(i, j + 0, k + 1, block);
world.setBlockWithNotify(i, j + 0, k + 2, block);
world.setBlockWithNotify(i, j + 0, k + 3, block);
world.setBlockWithNotify(i, j + 0, k + 4, block);
world.setBlockWithNotify(i, j + 1, k + 1, block);
world.setBlockWithNotify(i, j + 2, k + 1, block);
world.setBlockWithNotify(i, j + 3, k + 1, block);
world.setBlockWithNotify(i, j + 1, k + 4, block);
world.setBlockWithNotify(i, j + 2, k + 4, block);
world.setBlockWithNotify(i, j + 3, k + 4, block);
world.setBlockWithNotify(i, j + 3, k + 2, block);
world.setBlockWithNotify(i, j + 3, k + 3, block);
world.setBlockWithNotify(i + 1, j + 0, k + 5, block);
world.setBlockWithNotify(i + 2, j + 0, k + 5, block);
world.setBlockWithNotify(i + 3, j + 0, k + 5, block);
world.setBlockWithNotify(i + 4, j + 0, k + 5, block);
world.setBlockWithNotify(i + 1, j + 1, k + 5, block);
world.setBlockWithNotify(i + 1, j + 2, k + 5, block);
world.setBlockWithNotify(i + 1, j + 3, k + 5, block);
world.setBlockWithNotify(i + 4, j + 1, k + 5, block);
world.setBlockWithNotify(i + 4, j + 2, k + 5, block);
world.setBlockWithNotify(i + 4, j + 3, k + 5, block);
world.setBlockWithNotify(i + 2, j + 3, k + 5, block);
world.setBlockWithNotify(i + 3, j + 3, k + 5, block);
world.setBlockWithNotify(i + 5, j + 0, k + 1, block);
world.setBlockWithNotify(i + 5, j + 0, k + 2, block);
world.setBlockWithNotify(i + 5, j + 0, k + 3, block);
world.setBlockWithNotify(i + 5, j + 0, k + 4, block);
world.setBlockWithNotify(i + 5, j + 1, k + 1, block);
world.setBlockWithNotify(i + 5, j + 2, k + 1, block);
world.setBlockWithNotify(i + 5, j + 3, k + 1, block);
world.setBlockWithNotify(i + 5, j + 1, k + 4, block);
world.setBlockWithNotify(i + 5, j + 2, k + 4, block);
world.setBlockWithNotify(i + 5, j + 3, k + 4, block);
world.setBlockWithNotify(i + 5, j + 3, k + 2, block);
world.setBlockWithNotify(i + 5, j + 3, k + 3, block);
world.setBlockWithNotify(i + 3, j + 3, k, block);
//Walls (Glass)
world.setBlockWithNotify(i + 4, j + 1, k, block4);
world.setBlockWithNotify(i + 1, j + 1, k, block4);
world.setBlockWithNotify(i, j + 1, k + 2, block4);
world.setBlockWithNotify(i, j + 1, k + 3, block4);
world.setBlockWithNotify(i, j + 2, k + 2, block4);
world.setBlockWithNotify(i, j + 2, k + 3, block4);
world.setBlockWithNotify(i + 2, j + 1, k + 5, block4);
world.setBlockWithNotify(i + 3, j + 1, k + 5, block4);
world.setBlockWithNotify(i + 2, j + 2, k + 5, block4);
world.setBlockWithNotify(i + 3, j + 2, k + 5, block4);
world.setBlockWithNotify(i + 5, j + 1, k + 2, block4);
world.setBlockWithNotify(i + 5, j + 1, k + 3, block4);
world.setBlockWithNotify(i + 5, j + 2, k + 2, block4);
world.setBlockWithNotify(i + 5, j + 2, k + 3, block4);
//Roof
world.setBlockWithNotify(i + 1, j + 4, k + 1, block);
world.setBlockWithNotify(i + 1, j + 4, k + 2, block);
world.setBlockWithNotify(i + 1, j + 4, k + 3, block);
world.setBlockWithNotify(i + 1, j + 4, k + 4, block);
world.setBlockWithNotify(i + 2, j + 4, k + 1, block);
world.setBlockWithNotify(i + 2, j + 4, k + 2, block);
world.setBlockWithNotify(i + 2, j + 4, k + 3, block);
world.setBlockWithNotify(i + 2, j + 4, k + 4, block);
world.setBlockWithNotify(i + 3, j + 4, k + 1, block);
world.setBlockWithNotify(i + 3, j + 4, k + 2, block);
world.setBlockWithNotify(i + 3, j + 4, k + 3, block);
world.setBlockWithNotify(i + 3, j + 4, k + 4, block);
world.setBlockWithNotify(i + 4, j + 4, k + 1, block);
world.setBlockWithNotify(i + 4, j + 4, k + 2, block);
world.setBlockWithNotify(i + 4, j + 4, k + 3, block);
world.setBlockWithNotify(i + 4, j + 4, k + 4, block);
}
}
I am going to explain this so don't get to paranoid...
The first part is all the same. Then this new line is tell the world you punched the block.
public void onBlockClicked(World world, int i, int j, int k, EntityPlayer entityplayer)
Then each of these:
world.setBlockWithNotify(i, j, k, block);
is a block. You should be able to figure this out with A LOT of trial and error. It took me about 45mins to get this small 5x5 house. Good luck!
More to Come!
In the advanced block, how do i make it turn into something that i want. Can you explain to me how all that (i = 1, k) stuff works
I've forgotten but when making a recipe for a new whatever, what is the line of code for an item not a block (I know it's some like .shiftedindex). Thanks
== ERRORS FOUND ==
src/minecraft/net/minecraft/src/mod_DarkLight.java:29: cannot find symbol
symbol : class Random
location: class net.minecraft.src.mod_DarkLight
public void GenerateSurface(World world, Random rand, int chunkX, int chunkZ)
^
src/minecraft/net/minecraft/src/mod_DarkLight.java:33: operator + cannot be applied to int,Random.nextInt
int randPosX = chunkX + rand.nextInt(16);
^
src/minecraft/net/minecraft/src/mod_DarkLight.java:33: incompatible types
found : <nulltype>
required: int
int randPosX = chunkX + rand.nextInt(16);
^
src/minecraft/net/minecraft/src/mod_DarkLight.java:35: operator + cannot be applied to int,Random.nextInt
int randPosZ = chunkZ + rand.nextInt(16);
^
src/minecraft/net/minecraft/src/mod_DarkLight.java:35: incompatible types
found : <nulltype>
required: int
int randPosZ = chunkZ + rand.nextInt(16);
What has I done wrong? :sad.gif:
My Code:
package net.minecraft.src;
public class mod_DarkLight extends BaseMod
{
public static final Block Darkonium = new BlockDarkonium(190, 0).setHardness(3F).setResistance(5F).setBlockName("Darkonium");
public static Item DarkIgnot = new Item(3001).setItemName("DarkIgnot");
public String getVersion()
{
return "1.1";
}
public mod_DarkLight()
{
}
public void load()
{
ModLoader.RegisterBlock(Darkonium);
Darkonium.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Sprites/Darkonium.png");
ModLoader.AddName(Darkonium, "Darkonium");
ModLoader.AddSmelting(Darkonium.blockID, new ItemStack(mod_DarkLight.DarkIgnot, 1, 1));
DarkIgnot.iconIndex = ModLoader.addOverride("/gui/items.png", "/Sprites/DarkIgnot.png");
ModLoader.AddName(DarkIgnot, "DarkIgnot");
}
public void GenerateSurface(World world, Random rand, int chunkX, int chunkZ)
{
for(int i = 0; i < 50; i++) //The -50- is how many allowed per chunk.
{
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(128); //Height above Bedrock is allowed to spawn.
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenMinable(mod_DarkLight.Darkonium.blockID, 60)).generate(world, rand, randPosX, randPosY, randPosZ); // -60- is how many per vain.
}
}
}
Rollback Post to RevisionRollBack
Click Me!
GENERATION 31: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
Please tell me what i have done wrong here is the error report
Mods loaded: 1
ModLoader 1.1
Minecraft has crashed!
----------------------
Minecraft has stopped running because it encountered a problem.
If you wish to report this, please copy this entire text and email it to [email protected].
Please include a description of what you did when the error occured.
--- BEGIN ERROR REPORT 9c4f49b2 --------
Generated 13/02/12 10:56
Minecraft: Minecraft 1.1
OS: Windows Vista (x86) version 6.0
Java: 1.7.0_02, Oracle Corporation
VM: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
LWJGL: 2.4.2
OpenGL: GeForce 8600M GT/PCI/SSE2 version 2.1.1, NVIDIA Corporation
java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at net.minecraft.src.ModLoader.addMod(ModLoader.java:234)
at net.minecraft.src.ModLoader.readFromClassPath(ModLoader.java:1217)
at net.minecraft.src.ModLoader.init(ModLoader.java:708)
at net.minecraft.src.ModLoader.AddAllRenderers(ModLoader.java:150)
at net.minecraft.src.RenderManager.<init>(RenderManager.java:78)
at net.minecraft.src.RenderManager.<clinit>(RenderManager.java:9)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:316)
at net.minecraft.client.Minecraft.run(Minecraft.java:620)
at java.lang.Thread.run(Unknown Source)
--- END ERROR REPORT 5405d939 ----------
and heres the code for the mod_KoolBlock.java file
package net.minecraft.src ;
import java.util.Random;
public class BlockkoolBlock extends Block
{
public BlockkoolBlock(int i , int j)
{
super (i , j, Material.rock);
}
public int idDropped(int i, Random random, int j)
{
return mod_KoolBlock.koolblock.blockID;}
public int quantityDropped(Random random)
{
return 4;
}
}
and the BlockkoolBlock.java
package net.minecraft.src ;
import java.util.Random;
public class BlockkoolBlock extends Block
{
public BlockkoolBlock(int i , int j)
{
super (i , j, Material.rock);
}
public int idDropped(int i, Random random, int j)
{
return mod_KoolBlock.koolblock.blockID;}
public int quantityDropped(Random random)
{
return 4;
}
}
please help im an absolute beginner at minecraft programming
I don't know what the problem is, but please put the code in code format.
EDIT: your problem is that you forgot to specify if the block was craft able or if it was an ore. Look at the first page of this thread for details.
Just thought I'd tell you that on the ore generating part, the spot where you put the number 50 isn't how many are allowed per vain, but it's the rarity of the ore with 1 being the most common
All you do is change the idDropped
an example, if you wanted to make Iron ore drop diamond, you would write this:
instead of this:
31 days? Psshh.
package net.minecraft.src;
public class mod_Coal_Sword extends BaseMod
{
public static final Item Coal_Sword = new Item(31415).setItemName("Coal_Sword");
public String Version()
{
return "1.0.0";
}
public mod_Coal_Sword()
{
Coal_Sword.iconIndex = ModLoader.addOverride("/gui/items.png", "/mod/NameHere.png");
ModLoader.AddName(Coal_Sword, "Coal_Sword");
}
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
}
thanks!
Here this helped me out a BUNCH
try
ModLoader.AddRecipe(new ItemStack(Item.torch, 4), new Object[] {
" ", " 4 ", " 3 ", Character.valueOf('3'), mod_cstick.cstick, Character.valueOf('4'), Item.coal
});
LUK AT MI MAWDS THEY KEWL ARIGTE? MMK
What has I done wrong? :sad.gif:
My Code:
GENERATION 31: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
lol thats so usefull not! he said cange the 33 to 33
-the cat lord
TMDR Rules!!!
I don't know what the problem is, but please put the code in code format.
EDIT: your problem is that you forgot to specify if the block was craft able or if it was an ore. Look at the first page of this thread for details.
You need this at the end
TMDR Rules!!!
My bad, didn't mean to post that twice