Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.14+] Cloning a LootContext


Draco18s
 Share

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

What about adding a secondary constructor to LootContext.Builder that takes an existing LootContext?

public Builder(LootContext context) {
  this.world = context.world;
  this.field_216025_b.putAll(context.parameters);
  this.field_216026_c.putAll(context.field_216037_g);
  this.rand = context.random;
  this.luck = context.luck;
}

 

The "fake silk touch" could then just be:

LootContext contextWithSilkTouch = new LootContext.Builder(context).withParameter(LootParameters.TOOL, fakeTool).build();

 

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.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • The Chunk#isLoaded seems to be depreciated, nor is there a ChunkLoader#chunkExists (my research)... what's the new way of doing this? The Chunk#loaded field is private, and the Chunk#getStatus method always returns ChunkStatus.FULL... I can get the chunk with entity.level.getChunk(entity.getBlockPosition()), but what then? Must I use reflection for this? Surely there's a cleaner way.
    • 1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • I don't really know why, if someone could give me a hand and let me know what's wrong that would be great. Cheers   ---- Minecraft Crash Report ---- WARNING: coremods are present:   Inventory Tweaks Coremod (InventoryTweaks-1.63.jar)   MovingWorldCore (movingworld-1.12-6.353-full.jar)   Quark Plugin (Quark-r1.6-179.jar)   IvToolkit (IvToolkit-1.3.3-1.12.jar)   weaponlib (mw_2.0-0.4.4.6_mc1.12.2.jar)   ApotheosisCore (Apotheosis-1.12.2-1.12.5.jar) Contact their authors BEFORE contacting forge // Don't do that. Time: 9/29/21 4:48 AM Description: Initializing game java.lang.NoClassDefFoundError: net/minecraftforge/fml/common/registry/IForgeRegistryEntry     at java.lang.Class.forName0(Native Method)     at java.lang.Class.forName(Class.java:348)     at net.minecraftforge.fml.common.FMLModContainer.constructMod(FMLModContainer.java:539)     at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)     at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)     at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)     at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)     at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)     at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)     at com.google.common.eventbus.EventBus.post(EventBus.java:217)     at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)     at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)     at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)     at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)     at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)     at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)     at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)     at com.google.common.eventbus.EventBus.post(EventBus.java:217)     at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)     at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:595)     at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:232)     at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:467)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)     at net.minecraft.client.main.Main.main(SourceFile:123)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Caused by: java.lang.ClassNotFoundException: net.minecraftforge.fml.common.registry.IForgeRegistryEntry     at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 38 more Caused by: java.lang.NullPointerException A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace:     at java.lang.Class.forName0(Native Method)     at java.lang.Class.forName(Class.java:348)     at net.minecraftforge.fml.common.FMLModContainer.constructMod(FMLModContainer.java:539)     at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)     at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)     at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)     at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)     at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)     at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)     at com.google.common.eventbus.EventBus.post(EventBus.java:217)     at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)     at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)     at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)     at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)     at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)     at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)     at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)     at com.google.common.eventbus.EventBus.post(EventBus.java:217)     at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)     at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:595)     at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:232)     at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:467) -- Initialization -- Details: Stacktrace:     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)     at net.minecraft.client.main.Main.main(SourceFile:123)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) -- System Details -- Details:     Minecraft Version: 1.12.2     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_51, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 226393024 bytes (215 MB) / 536870912 bytes (512 MB) up to 2147483648 bytes (2048 MB)     JVM Flags: 8 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0     FML: MCP 9.42 Powered by Forge 14.23.5.2855 Optifine OptiFine_1.12.2_HD_U_G5 47 mods loaded, 47 mods active     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored     | State | ID                                           | Version                  | Source                                             | Signature                                |     |:----- |:-------------------------------------------- |:------------------------ |:-------------------------------------------------- |:---------------------------------------- |     | LC    | minecraft                                    | 1.12.2                   | minecraft.jar                                      | None                                     |     | LC    | mcp                                          | 9.42                     | minecraft.jar                                      | None                                     |     | LC    | FML                                          | 8.0.99.99                | forge-1.12.2-14.23.5.2855.jar                      | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LC    | forge                                        | 14.23.5.2855             | forge-1.12.2-14.23.5.2855.jar                      | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LC    | ivtoolkit                                    | 1.3.3-1.12               | minecraft.jar                                      | None                                     |     | LC    | com.elytradev.movingworld.common.asm.coremod |                          | minecraft.jar                                      | None                                     |     | LC    | biomesoplenty                                | 7.0.1.2444               | BiomesOPlenty-1.12.2-7.0.1.2444-universal.jar      | None                                     |     | LC    | craftstudioapi                               | 1.0.0                    | CraftStudio-1.0.0.93-mc1.12-alpha.jar              | None                                     |     | LC    | animania                                     | 2.0.3.28                 | animania-1.12.2-base-2.0.3.28.jar                  | None                                     |     | LC    | placebo                                      | 1.6.0                    | Placebo-1.12.2-1.6.0.jar                           | None                                     |     | LC    | apotheosis                                   | 1.12.4                   | Apotheosis-1.12.2-1.12.5.jar                       | None                                     |     | LC    | jei                                          | 4.16.1.301               | jei_1.12.2-4.16.1.301.jar                          | None                                     |     | LC    | quark                                        | r1.6-179                 | Quark-r1.6-179.jar                                 | None                                     |     | LC    | autoreglib                                   | 1.3-32                   | AutoRegLib-1.3-32.jar                              | None                                     |     | LC    | codechickenlib                               | 3.2.3.358                | CodeChickenLib-1.12.2-3.2.3.358-universal.jar      | f1850c39b2516232a2108a7bd84d1cb5df93b261 |     | LC    | redstoneflux                                 | 2.1.1                    | Redstone-Flux-API-1.12.2.jar                       | None                                     |     | LC    | brandonscore                                 | 2.4.20                   | BrandonsCore-1.12.2-2.4.20.162-universal.jar       | None                                     |     | LC    | controlling                                  | 3.0.10                   | Controlling-3.0.10.jar                             | None                                     |     | LC    | craft_gunpowder_11                           | 1.1.0                    | CraftableGunpowder_1-1.jar                         | None                                     |     | LC    | cucumber                                     | 1.1.3                    | Cucumber-1.12.2-1.1.3.jar                          | None                                     |     | LC    | movingworld                                  | 1.12-6.353               | movingworld-1.12-6.353-full.jar                    | None                                     |     | LC    | davincisvessels                              | @DVESSELSVER@            | davincisvessels-1.12-6.340-full.jar                | None                                     |     | LC    | ptrmodellib                                  | 1.0.5                    | PTRLib-1.0.5.jar                                   | None                                     |     | LC    | props                                        | 2.6.3.7                  | Decocraft-2.6.3.7_1.12.2.jar                       | None                                     |     | LC    | draconicevolution                            | 2.3.28                   | Draconic-Evolution-1.12.2-2.3.28.354-universal.jar | None                                     |     | LC    | reccomplex                                   | 1.4.8.2                  | RecurrentComplex-1.4.8.2.jar                       | None                                     |     | LC    | dynamictrees                                 | 1.12.2-0.9.25            | DynamicTrees-1.12.2-0.9.25.jar                     | None                                     |     | LC    | ftblib                                       | 5.4.7.2                  | FTBLib-5.4.7.2.jar                                 | None                                     |     | LC    | itemfilters                                  | 1.0.4.2                  | ItemFilters-1.0.4.2.jar                            | None                                     |     | LC    | ftbquests                                    | 1202.9.0.15              | FTBQuests-1202.9.0.15.jar                          | None                                     |     | LC    | cfm                                          | 6.3.1                    | furniture-6.3.1-1.12.2.jar                         | None                                     |     | LC    | gravestone                                   | 1.10.3                   | gravestone-1.10.3.jar                              | None                                     |     | LC    | waila                                        | 1.8.26                   | Hwyla-1.8.26-B41_1.12.2.jar                        | None                                     |     | LC    | inventorytweaks                              | 1.63+release.109.220f184 | InventoryTweaks-1.63.jar                           | 55d2cd4f5f0961410bf7b91ef6c6bf00a766dcbe |     | LC    | journeymap                                   | 1.12.2-5.7.1             | journeymap-1.12.2-5.7.1.jar                        | None                                     |     | LC    | numina                                       | 1.12.2-1.0.38            | Numina-1.12.2-1.0.38.jar                           | None                                     |     | LC    | refinedstorage                               | 1.6.15                   | refinedstorage-1.6.15.jar                          | 57893d5b90a7336e8c63fe1c1e1ce472c3d59578 |     | LC    | powersuits                                   | 1.12.2-1.0.46            | ModularPowersuits-1.12.2-1.0.46.jar                | None                                     |     | LC    | mw                                           | 0.4.4.6                  | mw_2.0-0.4.4.6_mc1.12.2.jar                        | None                                     |     | LC    | mysticalagriculture                          | 1.7.5                    | MysticalAgriculture-1.12.2-1.7.5.jar               | None                                     |     | LC    | mysticalagradditions                         | 1.3.2                    | MysticalAgradditions-1.12.2-1.3.2.jar              | None                                     |     | LC    | roguelike                                    | 1.8.0                    | RoguelikeDungeons-1.12.2-1.8.0.jar                 | None                                     |     | LC    | solarflux                                    | 12.4.11                  | SolarFluxReborn-1.12.2-12.4.11.jar                 | 9f5e2a811a8332a842b34f6967b7db0ac4f24856 |     | LC    | mo                                           | 1.0                      | sulfur-potassium-1.12-1.1.jar                      | None                                     |     | LC    | tektopia                                     | 1.1.0                    | tektopia-1.1.0.jar                                 | None                                     |     | L     | waystones                                    | 4.0.4                    | Waystones_1.12-4.0.4.jar                           | None                                     |     | L     | worldedit                                    | 6.1.10                   | worldedit-forge-mc1.12.2-6.1.10-dist.jar           | None                                     |     Loaded coremods (and transformers):  Inventory Tweaks Coremod (InventoryTweaks-1.63.jar)   invtweaks.forge.asm.ContainerTransformer MovingWorldCore (movingworld-1.12-6.353-full.jar)    Quark Plugin (Quark-r1.6-179.jar)   vazkii.quark.base.asm.ClassTransformer IvToolkit (IvToolkit-1.3.3-1.12.jar)    weaponlib (mw_2.0-0.4.4.6_mc1.12.2.jar)   com.vicmatskiv.weaponlib.core.WeaponlibClassTransformer ApotheosisCore (Apotheosis-1.12.2-1.12.5.jar)   shadows.ApotheosisTransformer     GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 471.96' Renderer: 'NVIDIA GeForce RTX 2080 Ti/PCIe/SSE2'     Launched Version: 1.12.2-forge-14.23.5.2855     LWJGL: 2.9.4     OpenGL: NVIDIA GeForce RTX 2080 Ti/PCIe/SSE2 GL version 4.6.0 NVIDIA 471.96, NVIDIA Corporation     GL Caps: Using GL 1.3 multitexturing. Using GL 1.3 texture combiners. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Shaders are available because OpenGL 2.1 is supported. VBOs are available because OpenGL 1.5 is supported.     Using VBOs: Yes     Is Modded: Definitely; Client brand changed to 'fml,forge'     Type: Client (map_client.txt)     Resource Packs:      Current Language: English (US)     Profiler Position: N/A (disabled)     CPU: 20x Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz     OptiFine Version: OptiFine_1.12.2_HD_U_G5     OptiFine Build: 20210124-142939     Render Distance Chunks: 8     Mipmaps: 4     Anisotropic Filtering: 1     Antialiasing: 0     Multitexture: false     Shaders: SEUS-Renewed-v1.0.1.zip     OpenGlVersion: 4.6.0 NVIDIA 471.96     OpenGlRenderer: NVIDIA GeForce RTX 2080 Ti/PCIe/SSE2     OpenGlVendor: NVIDIA Corporation     CpuCount: 20
    • 1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • so uh, i created a forge server to run on my pc, and followed a lot of steps seeing other threads, and trying them, but the mods folder is not appearing, and the vanilla server keeps appearing as vanilla, i de-installed and installed several times
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.