Skip to content

Commit

Permalink
Move loot table datagen to common
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Sep 10, 2023
1 parent d458771 commit 36909df
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@

import java.util.List;
import java.util.Set;

import org.jetbrains.annotations.NotNull;
import java.util.function.BiConsumer;

import net.minecraft.data.PackOutput;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.level.block.Block;
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.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;

import appeng.core.definitions.BlockDefinition;

import gripe._90.megacells.definition.MEGABlocks;

class LootTableProvider extends net.minecraft.data.loot.LootTableProvider {
public LootTableProvider(PackOutput output) {
public class CommonLootTableProvider extends LootTableProvider {
public CommonLootTableProvider(PackOutput output) {
super(output, Set.of(), List.of(new SubProviderEntry(BlockLoot::new, LootContextParamSets.BLOCK)));
}

Expand All @@ -31,22 +29,22 @@ protected BlockLoot() {
}

@Override
protected void generate() {
for (var block : getKnownBlocks()) {
public void generate(BiConsumer<ResourceLocation, LootTable.Builder> biConsumer) {
generate();
map.forEach(biConsumer);
}

@Override
public void generate() {
for (var block : MEGABlocks.getBlocks()) {
add(
block,
block.block(),
LootTable.lootTable()
.withPool(LootPool.lootPool()
.setRolls(ConstantValue.exactly(1))
.add(LootItem.lootTableItem(block))
.when(ExplosionCondition.survivesExplosion())));
}
}

@NotNull
@Override
protected Iterable<Block> getKnownBlocks() {
return MEGABlocks.getBlocks().stream().map(BlockDefinition::block).map(Block.class::cast)::iterator;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public void onInitializeDataGenerator(FabricDataGenerator generator) {
new CommonTagProvider.ItemTags(output, registries, blocks.contentsGetter()));

pack.addProvider((FabricDataOutput output) -> new CommonLanguageProvider(output));
pack.addProvider((FabricDataOutput output) -> new CommonLootTableProvider(output));
pack.addProvider(ModelProvider::new);
pack.addProvider(RecipeProvider::new);
pack.addProvider(LootTableProvider::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ public class MEGADataGenerators {
public static void onGatherData(GatherDataEvent event) {
var pack = event.getGenerator().getVanillaPack(true);
var existing = event.getExistingFileHelper();
var registries = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor());

var blockTags = pack.addProvider(output -> new CommonTagProvider.BlockTags(output, registries));
pack.addProvider(output -> new CommonTagProvider.ItemTags(output, registries, blockTags.contentsGetter()));

pack.addProvider(output -> new ModelProvider.Items(output, existing));
pack.addProvider(output -> new ModelProvider.Blocks(output, existing));
pack.addProvider(output -> new ModelProvider.Parts(output, existing));

pack.addProvider(RecipeProvider::new);
pack.addProvider(LootTableProvider::new);
var registries = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor());
var blockTags = pack.addProvider(output -> new CommonTagProvider.BlockTags(output, registries));
pack.addProvider(output -> new CommonTagProvider.ItemTags(output, registries, blockTags.contentsGetter()));

pack.addProvider(CommonLootTableProvider::new);
pack.addProvider(CommonLanguageProvider::new);
pack.addProvider(RecipeProvider::new);
}
}

0 comments on commit 36909df

Please sign in to comment.