adds datagen for block and entity loot
This commit is contained in:
@@ -11,5 +11,7 @@ public class DataGenerators implements DataGeneratorEntrypoint {
|
||||
pack.addProvider(FabricModModelProvider::new);
|
||||
pack.addProvider(FabricBlockTagProvider::new);
|
||||
pack.addProvider(FabricItemTagProvider::new);
|
||||
pack.addProvider(FabricBlockLootTableProvider::new);
|
||||
pack.addProvider(FabricEntityLootTableProvider::new);
|
||||
}
|
||||
}
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package net.cmr.jurassicrevived.datagen;
|
||||
|
||||
import net.cmr.jurassicrevived.block.ModBlocks;
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
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.ApplyBonusCount;
|
||||
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
|
||||
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class FabricBlockLootTableProvider extends net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider implements ModBlockLootTableProvider.BlockLootHelper {
|
||||
|
||||
//? if >1.20.1 {
|
||||
/*public FabricBlockLootTableProvider(FabricDataOutput dataOutput, CompletableFuture<HolderLookup.Provider> registryLookup) {
|
||||
super(dataOutput, registryLookup);
|
||||
}
|
||||
*///?} else {
|
||||
public FabricBlockLootTableProvider(FabricDataOutput dataOutput) {
|
||||
super(dataOutput);
|
||||
}
|
||||
//?}
|
||||
|
||||
@Override
|
||||
public void generate() {
|
||||
ModBlockLootTableProvider.registerBlockLootTables(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropSelf(Block block) {
|
||||
super.dropSelf(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Block block, LootTable.Builder builder) {
|
||||
super.add(block, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LootTable.Builder createMultipleOreDrops(Block block, Item item, float minDrops, float maxDrops) {
|
||||
//? if >1.20.1 {
|
||||
/*HolderLookup.RegistryLookup<Enchantment> registrylookup = this.registries.lookupOrThrow(Registries.ENCHANTMENT);
|
||||
return this.createSilkTouchDispatchTable(block, this.applyExplosionDecay(block,
|
||||
LootItem.lootTableItem(item)
|
||||
.apply(SetItemCountFunction.setCount(UniformGenerator.between(minDrops, maxDrops)))
|
||||
.apply(ApplyBonusCount.addOreBonusCount(registrylookup.getOrThrow(Enchantments.FORTUNE)))));
|
||||
*///?} else {
|
||||
return this.createSilkTouchDispatchTable(block, this.applyExplosionDecay(block,
|
||||
LootItem.lootTableItem(item)
|
||||
.apply(SetItemCountFunction.setCount(UniformGenerator.between(minDrops, maxDrops)))
|
||||
.apply(ApplyBonusCount.addOreBonusCount(Enchantments.BLOCK_FORTUNE))));
|
||||
//?}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LootTable.Builder createPotFlowerItemTable(Block block) {
|
||||
return super.createPotFlowerItemTable(block);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package net.cmr.jurassicrevived.datagen;
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.SimpleFabricLootTableProvider;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class FabricEntityLootTableProvider extends SimpleFabricLootTableProvider implements ModEntityLootTableProvider.EntityLootHelper {
|
||||
|
||||
//? if >1.20.1 {
|
||||
/*public FabricEntityLootTableProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registryLookup) {
|
||||
super(output, registryLookup, LootContextParamSets.ENTITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(BiConsumer<ResourceKey<LootTable>, LootTable.Builder> biConsumer) {
|
||||
this.currentBiConsumer = biConsumer;
|
||||
ModEntityLootTableProvider.registerEntityLootTables(this);
|
||||
this.currentBiConsumer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(EntityType<?> type, LootTable.Builder builder) {
|
||||
if (currentBiConsumer != null) {
|
||||
currentBiConsumer.accept(type.getDefaultLootTable(), builder);
|
||||
}
|
||||
}
|
||||
|
||||
private BiConsumer<ResourceKey<LootTable>, LootTable.Builder> currentBiConsumer;
|
||||
*///?} else {
|
||||
public FabricEntityLootTableProvider(FabricDataOutput output) {
|
||||
super(output, LootContextParamSets.ENTITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(BiConsumer<ResourceLocation, LootTable.Builder> biConsumer) {
|
||||
this.currentBiConsumer = biConsumer;
|
||||
ModEntityLootTableProvider.registerEntityLootTables(this);
|
||||
this.currentBiConsumer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(EntityType<?> type, LootTable.Builder builder) {
|
||||
if (currentBiConsumer != null) {
|
||||
currentBiConsumer.accept(type.getDefaultLootTable(), builder);
|
||||
}
|
||||
}
|
||||
|
||||
private BiConsumer<ResourceLocation, LootTable.Builder> currentBiConsumer;
|
||||
//?}
|
||||
}
|
||||
Reference in New Issue
Block a user