Skip to content

Commit

Permalink
Implement LootTableEvents.LOADED event
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Sep 30, 2023
1 parent 8a234a4 commit 7ac89dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Loaded> LOADED = EventFactory.createArrayBacked(Loaded.class, listeners -> (resourceManager, lootManager) -> {
for (Loaded listener : listeners) {
listener.onLootTableLoaded(resourceManager, lootManager);
}
});

public interface Replace {
/**
* Replaces loot tables.
Expand Down Expand Up @@ -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 onLootTableLoaded(ResourceManager resourceManager, LootManager lootManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ private void applyLootTableEvents(ResourceManager resourceManager, LootManager l
});

this.keyToValue = newTables.build();
LootTableEvents.LOADED.invoker().onLootTableLoaded(resourceManager, lootManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,12 @@ public void onInitialize() {
tableBuilder.modifyPools(poolBuilder -> poolBuilder.with(ItemEntry.builder(Items.EMERALD)));
}
});

LootTableEvents.LOADED.register((resourceManager, lootManager) -> {
LootTable blackWoolTable = lootManager.getLootTable(Blocks.BLACK_WOOL.getLootTableId());

Check failure on line 97 in fabric-loot-api-v2/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java

View workflow job for this annotation

GitHub Actions / build (20-jdk)

missing blank line before block at same indentation level
if(blackWoolTable == LootTable.EMPTY) {

Check failure on line 98 in fabric-loot-api-v2/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java

View workflow job for this annotation

GitHub Actions / build (20-jdk)

'if' is not followed by whitespace.

Check failure on line 98 in fabric-loot-api-v2/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java

View workflow job for this annotation

GitHub Actions / build (20-jdk)

'if' is not followed by whitespace.
throw new AssertionError("black wool loot table should not be empty");
}
});
}
}

0 comments on commit 7ac89dc

Please sign in to comment.