From 15aa7dc4c836efcc50ee30310ec7f75ebd6688c4 Mon Sep 17 00:00:00 2001 From: wolfieboy09 <105564186+wolfieboy09@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:51:32 -0500 Subject: [PATCH] Add datagen for disk assembler block --- .../recipes/basic_storage_disk.json | 21 ++++++ .../qstorage/recipe/basic_storage_disk.json | 23 ++++++ .../api/recipes/DiskAssemblerBuilder.java | 70 +++++++++++++++++++ .../qstorage/datagen/DataGeneration.java | 1 + .../qstorage/datagen/QSRecipeProvider.java | 46 ++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 src/generated/resources/data/qstorage/advancement/recipes/basic_storage_disk.json create mode 100644 src/generated/resources/data/qstorage/recipe/basic_storage_disk.json create mode 100644 src/main/java/dev/wolfieboy09/qstorage/api/recipes/DiskAssemblerBuilder.java create mode 100644 src/main/java/dev/wolfieboy09/qstorage/datagen/QSRecipeProvider.java diff --git a/src/generated/resources/data/qstorage/advancement/recipes/basic_storage_disk.json b/src/generated/resources/data/qstorage/advancement/recipes/basic_storage_disk.json new file mode 100644 index 0000000..b791b04 --- /dev/null +++ b/src/generated/resources/data/qstorage/advancement/recipes/basic_storage_disk.json @@ -0,0 +1,21 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_the_recipe": { + "conditions": { + "recipe": "qstorage:basic_storage_disk" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "qstorage:basic_storage_disk" + ] + } +} \ No newline at end of file diff --git a/src/generated/resources/data/qstorage/recipe/basic_storage_disk.json b/src/generated/resources/data/qstorage/recipe/basic_storage_disk.json new file mode 100644 index 0000000..f4c6766 --- /dev/null +++ b/src/generated/resources/data/qstorage/recipe/basic_storage_disk.json @@ -0,0 +1,23 @@ +{ + "type": "qstorage:disk_assembly", + "casing": { + "item": "qstorage:steel_casing" + }, + "energy": 1000, + "extras": [ + { + "item": "qstorage:data_crystal" + } + ], + "port": { + "item": "qstorage:item_port" + }, + "result": { + "count": 1, + "id": "qstorage:basic_storage_disk" + }, + "screws": { + "item": "qstorage:steel_screw" + }, + "ticks": 500 +} \ No newline at end of file diff --git a/src/main/java/dev/wolfieboy09/qstorage/api/recipes/DiskAssemblerBuilder.java b/src/main/java/dev/wolfieboy09/qstorage/api/recipes/DiskAssemblerBuilder.java new file mode 100644 index 0000000..46778a9 --- /dev/null +++ b/src/main/java/dev/wolfieboy09/qstorage/api/recipes/DiskAssemblerBuilder.java @@ -0,0 +1,70 @@ +package dev.wolfieboy09.qstorage.api.recipes; + +import dev.wolfieboy09.qstorage.api.annotation.NothingNullByDefault; +import dev.wolfieboy09.qstorage.block.disk_assembler.DiskAssemblerRecipe; +import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.AdvancementRequirements; +import net.minecraft.advancements.AdvancementRewards; +import net.minecraft.advancements.Criterion; +import net.minecraft.advancements.critereon.RecipeUnlockedTrigger; +import net.minecraft.data.recipes.RecipeBuilder; +import net.minecraft.data.recipes.RecipeOutput; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import org.jetbrains.annotations.Nullable; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@NothingNullByDefault +public class DiskAssemblerBuilder implements RecipeBuilder { + protected final ItemStack result; + protected final Ingredient diskPort; + protected final Ingredient diskCasing; + protected final Ingredient screws; + protected final List extras; + protected final int energyCost; + protected final int timeInTicks; + protected final Map> criteria = new LinkedHashMap<>(); + + public DiskAssemblerBuilder(Ingredient diskPort, Ingredient diskCasing, Ingredient screws, List extras, int energyCost, int timeInTicks, ItemStack result) { + this.diskPort = diskPort; + this.diskCasing = diskCasing; + this.screws = screws; + this.extras = extras; + this.energyCost = energyCost; + this.timeInTicks = timeInTicks; + this.result = result; + } + + + @Override + public RecipeBuilder unlockedBy(String name, Criterion criterion) { + this.criteria.put(name, criterion); + return this; + } + + @Override + public RecipeBuilder group(@Nullable String groupName) { + return this; + } + + @Override + public Item getResult() { + return this.result.getItem(); + } + + @Override + public void save(RecipeOutput output, ResourceLocation id) { + Advancement.Builder advancement = output.advancement() + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(id)) + .rewards(AdvancementRewards.Builder.recipe(id)) + .requirements(AdvancementRequirements.Strategy.OR); + this.criteria.forEach(advancement::addCriterion); + DiskAssemblerRecipe recipe = new DiskAssemblerRecipe(this.diskPort, this.diskCasing, this.screws, this.extras, this.energyCost, this.timeInTicks, this.result); + output.accept(id, recipe, advancement.build(id.withPrefix("recipes/"))); + } +} diff --git a/src/main/java/dev/wolfieboy09/qstorage/datagen/DataGeneration.java b/src/main/java/dev/wolfieboy09/qstorage/datagen/DataGeneration.java index e737302..ce470e7 100644 --- a/src/main/java/dev/wolfieboy09/qstorage/datagen/DataGeneration.java +++ b/src/main/java/dev/wolfieboy09/qstorage/datagen/DataGeneration.java @@ -27,5 +27,6 @@ public static void gatherData(@NotNull GatherDataEvent event) { generator.addProvider(event.includeClient(), new QSBlockStateProvider(output, existingFileHelper)); generator.addProvider(event.includeClient(), new QSItemModelProvider(output, existingFileHelper)); generator.addProvider(event.includeServer(), new QSItemTagsProvider(output, lookupProvider, blockTagsProvider.contentsGetter())); + generator.addProvider(event.includeServer(), new QSRecipeProvider(output, lookupProvider)); } } diff --git a/src/main/java/dev/wolfieboy09/qstorage/datagen/QSRecipeProvider.java b/src/main/java/dev/wolfieboy09/qstorage/datagen/QSRecipeProvider.java new file mode 100644 index 0000000..ccec9a0 --- /dev/null +++ b/src/main/java/dev/wolfieboy09/qstorage/datagen/QSRecipeProvider.java @@ -0,0 +1,46 @@ +package dev.wolfieboy09.qstorage.datagen; + +import dev.wolfieboy09.qstorage.api.recipes.DiskAssemblerBuilder; +import dev.wolfieboy09.qstorage.registries.QSItems; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.minecraft.data.recipes.RecipeCategory; +import net.minecraft.data.recipes.RecipeOutput; +import net.minecraft.data.recipes.RecipeProvider; +import net.minecraft.data.recipes.ShapedRecipeBuilder; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.ItemLike; +import net.neoforged.neoforge.registries.DeferredHolder; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class QSRecipeProvider extends RecipeProvider { + public QSRecipeProvider(PackOutput output, CompletableFuture registries) { + super(output, registries); + } + + private static @NotNull @Unmodifiable List extras(ItemLike @NotNull ... ingredients) { + // Might be really useless, but oh well + if (ingredients.length > 4) { + throw new IllegalArgumentException("More than four ingredients provided."); + } + return List.of(Ingredient.of(ingredients)); + } + + @Override + protected void buildRecipes(@NotNull RecipeOutput output) { + new DiskAssemblerBuilder( + Ingredient.of(QSItems.ITEM_PORT), + Ingredient.of(QSItems.STEEL_CASING), + Ingredient.of(QSItems.STEEL_SCREW), + extras(QSItems.DATA_CRYSTAL), + 1000, + 500, + new ItemStack(QSItems.BASIC_ITEM_DISK.get()) + ).save(output); + } +}