-
Notifications
You must be signed in to change notification settings - Fork 506
Add createSmithingTransformRecipe method on RecipeGenerator #4701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.21.6
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}. | ||
| * | ||
| * <p>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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it'd be better to just have one method with an This is probably fine too, but a bit messy with the long param lists.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implemented; i still kept some overloads for ingredient/item but switched to itemstack for the result (aside from the base method, since its probably better to leave specifying them individually as an option) |
||
| 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); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}. | ||
| * | ||
| * <p>Allows specification of the transform recipe result item count and component changes. | ||
| */ | ||
| public interface FabricSmithingTransformRecipeJsonBuilder { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| 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"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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;<init>(Ljava/util/Optional;Lnet/minecraft/recipe/Ingredient;Ljava/util/Optional;Lnet/minecraft/recipe/TransmuteRecipeResult;)V"), index = 3) | ||
| private TransmuteRecipeResult editResultParameters(TransmuteRecipeResult result) { | ||
| return new TransmuteRecipeResult(result.itemEntry(), getCount(), getComponentChanges()); | ||
| } | ||
|
|
||
| @Override | ||
| public ComponentChanges getComponentChanges() { | ||
| return componentChanges; | ||
| } | ||
|
|
||
| @Override | ||
| public int getCount() { | ||
| return count; | ||
| } | ||
|
|
||
| @Override | ||
| public void setComponentChanges(ComponentChanges componentChanges) { | ||
| this.componentChanges = componentChanges; | ||
| } | ||
|
|
||
| @Override | ||
| public void setCount(int count) { | ||
| this.count = count; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "parent": "minecraft:recipes/root", | ||
| "criteria": { | ||
| "has_book": { | ||
| "trigger": "minecraft:inventory_changed", | ||
| "conditions": { | ||
| "items": [ | ||
| { | ||
| "items": "minecraft:book" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "has_the_recipe": { | ||
| "trigger": "minecraft:recipe_unlocked", | ||
| "conditions": { | ||
| "recipe": "minecraft:stick_smithing" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the recipe key uses the wrong namespace since it ends up being wrong in here as well (use the I think the string overload should be fixed on FAPI level to give the correct ns, but it's out of scope for this PR and quite possibly annoying to implement with mixins 😄 |
||
| } | ||
| } | ||
| }, | ||
| "requirements": [ | ||
| [ | ||
| "has_the_recipe", | ||
| "has_book" | ||
| ] | ||
| ], | ||
| "rewards": { | ||
| "recipes": [ | ||
| "minecraft:stick_smithing" | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "type": "minecraft:smithing_transform", | ||
| "addition": "minecraft:experience_bottle", | ||
| "base": "minecraft:stick", | ||
| "result": { | ||
| "components": { | ||
| "minecraft:enchantment_glint_override": true | ||
| }, | ||
| "id": "minecraft:stick" | ||
| }, | ||
| "template": "minecraft:book" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use a short doc comment (the methods in this itf don't really need it since they're duplicates of the vanilla ones)