generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add datagen for disk assembler block
- Loading branch information
1 parent
8559c93
commit 15aa7dc
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/generated/resources/data/qstorage/advancement/recipes/basic_storage_disk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/generated/resources/data/qstorage/recipe/basic_storage_disk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/dev/wolfieboy09/qstorage/api/recipes/DiskAssemblerBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/dev/wolfieboy09/qstorage/datagen/QSRecipeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |