tutorial:adding_to_loot_tables
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:adding_to_loot_tables [2019/08/01 16:16] – fixed typo juuz | tutorial:adding_to_loot_tables [2024/02/05 16:08] (current) – Changed Minecraft wiki link to use minecraft.wiki mschae23 | ||
---|---|---|---|
Line 3: | Line 3: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Sometimes you want to add items to [[https:// | + | Sometimes you want to add items to [[https:// |
Our example will be adding eggs to the coal ore loot table. | Our example will be adding eggs to the coal ore loot table. | ||
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> | + | <yarncode |
- | LootTableLoadingCallback.EVENT.register((resourceManager, | + | // No magic constants! |
- | if (" | + | private static final class_2960 COAL_ORE_LOOT_TABLE_ID = class_2246.COAL_ORE.getLootTableId(); |
+ | |||
+ | // Actual code | ||
+ | |||
+ | LootTableEvents.MODIFY.register((resourceManager, | ||
+ | // Let's only modify built-in loot tables and leave data pack loot tables untouched by checking the source. | ||
+ | // We also check that the loot table ID is equal to the ID we want. | ||
+ | if (source.isBuiltin() && COAL_ORE_LOOT_TABLE_ID.equals(id)) { | ||
// Our code will go here | // Our code will go here | ||
} | } | ||
}); | }); | ||
- | </code> | + | </yarncode> |
===== Adding items to the table ===== | ===== Adding items to the 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. | + | In loot tables, items are stored in // |
- | We can make a pool with '' | + | We can make a pool with '' |
- | <code java> | + | <yarncode |
- | LootTableLoadingCallback.EVENT.register((resourceManager, | + | LootTableEvents.MODIFY.register((resourceManager, |
- | if (" | + | if (source.isBuiltin() && COAL_ORE_LOOT_TABLE_ID.equals(id)) { |
- | | + | |
- | .withRolls(ConstantLootTableRange.create(1)); // Same as " | + | |
- | | + | |
} | } | ||
}); | }); | ||
- | </code> | + | </yarncode> |
Our pool doesn’t have any items yet, so we’ll make an item entry and add it to the pool, and we're done: | Our pool doesn’t have any items yet, so we’ll make an item entry and add it to the pool, and we're done: | ||
- | <code java> | + | <yarncode |
- | LootTableLoadingCallback.EVENT.register((resourceManager, | + | LootTableEvents.MODIFY.register((resourceManager, |
- | if (" | + | if (source.isBuiltin() && COAL_ORE_LOOT_TABLE_ID.equals(id)) { |
- | | + | |
- | .withRolls(ConstantLootTableRange.create(1)) | + | .method_351(class_77.method_411(class_1802.field_8803)); |
- | .withEntry(ItemEntry.builder(Items.EGG)); | + | |
- | | + | |
} | } | ||
}); | }); | ||
- | </code> | + | </yarncode> |
{{: | {{: | ||
tutorial/adding_to_loot_tables.1564676173.txt.gz · Last modified: 2019/08/01 16:16 by juuz