Add LootTableEvents.LOADED event ()

* Implement `LootTableEvents.LOADED` event

* Update for checkstyle

* rename event

* Update fabric-loot-api-v2/src/main/java/net/fabricmc/fabric/api/loot/v2/LootTableEvents.java

Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com>

---------

Co-authored-by: modmuss <modmuss50@gmail.com>
Co-authored-by: Juuz <6596629+Juuxel@users.noreply.github.com>
(cherry picked from commit 96dfa9590d)
(cherry picked from commit 3ba460fb29)
This commit is contained in:
LLytho 2023-10-08 14:05:30 +02:00 committed by modmuss50
parent ebb15496af
commit 6f9f09e0c4
3 changed files with 28 additions and 0 deletions
fabric-loot-api-v2/src
main/java/net/fabricmc/fabric
testmod/java/net/fabricmc/fabric/test/loot

View file

@ -89,6 +89,15 @@ public final class LootTableEvents {
}
});
/**
* This event can be used for post-processing after all loot tables have been loaded and modified by Fabric.
*/
public static final Event<Loaded> 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 final class LootTableEvents {
*/
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);
}
}

View file

@ -95,5 +95,6 @@ abstract class LootManagerMixin {
});
this.keyToValue = newTables.build();
LootTableEvents.ALL_LOADED.invoker().onLootTablesLoaded(resourceManager, lootManager);
}
}

View file

@ -92,5 +92,13 @@ public class LootTest implements ModInitializer {
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");
}
});
}
}