Skip to content

Commit

Permalink
refactor: Add Data Generation for Block Loot Tables #765
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Dec 13, 2023
1 parent ec2a7a8 commit 6cd7ec3
Show file tree
Hide file tree
Showing 46 changed files with 1,246 additions and 1,203 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package net.blay09.mods.waystones.datagen;

import net.blay09.mods.waystones.block.ModBlocks;
import net.blay09.mods.waystones.block.WaystoneBlockBase;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction;
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;

public class ModBlockLootTableProvider extends FabricBlockLootTableProvider {
protected ModBlockLootTableProvider(FabricDataOutput dataOutput) {
Expand All @@ -10,5 +22,36 @@ protected ModBlockLootTableProvider(FabricDataOutput dataOutput) {

@Override
public void generate() {
add(ModBlocks.waystone, createDoubleBlockWaystoneLoot(ModBlocks.waystone));
add(ModBlocks.sandyWaystone, createDoubleBlockWaystoneLoot(ModBlocks.sandyWaystone));
add(ModBlocks.mossyWaystone, createDoubleBlockWaystoneLoot(ModBlocks.mossyWaystone));
add(ModBlocks.sharestone, createDoubleBlockWaystoneLoot(ModBlocks.sharestone));
add(ModBlocks.portstone, createDoubleBlockWaystoneLoot(ModBlocks.portstone));
add(ModBlocks.warpPlate, createWaystoneLoot(ModBlocks.warpPlate));
for (Block scopedSharestone : ModBlocks.scopedSharestones) {
add(scopedSharestone, createDoubleBlockWaystoneLoot(scopedSharestone));
}
}

private LootTable.Builder createWaystoneLoot(Block block) {
return LootTable.lootTable()
.withPool(applyExplosionCondition(block, LootPool.lootPool()
.setRolls(ConstantValue.exactly(1f))
.add(LootItem.lootTableItem(block))
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY)
.copy("UUID", "UUID", CopyNbtFunction.MergeStrategy.REPLACE)
.when(HAS_SILK_TOUCH))));
}

private LootTable.Builder createDoubleBlockWaystoneLoot(Block block) {
return LootTable.lootTable()
.withPool(applyExplosionCondition(block, LootPool.lootPool()
.setRolls(ConstantValue.exactly(1f))
.add(LootItem.lootTableItem(block))
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(block)
.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(WaystoneBlockBase.HALF, DoubleBlockHalf.LOWER)))
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY)
.copy("UUID", "UUID", CopyNbtFunction.MergeStrategy.REPLACE)
.when(HAS_SILK_TOUCH))));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"block": "waystones:black_sharestone",
"condition": "minecraft:block_state_property",
"properties": {
"half": "lower"
}
},
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "waystones:black_sharestone"
}
],
"functions": [
{
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
],
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "UUID",
"target": "UUID"
}
],
"source": "block_entity"
}
],
"rolls": 1.0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"block": "waystones:blue_sharestone",
"condition": "minecraft:block_state_property",
"properties": {
"half": "lower"
}
},
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "waystones:blue_sharestone"
}
],
"functions": [
{
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
],
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "UUID",
"target": "UUID"
}
],
"source": "block_entity"
}
],
"rolls": 1.0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"block": "waystones:brown_sharestone",
"condition": "minecraft:block_state_property",
"properties": {
"half": "lower"
}
},
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "waystones:brown_sharestone"
}
],
"functions": [
{
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
],
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "UUID",
"target": "UUID"
}
],
"source": "block_entity"
}
],
"rolls": 1.0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"block": "waystones:cyan_sharestone",
"condition": "minecraft:block_state_property",
"properties": {
"half": "lower"
}
},
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "waystones:cyan_sharestone"
}
],
"functions": [
{
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
],
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "UUID",
"target": "UUID"
}
],
"source": "block_entity"
}
],
"rolls": 1.0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"block": "waystones:gray_sharestone",
"condition": "minecraft:block_state_property",
"properties": {
"half": "lower"
}
},
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "waystones:gray_sharestone"
}
],
"functions": [
{
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
],
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "UUID",
"target": "UUID"
}
],
"source": "block_entity"
}
],
"rolls": 1.0
}
]
}
Loading

0 comments on commit 6cd7ec3

Please sign in to comment.