Jump to content

[1.10] Custom block drop from onBlockDestroyed has too much motion


Versepelles

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.