diff --git a/fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/api/loot/v2/LootTableEvents.java b/fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/api/loot/v2/LootTableEvents.java index 56776cb121..5e9d67ad7b 100644 --- a/fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/api/loot/v2/LootTableEvents.java +++ b/fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/api/loot/v2/LootTableEvents.java @@ -89,6 +89,15 @@ private LootTableEvents() { } }); + /** + * This event can be used for post-processing after all loot tables have been loaded and modified by Fabric. + */ + public static final Event ALL_LOADED = EventFactory.createArrayBacked(Loaded.class, listeners -> (resourceManager, lootManager) -> { + for (Loaded listener : listeners) { + listener.onLootTablesLoaded(resourceManager, lootManager); + } + }); + public interface Replace { /** * Replaces loot tables. @@ -116,4 +125,14 @@ public interface Modify { */ void modifyLootTable(ResourceManager resourceManager, LootManager lootManager, Identifier id, LootTable.Builder tableBuilder, LootTableSource source); } + + public interface Loaded { + /** + * Called when all loot tables have been loaded and {@link LootTableEvents#REPLACE} and {@link LootTableEvents#MODIFY} have been invoked. + * + * @param resourceManager the server resource manager + * @param lootManager the loot manager + */ + void onLootTablesLoaded(ResourceManager resourceManager, LootManager lootManager); + } } diff --git a/fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/mixin/loot/LootManagerMixin.java b/fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/mixin/loot/LootManagerMixin.java index aa684722b2..9c8625f77b 100644 --- a/fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/mixin/loot/LootManagerMixin.java +++ b/fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/mixin/loot/LootManagerMixin.java @@ -95,5 +95,6 @@ private void applyLootTableEvents(ResourceManager resourceManager, LootManager l }); this.keyToValue = newTables.build(); + LootTableEvents.ALL_LOADED.invoker().onLootTablesLoaded(resourceManager, lootManager); } } diff --git a/fabric-loot-api-v2/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java b/fabric-loot-api-v2/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java index 4a7236347d..1f34b42dd9 100644 --- a/fabric-loot-api-v2/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java +++ b/fabric-loot-api-v2/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java @@ -92,5 +92,13 @@ public void onInitialize() { tableBuilder.modifyPools(poolBuilder -> poolBuilder.with(ItemEntry.builder(Items.EMERALD))); } }); + + LootTableEvents.ALL_LOADED.register((resourceManager, lootManager) -> { + LootTable blackWoolTable = lootManager.getLootTable(Blocks.BLACK_WOOL.getLootTableId()); + + if (blackWoolTable == LootTable.EMPTY) { + throw new AssertionError("black wool loot table should not be empty"); + } + }); } }