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 0000000..f56d583 Binary files /dev/null and b/src/test/resources/assets/datagen_test/stationapi/textures/item/gravelly_ruby.png differ diff --git a/src/test/resources/assets/datagen_test/stationapi/textures/item/sandy_ruby.png b/src/test/resources/assets/datagen_test/stationapi/textures/item/sandy_ruby.png new file mode 100644 index 0000000..067acfd Binary files /dev/null and b/src/test/resources/assets/datagen_test/stationapi/textures/item/sandy_ruby.png differ