Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

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


import net.minecraft.component.ComponentChanges;

public interface SmithingTransformParameters {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should be 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");
}
}
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this


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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fabric api, we typically forgo the practice of naming injected interfaces after their purpose. usually it's something like FabricXX to allow the injected interface to remain once the functionality changes. I would guess this should be named FabricRecipeGenerator

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you; i moved the interfaces to the api package and renamed them to match conventions

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: usually the convention is for these to throw?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i forgot to clear out the Shadows after switching my implementation from an offerRecipe-type method to a createRecipe one, sorry

}

@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
Expand Up @@ -14,7 +14,9 @@
"loot.BlockLootTableGeneratorAccessor",
"loot.BlockLootTableGeneratorMixin",
"loot.EntityLootTableGeneratorAccessor",
"loot.EntityLootTableGeneratorMixin"
"loot.EntityLootTableGeneratorMixin",
"smithing.RecipeGeneratorMixin",
"smithing.SmithingTransformRecipeJsonBuilderMixin"
],
"server": [
"server.MainMixin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"loom:injected_interfaces": {
"net/minecraft/class_7788": ["net/fabricmc/fabric/api/datagen/v1/loot/FabricBlockLootTableGenerator"],
"net/minecraft/class_7789": ["net/fabricmc/fabric/api/datagen/v1/loot/FabricEntityLootTableGenerator"],
"net/minecraft/class_11389": ["net/fabricmc/fabric/api/datagen/v1/provider/FabricProvidedTagBuilder"]
"net/minecraft/class_11389": ["net/fabricmc/fabric/api/datagen/v1/provider/FabricProvidedTagBuilder"],
"net/minecraft/class_8074": ["net/fabricmc/fabric/impl/datagen/smithing/SmithingTransformParameters"],
"net/minecraft/class_2446": ["net/fabricmc/fabric/impl/datagen/smithing/SmithingTransformRecipeCreator"]
}
}
}
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"
Copy link
Member

Choose a reason for hiding this comment

The 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 RegistryKey<Recipe> overload instead of the String overload of offerTo).

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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ protected RecipeGenerator getRecipeGenerator(RegistryWrapper.WrapperLookup regis
@Override
public void generate() {
offerPlanksRecipe2(SIMPLE_BLOCK, ItemTags.ACACIA_LOGS, 1);
createSmithingTransformRecipe(Items.BOOK, Items.STICK, Items.EXPERIENCE_BOTTLE, RecipeCategory.MISC, Items.STICK, 1, ComponentChanges.builder().add(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true).build())
.criterion("has_book", conditionsFromItem(Items.BOOK))
.offerTo(this.exporter, getItemPath(Items.STICK) + "_smithing");

createShapeless(RecipeCategory.MISC, Items.DIAMOND_ORE, 4).input(Items.ITEM_FRAME)
.criterion("has_frame", conditionsFromItem(Items.ITEM_FRAME))
Expand Down