Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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,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 {
Copy link
Member

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)

default SmithingTransformRecipeJsonBuilder createSmithingTransformRecipe(Ingredient template, Ingredient input, Ingredient addition, RecipeCategory category, Item result, int count, @Nullable ComponentChanges componentChanges) {
Copy link
Member

Choose a reason for hiding this comment

The 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 ItemStack result parameter instead of all the overloads 🤔

This is probably fine too, but a bit messy with the long param lists.

Copy link
Author

Choose a reason for hiding this comment

The 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 {
Copy link
Member

Choose a reason for hiding this comment

The 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
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/api/datagen/v1/smithing/FabricSmithingTransformRecipeJsonBuilder"],
"net/minecraft/class_2446": ["net/fabricmc/fabric/api/datagen/v1/smithing/FabricRecipeGenerator"]
}
}
}
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 @@ -52,6 +52,7 @@
import net.minecraft.data.recipe.RecipeGenerator;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.LootTable;
Expand Down Expand Up @@ -174,6 +175,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, new ItemStack(Items.STICK.getRegistryEntry(), 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