Line 46: |
Line 46: |
| | | |
| == The actual Class for Lootables == | | == The actual Class for Lootables == |
| + | Here's an example Lootprovider class. The class is abstract and will be extended by the actual lootprovider class. This is however, optional. The class could also be used directly. |
| <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> |
| public abstract class BaseLootTableProvider extends LootTableProvider { | | public abstract class BaseLootTableProvider extends LootTableProvider { |
Line 88: |
Line 89: |
| @Override | | @Override |
| public String getName() { | | public String getName() { |
− | return "MagicScrolls LootTables"; | + | return "Example LootTables"; |
| } | | } |
| } | | } |
| </syntaxhighlight> | | </syntaxhighlight> |
| === Another class (Optional) === | | === 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 | + | 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. |
| + | <syntaxhighlight lang="java"> |
| + | public class LootTables extends BaseLootTableProvider{ |
| | | |
| + | @Override |
| + | protected void addTables() { |
| + | lootTables.put(BLOCK, LootTable.Builder); |
| + | } |
| + | } |
| + | </syntaxhighlight> |
| === The LootPool Builder === | | === The LootPool Builder === |
− | This is where the magic happens /s. | + | This is where you actually make a loottable. If you have multiple blocks with similar loottables, making a general method could be a good idea. The Method should return a LootTable.Builder. This builder can be made by using the LootPool.lootPool() 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 or conditions (see https://minecraft.fandom.com/wiki/Loot_table for possible vanilla funtions and conditions). After having made the builder, you return LootTable.lootTable().withPool(builder). A example of a "shulkerbox-like" block, copying its name, inventory and "energy" data to the block and restoring its contents. |
− | | + | <syntaxhighlight lang="java"> |
− | | + | protected LootTable.Builder createTable(String name, Block block) { |
| + | LootPool.Builder builder = LootPool.lootPool() |
| + | .name(name) |
| + | .setRolls(ConstantRange.exactly(1)) |
| + | .add(ItemLootEntry.lootTableItem(block) |
| + | .apply(CopyName.copyName(CopyName.Source.BLOCK_ENTITY)) |
| + | .apply(CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY) |
| + | .copy("inv", "BlockEntityTag.inv", CopyNbt.Action.REPLACE) |
| + | .copy("energy", "BlockEntityTag.energy", CopyNbt.Action.REPLACE)) |
| + | .apply(SetContents.setContents() |
| + | .withEntry(DynamicLootEntry.dynamicEntry(new ResourceLocation("minecraft", "contents")))) |
| + | ); |
| + | return LootTable.lootTable().withPool(builder); |
| + | } |
| + | </syntaxhighlight> |
| [[Category:Data Generation]] | | [[Category:Data Generation]] |