Jump to content

[1.16.5] How to get drops from a block that player mined?


Recommended Posts

Posted

As the title says I need a way to get drops from a block that the player has just mined. How to do that? I have seen that getDrops exists but I don't know how to use it or if it is the right solution for this problem. Ideally, it should apply enchants that player has that affect drops (eg. Silk Touch or Fortune) automatically. Any help would be appreciated.

Posted
3 hours ago, Mislo_ said:

Ideally, it should apply enchants that player has that affect drops (eg. Silk Touch or Fortune) automatically.

GlobalLootModifiers are most likely the solution you're looking for. You are not required to actually modify the drops if you're only interested in knowing what dropped.

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
3 hours ago, diesieben07 said:

What is your goal? What effect do you want to achieve?

I am making an enchant (for tools) that will put drops from a block directly into a player's inventory. If the inventory is full I just drop items on player's coordinates.

56 minutes ago, Draco18s said:

GlobalLootModifiers are most likely the solution you're looking for.

I have stumbled upon that once but it looks complicated. If it is the best solution I will study it thoroughly and make use of it.

Posted
11 hours ago, diesieben07 said:

There is no simple way to do this. If you look at PlayerInteractionManager#destroyBlock you'll see that there isn't really any hook to influence the spawning of drops. Block#playerDestroy will eventually be called and simply spawn the drops into the world. You can in theory detect EntityJoinWorldEvent of the ItemEntities, but you don't really have a way to detect whether these are drops of a block mined with a tool that has your enchantment.

So using GlobalLootModifiers would be the best solution. Thanks for making that clear. I would probably spend a few more hours trying to find a different solution. Thanks for help.

Posted
6 hours ago, diesieben07 said:

They only allow you to modify what is dropped, not capture what will be dropped or change what is done with the drops.

While I haven't checked, I do believe that the player is part of the LootParameters, so the entire generated drops could be inserted into the player's inventory, and then cleared so nothing actually drops.

Not what the modifiers were intended for, but it might work.

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

*puts up a sign: here there be dragons, woe unto thee who venture here*

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.