Modding: Custom block drops

In this tutorial I will teach you how to change the block drop. I will be using this file.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Material;

public class BlockOres extends Block
{
    public BlockOres(int par1, int par2)
    {
        super(par1, par2, Material.rock);
        this.setCreativeTab(CreativeTabs.tabBlock);
    }
    
    public String getTextureFile()
    {
            return “/TutTextures.png”;
    }
}


To change the item drop you will have to add this.


public int idDropped(int par1, Random par2Random, int par3)
    {
        return Tutorial.youritem.shiftedIndex;
    }


This method is used for the drop of the item.
The thing you return is the item it will drop. In this case the block will drop the item we have made before.
The full file should now look like this.


package Tutorial.common;

import java.util.Random;

import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Item;
import net.minecraft.src.Material;

public class BlockOres extends Block
{
    public BlockOres(int par1, int par2)
    {
        super(par1, par2, Material.rock);
        this.setCreativeTab(CreativeTabs.tabBlock);
    }
    
    public String getTextureFile()
    {
            return “/TutTextures.png”;
    }
    
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return Tutorial.youritem.shiftedIndex;
    }
}


You can also change the amount of items it drops by adding this.


public int quantityDropped(Random par1Random)
    {
        return 3;
    }


This will return 3 items. By using the Random you can return a random amount of the item.
To get the random to work you should use something like this.


public int quantityDropped(Random par1Random)
    {
        return par1Random.nextInt(2) + 1;
    }


When you use this code the block will drop 1 or 2 items when you destroy it. It doesn’t drop 3, because java starts counting at 0. The random will choose between the amount of numbers between the brackets.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">