Skip to content

Commit 5d1ca56

Browse files
authored
Add grindstone category [1.21.1] (#4050)
1 parent 09c73b3 commit 5d1ca56

File tree

16 files changed

+472
-4
lines changed

16 files changed

+472
-4
lines changed

Common/src/main/java/mezz/jei/common/platform/IPlatformRecipeHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import mezz.jei.api.recipe.vanilla.IJeiBrewingRecipe;
44
import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory;
55
import mezz.jei.api.runtime.IIngredientManager;
6+
import net.minecraft.core.Holder;
7+
import net.minecraft.world.item.ItemStack;
68
import net.minecraft.world.item.alchemy.PotionBrewing;
79
import net.minecraft.world.item.crafting.Ingredient;
810
import net.minecraft.world.item.crafting.SmithingRecipe;
11+
import net.minecraft.world.item.enchantment.Enchantment;
912

1013
import java.util.List;
1114

@@ -15,4 +18,6 @@ public interface IPlatformRecipeHelper {
1518
Ingredient getTemplate(SmithingRecipe recipe);
1619

1720
List<IJeiBrewingRecipe> getBrewingRecipes(IIngredientManager ingredientManager, IVanillaRecipeFactory vanillaRecipeFactory, PotionBrewing potionBrewing);
21+
22+
boolean isItemEnchantable(ItemStack stack, Holder<Enchantment> enchantment);
1823
}

Common/src/main/resources/assets/jei/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
"gui.jei.category.brewing.steps": "Steps: %s",
298298
"gui.jei.category.compostable": "Composting",
299299
"gui.jei.category.compostable.chance": "Chance: %s%%",
300+
"gui.jei.category.grindstone.experience": "%s to %s XP",
300301
"gui.jei.category.itemInformation": "Information",
301302
"gui.jei.category.tagInformation": "%s Tags",
302303
"gui.jei.category.tagInformation.block": "Block Tags",

CommonApi/src/main/java/mezz/jei/api/constants/RecipeTypes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import mezz.jei.api.recipe.vanilla.IJeiBrewingRecipe;
66
import mezz.jei.api.recipe.vanilla.IJeiCompostingRecipe;
77
import mezz.jei.api.recipe.vanilla.IJeiFuelingRecipe;
8+
import mezz.jei.api.recipe.vanilla.IJeiGrindstoneRecipe;
89
import mezz.jei.api.recipe.vanilla.IJeiIngredientInfoRecipe;
910
import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory;
1011
import mezz.jei.api.registration.IRecipeRegistration;
@@ -117,6 +118,16 @@ public final class RecipeTypes {
117118
public static final RecipeType<IJeiAnvilRecipe> ANVIL =
118119
RecipeType.create(ModIds.MINECRAFT_ID, "anvil", IJeiAnvilRecipe.class);
119120

121+
/**
122+
* The grindstone recipe type.
123+
*
124+
* @see IVanillaRecipeFactory#createGrindstoneRecipe to create new grindstone recipes in JEI.
125+
*
126+
* @since 19.22.1
127+
*/
128+
public static final RecipeType<IJeiGrindstoneRecipe> GRINDSTONE =
129+
RecipeType.create(ModIds.MINECRAFT_ID, "grindstone", IJeiGrindstoneRecipe.class);
130+
120131
/**
121132
* The smithing recipe type.
122133
* Automatically includes every
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package mezz.jei.api.recipe.vanilla;
2+
3+
import net.minecraft.resources.ResourceLocation;
4+
import net.minecraft.world.item.ItemStack;
5+
import org.jetbrains.annotations.Nullable;
6+
import org.jetbrains.annotations.Unmodifiable;
7+
8+
import java.util.List;
9+
10+
/**
11+
* There is no vanilla registry of Grindstone Recipes,
12+
* so JEI creates these Grindstone recipes to use internally.
13+
*
14+
* Create your own with {@link IVanillaRecipeFactory#createGrindstoneRecipe}
15+
* @since 19.22.1
16+
*/
17+
public interface IJeiGrindstoneRecipe {
18+
/**
19+
* Get the inputs that go into the top slot of the Grindstone.
20+
*
21+
* @since 19.22.1
22+
*/
23+
@Unmodifiable
24+
List<ItemStack> getTopInputs();
25+
26+
/**
27+
* Get the inputs that go into the bottom slot of the Grindstone.
28+
*
29+
* @since 19.22.1
30+
*/
31+
@Unmodifiable
32+
List<ItemStack> getBottomInputs();
33+
34+
/**
35+
* Get the outputs of the Grindstone recipe.
36+
*
37+
* @since 19.22.1
38+
*/
39+
@Unmodifiable
40+
List<ItemStack> getOutputs();
41+
42+
/**
43+
* The minimum XP that a player can receive.
44+
*
45+
* @since 19.22.1
46+
*/
47+
int getMinXpReward();
48+
49+
/**
50+
* The maximum XP that a player can receive.
51+
*
52+
* @since 19.22.1
53+
*/
54+
int getMaxXpReward();
55+
56+
/**
57+
* Unique ID for this recipe.
58+
*
59+
* @since 19.22.1
60+
*/
61+
@Nullable
62+
ResourceLocation getUid();
63+
64+
/**
65+
* Make the output render only, to avoid displaying unnecessary crafting recipes when looking up outputs.
66+
*
67+
* @since 19.22.1
68+
*/
69+
@Unmodifiable
70+
boolean isOutputRenderOnly();
71+
}

CommonApi/src/main/java/mezz/jei/api/recipe/vanilla/IVanillaRecipeFactory.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ public interface IVanillaRecipeFactory {
4242
*/
4343
IJeiAnvilRecipe createAnvilRecipe(List<ItemStack> leftInputs, List<ItemStack> rightInputs, List<ItemStack> outputs, ResourceLocation uid);
4444

45+
/**
46+
* Create a grindstone recipe for the given inputs and output.
47+
* The number of inputs in the top and bottom must match.
48+
*
49+
* @param topInputs The itemStack(s) placed on the top slot.
50+
* @param bottomInputs The itemStack(s) placed on the bottom slot.
51+
* @param outputs The resulting itemStack(s).
52+
* @param minXp The minimum amount of XP that a player can receive.
53+
* @param maxXp The maximum amount of XP that a player can receive.
54+
* @param uid The unique ID for this recipe.
55+
*
56+
* @since 19.22.1
57+
*/
58+
IJeiGrindstoneRecipe createGrindstoneRecipe(List<ItemStack> topInputs, List<ItemStack> bottomInputs, List<ItemStack> outputs, int minXp, int maxXp, ResourceLocation uid);
59+
4560
/**
4661
* Create a new brewing recipe.
4762
* By default, all brewing recipes are already detected and added by JEI.

Fabric/src/main/java/mezz/jei/fabric/platform/RecipeHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory;
55
import mezz.jei.api.runtime.IIngredientManager;
66
import mezz.jei.common.platform.IPlatformRecipeHelper;
7+
import net.minecraft.core.Holder;
8+
import net.minecraft.world.item.ItemStack;
79
import net.minecraft.world.item.alchemy.PotionBrewing;
810
import net.minecraft.world.item.crafting.Ingredient;
911
import net.minecraft.world.item.crafting.SmithingRecipe;
1012
import net.minecraft.world.item.crafting.SmithingTransformRecipe;
1113
import net.minecraft.world.item.crafting.SmithingTrimRecipe;
14+
import net.minecraft.world.item.enchantment.Enchantment;
1215

1316
import java.util.List;
1417

@@ -50,4 +53,9 @@ public Ingredient getTemplate(SmithingRecipe recipe) {
5053
public List<IJeiBrewingRecipe> getBrewingRecipes(IIngredientManager ingredientManager, IVanillaRecipeFactory vanillaRecipeFactory, PotionBrewing potionBrewing) {
5154
return BrewingRecipeMaker.getBrewingRecipes(ingredientManager, vanillaRecipeFactory, potionBrewing);
5255
}
56+
57+
@Override
58+
public boolean isItemEnchantable(ItemStack stack, Holder<Enchantment> enchantment) {
59+
return true;
60+
}
5361
}

Forge/src/main/java/mezz/jei/forge/platform/RecipeHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory;
55
import mezz.jei.api.runtime.IIngredientManager;
66
import mezz.jei.common.platform.IPlatformRecipeHelper;
7+
import net.minecraft.core.Holder;
8+
import net.minecraft.world.item.ItemStack;
79
import net.minecraft.world.item.alchemy.PotionBrewing;
810
import net.minecraft.world.item.crafting.Ingredient;
911
import net.minecraft.world.item.crafting.SmithingRecipe;
1012
import net.minecraft.world.item.crafting.SmithingTransformRecipe;
1113
import net.minecraft.world.item.crafting.SmithingTrimRecipe;
14+
import net.minecraft.world.item.enchantment.Enchantment;
1215

1316
import java.util.List;
1417

@@ -50,4 +53,9 @@ public Ingredient getTemplate(SmithingRecipe recipe) {
5053
public List<IJeiBrewingRecipe> getBrewingRecipes(IIngredientManager ingredientManager, IVanillaRecipeFactory vanillaRecipeFactory, PotionBrewing potionBrewing) {
5154
return BrewingRecipeMaker.getBrewingRecipes(ingredientManager, vanillaRecipeFactory, potionBrewing);
5255
}
56+
57+
@Override
58+
public boolean isItemEnchantable(ItemStack stack, Holder<Enchantment> enchantment) {
59+
return stack.getItem().isEnchantable(stack);
60+
}
5361
}

Library/src/main/java/mezz/jei/library/plugins/vanilla/VanillaPlugin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
import mezz.jei.library.plugins.vanilla.crafting.replacers.ShulkerBoxColoringRecipeMaker;
5757
import mezz.jei.library.plugins.vanilla.crafting.replacers.SuspiciousStewRecipeMaker;
5858
import mezz.jei.library.plugins.vanilla.crafting.replacers.TippedArrowRecipeMaker;
59+
import mezz.jei.library.plugins.vanilla.grindstone.GrindstoneRecipeCategory;
60+
import mezz.jei.library.plugins.vanilla.grindstone.GrindstoneRecipeMaker;
5961
import mezz.jei.library.plugins.vanilla.gui.InventoryEffectRendererGuiHandler;
6062
import mezz.jei.library.plugins.vanilla.gui.RecipeBookGuiHandler;
6163
import mezz.jei.library.plugins.vanilla.gui.ToastGuiHandler;
@@ -84,6 +86,7 @@
8486
import net.minecraft.client.gui.screens.inventory.CraftingScreen;
8587
import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen;
8688
import net.minecraft.client.gui.screens.inventory.FurnaceScreen;
89+
import net.minecraft.client.gui.screens.inventory.GrindstoneScreen;
8790
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
8891
import net.minecraft.client.gui.screens.inventory.SmithingScreen;
8992
import net.minecraft.client.gui.screens.inventory.SmokerScreen;
@@ -224,7 +227,8 @@ public void registerCategories(IRecipeCategoryRegistration registration) {
224227
new CompostableRecipeCategory(guiHelper),
225228
new FurnaceFuelCategory(textures),
226229
new BrewingRecipeCategory(guiHelper),
227-
new AnvilRecipeCategory(guiHelper)
230+
new AnvilRecipeCategory(guiHelper),
231+
new GrindstoneRecipeCategory(guiHelper)
228232
);
229233
}
230234

@@ -280,6 +284,7 @@ public void registerRecipes(IRecipeRegistration registration) {
280284
List<IJeiBrewingRecipe> brewingRecipes = recipeHelper.getBrewingRecipes(ingredientManager, vanillaRecipeFactory, potionBrewing);
281285
brewingRecipes.sort(Comparator.comparingInt(IJeiBrewingRecipe::getBrewingSteps));
282286
registration.addRecipes(RecipeTypes.BREWING, brewingRecipes);
287+
registration.addRecipes(RecipeTypes.GRINDSTONE, GrindstoneRecipeMaker.getGrindstoneRecipes(ingredientManager, recipeHelper));
283288
}
284289

285290
@Override
@@ -292,6 +297,7 @@ public void registerGuiHandlers(IGuiHandlerRegistration registration) {
292297
registration.addRecipeClickArea(SmokerScreen.class, 78, 32, 28, 23, RecipeTypes.SMOKING, RecipeTypes.FUELING);
293298
registration.addRecipeClickArea(BlastFurnaceScreen.class, 78, 32, 28, 23, RecipeTypes.BLASTING, RecipeTypes.FUELING);
294299
registration.addRecipeClickArea(AnvilScreen.class, 102, 48, 22, 15, RecipeTypes.ANVIL);
300+
registration.addRecipeClickArea(GrindstoneScreen.class, 92, 31, 28, 21, RecipeTypes.GRINDSTONE);
295301
registration.addRecipeClickArea(SmithingScreen.class, 68, 49, 22, 15, RecipeTypes.SMITHING);
296302

297303
registration.addGenericGuiContainerHandler(EffectRenderingInventoryScreen.class, new InventoryEffectRendererGuiHandler<>());
@@ -341,6 +347,7 @@ public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
341347
registration.addRecipeCatalyst(Blocks.BLAST_FURNACE, RecipeTypes.BLASTING);
342348
registration.addRecipeCatalyst(Blocks.BREWING_STAND, RecipeTypes.BREWING);
343349
registration.addRecipeCatalyst(Blocks.ANVIL, RecipeTypes.ANVIL);
350+
registration.addRecipeCatalyst(Blocks.GRINDSTONE, RecipeTypes.GRINDSTONE);
344351
registration.addRecipeCatalyst(Blocks.SMITHING_TABLE, RecipeTypes.SMITHING);
345352
registration.addRecipeCatalyst(Blocks.COMPOSTER, RecipeTypes.COMPOSTING);
346353
}

Library/src/main/java/mezz/jei/library/plugins/vanilla/VanillaRecipeFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
import mezz.jei.library.plugins.vanilla.brewing.BrewingRecipeUtil;
1313
import mezz.jei.library.plugins.vanilla.brewing.JeiBrewingRecipe;
1414
import mezz.jei.library.plugins.vanilla.crafting.JeiShapedRecipeBuilder;
15+
import mezz.jei.library.plugins.vanilla.grindstone.GrindstoneRecipe;
1516
import net.minecraft.resources.ResourceLocation;
1617
import net.minecraft.world.item.ItemStack;
1718
import net.minecraft.world.item.crafting.CraftingBookCategory;
19+
import org.jetbrains.annotations.Nullable;
1820

1921
import java.util.List;
2022

@@ -64,6 +66,15 @@ public AnvilRecipe createAnvilRecipe(List<ItemStack> leftInputs, List<ItemStack>
6466
return new AnvilRecipe(List.copyOf(leftInputs), List.copyOf(rightInputs), List.copyOf(outputs), null);
6567
}
6668

69+
@Override
70+
public GrindstoneRecipe createGrindstoneRecipe(List<ItemStack> topInputs, List<ItemStack> bottomInputs, List<ItemStack> outputs, int minXp, int maxXp, @Nullable ResourceLocation uid) {
71+
ErrorUtil.checkNotEmpty(topInputs, "topInputs");
72+
ErrorUtil.checkNotNull(bottomInputs, "bottomInputs");
73+
ErrorUtil.checkNotEmpty(outputs, "outputs");
74+
75+
return new GrindstoneRecipe(List.copyOf(topInputs), List.copyOf(bottomInputs), List.copyOf(outputs), minXp, maxXp, uid);
76+
}
77+
6778
@Override
6879
public IJeiBrewingRecipe createBrewingRecipe(List<ItemStack> ingredients, ItemStack potionInput, ItemStack potionOutput, ResourceLocation uid) {
6980
ErrorUtil.checkNotEmpty(ingredients, "ingredients");

Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/AnvilRecipeMaker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ private static Stream<IJeiAnvilRecipe> getRepairRecipes(
287287
damagedThreeQuartersSingletonList,
288288
damagedThreeQuartersSingletonList,
289289
List.of(damagedHalf),
290-
ResourceLocation.fromNamespaceAndPath(itemModId, "self_repair." + ingredientIdPath)
290+
ResourceLocation.fromNamespaceAndPath(itemModId, "anvil.self_repair." + ingredientIdPath)
291291
);
292292
consumer.accept(repairWithSame);
293293

@@ -298,7 +298,7 @@ private static Stream<IJeiAnvilRecipe> getRepairRecipes(
298298
List.of(damagedFully),
299299
repairMaterials,
300300
damagedThreeQuartersSingletonList,
301-
ResourceLocation.fromNamespaceAndPath(itemModId, "materials_repair." + ingredientIdPath)
301+
ResourceLocation.fromNamespaceAndPath(itemModId, "anvil.materials_repair." + ingredientIdPath)
302302
);
303303
consumer.accept(repairWithMaterial);
304304
}

0 commit comments

Comments
 (0)