-
Notifications
You must be signed in to change notification settings - Fork 507
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 1 commit
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,37 @@ | ||
| /* | ||
| * 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.impl.datagen.smithing; | ||
|
|
||
| import net.minecraft.component.ComponentChanges; | ||
|
|
||
| public interface SmithingTransformParameters { | ||
|
||
| 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,43 @@ | ||
| /* | ||
| * 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.impl.datagen.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.recipe.Ingredient; | ||
| import net.minecraft.recipe.book.RecipeCategory; | ||
|
|
||
| public interface SmithingTransformRecipeCreator { | ||
|
||
| 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(Item template, Item input, Item addition, RecipeCategory category, Item result, int count, @Nullable ComponentChanges componentChanges) { | ||
| return createSmithingTransformRecipe(Ingredient.ofItem(template), Ingredient.ofItem(input), Ingredient.ofItem(addition), category, result, count, componentChanges); | ||
| } | ||
|
|
||
| default SmithingTransformRecipeJsonBuilder createSmithingTransformRecipe(Ingredient template, Ingredient input, Ingredient addition, RecipeCategory category, Item result, int count) { | ||
| return createSmithingTransformRecipe(template, input, addition, category, result, count, null); | ||
| } | ||
|
|
||
| default SmithingTransformRecipeJsonBuilder createSmithingTransformRecipe(Ingredient template, Ingredient input, Ingredient addition, RecipeCategory category, Item result, @Nullable ComponentChanges componentChanges) { | ||
| return createSmithingTransformRecipe(template, input, addition, category, result, 1, componentChanges); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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.Final; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.Unique; | ||
|
|
||
| import net.minecraft.component.ComponentChanges; | ||
| import net.minecraft.data.recipe.RecipeExporter; | ||
| import net.minecraft.data.recipe.RecipeGenerator; | ||
| import net.minecraft.data.recipe.SmithingTransformRecipeJsonBuilder; | ||
| import net.minecraft.item.Item; | ||
| import net.minecraft.item.ItemConvertible; | ||
| import net.minecraft.recipe.Ingredient; | ||
| import net.minecraft.recipe.book.RecipeCategory; | ||
|
|
||
| import net.fabricmc.fabric.impl.datagen.smithing.SmithingTransformRecipeCreator; | ||
|
|
||
| @Mixin(RecipeGenerator.class) | ||
| public abstract class RecipeGeneratorMixin implements SmithingTransformRecipeCreator { | ||
| @Shadow | ||
| @Final | ||
| protected RecipeExporter exporter; | ||
|
|
||
| @Shadow | ||
| public static String getItemPath(ItemConvertible item) { | ||
| return null; | ||
|
||
| } | ||
|
|
||
| @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.impl.datagen.smithing.SmithingTransformParameters; | ||
|
|
||
| @Mixin(SmithingTransformRecipeJsonBuilder.class) | ||
| public class SmithingTransformRecipeJsonBuilderMixin implements SmithingTransformParameters { | ||
| @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.
pretty sure this should be an api class, as otherwise, all the methods added are implementation methods