Skip to content

Commit

Permalink
Add datagen for disk assembler block
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfieboy09 committed Nov 4, 2024
1 parent 8559c93 commit 15aa7dc
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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<Ingredient> extras;
protected final int energyCost;
protected final int timeInTicks;
protected final Map<String, Criterion<?>> criteria = new LinkedHashMap<>();

public DiskAssemblerBuilder(Ingredient diskPort, Ingredient diskCasing, Ingredient screws, List<Ingredient> 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/")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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<HolderLookup.Provider> registries) {
super(output, registries);
}

private static @NotNull @Unmodifiable List<Ingredient> 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);
}
}

0 comments on commit 15aa7dc

Please sign in to comment.