Line 50:
Line 50:
=== The LootPool Builder ===
=== The LootPool Builder ===
−
This is where you actually make a loottable (this is an explanation for a block loottable). If you have multiple blocks with similar loottables, making a general method could be a good idea. The method should return a <code>LootTable.Builder</code>. This builder can be made by using the <code>LootPool.lootPool()</code> method, but you still need to add attributes. You need a name for the pool, the amount you get and also "what" you get. The "what" can modified using functions and/or conditions (see [https://minecraft.fandom.com/wiki/Loot_table LootTables] for possible vanilla funtions and conditions). After having made the builder, you return <code>LootTable.lootTable().withPool(builder)</code>. An example of a "shulkerbox-like" block, copying its name, inventory and "energy" data to the block and restoring its contents when placed.
+
This is where you actually make a loottable. You start with a <code>LootPool.Builder</code> and add the necessary attributes to it.
+
* <code>.name</code> is used for the pool name.
+
* <code>.setRolls</code> is used for the amount.
+
* <code>.add</code> is used to add an <code>ItemLootEntry</code>.
+
+
An <code>ItemLootEntry</code> defines what is returned, and which functions and/or conditions are applied (see [https://minecraft.fandom.com/wiki/Loot_table Loot table] for the vanilla functions and conditions).
+
* <code>.lootTableItem</code> is used to define which item is returned.
+
* <code>.apply</code> is used to apply a function or condition
+
+
After all attributes have been added the <code>LootPool.Builder</code> can be used to make a <code>LootTable.Builder</code> of the proper <code>LootParameterSets</code>. This builder can then be added to the <code>lootTables</code> map made in the previous section (in the overwritten abstract method).
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
−
protected LootTable.Builder createTable(String name, Block block) {
+
LootPool.Builder builder = LootPool.lootPool()
−
LootPool.Builder builder = LootPool.lootPool()
+
.name(...)
−
.name(name)
+
.setRolls(...)
−
.setRolls(ConstantRange.exactly(1))
+
.add(ItemLootEntry.lootTableItem(...)
−
.add(ItemLootEntry.lootTableItem(block)
+
.apply(Function1)
−
.apply(CopyName.copyName(CopyName.Source.BLOCK_ENTITY))
+
.apply(Function2
−
.apply(CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY)
+
.options(option1)
−
.copy("inv", "BlockEntityTag.inv", CopyNbt.Action.REPLACE)
+
.options(option2))
−
.copy("energy", "BlockEntityTag.energy", CopyNbt.Action.REPLACE))
−
.apply(SetContents.setContents()
−
.withEntry(DynamicLootEntry.dynamicEntry(new ResourceLocation("minecraft", "contents"))))
);
);
−
return LootTable.lootTable().withPool(builder).setParamSet(LootParameterSets.BLOCK);
+
LootTable.lootTable().withPool(builder).setParamSet(...);
−
}
</syntaxhighlight>
</syntaxhighlight>
−
Thanks and creddits to McJty with his amazing tutorials: [https://wiki.mcjty.eu/modding/index.php?title=YouTube-Tutorials Full list of his tutorials] and [https://github.com/McJty/YouTubeModding14/tree/1.16/src/main/java/com/mcjty/mytutorial/datagen Lootprovider and other datagen classes]
[[Category:Data Generation]]
[[Category:Data Generation]]