mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-31 01:00:18 -04:00
Add LootTableEvents.LOADED event (#3352)
* 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 commit96dfa9590d
) (cherry picked from commit3ba460fb29
)
This commit is contained in:
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
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,5 +95,6 @@ abstract class LootManagerMixin {
|
|||
});
|
||||
|
||||
this.keyToValue = newTables.build();
|
||||
LootTableEvents.ALL_LOADED.invoker().onLootTablesLoaded(resourceManager, lootManager);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue