IC2 Classic

IC2 Classic

2M Downloads

IC2Block ignores forge loot modification

Sleepwalkerx opened this issue ยท 9 comments

commented

When writing my loot modification mod, I ran into the problem that IC2Block does not trigger a loot modification event.
I went to look for the problem in the mod's source files and noticed that the mod has its own loot generation logic, but the forge event call was missed.
I fixed this problem with mixin.

@Mixin(IC2Block.class)
public class IC2BlockMixin {

    @Inject(method = "getDrops", at = @At(value = "RETURN", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD)
    private void injectDrop(@Nonnull BlockState state, LootContext.Builder builder, CallbackInfoReturnable<List<ItemStack>> cir, LootTable lootTable, List<ItemStack> drops){
        ResourceLocation resourcelocation = state.getBlock().getLootTable();
        if(resourcelocation != BuiltInLootTables.EMPTY) {
            LootContext lootContext = builder.withParameter(LootContextParams.BLOCK_STATE, state).create(LootContextParamSets.BLOCK);
            ServerLevel serverlevel = lootContext.getLevel();
            LootTable loottable = serverlevel.getServer().getLootTables().get(resourcelocation);

            ObjectArrayList<ItemStack> objectarraylist = new ObjectArrayList<>(drops);
            objectarraylist = net.minecraftforge.common.ForgeHooks.modifyLoot(loottable.getLootTableId(), objectarraylist, lootContext);
            drops.clear();
            drops.addAll(objectarraylist);
        }
    }
}
commented

o/
You are half right and wrong.
In your example you are 100% wrong actually.

First the modifyLoot function isn't called if it is the internal loottable (aka non set by datapacks),
and that will not change.

That is the part where you are correct.

The part you are wrong at is that the function is not called with datapack set loottable.

If you set a loottable in the datapacks i actually call: loottable.getRandomItems which calls the ForgeHooks function you think it is actually not calling.

Your patch is actually fixing nothing.

Edit:
This is the function i am calling: Loottable#getRandomItems(LootContext)

   public ObjectArrayList<ItemStack> getRandomItems(LootContext p_230923_) {
      ObjectArrayList<ItemStack> objectarraylist = new ObjectArrayList<>();
      this.getRandomItems(p_230923_, objectarraylist::add);
      objectarraylist = net.minecraftforge.common.ForgeHooks.modifyLoot(this.getLootTableId(), objectarraylist, p_230923_);
      return objectarraylist;
   }
commented

This is the function i am calling: Loottable#getRandomItems(LootContext)

Yes, I have seen it, but in fact this part of the code is never called unless a loot generator is registered. Therefore, I made a mix for the 2nd part of the code, where the event call was just missing.

As a result, I would like to see a fix for this bug in your mod :)

commented

@Sleepwalkerx
Well for now you have your mixin.
If i implement it myself i haven't decided.
But ill think about it.

Don't expect a decision anytime soon though. I am swamped until christmas eve with other projects and then i am no longer capable of working on ic2c until next year.

commented

If i implement it myself i haven't decided.

If you had an open source code, I would create a pull request...
in general, my job is to show it further yourself.

commented

@Sleepwalkerx just because you make a dumb point doesn't mean i am automatically discarding your feature request.

I said i think about it. Not that i won't do it or that i will do it.
So closing the issue makes no sense.

OpenSource != "YOU HAVE TO ACCEPT MY PATCHES".
If you make a pullrequest i could still decide: I dont want that and close your pullrequest.

commented

If you had an open source code, I would create a pull request...

@Sleepwalkerx
That is such a dumb statement.
OpenSource is great.

But me implementing such a feature is taking me 5 mins max. (That includes starting my PC/IDE and creating the build)
As if a pullrequest would be faster.
The reason i let myself time is because i want to think about if i want to support it or not.
And on top of that any coding time i have right now i am working on a mega patch for chunkpregen that i am porting back right now.

And before you take your offer to help me with chunkpregen.
Don't. You wouldn't be even finished with 1 version while i have the rest done in most likely less time.

So fuck off with your "If it were open source, then i would help you" argument bs.
This bugreport/feature request is proof that the lack of open source hasn't stopped you in the first place.

commented

If you had an open source code, I would create a pull request...

and just one additional point about this... if this mod would be open source, that would just come along with a lawsuit from the ic2 experimental team (which they would most definitely win) as ic2 classic being closed source is part of the requirements for it even being allowed to exist

commented

Your business, guys.

commented

OpenSource != "YOU HAVE TO ACCEPT MY PATCHES".

Guys, I'm not forcing you to accept my patches, I just asked a question and that's it... Maybe it sounded wrong somehow, because English is not my native language.
In general, okay, I think we figured it out.