Jump to content

[1.8+][Solved] How to get a Block to drop an item...?


GenFrogKing

Recommended Posts

As the name suggests, I simply wish to have a block drop an item- specifically, this is an ore block meant to drop minerals when mined.  (Below is the code.)

 

I'm sure it's a simple fix, but I've been googling for a day now (minus time spent sleeping and at work) and scouring this forum without any luck.  There's plenty of 1.7+ tutorials/code out there that use the getItemDropped(int metadata, Random random, int fortune) implementation from the Block class which has changed to getItemDropped(IBlockState state, Random random, int fortune).  I updated to the new implementation, but the @Override above both getItemDropped and quantityDropped apparently doesn't belong even though Ctrl-clicking on them allows me to open them in the Block class directory.  This is a bit frustrating. I'm using Eclipse and I'm a bit new to Java but not to coding (and I've been reading up with a Sam's).

 

Thank you for any help!

 

 

The Code

package genfrogking.supercraft.init.blocks;

 

import java.lang.annotation.Target;

 

import genfrogking.supercraft.init.SupercraftItems;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.block.state.IBlockState;

import net.minecraft.item.Item;

import scala.util.Random;

 

public class Block_Ore_Mithril extends Block

{

public Block_Ore_Mithril(Material materialIn)

{

super(materialIn);

this.setResistance(25.0F);

this.setHardness(5.0F);

this.setHarvestLevel("pickaxe", 4);

this.setLightLevel(1.0F);

this.setLightOpacity(0);

}

 

@Override

public Item getItemDropped(IBlockState state, Random rand, int fortune)

    {

        return SupercraftItems.mithril_mineral;

    }

 

@Override

public int quantityDropped(Random rand)

{

return 1 + rand.nextInt(2);

}

}

 

Sorry.  I tried to put the code in a spoiler and code format, but the formatting options, when I was setting this post up, weren't working properly.

Link to comment
Share on other sites

:o Yup, that was it.  Thank you! 

 

When you say

This is why you should not override manually.
are you referring to auto-organizing (Ctrl-Shift-O) imports in Eclipse?  It automatically imported scala for me instead of java; I didn't even notice!

 

Fortunately, Eclipse noticed there was an error here.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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