How would i make a block drop an item with random Meta Data when broken?
here is my Block:
public class BlockCrystalOre extends Block {
public BlockCrystalOre(int id, Material material)
{
super(material);
this.setCreativeTab(Mod.BlockTab);
}
@Override
public void registerBlockIcons(IIconRegister iicon)
{
this.blockIcon = iicon.registerIcon("Mod:CrystalOre");
}
@Override
public Item getItemDropped(int par1, Random rand, int par2)
{
return Mod.Crystal;
}
}
and here is the Item:
public class Crystal extends Item {
private IIcon[] theIcon;
public static final String[] IconList = new String[] {"Red", "Yellow", "Green", "Blue"};
public Crystal(int i) {
this.setHasSubtypes(true);
this.setCreativeTab(Mod.MiscTab);
}
/**
* Gets an icon index based on an item's damage value
*/
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1)
{
int j = MathHelper.clamp_int(par1, 0, 3);
return this.theIcon[j];
}
/**
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
* different names based on their damage or NBT.
*/
public String getUnlocalizedName(ItemStack itemstack)
{
int i = MathHelper.clamp_int(itemstack.getItemDamage(), 0, 3);
return super.getUnlocalizedName() + "." + IconList;
}
/**
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
*/
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tabs, List list)
{
for (int i = 0; i < 4; ++i)
{
list.add(new ItemStack(item, 1, i));
}
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconregistry)
{
this.theIcon = new IIcon[IconList.length];
for (int i = 0; i < IconList.length; ++i)
{
this.theIcon = iconregistry.registerIcon("Mod:Crystal_" + IconList);
}
}
}
All help is welcome,
Rollback Post to RevisionRollBack
Choose for yourselves this day whom you will serve... but as for me and my house, we will serve the Lord. Joshua 24:15
here is my Block:
public BlockCrystalOre(int id, Material material)
{
super(material);
this.setCreativeTab(Mod.BlockTab);
}
@Override
public void registerBlockIcons(IIconRegister iicon)
{
this.blockIcon = iicon.registerIcon("Mod:CrystalOre");
}
@Override
public Item getItemDropped(int par1, Random rand, int par2)
{
return Mod.Crystal;
}
}
and here is the Item:
private IIcon[] theIcon;
public static final String[] IconList = new String[] {"Red", "Yellow", "Green", "Blue"};
public Crystal(int i) {
this.setHasSubtypes(true);
this.setCreativeTab(Mod.MiscTab);
}
/**
* Gets an icon index based on an item's damage value
*/
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1)
{
int j = MathHelper.clamp_int(par1, 0, 3);
return this.theIcon[j];
}
/**
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
* different names based on their damage or NBT.
*/
public String getUnlocalizedName(ItemStack itemstack)
{
int i = MathHelper.clamp_int(itemstack.getItemDamage(), 0, 3);
return super.getUnlocalizedName() + "." + IconList;
}
/**
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
*/
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tabs, List list)
{
for (int i = 0; i < 4; ++i)
{
list.add(new ItemStack(item, 1, i));
}
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconregistry)
{
this.theIcon = new IIcon[IconList.length];
for (int i = 0; i < IconList.length; ++i)
{
this.theIcon = iconregistry.registerIcon("Mod:Crystal_" + IconList);
}
}
}
All help is welcome,
In your block class, do
return metadataToDrop;
}