From ef1aff5416231aca568f5a9b9f45f422c499a644 Mon Sep 17 00:00:00 2001 From: EmmaTheMartian Date: Mon, 8 Jul 2024 19:29:37 -0400 Subject: [PATCH] Make target path defined in buildscript Add tag providers Rename Ingredient to DataIngredient --- build.gradle | 1 + gradle.properties | 2 +- readme.md | 9 ++--- .../datagen_test/stationapi/lang/en_US.lang | 2 + .../stationapi/models/item/gravelly_ruby.json | 1 + .../stationapi/models/item/sandy_ruby.json | 1 + .../recipes/crafting/dirty_ruby.json | 1 - .../recipes/smelting/dirty_ruby_to_ruby.json | 1 - .../recipes/crafting/dirt_to_clay.json | 0 .../recipes/crafting/dirty_ruby.json | 1 + .../recipes/crafting/gravelly_ruby.json | 1 + .../stationapi/recipes/crafting/ruby_rod.json | 0 .../recipes/crafting/sandy_ruby.json | 1 + .../recipes/smelting/dirty_ruby_to_ruby.json | 1 + .../stationapi/tags/blocks/gem_blocks.json | 1 + .../tags/items/dirty_ruby_gems.json | 1 + .../stationapi/tags/items/ruby_gems.json | 1 + .../datagen/AbstractDataProvider.java | 4 +- .../datagen/DataGenContext.java | 14 +++---- .../emmathemartian/datagen/DataGenMod.java | 22 +++++++++-- .../emmathemartian/datagen/DataTarget.java | 12 ++++++ .../datagen/builder/ShapedRecipeBuilder.java | 6 +-- .../builder/ShapelessRecipeBuilder.java | 6 +-- .../builder/SmeltingRecipeBuilder.java | 6 +-- .../datagen/builder/TagBuilder.java | 35 ++++++++++++++++++ .../provider/AbstractModelProvider.java | 3 +- .../provider/AbstractRecipeProvider.java | 3 +- .../datagen/provider/BlockStateProvider.java | 3 +- .../datagen/provider/BlockTagProvider.java | 17 +++++++++ .../datagen/provider/ItemTagProvider.java | 17 +++++++++ .../datagen/provider/LanguageProvider.java | 3 +- .../provider/SmeltingRecipeProvider.java | 4 +- .../datagen/provider/TagProvider.java | 14 +++++++ .../{Ingredient.java => DataIngredient.java} | 18 ++++----- .../emmathemartian/datagen/test/TestMod.java | 20 ++-------- .../datagen/test/TestModData.java | 17 ++++++--- .../test/data/ModBlockTagProvider.java | 20 ++++++++++ .../test/data/ModCraftingRecipeProvider.java | 25 ++++++++++--- .../test/data/ModItemModelProvider.java | 2 + .../datagen/test/data/ModItemTagProvider.java | 25 +++++++++++++ .../datagen/test/data/ModLangProvider.java | 2 + .../test/data/ModSmeltingRecipeProvider.java | 6 ++- .../textures/item/gravelly_ruby.png | Bin 0 -> 538 bytes .../stationapi/textures/item/sandy_ruby.png | Bin 0 -> 501 bytes 44 files changed, 252 insertions(+), 77 deletions(-) create mode 100644 src/generated/resources/assets/datagen_test/stationapi/models/item/gravelly_ruby.json create mode 100644 src/generated/resources/assets/datagen_test/stationapi/models/item/sandy_ruby.json delete mode 100644 src/generated/resources/assets/datagen_test/stationapi/recipes/crafting/dirty_ruby.json delete mode 100644 src/generated/resources/assets/datagen_test/stationapi/recipes/smelting/dirty_ruby_to_ruby.json rename src/generated/resources/{assets => data}/datagen_test/stationapi/recipes/crafting/dirt_to_clay.json (100%) create mode 100644 src/generated/resources/data/datagen_test/stationapi/recipes/crafting/dirty_ruby.json create mode 100644 src/generated/resources/data/datagen_test/stationapi/recipes/crafting/gravelly_ruby.json rename src/generated/resources/{assets => data}/datagen_test/stationapi/recipes/crafting/ruby_rod.json (100%) create mode 100644 src/generated/resources/data/datagen_test/stationapi/recipes/crafting/sandy_ruby.json create mode 100644 src/generated/resources/data/datagen_test/stationapi/recipes/smelting/dirty_ruby_to_ruby.json create mode 100644 src/generated/resources/data/datagen_test/stationapi/tags/blocks/gem_blocks.json create mode 100644 src/generated/resources/data/datagen_test/stationapi/tags/items/dirty_ruby_gems.json create mode 100644 src/generated/resources/data/datagen_test/stationapi/tags/items/ruby_gems.json create mode 100644 src/main/java/emmathemartian/datagen/DataTarget.java create mode 100644 src/main/java/emmathemartian/datagen/builder/TagBuilder.java create mode 100644 src/main/java/emmathemartian/datagen/provider/BlockTagProvider.java create mode 100644 src/main/java/emmathemartian/datagen/provider/ItemTagProvider.java create mode 100644 src/main/java/emmathemartian/datagen/provider/TagProvider.java rename src/main/java/emmathemartian/datagen/util/{Ingredient.java => DataIngredient.java} (71%) create mode 100644 src/test/java/emmathemartian/datagen/test/data/ModBlockTagProvider.java create mode 100644 src/test/java/emmathemartian/datagen/test/data/ModItemTagProvider.java create mode 100644 src/test/resources/assets/datagen_test/stationapi/textures/item/gravelly_ruby.png create mode 100644 src/test/resources/assets/datagen_test/stationapi/textures/item/sandy_ruby.png diff --git a/build.gradle b/build.gradle index 04a986b..d55d6aa 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ loom { register("testData") { source("test") property("datagen.run", "datagen_test") + property("datagen.path", project.projectDir.toPath().resolve("src/generated/resources/").toAbsolutePath().toString()) client() } } diff --git a/gradle.properties b/gradle.properties index 53b273f..e8f491a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.daemon=false loader_version=0.15.6-babric.1 # Mod Properties - mod_version=1.0.0 + mod_version=0.0.1 maven_group=emmathemartian archives_base_name=datagen diff --git a/readme.md b/readme.md index 5104161..dd31038 100644 --- a/readme.md +++ b/readme.md @@ -15,7 +15,7 @@ before making a release just to be certain that there are no stale files. > The buildscript codeblocks are Groovy, however it should be very similar (if not then > exactly the same) in Kotlin DSL. -1. Include the datagen library. You can do this via Jitpack. +1. Include the datagen library. You can do this via Jitpack: ```groovy dependencies { @@ -49,6 +49,7 @@ before making a release just to be certain that there are no stale files. runs { register("data") { property("datagen.run", "MODID") // replace with your mod's id + property("datagen.path", project.projectDir.toPath().resolve("src/generated/resources/").toAbsolutePath().toString()) client() } } @@ -59,14 +60,12 @@ before making a release just to be certain that there are no stale files. ```java public class ModData implements DataEntrypoint { - public static final String MODID = "example_mod"; - @Entrypoint.Namespace private static final Namespace NAMESPACE = Null.get(); @Override public void run() { - DataGenContext context = new DataGenContext(NAMESPACE, "../src/generated/resources/assets/" + MODID + "/stationapi/"); + DataGenContext context = new DataGenContext(NAMESPACE); context.run(new CraftingRecipeProvider(context) { @Override @@ -100,7 +99,7 @@ before making a release just to be certain that there are no stale files. ## Troubleshooting -### The window does not appear +### The window does not appear or it closes after loading This is intentional when running the data generator. Due to when data is made and when the mod's JAR is made, you can't use any freshly generated files until the next run. diff --git a/src/generated/resources/assets/datagen_test/stationapi/lang/en_US.lang b/src/generated/resources/assets/datagen_test/stationapi/lang/en_US.lang index 0e0d8e4..d744a83 100644 --- a/src/generated/resources/assets/datagen_test/stationapi/lang/en_US.lang +++ b/src/generated/resources/assets/datagen_test/stationapi/lang/en_US.lang @@ -1,5 +1,7 @@ item.datagen_test.dirty_ruby.name=Dirty Ruby +item.datagen_test.gravelly_ruby.name=Gravelly Ruby tile.datagen_test.ruby_block.name=Block of Ruby +item.datagen_test.sandy_ruby.name=Sandy Ruby item.datagen_test.ruby.name=Ruby item.datagen_test.ruby_rod.name=Ruby Rod diff --git a/src/generated/resources/assets/datagen_test/stationapi/models/item/gravelly_ruby.json b/src/generated/resources/assets/datagen_test/stationapi/models/item/gravelly_ruby.json new file mode 100644 index 0000000..1d478f5 --- /dev/null +++ b/src/generated/resources/assets/datagen_test/stationapi/models/item/gravelly_ruby.json @@ -0,0 +1 @@ +{"parent":"minecraft:item/generated","textures":{"layer0":"datagen_test:item/gravelly_ruby"}} diff --git a/src/generated/resources/assets/datagen_test/stationapi/models/item/sandy_ruby.json b/src/generated/resources/assets/datagen_test/stationapi/models/item/sandy_ruby.json new file mode 100644 index 0000000..7860df6 --- /dev/null +++ b/src/generated/resources/assets/datagen_test/stationapi/models/item/sandy_ruby.json @@ -0,0 +1 @@ +{"parent":"minecraft:item/generated","textures":{"layer0":"datagen_test:item/sandy_ruby"}} diff --git a/src/generated/resources/assets/datagen_test/stationapi/recipes/crafting/dirty_ruby.json b/src/generated/resources/assets/datagen_test/stationapi/recipes/crafting/dirty_ruby.json deleted file mode 100644 index f5b285b..0000000 --- a/src/generated/resources/assets/datagen_test/stationapi/recipes/crafting/dirty_ruby.json +++ /dev/null @@ -1 +0,0 @@ -{"type":"minecraft:crafting_shapeless","ingredients":[{"item":"minecraft:diamond"},{"item":"minecraft:dirt"},{"item":"minecraft:dirt"}],"result":{"item":"datagen_test:dirty_ruby"}} diff --git a/src/generated/resources/assets/datagen_test/stationapi/recipes/smelting/dirty_ruby_to_ruby.json b/src/generated/resources/assets/datagen_test/stationapi/recipes/smelting/dirty_ruby_to_ruby.json deleted file mode 100644 index eba0a6b..0000000 --- a/src/generated/resources/assets/datagen_test/stationapi/recipes/smelting/dirty_ruby_to_ruby.json +++ /dev/null @@ -1 +0,0 @@ -{"type":"minecraft:smelting","ingredient":{"item":"datagen_test:dirty_ruby"},"result":{"item":"datagen_test:ruby"}} diff --git a/src/generated/resources/assets/datagen_test/stationapi/recipes/crafting/dirt_to_clay.json b/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/dirt_to_clay.json similarity index 100% rename from src/generated/resources/assets/datagen_test/stationapi/recipes/crafting/dirt_to_clay.json rename to src/generated/resources/data/datagen_test/stationapi/recipes/crafting/dirt_to_clay.json diff --git a/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/dirty_ruby.json b/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/dirty_ruby.json new file mode 100644 index 0000000..3fc3b6c --- /dev/null +++ b/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/dirty_ruby.json @@ -0,0 +1 @@ +{"type":"minecraft:crafting_shapeless","ingredients":[{"item":"datagen_test:ruby"},{"item":"minecraft:dirt"},{"item":"minecraft:dirt"}],"result":{"item":"datagen_test:dirty_ruby"}} diff --git a/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/gravelly_ruby.json b/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/gravelly_ruby.json new file mode 100644 index 0000000..71c09eb --- /dev/null +++ b/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/gravelly_ruby.json @@ -0,0 +1 @@ +{"type":"minecraft:crafting_shapeless","ingredients":[{"item":"datagen_test:ruby"},{"item":"minecraft:gravel"},{"item":"minecraft:gravel"}],"result":{"item":"datagen_test:gravelly_ruby"}} diff --git a/src/generated/resources/assets/datagen_test/stationapi/recipes/crafting/ruby_rod.json b/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/ruby_rod.json similarity index 100% rename from src/generated/resources/assets/datagen_test/stationapi/recipes/crafting/ruby_rod.json rename to src/generated/resources/data/datagen_test/stationapi/recipes/crafting/ruby_rod.json diff --git a/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/sandy_ruby.json b/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/sandy_ruby.json new file mode 100644 index 0000000..98a2159 --- /dev/null +++ b/src/generated/resources/data/datagen_test/stationapi/recipes/crafting/sandy_ruby.json @@ -0,0 +1 @@ +{"type":"minecraft:crafting_shapeless","ingredients":[{"item":"datagen_test:ruby"},{"item":"minecraft:sand"},{"item":"minecraft:sand"}],"result":{"item":"datagen_test:sandy_ruby"}} diff --git a/src/generated/resources/data/datagen_test/stationapi/recipes/smelting/dirty_ruby_to_ruby.json b/src/generated/resources/data/datagen_test/stationapi/recipes/smelting/dirty_ruby_to_ruby.json new file mode 100644 index 0000000..070ad4a --- /dev/null +++ b/src/generated/resources/data/datagen_test/stationapi/recipes/smelting/dirty_ruby_to_ruby.json @@ -0,0 +1 @@ +{"type":"minecraft:smelting","ingredient":{"tag":"datagen_test:dirty_ruby_gems"},"result":{"item":"datagen_test:ruby"}} diff --git a/src/generated/resources/data/datagen_test/stationapi/tags/blocks/gem_blocks.json b/src/generated/resources/data/datagen_test/stationapi/tags/blocks/gem_blocks.json new file mode 100644 index 0000000..7c0373e --- /dev/null +++ b/src/generated/resources/data/datagen_test/stationapi/tags/blocks/gem_blocks.json @@ -0,0 +1 @@ +{"values":["minecraft:diamond_block","datagen_test:ruby_block"]} diff --git a/src/generated/resources/data/datagen_test/stationapi/tags/items/dirty_ruby_gems.json b/src/generated/resources/data/datagen_test/stationapi/tags/items/dirty_ruby_gems.json new file mode 100644 index 0000000..40e5785 --- /dev/null +++ b/src/generated/resources/data/datagen_test/stationapi/tags/items/dirty_ruby_gems.json @@ -0,0 +1 @@ +{"values":["datagen_test:dirty_ruby","datagen_test:sandy_ruby","datagen_test:gravelly_ruby"]} diff --git a/src/generated/resources/data/datagen_test/stationapi/tags/items/ruby_gems.json b/src/generated/resources/data/datagen_test/stationapi/tags/items/ruby_gems.json new file mode 100644 index 0000000..3e87bd5 --- /dev/null +++ b/src/generated/resources/data/datagen_test/stationapi/tags/items/ruby_gems.json @@ -0,0 +1 @@ +{"values":["datagen_test:ruby","datagen_test:dirty_ruby"]} diff --git a/src/main/java/emmathemartian/datagen/AbstractDataProvider.java b/src/main/java/emmathemartian/datagen/AbstractDataProvider.java index 93c948f..8d3ce81 100644 --- a/src/main/java/emmathemartian/datagen/AbstractDataProvider.java +++ b/src/main/java/emmathemartian/datagen/AbstractDataProvider.java @@ -6,8 +6,8 @@ public abstract class AbstractDataProvider { public final Path path; public final String name; - public AbstractDataProvider(String path, String name, DataGenContext context) { - this.path = context.root.resolve(path); + public AbstractDataProvider(String path, String name, DataTarget target, DataGenContext context) { + this.path = target.getPath(context).resolve(path); this.name = name; } diff --git a/src/main/java/emmathemartian/datagen/DataGenContext.java b/src/main/java/emmathemartian/datagen/DataGenContext.java index 1d776ae..a2ab274 100644 --- a/src/main/java/emmathemartian/datagen/DataGenContext.java +++ b/src/main/java/emmathemartian/datagen/DataGenContext.java @@ -11,15 +11,7 @@ import java.util.List; import java.util.function.Function; -public class DataGenContext { - public final Namespace namespace; - public final Path root; - - public DataGenContext(Namespace namespace, String rootPath) { - this.namespace = namespace; - this.root = Path.of(rootPath); - } - +public record DataGenContext(Namespace namespace) { public void run(Function provider) { run(provider.apply(this)); } @@ -41,4 +33,8 @@ public void save(Path path, String data) { public void save(Path path, JsonObject object) { save(path, new Gson().toJson(object)); } + + public Path getTargetPath(String parent) { + return DataGenMod.targetPath.resolve(parent).resolve(namespace.toString()).resolve("stationapi"); + } } diff --git a/src/main/java/emmathemartian/datagen/DataGenMod.java b/src/main/java/emmathemartian/datagen/DataGenMod.java index adff879..d029483 100644 --- a/src/main/java/emmathemartian/datagen/DataGenMod.java +++ b/src/main/java/emmathemartian/datagen/DataGenMod.java @@ -3,27 +3,41 @@ import emmathemartian.datagen.entrypoint.DataEntrypoint; import net.fabricmc.loader.api.FabricLoader; import net.mine_diver.unsafeevents.listener.EventListener; -import net.modificationstation.stationapi.api.event.registry.AfterBlockAndItemRegisterEvent; +import net.mine_diver.unsafeevents.listener.ListenerPriority; +import net.modificationstation.stationapi.api.event.registry.DimensionRegistryEvent; import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint; import net.modificationstation.stationapi.api.util.Null; import org.apache.logging.log4j.Logger; -@SuppressWarnings("unused") +import java.nio.file.Path; +import java.util.Objects; + public class DataGenMod { @Entrypoint.Logger public static final Logger LOGGER = Null.get(); - @EventListener - private static void onPostRegistries(AfterBlockAndItemRegisterEvent event) { + public static Path targetPath; + + private static Path getTargetPath() { + String strPath = Objects.requireNonNull(System.getProperty("datagen.path"), "System property datagen.path was null. Make sure it is defined in your buildscript."); + return Path.of(strPath); + } + + @SuppressWarnings("unused") + @EventListener(priority = ListenerPriority.LOWEST) + private static void onPostRegistries(DimensionRegistryEvent event) { String property = System.getProperty("datagen.run"); if (property == null) return; final String[] toRun = property.split(","); LOGGER.info("Data generator will be executed for mods: [{}]", String.join(", ", toRun)); + LOGGER.info("Data generation target path is `{}`", getTargetPath()); LOGGER.info("Note: The game will be stopped after data generation finishes."); if (toRun.length > 0) { + targetPath = getTargetPath(); + if (!FabricLoader.getInstance().isDevelopmentEnvironment()) { throw new DataGenException("Data generators should not be executed in production environments. Exiting."); } diff --git a/src/main/java/emmathemartian/datagen/DataTarget.java b/src/main/java/emmathemartian/datagen/DataTarget.java new file mode 100644 index 0000000..357886e --- /dev/null +++ b/src/main/java/emmathemartian/datagen/DataTarget.java @@ -0,0 +1,12 @@ +package emmathemartian.datagen; + +import java.nio.file.Path; + +public record DataTarget(String target) { + public static final DataTarget ASSETS = new DataTarget("assets"); + public static final DataTarget DATA = new DataTarget("data"); + + public Path getPath(DataGenContext context) { + return context.getTargetPath(target); + } +} diff --git a/src/main/java/emmathemartian/datagen/builder/ShapedRecipeBuilder.java b/src/main/java/emmathemartian/datagen/builder/ShapedRecipeBuilder.java index 85136bb..c3b2e56 100644 --- a/src/main/java/emmathemartian/datagen/builder/ShapedRecipeBuilder.java +++ b/src/main/java/emmathemartian/datagen/builder/ShapedRecipeBuilder.java @@ -3,7 +3,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import emmathemartian.datagen.IDataBuilder; -import emmathemartian.datagen.util.Ingredient; +import emmathemartian.datagen.util.DataIngredient; import emmathemartian.datagen.util.ItemStackHelpers; import net.minecraft.item.ItemStack; import net.modificationstation.stationapi.api.util.Identifier; @@ -14,7 +14,7 @@ public class ShapedRecipeBuilder implements IDataBuilder { public static final Identifier TYPE_ID = Identifier.of("minecraft:crafting_shaped"); protected List pattern = new ArrayList<>(); - protected Map key = new HashMap<>(); + protected Map key = new HashMap<>(); protected ItemStack result; public ShapedRecipeBuilder pattern(String... patterns) { @@ -22,7 +22,7 @@ public ShapedRecipeBuilder pattern(String... patterns) { return this; } - public ShapedRecipeBuilder define(char key, Ingredient ingredient) { + public ShapedRecipeBuilder define(char key, DataIngredient ingredient) { this.key.put(key, ingredient); return this; } diff --git a/src/main/java/emmathemartian/datagen/builder/ShapelessRecipeBuilder.java b/src/main/java/emmathemartian/datagen/builder/ShapelessRecipeBuilder.java index 46859f8..186496d 100644 --- a/src/main/java/emmathemartian/datagen/builder/ShapelessRecipeBuilder.java +++ b/src/main/java/emmathemartian/datagen/builder/ShapelessRecipeBuilder.java @@ -3,7 +3,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import emmathemartian.datagen.IDataBuilder; -import emmathemartian.datagen.util.Ingredient; +import emmathemartian.datagen.util.DataIngredient; import emmathemartian.datagen.util.ItemStackHelpers; import net.minecraft.item.ItemStack; import net.modificationstation.stationapi.api.util.Identifier; @@ -13,10 +13,10 @@ public class ShapelessRecipeBuilder implements IDataBuilder { public static final Identifier TYPE_ID = Identifier.of("minecraft:crafting_shapeless"); - protected List ingredients = new ArrayList<>(); + protected List ingredients = new ArrayList<>(); protected ItemStack result; - public ShapelessRecipeBuilder ingredient(Ingredient ingredient) { + public ShapelessRecipeBuilder ingredient(DataIngredient ingredient) { this.ingredients.add(ingredient); return this; } diff --git a/src/main/java/emmathemartian/datagen/builder/SmeltingRecipeBuilder.java b/src/main/java/emmathemartian/datagen/builder/SmeltingRecipeBuilder.java index f99d106..fd88259 100644 --- a/src/main/java/emmathemartian/datagen/builder/SmeltingRecipeBuilder.java +++ b/src/main/java/emmathemartian/datagen/builder/SmeltingRecipeBuilder.java @@ -2,7 +2,7 @@ import com.google.gson.JsonObject; import emmathemartian.datagen.IDataBuilder; -import emmathemartian.datagen.util.Ingredient; +import emmathemartian.datagen.util.DataIngredient; import emmathemartian.datagen.util.ItemStackHelpers; import net.minecraft.item.ItemStack; import net.modificationstation.stationapi.api.util.Identifier; @@ -10,10 +10,10 @@ public class SmeltingRecipeBuilder implements IDataBuilder { public static final Identifier TYPE_ID = Identifier.of("minecraft:smelting"); - protected Ingredient ingredient; + protected DataIngredient ingredient; protected ItemStack result; - public SmeltingRecipeBuilder ingredient(Ingredient ingredient) { + public SmeltingRecipeBuilder ingredient(DataIngredient ingredient) { this.ingredient = ingredient; return this; } diff --git a/src/main/java/emmathemartian/datagen/builder/TagBuilder.java b/src/main/java/emmathemartian/datagen/builder/TagBuilder.java new file mode 100644 index 0000000..a504676 --- /dev/null +++ b/src/main/java/emmathemartian/datagen/builder/TagBuilder.java @@ -0,0 +1,35 @@ +package emmathemartian.datagen.builder; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import emmathemartian.datagen.IDataBuilder; +import net.modificationstation.stationapi.api.registry.Registry; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class TagBuilder implements IDataBuilder { + protected final Registry registry; + protected final List entries = new ArrayList<>(); + + public TagBuilder(Registry registry) { + this.registry = registry; + } + + public TagBuilder add(T entry) { + this.entries.add(entry); + return this; + } + + @Override + public JsonObject build() { + JsonObject object = new JsonObject(); + + JsonArray entriesArray = new JsonArray(); + entries.forEach(it -> entriesArray.add(Objects.requireNonNull(registry.getId(it)).toString())); + object.add("values", entriesArray); + + return object; + } +} diff --git a/src/main/java/emmathemartian/datagen/provider/AbstractModelProvider.java b/src/main/java/emmathemartian/datagen/provider/AbstractModelProvider.java index 1b30695..9d61971 100644 --- a/src/main/java/emmathemartian/datagen/provider/AbstractModelProvider.java +++ b/src/main/java/emmathemartian/datagen/provider/AbstractModelProvider.java @@ -2,9 +2,10 @@ import emmathemartian.datagen.AbstractDataProvider; import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.DataTarget; public abstract class AbstractModelProvider extends AbstractDataProvider { public AbstractModelProvider(String subpath, String name, DataGenContext context) { - super("models/" + subpath, name, context); + super("models/" + subpath, name, DataTarget.ASSETS, context); } } diff --git a/src/main/java/emmathemartian/datagen/provider/AbstractRecipeProvider.java b/src/main/java/emmathemartian/datagen/provider/AbstractRecipeProvider.java index fe8cd4e..ae32f58 100644 --- a/src/main/java/emmathemartian/datagen/provider/AbstractRecipeProvider.java +++ b/src/main/java/emmathemartian/datagen/provider/AbstractRecipeProvider.java @@ -2,9 +2,10 @@ import emmathemartian.datagen.AbstractDataProvider; import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.DataTarget; public abstract class AbstractRecipeProvider extends AbstractDataProvider { public AbstractRecipeProvider(String subpath, DataGenContext context) { - super("recipes/" + subpath, "Recipes", context); + super("recipes/" + subpath, "Recipes", DataTarget.DATA, context); } } diff --git a/src/main/java/emmathemartian/datagen/provider/BlockStateProvider.java b/src/main/java/emmathemartian/datagen/provider/BlockStateProvider.java index 72faa09..f354641 100644 --- a/src/main/java/emmathemartian/datagen/provider/BlockStateProvider.java +++ b/src/main/java/emmathemartian/datagen/provider/BlockStateProvider.java @@ -2,11 +2,12 @@ import emmathemartian.datagen.AbstractDataProvider; import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.DataTarget; import emmathemartian.datagen.builder.VariantStateBuilder; public abstract class BlockStateProvider extends AbstractDataProvider { public BlockStateProvider(DataGenContext context) { - super("blockstates", "Block States", context); + super("blockstates", "Block States", DataTarget.ASSETS, context); } protected VariantStateBuilder variant() { diff --git a/src/main/java/emmathemartian/datagen/provider/BlockTagProvider.java b/src/main/java/emmathemartian/datagen/provider/BlockTagProvider.java new file mode 100644 index 0000000..3d869de --- /dev/null +++ b/src/main/java/emmathemartian/datagen/provider/BlockTagProvider.java @@ -0,0 +1,17 @@ +package emmathemartian.datagen.provider; + +import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.builder.TagBuilder; +import net.minecraft.block.Block; +import net.modificationstation.stationapi.api.registry.BlockRegistry; + +public abstract class BlockTagProvider extends TagProvider { + public BlockTagProvider(DataGenContext context) { + super("blocks", "Block Tags", context); + } + + @Override + protected TagBuilder tag() { + return new TagBuilder<>(BlockRegistry.INSTANCE); + } +} diff --git a/src/main/java/emmathemartian/datagen/provider/ItemTagProvider.java b/src/main/java/emmathemartian/datagen/provider/ItemTagProvider.java new file mode 100644 index 0000000..eff2543 --- /dev/null +++ b/src/main/java/emmathemartian/datagen/provider/ItemTagProvider.java @@ -0,0 +1,17 @@ +package emmathemartian.datagen.provider; + +import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.builder.TagBuilder; +import net.minecraft.item.Item; +import net.modificationstation.stationapi.api.registry.ItemRegistry; + +public abstract class ItemTagProvider extends TagProvider { + public ItemTagProvider(DataGenContext context) { + super("items", "Item Tags", context); + } + + @Override + protected TagBuilder tag() { + return new TagBuilder<>(ItemRegistry.INSTANCE); + } +} diff --git a/src/main/java/emmathemartian/datagen/provider/LanguageProvider.java b/src/main/java/emmathemartian/datagen/provider/LanguageProvider.java index e45a639..5770afa 100644 --- a/src/main/java/emmathemartian/datagen/provider/LanguageProvider.java +++ b/src/main/java/emmathemartian/datagen/provider/LanguageProvider.java @@ -2,9 +2,10 @@ import emmathemartian.datagen.AbstractDataProvider; import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.DataTarget; public abstract class LanguageProvider extends AbstractDataProvider { public LanguageProvider(DataGenContext context) { - super("lang", "Languages", context); + super("lang", "Languages", DataTarget.ASSETS, context); } } diff --git a/src/main/java/emmathemartian/datagen/provider/SmeltingRecipeProvider.java b/src/main/java/emmathemartian/datagen/provider/SmeltingRecipeProvider.java index 3264368..801b45a 100644 --- a/src/main/java/emmathemartian/datagen/provider/SmeltingRecipeProvider.java +++ b/src/main/java/emmathemartian/datagen/provider/SmeltingRecipeProvider.java @@ -2,7 +2,7 @@ import emmathemartian.datagen.DataGenContext; import emmathemartian.datagen.builder.SmeltingRecipeBuilder; -import emmathemartian.datagen.util.Ingredient; +import emmathemartian.datagen.util.DataIngredient; import net.minecraft.item.ItemStack; public abstract class SmeltingRecipeProvider extends AbstractRecipeProvider { @@ -14,7 +14,7 @@ protected SmeltingRecipeBuilder smelting() { return new SmeltingRecipeBuilder(); } - protected SmeltingRecipeBuilder smelting(Ingredient input, ItemStack output) { + protected SmeltingRecipeBuilder smelting(DataIngredient input, ItemStack output) { return new SmeltingRecipeBuilder() .ingredient(input) .result(output); diff --git a/src/main/java/emmathemartian/datagen/provider/TagProvider.java b/src/main/java/emmathemartian/datagen/provider/TagProvider.java new file mode 100644 index 0000000..bd49d8b --- /dev/null +++ b/src/main/java/emmathemartian/datagen/provider/TagProvider.java @@ -0,0 +1,14 @@ +package emmathemartian.datagen.provider; + +import emmathemartian.datagen.AbstractDataProvider; +import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.DataTarget; +import emmathemartian.datagen.builder.TagBuilder; + +public abstract class TagProvider extends AbstractDataProvider { + public TagProvider(String path, String name, DataGenContext context) { + super("tags/" + path, name, DataTarget.DATA, context); + } + + protected abstract TagBuilder tag(); +} diff --git a/src/main/java/emmathemartian/datagen/util/Ingredient.java b/src/main/java/emmathemartian/datagen/util/DataIngredient.java similarity index 71% rename from src/main/java/emmathemartian/datagen/util/Ingredient.java rename to src/main/java/emmathemartian/datagen/util/DataIngredient.java index def984e..ff82987 100644 --- a/src/main/java/emmathemartian/datagen/util/Ingredient.java +++ b/src/main/java/emmathemartian/datagen/util/DataIngredient.java @@ -9,7 +9,7 @@ import net.modificationstation.stationapi.api.tag.TagKey; import net.modificationstation.stationapi.api.util.Identifier; -public record Ingredient(Either> item, int count, int damage) { +public record DataIngredient(Either> item, int count, int damage) { public JsonObject toJson() { JsonObject object = new JsonObject(); @@ -32,27 +32,27 @@ public JsonObject toJson() { return object; } - public static Ingredient of(Item item, int count, int damage) { - return new Ingredient(Either.left(item), count, damage); + public static DataIngredient of(Item item, int count, int damage) { + return new DataIngredient(Either.left(item), count, damage); } - public static Ingredient of(Item item, int count) { + public static DataIngredient of(Item item, int count) { return of(item, count, 0); } - public static Ingredient of(Item item) { + public static DataIngredient of(Item item) { return of(item, 1, 0); } - public static Ingredient of(ItemStack stack) { + public static DataIngredient of(ItemStack stack) { return of(stack.getItem(), stack.count, stack.getDamage()); } - public static Ingredient of(TagKey tag, int count) { - return new Ingredient(Either.right(tag), count, 0); + public static DataIngredient of(TagKey tag, int count) { + return new DataIngredient(Either.right(tag), count, 0); } - public static Ingredient of(TagKey tag) { + public static DataIngredient of(TagKey tag) { return of(tag, 1); } } diff --git a/src/test/java/emmathemartian/datagen/test/TestMod.java b/src/test/java/emmathemartian/datagen/test/TestMod.java index b82809b..a5790b9 100644 --- a/src/test/java/emmathemartian/datagen/test/TestMod.java +++ b/src/test/java/emmathemartian/datagen/test/TestMod.java @@ -4,9 +4,6 @@ import net.minecraft.block.Block; import net.minecraft.block.Material; import net.minecraft.item.Item; -import net.modificationstation.stationapi.api.client.event.texture.TextureRegisterEvent; -import net.modificationstation.stationapi.api.client.texture.atlas.Atlases; -import net.modificationstation.stationapi.api.client.texture.atlas.ExpandableAtlas; import net.modificationstation.stationapi.api.event.registry.BlockRegistryEvent; import net.modificationstation.stationapi.api.event.registry.ItemRegistryEvent; import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint; @@ -20,13 +17,15 @@ public class TestMod { @Entrypoint.Namespace public static final Namespace NAMESPACE = Null.get(); - public static Item itemRuby, itemDirtyRuby, itemRubyRod; + public static Item itemRuby, itemDirtyRuby, itemSandyRuby, itemGravellyRuby, itemRubyRod; public static Block blockRuby; @EventListener private static void onRegisterItems(ItemRegistryEvent event) { itemRuby = new TemplateItem(NAMESPACE.id("ruby")).setTranslationKey(NAMESPACE, "ruby"); itemDirtyRuby = new TemplateItem(NAMESPACE.id("dirty_ruby")).setTranslationKey(NAMESPACE, "dirty_ruby"); + itemSandyRuby = new TemplateItem(NAMESPACE.id("sandy_ruby")).setTranslationKey(NAMESPACE, "sandy_ruby"); + itemGravellyRuby = new TemplateItem(NAMESPACE.id("gravelly_ruby")).setTranslationKey(NAMESPACE, "gravelly_ruby"); itemRubyRod = new TemplateItem(NAMESPACE.id("ruby_rod")).setTranslationKey(NAMESPACE, "ruby_rod"); } @@ -34,17 +33,4 @@ private static void onRegisterItems(ItemRegistryEvent event) { private static void onRegisterBlocks(BlockRegistryEvent event) { blockRuby = new TemplateBlock(NAMESPACE.id("ruby_block"), Material.STONE).setTranslationKey(NAMESPACE, "ruby_block").setHardness(2.0f).setResistance(4.0f); } - - public static class Client { - public static int blockRubyTexture; - - @EventListener - private static void onRegisterTextures(TextureRegisterEvent event) { - itemRuby.setTexture(NAMESPACE.id("item/ruby")); - - ExpandableAtlas atlas = Atlases.getTerrain(); - blockRubyTexture = atlas.addTexture(NAMESPACE.id("block/ruby_block")).index; - blockRuby.textureId = blockRubyTexture; - } - } } diff --git a/src/test/java/emmathemartian/datagen/test/TestModData.java b/src/test/java/emmathemartian/datagen/test/TestModData.java index bb10e3f..3e34fde 100644 --- a/src/test/java/emmathemartian/datagen/test/TestModData.java +++ b/src/test/java/emmathemartian/datagen/test/TestModData.java @@ -4,7 +4,7 @@ import emmathemartian.datagen.entrypoint.DataEntrypoint; import emmathemartian.datagen.provider.CraftingRecipeProvider; import emmathemartian.datagen.test.data.*; -import emmathemartian.datagen.util.Ingredient; +import emmathemartian.datagen.util.DataIngredient; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -12,20 +12,27 @@ public class TestModData implements DataEntrypoint { @Override public void run() { - DataGenContext context = new DataGenContext(TestMod.NAMESPACE, "../src/generated/resources/assets/datagen_test/stationapi/"); + DataGenContext context = new DataGenContext(TestMod.NAMESPACE); + + // Assets context.run(ModItemModelProvider::new); context.run(ModBlockModelProvider::new); context.run(ModBlockStateProvider::new); + context.run(ModLangProvider::new); + + // Data context.run(ModCraftingRecipeProvider::new); context.run(ModSmeltingRecipeProvider::new); - context.run(ModLangProvider::new); + context.run(ModBlockTagProvider::new); + context.run(ModItemTagProvider::new); + // For smaller providers you can just use an anonymous object :p context.run(new CraftingRecipeProvider(context) { @Override public void run(DataGenContext context) { shapeless() - .ingredient(Ingredient.of(Block.DIRT.asItem())) - .ingredient(Ingredient.of(Item.WATER_BUCKET)) + .ingredient(DataIngredient.of(Block.DIRT.asItem())) + .ingredient(DataIngredient.of(Item.WATER_BUCKET)) .result(new ItemStack(Block.CLAY.asItem())) .save("dirt_to_clay", this, context); } diff --git a/src/test/java/emmathemartian/datagen/test/data/ModBlockTagProvider.java b/src/test/java/emmathemartian/datagen/test/data/ModBlockTagProvider.java new file mode 100644 index 0000000..79941e7 --- /dev/null +++ b/src/test/java/emmathemartian/datagen/test/data/ModBlockTagProvider.java @@ -0,0 +1,20 @@ +package emmathemartian.datagen.test.data; + +import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.provider.BlockTagProvider; +import emmathemartian.datagen.test.TestMod; +import net.minecraft.block.Block; + +public class ModBlockTagProvider extends BlockTagProvider { + public ModBlockTagProvider(DataGenContext context) { + super(context); + } + + @Override + public void run(DataGenContext context) { + tag() + .add(Block.DIAMOND_BLOCK) + .add(TestMod.blockRuby) + .save("gem_blocks", this, context); + } +} diff --git a/src/test/java/emmathemartian/datagen/test/data/ModCraftingRecipeProvider.java b/src/test/java/emmathemartian/datagen/test/data/ModCraftingRecipeProvider.java index d91696e..185766d 100644 --- a/src/test/java/emmathemartian/datagen/test/data/ModCraftingRecipeProvider.java +++ b/src/test/java/emmathemartian/datagen/test/data/ModCraftingRecipeProvider.java @@ -3,9 +3,8 @@ import emmathemartian.datagen.DataGenContext; import emmathemartian.datagen.provider.CraftingRecipeProvider; import emmathemartian.datagen.test.TestMod; -import emmathemartian.datagen.util.Ingredient; +import emmathemartian.datagen.util.DataIngredient; import net.minecraft.block.Block; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class ModCraftingRecipeProvider extends CraftingRecipeProvider { @@ -16,17 +15,31 @@ public ModCraftingRecipeProvider(DataGenContext context) { @Override public void run(DataGenContext context) { shapeless() - .ingredient(Ingredient.of(Item.DIAMOND)) - .ingredient(Ingredient.of(Block.DIRT.asItem())) - .ingredient(Ingredient.of(Block.DIRT.asItem())) + .ingredient(DataIngredient.of(TestMod.itemRuby)) + .ingredient(DataIngredient.of(Block.DIRT.asItem())) + .ingredient(DataIngredient.of(Block.DIRT.asItem())) .result(new ItemStack(TestMod.itemDirtyRuby)) .save("dirty_ruby", this, context); + shapeless() + .ingredient(DataIngredient.of(TestMod.itemRuby)) + .ingredient(DataIngredient.of(Block.SAND.asItem())) + .ingredient(DataIngredient.of(Block.SAND.asItem())) + .result(new ItemStack(TestMod.itemSandyRuby)) + .save("sandy_ruby", this, context); + + shapeless() + .ingredient(DataIngredient.of(TestMod.itemRuby)) + .ingredient(DataIngredient.of(Block.GRAVEL.asItem())) + .ingredient(DataIngredient.of(Block.GRAVEL.asItem())) + .result(new ItemStack(TestMod.itemGravellyRuby)) + .save("gravelly_ruby", this, context); + shaped() .pattern(" R") .pattern(" R ") .pattern("R ") - .define('R', Ingredient.of(TestMod.itemRuby)) + .define('R', DataIngredient.of(TestMod.itemRuby)) .result(new ItemStack(TestMod.itemRubyRod)) .save("ruby_rod", this, context); } diff --git a/src/test/java/emmathemartian/datagen/test/data/ModItemModelProvider.java b/src/test/java/emmathemartian/datagen/test/data/ModItemModelProvider.java index d5a8bb0..d2bdbd8 100644 --- a/src/test/java/emmathemartian/datagen/test/data/ModItemModelProvider.java +++ b/src/test/java/emmathemartian/datagen/test/data/ModItemModelProvider.java @@ -13,6 +13,8 @@ public ModItemModelProvider(DataGenContext context) { public void run(DataGenContext context) { simpleItem(TestMod.itemRuby).save("ruby", this, context); simpleItem(TestMod.itemDirtyRuby).save("dirty_ruby", this, context); + simpleItem(TestMod.itemSandyRuby).save("sandy_ruby", this, context); + simpleItem(TestMod.itemGravellyRuby).save("gravelly_ruby", this, context); handheldRod() .texture("layer0", TestMod.NAMESPACE.id("item/ruby_rod")) diff --git a/src/test/java/emmathemartian/datagen/test/data/ModItemTagProvider.java b/src/test/java/emmathemartian/datagen/test/data/ModItemTagProvider.java new file mode 100644 index 0000000..3cb022d --- /dev/null +++ b/src/test/java/emmathemartian/datagen/test/data/ModItemTagProvider.java @@ -0,0 +1,25 @@ +package emmathemartian.datagen.test.data; + +import emmathemartian.datagen.DataGenContext; +import emmathemartian.datagen.provider.ItemTagProvider; +import emmathemartian.datagen.test.TestMod; + +public class ModItemTagProvider extends ItemTagProvider { + public ModItemTagProvider(DataGenContext context) { + super(context); + } + + @Override + public void run(DataGenContext context) { + tag() + .add(TestMod.itemRuby) + .add(TestMod.itemDirtyRuby) + .save("ruby_gems", this, context); + + tag() + .add(TestMod.itemDirtyRuby) + .add(TestMod.itemSandyRuby) + .add(TestMod.itemGravellyRuby) + .save("dirty_ruby_gems", this, context); + } +} diff --git a/src/test/java/emmathemartian/datagen/test/data/ModLangProvider.java b/src/test/java/emmathemartian/datagen/test/data/ModLangProvider.java index fa4b77c..ca1ad03 100644 --- a/src/test/java/emmathemartian/datagen/test/data/ModLangProvider.java +++ b/src/test/java/emmathemartian/datagen/test/data/ModLangProvider.java @@ -15,6 +15,8 @@ public void run(DataGenContext context) { new LangBuilder() .add(TestMod.itemRuby, "Ruby") .add(TestMod.itemDirtyRuby, "Dirty Ruby") + .add(TestMod.itemSandyRuby, "Sandy Ruby") + .add(TestMod.itemGravellyRuby, "Gravelly Ruby") .add(TestMod.itemRubyRod, "Ruby Rod") .add(TestMod.blockRuby, "Block of Ruby") .save("en_US", this, context); diff --git a/src/test/java/emmathemartian/datagen/test/data/ModSmeltingRecipeProvider.java b/src/test/java/emmathemartian/datagen/test/data/ModSmeltingRecipeProvider.java index 5751616..56317f2 100644 --- a/src/test/java/emmathemartian/datagen/test/data/ModSmeltingRecipeProvider.java +++ b/src/test/java/emmathemartian/datagen/test/data/ModSmeltingRecipeProvider.java @@ -3,8 +3,10 @@ import emmathemartian.datagen.DataGenContext; import emmathemartian.datagen.provider.SmeltingRecipeProvider; import emmathemartian.datagen.test.TestMod; -import emmathemartian.datagen.util.Ingredient; +import emmathemartian.datagen.util.DataIngredient; import net.minecraft.item.ItemStack; +import net.modificationstation.stationapi.api.registry.ItemRegistry; +import net.modificationstation.stationapi.api.tag.TagKey; public class ModSmeltingRecipeProvider extends SmeltingRecipeProvider { public ModSmeltingRecipeProvider(DataGenContext context) { @@ -13,7 +15,7 @@ public ModSmeltingRecipeProvider(DataGenContext context) { @Override public void run(DataGenContext context) { - smelting(Ingredient.of(TestMod.itemDirtyRuby), new ItemStack(TestMod.itemRuby)) + smelting(DataIngredient.of(TagKey.of(ItemRegistry.KEY, TestMod.NAMESPACE.id("dirty_ruby_gems"))), new ItemStack(TestMod.itemRuby)) .save("dirty_ruby_to_ruby", this, context); } } diff --git a/src/test/resources/assets/datagen_test/stationapi/textures/item/gravelly_ruby.png b/src/test/resources/assets/datagen_test/stationapi/textures/item/gravelly_ruby.png new file mode 100644 index 0000000000000000000000000000000000000000..f56d583d00cd0e525c5b7cd9e3f0d6a0beb159cb GIT binary patch literal 538 zcmV+#0_FXQP)_7>1wCO7x7tcQLc*k8Cs~0+Y3Z@J8q^5}~9FJRJ>08;mgW!i%K^ z#SCqzg^b zEz-SVK6kjW?62d|#Dq#;vXuzCiC@fH8G8ItQzTU9|rt^Mws@Vr>4*A@ny z9d3C|Z{XF3Fqv%jFBuH799!V^`#GFP+X(o5a#4dj*Kf++PA{=5>7KoHROUIV?1@8Nv_nhH8l z3{D?A41ko9h%bM~vZoySZUEr0?qemlj?Geo)oMkWeW^BhFg^~z*)u26rt@4K6abi< z3=p21MW-#L*%pnL_aYwJgNwuho(8=Y~y&li^$#Ovu|x7o~6Btq-dV*nO_ zv4RIweO5onqoPQ#+Q#BiltYb;tY$ON)1xZhw1a;b1C24CkxjWY2O64)#}`T79#C>c c=h#;K0knFY4@8Xu=>Px#07*qoM6N<$g0mO8G3+ueEEQ!AY%4;{oggJ>evK?#8W|z4K zmX`^_h$xQ8^mW|T+aeXP_T-8GeGB+Fc5rhykoOj#kTXT6y}GI@N0s{s}IPkCaq=*9A_ZdxnmN`GSRo{2{Q~mQtAF> zaqLn1$L@~9%M%kQs*31~L3bCp^qVj7SqmT*9fuERrm4JnjW()djgPZZm`|8f0RYdQ rUK0`$d-DgVHyT_ooPred{}JB-dl90)2;5a{00000NkvXXu0mjf_~hX` literal 0 HcmV?d00001