diff --git a/RebornCore/src/main/java/reborncore/common/recipes/PaddedShapedRecipeJsonBuilder.java b/RebornCore/src/main/java/reborncore/common/recipes/PaddedShapedRecipeJsonBuilder.java new file mode 100644 index 000000000..2592f7134 --- /dev/null +++ b/RebornCore/src/main/java/reborncore/common/recipes/PaddedShapedRecipeJsonBuilder.java @@ -0,0 +1,79 @@ +/* + * This file is part of RebornCore, licensed under the MIT License (MIT). + * + * Copyright (c) 2022 TeamReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package reborncore.common.recipes; + +import net.minecraft.advancement.Advancement; +import net.minecraft.advancement.CriterionMerger; +import net.minecraft.advancement.criterion.RecipeUnlockedCriterion; +import net.minecraft.data.server.recipe.RecipeJsonProvider; +import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder; +import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; +import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.book.CraftingRecipeCategory; +import net.minecraft.recipe.book.RecipeCategory; +import net.minecraft.util.Identifier; + +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +public class PaddedShapedRecipeJsonBuilder extends ShapedRecipeJsonBuilder { + + public PaddedShapedRecipeJsonBuilder(RecipeCategory category, ItemConvertible output, int outputCount) { + super(category, output, outputCount); + } + + public static PaddedShapedRecipeJsonBuilder create(RecipeCategory category, ItemConvertible output) { + return create(category, output, 1); + } + + public static PaddedShapedRecipeJsonBuilder create(RecipeCategory category, ItemConvertible output, int outputCount) { + return new PaddedShapedRecipeJsonBuilder(category, output, outputCount); + } + + @Override + public void offerTo(Consumer exporter, Identifier recipeId) { + validate(recipeId); + advancementBuilder.parent(ROOT).criterion("has_the_recipe", RecipeUnlockedCriterion.create(recipeId)).rewards(net.minecraft.advancement.AdvancementRewards.Builder.recipe(recipeId)).criteriaMerger(CriterionMerger.OR); + String group = this.group == null ? "" : this.group; + exporter.accept(new PaddedShapedRecipeJsonProvider(recipeId, output, count, group, getCraftingCategory(category), pattern, inputs, advancementBuilder, + new Identifier(recipeId.getNamespace(), "recipes/" + category.getName() + "/" + recipeId.getPath()))); + } + + static class PaddedShapedRecipeJsonProvider extends PaddedShapedRecipeJsonBuilder.ShapedRecipeJsonProvider { + + public PaddedShapedRecipeJsonProvider(Identifier recipeId, Item output, int resultCount, String group, CraftingRecipeCategory category, List pattern, Map inputs, Advancement.Builder advancementBuilder, Identifier advancementId) { + super(recipeId, output, resultCount, group, category, pattern, inputs, advancementBuilder, advancementId); + } + + @Override + public RecipeSerializer getSerializer() { + return PaddedShapedRecipe.PADDED; + } + } + +} diff --git a/RebornCore/src/main/resources/reborncore.accesswidener b/RebornCore/src/main/resources/reborncore.accesswidener index ec3424d2f..8383be41d 100644 --- a/RebornCore/src/main/resources/reborncore.accesswidener +++ b/RebornCore/src/main/resources/reborncore.accesswidener @@ -3,6 +3,17 @@ accessWidener v2 named accessible method net/minecraft/recipe/ShapedRecipe readSymbols (Lcom/google/gson/JsonObject;)Ljava/util/Map; accessible method net/minecraft/recipe/ShapedRecipe getPattern (Lcom/google/gson/JsonArray;)[Ljava/lang/String; accessible method net/minecraft/recipe/ShapedRecipe createPatternMatrix ([Ljava/lang/String;Ljava/util/Map;II)Lnet/minecraft/util/collection/DefaultedList; +accessible method net/minecraft/recipe/ShapedRecipe matchesPattern (Lnet/minecraft/inventory/CraftingInventory;IIZ)Z + +accessible class net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder$ShapedRecipeJsonProvider +accessible method net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder validate (Lnet/minecraft/util/Identifier;)V +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder advancementBuilder Lnet/minecraft/advancement/Advancement$Builder; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder output Lnet/minecraft/item/Item; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder count I +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder group Ljava/lang/String; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder pattern Ljava/util/List; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder inputs Ljava/util/Map; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder category Lnet/minecraft/recipe/book/RecipeCategory; accessible class net/minecraft/recipe/Ingredient$Entry accessible class net/minecraft/recipe/Ingredient$TagEntry @@ -21,7 +32,6 @@ accessible field net/minecraft/block/FluidBlock fluid Lnet/minecraft accessible method net/minecraft/world/gen/foliage/FoliagePlacerType register (Ljava/lang/String;Lcom/mojang/serialization/Codec;)Lnet/minecraft/world/gen/foliage/FoliagePlacerType; accessible method net/minecraft/recipe/RecipeManager getAllOfType (Lnet/minecraft/recipe/RecipeType;)Ljava/util/Map; accessible field net/minecraft/screen/ScreenHandler listeners Ljava/util/List; -accessible method net/minecraft/recipe/ShapedRecipe matchesPattern (Lnet/minecraft/inventory/CraftingInventory;IIZ)Z accessible field net/minecraft/structure/pool/StructurePool elements Lit/unimi/dsi/fastutil/objects/ObjectArrayList; diff --git a/src/datagen/groovy/techreborn/datagen/recipes/crafting/CraftingRecipesProvider.groovy b/src/datagen/groovy/techreborn/datagen/recipes/crafting/CraftingRecipesProvider.groovy index 7b63fab2c..77bea0bbc 100644 --- a/src/datagen/groovy/techreborn/datagen/recipes/crafting/CraftingRecipesProvider.groovy +++ b/src/datagen/groovy/techreborn/datagen/recipes/crafting/CraftingRecipesProvider.groovy @@ -35,6 +35,7 @@ import net.minecraft.recipe.RecipeSerializer import net.minecraft.recipe.book.RecipeCategory import net.minecraft.registry.RegistryWrapper import net.minecraft.util.Identifier +import reborncore.common.recipes.PaddedShapedRecipeJsonBuilder import techreborn.TechReborn import techreborn.datagen.recipes.TechRebornRecipesProvider import techreborn.init.TRContent @@ -85,6 +86,7 @@ class CraftingRecipesProvider extends TechRebornRecipesProvider { } generateToolRecipes() generateArmorRecipes() + generateUuMatterRecipes() } def generateToolRecipes() { @@ -182,6 +184,62 @@ class CraftingRecipesProvider extends TechRebornRecipesProvider { } } + def generateUuMatterRecipes() { + String rootDir = "crafting_table/uu_matter/" + String dir + // dusts + dir = rootDir + "dust/" + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, TRContent.Dusts.ALUMINUM) + .pattern("UUU") + .pattern("U ") + .pattern(" ") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, TRContent.Dusts.ALUMINUM))) + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, TRContent.Dusts.CHROME) + .pattern("UUU") + .pattern("UU ") + .pattern(" U ") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, TRContent.Dusts.CHROME))) + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, TRContent.Dusts.PLATINUM) + .pattern("UUU") + .pattern("UU ") + .pattern(" ") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, TRContent.Dusts.PLATINUM))) + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, TRContent.Dusts.TITANIUM) + .pattern("UUU") + .pattern("U U") + .pattern(" ") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, TRContent.Dusts.TITANIUM))) + // nuggets + dir = rootDir + "nugget/" + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, TRContent.Nuggets.NETHERITE) + .pattern("UUU") + .pattern("UUU") + .pattern("UU ") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, TRContent.Nuggets.NETHERITE))) + // raw ores + dir = rootDir + "raw/" + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, Items.RAW_COPPER) + .pattern("U ") + .pattern(" ") + .pattern(" U ") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, Items.RAW_COPPER))) + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, TRContent.RawMetals.LEAD) + .pattern(" ") + .pattern("U ") + .pattern("U ") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, TRContent.RawMetals.LEAD))) + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, TRContent.RawMetals.TIN) + .pattern(" ") + .pattern(" U ") + .pattern(" U") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, TRContent.RawMetals.TIN))) + createPureUuMatterPaddedRecipe(RecipeCategory.MISC, TRContent.RawMetals.TUNGSTEN) + .pattern("UUU") + .pattern("UUU") + .pattern(" ") + .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, recipeNameString(dir, null, TRContent.RawMetals.TUNGSTEN))) + } + def static recipeNameString(String prefix, def input, def output, String source = null, String result = null) { StringBuilder s = new StringBuilder() s.append(prefix) @@ -344,5 +402,11 @@ class CraftingRecipesProvider extends TechRebornRecipesProvider { .offerTo(this.exporter, new Identifier(TechReborn.MOD_ID, materialTypeString(prefix, material, type, TechRebornRecipesProvider::getNamePart1))) } + def static createPureUuMatterPaddedRecipe(RecipeCategory category, ItemConvertible output) { + var input = TRContent.Parts.UU_MATTER + return PaddedShapedRecipeJsonBuilder.create(category, output, 1) + .input('U' as char, createIngredient(input)) + .criterion(getCriterionName(input), getCriterionConditions(input)) + } } diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/aluminum_dust.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/aluminum_dust.json deleted file mode 100644 index f055f71aa..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/aluminum_dust.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - "UUU", - "U ", - " " - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "techreborn:aluminum_dust" - } -} \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/chrome_dust.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/chrome_dust.json deleted file mode 100644 index b700d511a..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/chrome_dust.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - "UUU", - "UU ", - " U " - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "techreborn:chrome_dust" - } -} \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/platinum_dust.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/platinum_dust.json deleted file mode 100644 index 28c7b6797..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/platinum_dust.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - "UUU", - "UU ", - " " - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "techreborn:platinum_dust" - } -} \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/titanium_dust.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/titanium_dust.json deleted file mode 100644 index 855f9d979..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/dust/titanium_dust.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - "UUU", - "U U", - " " - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "techreborn:titanium_dust" - } -} \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/nugget/netherite_nugget.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/nugget/netherite_nugget.json deleted file mode 100644 index 9bbc51273..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/nugget/netherite_nugget.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - "UUU", - "UUU", - "UU " - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "techreborn:netherite_nugget" - } -} \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_copper.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_copper.json deleted file mode 100644 index 66a1aea81..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_copper.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - "U ", - " ", - " U " - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "minecraft:raw_copper" - } -} \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_lead.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_lead.json deleted file mode 100644 index b293fedab..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_lead.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - " ", - "U ", - "U " - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "techreborn:raw_lead" - } -} \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_tin.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_tin.json deleted file mode 100644 index 993768078..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_tin.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - " ", - " U ", - " U" - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "techreborn:raw_tin" - } -} \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_tungsten.json b/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_tungsten.json deleted file mode 100644 index 0c3c98aa5..000000000 --- a/src/main/resources/data/techreborn/recipes/crafting_table/uu_matter/raw/raw_tungsten.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "reborncore:padded", - "pattern": [ - "UUU", - "UUU", - " " - ], - "key": { - "U": { - "item": "techreborn:uu_matter" - } - }, - "result": { - "item": "techreborn:raw_tungsten" - } -} \ No newline at end of file diff --git a/src/main/resources/techreborn.accesswidener b/src/main/resources/techreborn.accesswidener index 8a4c99175..e003862d1 100644 --- a/src/main/resources/techreborn.accesswidener +++ b/src/main/resources/techreborn.accesswidener @@ -3,6 +3,17 @@ accessWidener v2 named accessible method net/minecraft/recipe/ShapedRecipe readSymbols (Lcom/google/gson/JsonObject;)Ljava/util/Map; accessible method net/minecraft/recipe/ShapedRecipe getPattern (Lcom/google/gson/JsonArray;)[Ljava/lang/String; accessible method net/minecraft/recipe/ShapedRecipe createPatternMatrix ([Ljava/lang/String;Ljava/util/Map;II)Lnet/minecraft/util/collection/DefaultedList; +accessible method net/minecraft/recipe/ShapedRecipe matchesPattern (Lnet/minecraft/inventory/CraftingInventory;IIZ)Z + +accessible class net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder$ShapedRecipeJsonProvider +accessible method net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder validate (Lnet/minecraft/util/Identifier;)V +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder advancementBuilder Lnet/minecraft/advancement/Advancement$Builder; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder output Lnet/minecraft/item/Item; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder count I +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder group Ljava/lang/String; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder pattern Ljava/util/List; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder inputs Ljava/util/Map; +accessible field net/minecraft/data/server/recipe/ShapedRecipeJsonBuilder category Lnet/minecraft/recipe/book/RecipeCategory; accessible class net/minecraft/recipe/Ingredient$Entry accessible class net/minecraft/recipe/Ingredient$TagEntry @@ -21,7 +32,6 @@ accessible field net/minecraft/block/FluidBlock fluid Lnet/minecraft accessible method net/minecraft/world/gen/foliage/FoliagePlacerType register (Ljava/lang/String;Lcom/mojang/serialization/Codec;)Lnet/minecraft/world/gen/foliage/FoliagePlacerType; accessible method net/minecraft/recipe/RecipeManager getAllOfType (Lnet/minecraft/recipe/RecipeType;)Ljava/util/Map; accessible field net/minecraft/screen/ScreenHandler listeners Ljava/util/List; -accessible method net/minecraft/recipe/ShapedRecipe matchesPattern (Lnet/minecraft/inventory/CraftingInventory;IIZ)Z accessible field net/minecraft/structure/pool/StructurePool elements Lit/unimi/dsi/fastutil/objects/ObjectArrayList;