Skip to content

Commit

Permalink
Move tag datagen to common
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Aug 27, 2023
1 parent dd5d3df commit ae87e6b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 159 deletions.
Original file line number Diff line number Diff line change
@@ -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<HolderLookup.Provider> registries,
CompletableFuture<TagLookup<Block>> 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<Block> {
public Blocks(PackOutput packOutput, CompletableFuture<HolderLookup.Provider> 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());
}
}
}
31 changes: 13 additions & 18 deletions common/src/main/java/gripe/_90/megacells/definition/MEGATags.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,22 @@
import gripe._90.megacells.MEGACells;

public final class MEGATags {
public static final TagKey<Item> SKY_STEEL_INGOT = itemTag(
switch (MEGACells.PLATFORM.getLoader()) {
case FABRIC -> "c:sky_steel_ingots";
case FORGE -> "forge:ingots/sky_steel";
});
public static final TagKey<Item> 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<Block> SKY_STEEL_BLOCK = blockTag(SKY_STEEL_BLOCK_TAG);
public static final TagKey<Item> SKY_STEEL_BLOCK_ITEM = itemTag(SKY_STEEL_BLOCK_TAG);

public static final TagKey<Item> MEGA_PATTERN_PROVIDER = itemTag("megacells:mega_pattern_provider");

private static TagKey<Item> itemTag(String name) {
return TagKey.create(Registries.ITEM, new ResourceLocation(name));
}
});
public static final TagKey<Block> SKY_STEEL_BLOCK = TagKey.create(Registries.BLOCK, SKY_STEEL_BLOCK_TAG);
public static final TagKey<Item> SKY_STEEL_BLOCK_ITEM = TagKey.create(Registries.ITEM, SKY_STEEL_BLOCK_TAG);

private static TagKey<Block> blockTag(String name) {
return TagKey.create(Registries.BLOCK, new ResourceLocation(name));
}
public static final TagKey<Item> MEGA_PATTERN_PROVIDER =
TagKey.create(Registries.ITEM, MEGACells.makeId("mega_pattern_provider"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 0 additions & 63 deletions fabric/src/data/java/gripe/_90/megacells/datagen/TagProvider.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
74 changes: 0 additions & 74 deletions forge/src/data/java/gripe/_90/megacells/datagen/TagProvider.java

This file was deleted.

0 comments on commit ae87e6b

Please sign in to comment.