CraftTweaker

CraftTweaker

151M Downloads

[Request] Add entries to existing structure/chest loot tables

chimericdream opened this issue ยท 6 comments

commented

Feature request name
Modify loot tables for chests in vanilla and modded structures

Feature request description
I know that some support for loot table modification was recently added, but if I'm understanding it correctly, it cannot modify loot tables for things like dungeon chests. I want the ability to add items to (or remove items from) the loot tables of vanilla and modded treasure chests / structures.

Feature request reason
I have a modpack that includes a lot of exploration-focused mods, and many of them add structures whose treasure chests I would like to sort of "cross-pollinate" mod content and encourage exploration. Most of the mods add their loot to the vanilla structures' loot tables, but for obvious reasons they don't try to modify loot tables from other mods to include their treasure items.

Feature request dependencies
I don't know if this would require any significant new dependencies. My hope is that with the recent addition of the LootManager functionality, adding support for something like this would be relatively straightforward.

**Game Version
1.16.5

commented

Does the code mentioned above still work for 1.18.2 version of crafttweaker?

commented

how i can make for remove the item from all chest, also this work on 1.18.2?

commented

So global loot modifiers work and can do what you would want to do.
Here is an example:

import crafttweaker.api.loot.conditions.vanilla.LootTableId;
import crafttweaker.api.loot.conditions.LootConditionBuilder;
import crafttweaker.api.loot.modifiers.CommonLootModifiers;

loot.modifiers.register(
    "no_bones",
    LootConditionBuilder.createForSingle<LootTableId>((condition) => {
        condition.withTableId(<resource:minecraft:chests/desert_pyramid>);
    }),
    CommonLootModifiers.remove(<item:minecraft:bone>)
);

That removes bone from the desert pyramid dungeon chests, you can change that CommonLootModifiers line to add to the chest as well.

This isn't a perfect solution for what you want though, if you changed it to add items, it would always add the item to the chest.

You could do something along the lines of:

import stdlib.List;
import crafttweaker.api.world.MCWorld;
import crafttweaker.api.loot.conditions.vanilla.LootTableId;
import crafttweaker.api.loot.conditions.LootConditionBuilder;


loot.modifiers.register(
    "rods",
    LootConditionBuilder.createForSingle<LootTableId>((condition) => {
        condition.withTableId(<resource:minecraft:chests/desert_pyramid>);
    }),
    (stacks, context) => {
    if (context.world as MCWorld).random.nextDouble() <= 0.5 {
        stacks.add(<item:minecraft:blaze_rod> * 3);
    }

    return stacks;
})
);

Which will add 3 blaze rods 50% of the time, it won't be perfect, but you can do it.

In general, I would like proper loot table modification in the future, but you can use the above scripts to achieve what you want to do in the mean time.

commented

This is awesome, thank you! Since my request is technically possible already (even though you plan to improve the way it works in ZS down the road), I'll close this ticket.

commented

I actually wanted to keep this open to remind us, since the feature request itself is fully valid

commented

Works for me. :-)