Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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.

  • Author

: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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.