diff --git a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/smithing/FabricRecipeGenerator.java b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/smithing/FabricRecipeGenerator.java new file mode 100644 index 0000000000..4374b91de6 --- /dev/null +++ b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/smithing/FabricRecipeGenerator.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.datagen.v1.smithing; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.component.ComponentChanges; +import net.minecraft.data.recipe.SmithingTransformRecipeJsonBuilder; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.book.RecipeCategory; + +/** + * Fabric-provided extensions for {@link net.minecraft.data.recipe.RecipeGenerator}. + * + *
Adds recipe types that the vanilla class does not implement. + */ +public interface FabricRecipeGenerator { + default SmithingTransformRecipeJsonBuilder createSmithingTransformRecipe(Ingredient template, Ingredient input, Ingredient addition, RecipeCategory category, Item result, int count, @Nullable ComponentChanges componentChanges) { + throw new UnsupportedOperationException("Implemented via mixin"); + } + + default SmithingTransformRecipeJsonBuilder createSmithingTransformRecipe(Ingredient template, Ingredient input, Ingredient addition, RecipeCategory category, ItemStack result) { + return createSmithingTransformRecipe(template, input, addition, category, result.getItem(), result.getCount(), result.getComponentChanges()); + } + + default SmithingTransformRecipeJsonBuilder createSmithingTransformRecipe(Item template, Item input, Item addition, RecipeCategory category, ItemStack result) { + return createSmithingTransformRecipe(Ingredient.ofItem(template), Ingredient.ofItem(input), Ingredient.ofItem(addition), category, result); + } +} diff --git a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/smithing/FabricSmithingTransformRecipeJsonBuilder.java b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/smithing/FabricSmithingTransformRecipeJsonBuilder.java new file mode 100644 index 0000000000..4a045463b3 --- /dev/null +++ b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/smithing/FabricSmithingTransformRecipeJsonBuilder.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.datagen.v1.smithing; + +import net.minecraft.component.ComponentChanges; + +/** + * Fabric-provided extensions for {@link net.minecraft.data.recipe.SmithingTransformRecipeJsonBuilder}. + * + *
Allows specification of the transform recipe result item count and component changes.
+ */
+public interface FabricSmithingTransformRecipeJsonBuilder {
+ default ComponentChanges getComponentChanges() {
+ throw new UnsupportedOperationException("Implemented via mixin");
+ }
+
+ default int getCount() {
+ throw new UnsupportedOperationException("Implemented via mixin");
+ }
+
+ default void setComponentChanges(ComponentChanges componentChanges) {
+ throw new UnsupportedOperationException("Implemented via mixin");
+ }
+
+ default void setCount(int count) {
+ throw new UnsupportedOperationException("Implemented via mixin");
+ }
+}
diff --git a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/mixin/datagen/smithing/RecipeGeneratorMixin.java b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/mixin/datagen/smithing/RecipeGeneratorMixin.java
new file mode 100644
index 0000000000..2c9c8434e7
--- /dev/null
+++ b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/mixin/datagen/smithing/RecipeGeneratorMixin.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016, 2017, 2018, 2019 FabricMC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.fabricmc.fabric.mixin.datagen.smithing;
+
+import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+import net.minecraft.component.ComponentChanges;
+import net.minecraft.data.recipe.RecipeGenerator;
+import net.minecraft.data.recipe.SmithingTransformRecipeJsonBuilder;
+import net.minecraft.item.Item;
+import net.minecraft.recipe.Ingredient;
+import net.minecraft.recipe.book.RecipeCategory;
+
+import net.fabricmc.fabric.api.datagen.v1.smithing.FabricRecipeGenerator;
+
+@Mixin(RecipeGenerator.class)
+abstract class RecipeGeneratorMixin implements FabricRecipeGenerator {
+ @Override
+ @Unique
+ public SmithingTransformRecipeJsonBuilder createSmithingTransformRecipe(Ingredient template, Ingredient input, Ingredient addition, RecipeCategory category, Item result, int count, @Nullable ComponentChanges componentChanges) {
+ SmithingTransformRecipeJsonBuilder builder = SmithingTransformRecipeJsonBuilder.create(template, input, addition, category, result);
+ builder.setCount(count);
+ builder.setComponentChanges(componentChanges != null ? componentChanges : ComponentChanges.EMPTY);
+ return builder;
+ }
+}
diff --git a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/mixin/datagen/smithing/SmithingTransformRecipeJsonBuilderMixin.java b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/mixin/datagen/smithing/SmithingTransformRecipeJsonBuilderMixin.java
new file mode 100644
index 0000000000..fdb258303a
--- /dev/null
+++ b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/mixin/datagen/smithing/SmithingTransformRecipeJsonBuilderMixin.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016, 2017, 2018, 2019 FabricMC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.fabricmc.fabric.mixin.datagen.smithing;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.ModifyArg;
+
+import net.minecraft.component.ComponentChanges;
+import net.minecraft.data.recipe.SmithingTransformRecipeJsonBuilder;
+import net.minecraft.recipe.TransmuteRecipeResult;
+
+import net.fabricmc.fabric.api.datagen.v1.smithing.FabricSmithingTransformRecipeJsonBuilder;
+
+@Mixin(SmithingTransformRecipeJsonBuilder.class)
+class SmithingTransformRecipeJsonBuilderMixin implements FabricSmithingTransformRecipeJsonBuilder {
+ @Unique
+ private int count = 1;
+
+ @Unique
+ private ComponentChanges componentChanges = ComponentChanges.EMPTY;
+
+ @ModifyArg(method = "offerTo(Lnet/minecraft/data/recipe/RecipeExporter;Lnet/minecraft/registry/RegistryKey;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/SmithingTransformRecipe;