From 36909df7ad1a1dbe30e21b7d8a5412714289449a Mon Sep 17 00:00:00 2001 From: 90 Date: Sun, 10 Sep 2023 16:05:50 +0100 Subject: [PATCH] Move loot table datagen to common --- .../datagen/CommonLootTableProvider.java | 30 +++++++-------- .../megacells/datagen/LootTableProvider.java | 37 ------------------- .../megacells/datagen/MEGADataGenerators.java | 2 +- .../megacells/datagen/MEGADataGenerators.java | 12 +++--- 4 files changed, 21 insertions(+), 60 deletions(-) rename forge/src/data/java/gripe/_90/megacells/datagen/LootTableProvider.java => common/src/data/java/gripe/_90/megacells/datagen/CommonLootTableProvider.java (71%) delete mode 100644 fabric/src/data/java/gripe/_90/megacells/datagen/LootTableProvider.java diff --git a/forge/src/data/java/gripe/_90/megacells/datagen/LootTableProvider.java b/common/src/data/java/gripe/_90/megacells/datagen/CommonLootTableProvider.java similarity index 71% rename from forge/src/data/java/gripe/_90/megacells/datagen/LootTableProvider.java rename to common/src/data/java/gripe/_90/megacells/datagen/CommonLootTableProvider.java index 943cea44..4d5148d7 100644 --- a/forge/src/data/java/gripe/_90/megacells/datagen/LootTableProvider.java +++ b/common/src/data/java/gripe/_90/megacells/datagen/CommonLootTableProvider.java @@ -2,13 +2,13 @@ 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; @@ -16,12 +16,10 @@ 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))); } @@ -31,10 +29,16 @@ protected BlockLoot() { } @Override - protected void generate() { - for (var block : getKnownBlocks()) { + public void generate(BiConsumer 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)) @@ -42,11 +46,5 @@ protected void generate() { .when(ExplosionCondition.survivesExplosion()))); } } - - @NotNull - @Override - protected Iterable getKnownBlocks() { - return MEGABlocks.getBlocks().stream().map(BlockDefinition::block).map(Block.class::cast)::iterator; - } } } diff --git a/fabric/src/data/java/gripe/_90/megacells/datagen/LootTableProvider.java b/fabric/src/data/java/gripe/_90/megacells/datagen/LootTableProvider.java deleted file mode 100644 index 5f8c6655..00000000 --- a/fabric/src/data/java/gripe/_90/megacells/datagen/LootTableProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -package gripe._90.megacells.datagen; - -import java.util.function.BiConsumer; - -import org.jetbrains.annotations.NotNull; - -import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; -import net.fabricmc.fabric.api.datagen.v1.provider.SimpleFabricLootTableProvider; -import net.minecraft.resources.ResourceLocation; -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 gripe._90.megacells.MEGACells; -import gripe._90.megacells.definition.MEGABlocks; - -class LootTableProvider extends SimpleFabricLootTableProvider { - LootTableProvider(FabricDataOutput output) { - super(output, LootContextParamSets.BLOCK); - } - - @Override - public void generate(@NotNull BiConsumer consumer) { - for (var block : MEGABlocks.getBlocks()) { - consumer.accept( - MEGACells.makeId("blocks/" + block.id().getPath()), - LootTable.lootTable() - .withPool(LootPool.lootPool() - .setRolls(ConstantValue.exactly(1)) - .add(LootItem.lootTableItem(block)) - .when(ExplosionCondition.survivesExplosion()))); - } - } -} diff --git a/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java b/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java index f86ad7f8..3f66070f 100644 --- a/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java +++ b/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java @@ -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); } } diff --git a/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java b/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java index b2149293..9e967b4d 100644 --- a/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java +++ b/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java @@ -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); } }