{{Under construction}}
Loot Tables are not so polished like the other Providers. You need need to do some work to get them to a good state.
== Preperation ==
First you would need a new Class that extend the <code>LootTableProvider</code>. In this class you would override the <code>act</code> and optionally <code>getName</code> Method.
In the <code>getName</code> you just return the Name shown in the Logs.
Also you should create a abstract Method which you would override in subclasses but this is not strickly needded.
Also you need a Gson constant. You would create it like this <code> private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); </code>
You should also save the <code>DataGenerator</code> for later use since you can't access from the <code>LootTableProvider</code>.
Also you would need two Maps, one with the the Class witch is used to get the Lootable Resource Location in this example the Block and one the Loot Table Builder.
The second Map consist of a <code>ResourceLocation</code> and the actual <code>LootTable</code>. Look at the Code for more info.
<syntaxhighlight lang="java">
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
protected final Map<Block, LootTable.Builder> lootTables = new HashSet<>();
public static Map<ResourceLocation, LootTable> tables = new HashMap<>();
protected final DataGenerator generator;
</syntaxhighlight>
Also you would need a Function to save the Tables
<syntaxhighlight lang="java">
private void writeTables(DirectoryCache cache, Map<ResourceLocation, LootTable> tables) {
Path outputFolder = this.generator.getOutputFolder();
tables.forEach((key, lootTable) -> {
Path path = outputFolder.resolve("data/" + key.getNamespace() + "/loot_tables/" + key.getPath() + ".json");
try {
IDataProvider.save(GSON, cache, LootTableManager.toJson(lootTable), path);
} catch (IOException e) {
LOGGER.error("Couldn't write loot table {}", path, (Object) e);
}
});
}
</syntaxhighlight>
For the writeTables method you would need to convert the First Map to the second map, for this we need to iterate over the first map.
<syntaxhighlight lang="java">
lootTables.forEach(blockBuilderMap -> {
for (Map.Entry<Block, LootTable.Builder> entry : blockBuilderMap.entrySet()) {
tables.put(entry.getKey().getLootTable(), entry.getValue().build());
}
});
</syntaxhighlight>
in the act Method you would then first call the Method where you create the tables or just create them in there (if you do you can ignore the next section), then you would convert the Tables and at last you would save the loottables.
== The actual Class for Lootables ==
=== Another class (Optional) ===
Create a new class that extends from the Class you created in the Section above and override the abstract function in there you can begin to create your Lootables
=== The LootPool Builder ===
This is where the magic happens /s.