tutorial:adding_to_loot_tables
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:adding_to_loot_tables [2019/08/12 23:06] – fixed parenthesis yanis48 | tutorial:adding_to_loot_tables [2022/03/27 06:01] – Added syntax clarification for 1.17.1+ support. stormyfabric | ||
---|---|---|---|
Line 9: | Line 9: | ||
===== Listening to loot table loading ===== | ===== Listening to loot table loading ===== | ||
- | Fabric API has an event that’s fired when loot tables are loaded, '' | + | Fabric API has an event that’s fired when loot tables are loaded, '' |
<code java> | <code java> | ||
- | LootTableLoadingCallback.EVENT.register((resourceManager, | + | // No magic constants! |
- | if (" | + | private static final Identifier COAL_ORE_LOOT_TABLE_ID = Blocks.COAL_ORE.getLootTableId(); |
+ | |||
+ | // Actual code | ||
+ | |||
+ | LootTableLoadingCallback.EVENT.register((resourceManager, | ||
+ | if (COAL_ORE_LOOT_TABLE_ID.equals(id)) { | ||
// Our code will go here | // Our code will go here | ||
} | } | ||
Line 19: | Line 24: | ||
</ | </ | ||
- | ===== Adding items to the table ===== | + | ===== Adding items to the table 1.16.5 and Below ===== |
In loot tables, items are stored in //loot entries,// and entries are stored in //loot pools//. To add an item, we’ll need to add a pool with an item entry to the loot table. | In loot tables, items are stored in //loot entries,// and entries are stored in //loot pools//. To add an item, we’ll need to add a pool with an item entry to the loot table. | ||
Line 26: | Line 31: | ||
<code java> | <code java> | ||
- | LootTableLoadingCallback.EVENT.register((resourceManager, | + | LootTableLoadingCallback.EVENT.register((resourceManager, |
- | if (" | + | if (COAL_ORE_LOOT_TABLE_ID.equals(id)) { |
FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() | FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() | ||
- | .withRolls(ConstantLootTableRange.create(1)); | + | .rolls(ConstantLootTableRange.create(1)); |
- | | + | |
} | } | ||
}); | }); | ||
Line 38: | Line 43: | ||
<code java> | <code java> | ||
- | LootTableLoadingCallback.EVENT.register((resourceManager, | + | LootTableLoadingCallback.EVENT.register((resourceManager, |
- | if (" | + | if (COAL_ORE_LOOT_TABLE_ID.equals(id)) { |
FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() | FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() | ||
- | .withRolls(ConstantLootTableRange.create(1)) | + | .rolls(ConstantLootTableRange.create(1)) |
- | .withEntry(ItemEntry.builder(Items.EGG)); | + | .with(ItemEntry.builder(Items.EGG)); |
- | | + | |
} | } | ||
}); | }); | ||
</ | </ | ||
+ | |||
+ | ===== Adding items to the table 1.17.1 and Above===== | ||
+ | |||
+ | The process is the same, the only change is in Syntax for 1.17.1+ you will need to replace '' | ||
+ | |||
+ | <code java> | ||
+ | LootTableLoadingCallback.EVENT.register((resourceManager, | ||
+ | if (COAL_ORE_LOOT_TABLE_ID.equals(id)) { | ||
+ | FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() | ||
+ | .rolls(ConstantLootNumberProvider.create(1)) | ||
+ | .with(ItemEntry.builder(Items.EGG)); | ||
+ | |||
+ | table.pool(poolBuilder); | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | |||
{{: | {{: | ||
tutorial/adding_to_loot_tables.txt · Last modified: 2024/02/05 16:08 by mschae23