diff --git a/common/src/data/java/gripe/_90/megacells/datagen/CommonTagProvider.java b/common/src/data/java/gripe/_90/megacells/datagen/CommonTagProvider.java new file mode 100644 index 00000000..cee72b78 --- /dev/null +++ b/common/src/data/java/gripe/_90/megacells/datagen/CommonTagProvider.java @@ -0,0 +1,58 @@ +package gripe._90.megacells.datagen; + +import java.util.concurrent.CompletableFuture; + +import net.minecraft.core.HolderLookup; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.PackOutput; +import net.minecraft.data.tags.IntrinsicHolderTagsProvider; +import net.minecraft.data.tags.ItemTagsProvider; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.level.block.Block; + +import appeng.api.features.P2PTunnelAttunement; + +import gripe._90.megacells.definition.MEGABlocks; +import gripe._90.megacells.definition.MEGAItems; +import gripe._90.megacells.definition.MEGATags; + +public class CommonTagProvider { + public static class Items extends ItemTagsProvider { + public Items( + PackOutput output, + CompletableFuture registries, + CompletableFuture> blockTags) { + super(output, registries, blockTags); + } + + @Override + protected void addTags(HolderLookup.Provider provider) { + tag(MEGATags.SKY_STEEL_INGOT).add(MEGAItems.SKY_STEEL_INGOT.asItem()); + tag(MEGATags.SKY_STEEL_BLOCK_ITEM).add(MEGABlocks.SKY_STEEL_BLOCK.asItem()); + + tag(P2PTunnelAttunement.getAttunementTag(P2PTunnelAttunement.ENERGY_TUNNEL)) + .add(MEGABlocks.MEGA_ENERGY_CELL.asItem()); + tag(MEGATags.MEGA_PATTERN_PROVIDER) + .add(MEGABlocks.MEGA_PATTERN_PROVIDER.asItem()) + .add(MEGAItems.MEGA_PATTERN_PROVIDER.asItem()); + } + } + + public static class Blocks extends IntrinsicHolderTagsProvider { + public Blocks(PackOutput packOutput, CompletableFuture registries) { + super(packOutput, Registries.BLOCK, registries, block -> BuiltInRegistries.BLOCK + .getResourceKey(block) + .orElseThrow()); + } + + @Override + protected void addTags(HolderLookup.Provider provider) { + for (var block : MEGABlocks.getBlocks()) { + tag(BlockTags.MINEABLE_WITH_PICKAXE).add(block.block()); + } + + tag(MEGATags.SKY_STEEL_BLOCK).add(MEGABlocks.SKY_STEEL_BLOCK.block()); + } + } +} diff --git a/common/src/main/java/gripe/_90/megacells/definition/MEGATags.java b/common/src/main/java/gripe/_90/megacells/definition/MEGATags.java index a77a39b8..1b27627f 100644 --- a/common/src/main/java/gripe/_90/megacells/definition/MEGATags.java +++ b/common/src/main/java/gripe/_90/megacells/definition/MEGATags.java @@ -9,27 +9,22 @@ import gripe._90.megacells.MEGACells; public final class MEGATags { - public static final TagKey SKY_STEEL_INGOT = itemTag( - switch (MEGACells.PLATFORM.getLoader()) { - case FABRIC -> "c:sky_steel_ingots"; - case FORGE -> "forge:ingots/sky_steel"; - }); + public static final TagKey SKY_STEEL_INGOT = TagKey.create( + Registries.ITEM, + new ResourceLocation( + switch (MEGACells.PLATFORM.getLoader()) { + case FABRIC -> "c:sky_steel_ingots"; + case FORGE -> "forge:ingots/sky_steel"; + })); - private static final String SKY_STEEL_BLOCK_TAG = + private static final ResourceLocation SKY_STEEL_BLOCK_TAG = new ResourceLocation( switch (MEGACells.PLATFORM.getLoader()) { case FABRIC -> "c:sky_steel_blocks"; case FORGE -> "forge:storage_blocks/sky_steel"; - }; - public static final TagKey SKY_STEEL_BLOCK = blockTag(SKY_STEEL_BLOCK_TAG); - public static final TagKey SKY_STEEL_BLOCK_ITEM = itemTag(SKY_STEEL_BLOCK_TAG); - - public static final TagKey MEGA_PATTERN_PROVIDER = itemTag("megacells:mega_pattern_provider"); - - private static TagKey itemTag(String name) { - return TagKey.create(Registries.ITEM, new ResourceLocation(name)); - } + }); + public static final TagKey SKY_STEEL_BLOCK = TagKey.create(Registries.BLOCK, SKY_STEEL_BLOCK_TAG); + public static final TagKey SKY_STEEL_BLOCK_ITEM = TagKey.create(Registries.ITEM, SKY_STEEL_BLOCK_TAG); - private static TagKey blockTag(String name) { - return TagKey.create(Registries.BLOCK, new ResourceLocation(name)); - } + public static final TagKey MEGA_PATTERN_PROVIDER = + TagKey.create(Registries.ITEM, MEGACells.makeId("mega_pattern_provider")); } 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 60400f52..3003ca5d 100644 --- a/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java +++ b/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java @@ -14,8 +14,9 @@ public void onInitializeDataGenerator(FabricDataGenerator generator) { var pack = generator.createPack(); var registries = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); - var blockTags = pack.addProvider((FabricDataOutput output) -> new TagProvider.Blocks(output, registries)); - pack.addProvider((FabricDataOutput output) -> new TagProvider.Items(output, registries, blockTags)); + var blockTags = pack.addProvider((FabricDataOutput output) -> new CommonTagProvider.Blocks(output, registries)); + pack.addProvider((FabricDataOutput output) -> + new CommonTagProvider.Items(output, registries, blockTags.contentsGetter())); pack.addProvider(ModelProvider::new); pack.addProvider(RecipeProvider::new); diff --git a/fabric/src/data/java/gripe/_90/megacells/datagen/TagProvider.java b/fabric/src/data/java/gripe/_90/megacells/datagen/TagProvider.java deleted file mode 100644 index 0c58e24e..00000000 --- a/fabric/src/data/java/gripe/_90/megacells/datagen/TagProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -package gripe._90.megacells.datagen; - -import java.util.concurrent.CompletableFuture; - -import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; -import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; -import net.minecraft.core.HolderLookup; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.tags.BlockTags; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; - -import appeng.api.features.P2PTunnelAttunement; -import appeng.core.definitions.BlockDefinition; -import appeng.core.definitions.ItemDefinition; - -import gripe._90.megacells.definition.MEGABlocks; -import gripe._90.megacells.definition.MEGAItems; -import gripe._90.megacells.definition.MEGATags; - -abstract class TagProvider { - static class Items extends FabricTagProvider.ItemTagProvider { - Items(FabricDataOutput output, CompletableFuture registries, BlockTagProvider block) { - super(output, registries, block); - } - - @Override - protected void addTags(HolderLookup.Provider provider) { - tag(MEGATags.SKY_STEEL_INGOT).add(getKey(MEGAItems.SKY_STEEL_INGOT)); - tag(MEGATags.SKY_STEEL_BLOCK_ITEM).add(getKey(MEGABlocks.SKY_STEEL_BLOCK)); - - tag(P2PTunnelAttunement.getAttunementTag(P2PTunnelAttunement.ENERGY_TUNNEL)) - .add(getKey(MEGABlocks.MEGA_ENERGY_CELL)); - tag(MEGATags.MEGA_PATTERN_PROVIDER) - .add(getKey(MEGABlocks.MEGA_PATTERN_PROVIDER)) - .add(getKey(MEGAItems.MEGA_PATTERN_PROVIDER)); - } - - private ResourceKey getKey(ItemDefinition item) { - return BuiltInRegistries.ITEM.getResourceKey(item.asItem()).orElse(null); - } - } - - static class Blocks extends FabricTagProvider.BlockTagProvider { - Blocks(FabricDataOutput output, CompletableFuture registries) { - super(output, registries); - } - - @Override - protected void addTags(HolderLookup.Provider provider) { - for (var block : MEGABlocks.getBlocks()) { - tag(BlockTags.MINEABLE_WITH_PICKAXE).add(getKey(block)); - } - - tag(MEGATags.SKY_STEEL_BLOCK).add(getKey(MEGABlocks.SKY_STEEL_BLOCK)); - } - - private ResourceKey getKey(BlockDefinition block) { - return BuiltInRegistries.BLOCK.getResourceKey(block.block()).orElse(null); - } - } -} 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 0e4e873b..0689ae3b 100644 --- a/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java +++ b/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java @@ -19,8 +19,8 @@ public static void onGatherData(GatherDataEvent event) { var existing = event.getExistingFileHelper(); var registries = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); - var blockTags = pack.addProvider(output -> new TagProvider.Blocks(output, registries, existing)); - pack.addProvider(output -> new TagProvider.Items(output, registries, blockTags.contentsGetter(), existing)); + var blockTags = pack.addProvider(output -> new CommonTagProvider.Blocks(output, registries)); + pack.addProvider(output -> new CommonTagProvider.Items(output, registries, blockTags.contentsGetter())); pack.addProvider(output -> new ModelProvider.Items(output, existing)); pack.addProvider(output -> new ModelProvider.Blocks(output, existing)); diff --git a/forge/src/data/java/gripe/_90/megacells/datagen/TagProvider.java b/forge/src/data/java/gripe/_90/megacells/datagen/TagProvider.java deleted file mode 100644 index 8cf6318e..00000000 --- a/forge/src/data/java/gripe/_90/megacells/datagen/TagProvider.java +++ /dev/null @@ -1,74 +0,0 @@ -package gripe._90.megacells.datagen; - -import java.util.concurrent.CompletableFuture; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.core.HolderLookup; -import net.minecraft.data.PackOutput; -import net.minecraft.data.tags.ItemTagsProvider; -import net.minecraft.resources.ResourceKey; -import net.minecraft.tags.BlockTags; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.minecraftforge.common.data.BlockTagsProvider; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.ForgeRegistries; - -import appeng.api.features.P2PTunnelAttunement; -import appeng.core.definitions.BlockDefinition; -import appeng.core.definitions.ItemDefinition; - -import gripe._90.megacells.MEGACells; -import gripe._90.megacells.definition.MEGABlocks; -import gripe._90.megacells.definition.MEGAItems; -import gripe._90.megacells.definition.MEGATags; - -abstract class TagProvider { - static class Items extends ItemTagsProvider { - public Items( - PackOutput output, - CompletableFuture registries, - CompletableFuture> blockTags, - @Nullable ExistingFileHelper existing) { - super(output, registries, blockTags, MEGACells.MODID, existing); - } - - @Override - protected void addTags(@NotNull HolderLookup.Provider provider) { - tag(MEGATags.SKY_STEEL_INGOT).add(getKey(MEGAItems.SKY_STEEL_INGOT)); - tag(MEGATags.SKY_STEEL_BLOCK_ITEM).add(getKey(MEGABlocks.SKY_STEEL_BLOCK)); - - tag(P2PTunnelAttunement.getAttunementTag(P2PTunnelAttunement.ENERGY_TUNNEL)) - .add(getKey(MEGABlocks.MEGA_ENERGY_CELL)); - tag(MEGATags.MEGA_PATTERN_PROVIDER) - .add(getKey(MEGABlocks.MEGA_PATTERN_PROVIDER)) - .add(getKey(MEGAItems.MEGA_PATTERN_PROVIDER)); - } - - private ResourceKey getKey(ItemDefinition item) { - return ForgeRegistries.ITEMS.getResourceKey(item.asItem()).orElse(null); - } - } - - static class Blocks extends BlockTagsProvider { - public Blocks( - PackOutput output, - CompletableFuture registries, - @Nullable ExistingFileHelper existing) { - super(output, registries, MEGACells.MODID, existing); - } - - @Override - protected void addTags(@NotNull HolderLookup.Provider provider) { - MEGABlocks.getBlocks() - .forEach(block -> tag(BlockTags.MINEABLE_WITH_PICKAXE).add(getKey(block))); - tag(MEGATags.SKY_STEEL_BLOCK).add(getKey(MEGABlocks.SKY_STEEL_BLOCK)); - } - - private ResourceKey getKey(BlockDefinition block) { - return ForgeRegistries.BLOCKS.getResourceKey(block.block()).orElse(null); - } - } -}