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.

Featured Replies

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

 

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.

  • Author
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?

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.

  • Author
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

Use the HarvestDropsEvent instead.

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

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.