Jump to content

Recommended Posts

Posted

I have a custom tool which overrides the onBlockDestroyed(...) method from the minecraft ItemTool class. In this, a new item stack is spawned at the location of the destroyed block with no motion. However, the item stack flies a fair distance, as if it were spawned inside the block and gained motion from trying to escape- this seems to imply that it is created (and ticked?) before the block is fully destroyed. I would like the custom drop to not have any motion; any advice would be appreciated. If possible, I'd like to keep this contained to the custom tool's class. It seems that past versions of forge may have had a method called onBlockHarvested, which was called after the block was destroyed. If that is true, something like that is what I'm looking for.

 

public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {

...

EntityItem entityitem = new EntityItem(worldIn, pos.getX(), pos.getY() + 0.5f, pos.getZ(), customDrop);
entityitem.motionX = 0f;
entityitem.motionY = 0f;
entityitem.motionZ = 0f;
entityitem.setDefaultPickupDelay();

worldIn.spawnEntityInWorld(entityitem);
}

 

Posted

That's because onBlockDestroyed is called before the block gets set to air.  So yes, the item is, in fact, inside a solid block.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 minute ago, Draco18s said:

That's because onBlockDestroyed is called before the block gets set to air.  So yes, the item is, in fact, inside a solid block.

What method could be called to after the block has been broken? Or what other workarounds might be good?

Posted

Try using harvestBlock

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
44 minutes ago, Draco18s said:

Try using harvestBlock

Thanks for the suggestion. Where is the method harvestBlock located? I can't seem to find it in Item or ItemTool. (Is it an event? I'm not familiar.)

 

EDIT: I think you are referencing the Block.harvestBlock method. This approach wont work, I think, as I'm trying to get a custom drop from vanilla blocks when using a custom tool. Other approaches would still be appreciated!

Edited by Versepelles
Posted

Use the HarvestDropsEvent instead.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.