Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.6.4]Ore Item Drops


Recommended Posts

Hello everyone, I am kind of new at modding and having a little trouble finding out how to make a ore drop different items each time you break the ore.


Detailed Explanation:

For instance, if I were to break my ore, and it drops for say, yellow dust, and then I break the second ore, it drops red dust, and so on, what would be the way to go about doing that.



I am still in the progress of learning modding and java. You don't have to give me the code, but an explanation would be helpful.

Link to comment
Share on other sites



do you mean, there are different types of ore with different dusts, eg like birch tree becomes birch wood, or do you mean - you get a different type of ore every time you harvest the same block, eg you break the rainbow block and you randomly wind up with a red, an orange, or a yellow, etc dust.


Block.getBlockDropped is your friend here.  Just return a random ItemStack.





Link to comment
Share on other sites

Just in case you didn't know, here's the Java Random class : http://docs.oracle.com/javase/6/docs/api/java/util/Random.html


I think using the Random class like AndyLun said above and then either an if/switch statement could give you exactly what you are looking for. Unless you are expecting that it will always be a pattern in which case you could just increment a counter and when it hits it's max, set it to the first.


I wrote this up pretty quick as an example of a generic block.


public int idDropped(int par1, Random par2Random, int par3){
	int drop = par2Random.nextInt(4);
	if (drop == 0){
		return Item.diamond.itemID;
	} else if (drop == 1){
		return Item.ingotIron.itemID;
	} else if (drop == 2){
		return Item.ingotGold.itemID;
	} else {
		return Item.emerald.itemID;

Link to comment
Share on other sites

Thank you for the replies! Sorry I wasn't clear enough:


I have one ore, if I break the ore, it drops one of the items specified, if I break the same ore a second time, it drops another ore that is specified.

But the item it drops is random each time.


Roymond, and AndyLun, thank you for supplying sufficient explanations. I will reply with the product of what I come up with.



package betterblocks.ores;

import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import betterblocks.items.YellowDust;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class MagicOre extends Block {

public MagicOre(int id, Material material) {
	super(id, material);



public int idDropped(int metadata, Random random, int fortune){
	int drop = random.nextInt(4);
	if (drop == 0){
		return betterblocks.BBCore.whiteDust.itemID;
	}else if (drop == 1);
		return betterblocks.BBCore.yellowDustBB.itemID;


    protected boolean canSilkHarvest(){
        return true;


Roymond's suggestion did work, drops the two items randomly, I will be adding more to the ore, thank you very much, also AndyLun, thank you very much for pointing me towards the Random class, I will get to learning that. :)

Link to comment
Share on other sites

This topic is now closed to further replies.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.