Jump to content

[1.14+] Cloning a LootContext


Draco18s

Recommended Posts

Based on comments from Lex on my PR for global loot modifiers (so that modders don't need to replace loot tables when creating new enchantments and other effects), one of the sample test mods is set as making a specific item act like silk touch (the use-case was someone wanted one of their mod items to silk-touch harvest glass blocks and only glass blocks, the test mod doesn't do the check for glass, but the general process is going to be the same).

 

As such, invoking the existing loot tables with the extra context parameter (or rather, a modified itemstack parameter) in order to not make assumptions about what silk touch actually does (as someone could create a block that drops something besides itself when harvested with silk touch) to generate the correct loot is the correct approach.

 

However, this requires rebuilding the LootContext object and Lex made this comment:

Quote

How can you possibly know the context and what parts need copying?

https://github.com/MinecraftForge/MinecraftForge/pull/6401#discussion_r363968404

 

What is the better way to do this? Using reflection to access the private-final fields does not feel correct to me, as any changes made need to be undone after invoking the loot table generate (as there may be future loot modifiers waiting to be processed), which is why I (attempted to) clone the context object.

  • 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

Works for me, I just wanted to query whether or not that was the best practice for something like this.

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

4 minutes ago, diesieben07 said:

I don't see a different way to do it.

I didn't either, but I am aware that there are things that I am not aware of.

(Any other comments on that PR? I've been literally begging for feedback for months).

Thanks.

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.