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.7.2]How can I make my tool drop different item after breaking a block?

Featured Replies

Posted

Hi, I want to do something like autosmelting pickaxe, or like Thaumcraft's Pickaxe of the core, but I just don't know how to deal with it. First of all I don't know where to put Random, because if I put it in function func_150897_b (which should be named canToolBreak or something) it's called multiple times. I could set return of this function to always be false and spawn my item in onBlockDestroyed, but that just makes speed of breaking blocks as if I were breaking them with a fist. So my question is - could I still be breaking blocks at reasonable speed without them dropping?

 

Something like this should work:

 

public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player){
    if (!player.worldObj.isRemote){

    player.worldObj.setBlockToAir(x, y, z);
    // spawn item here
    }

itemstack.damageItem(1, player);
return false;
}

  • Author

Something like this should work:

 

public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player){
    if (!player.worldObj.isRemote){

    player.worldObj.setBlockToAir(x, y, z);
    // spawn item here
    }

itemstack.damageItem(1, player);
return false;
}

Thanks, it worked, I didn't realise that I can look for this method in Item.class, I checked ItemPickaxe and ItemTool, but it wasn't there. TY very much.

Thanks, it worked, I didn't realise that I can look for this method in Item.class, I checked ItemPickaxe and ItemTool, but it wasn't there. TY very much.

 

That is what "extends" means in Java.  If a class extends another class it gets all of its methods unless you purposefully override them.  As a modder it is a good idea to check out the methods in all the parent classes for whatever you're modding.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.