Jump to content

[1.7.2]How can I make my tool drop different item after breaking a block?


Recommended Posts

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?

 

Posted

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;
}

Posted

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.

Posted

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

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

Announcements



×
×
  • Create New...

Important Information

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