Skip to content

Commit db77147

Browse files
authored
Add grindstone category (#4038)
1 parent e34c5c1 commit db77147

File tree

15 files changed

+464
-4
lines changed

15 files changed

+464
-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
import java.util.Optional;
@@ -18,4 +21,6 @@ public interface IPlatformRecipeHelper {
1821
List<IJeiBrewingRecipe> getBrewingRecipes(IIngredientManager ingredientManager, IVanillaRecipeFactory vanillaRecipeFactory, PotionBrewing potionBrewing);
1922

2023
String[] shrinkShapedRecipePattern(List<String> pattern);
24+
25+
boolean isItemEnchantable(ItemStack stack, Holder<Enchantment> enchantment);
2126
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
"gui.jei.category.brewing.steps": "Steps: %s",
300300
"gui.jei.category.compostable": "Composting",
301301
"gui.jei.category.compostable.chance": "Chance: %s%%",
302+
"gui.jei.category.grindstone.experience": "%s to %s XP",
302303
"gui.jei.category.itemInformation": "Information",
303304
"gui.jei.category.tagInformation": "%s Tags",
304305
"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
@@ -6,6 +6,7 @@
66
import mezz.jei.api.recipe.vanilla.IJeiBrewingRecipe;
77
import mezz.jei.api.recipe.vanilla.IJeiCompostingRecipe;
88
import mezz.jei.api.recipe.vanilla.IJeiFuelingRecipe;
9+
import mezz.jei.api.recipe.vanilla.IJeiGrindstoneRecipe;
910
import mezz.jei.api.recipe.vanilla.IJeiIngredientInfoRecipe;
1011
import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory;
1112
import mezz.jei.api.registration.IRecipeRegistration;
@@ -138,6 +139,16 @@ public final class RecipeTypes {
138139
public static final IRecipeType<IJeiAnvilRecipe> ANVIL =
139140
IRecipeType.create(ModIds.MINECRAFT_ID, "anvil", IJeiAnvilRecipe.class);
140141

142+
/**
143+
* The grindstone recipe type.
144+
*
145+
* @see IVanillaRecipeFactory#createGrindstoneRecipe to create new grindstone recipes in JEI.
146+
*
147+
* @since 21.4.0
148+
*/
149+
public static final IRecipeType<IJeiGrindstoneRecipe> GRINDSTONE =
150+
IRecipeType.create(ModIds.MINECRAFT_ID, "grindstone", IJeiGrindstoneRecipe.class);
151+
141152
/**
142153
* The smithing recipe type.
143154
* 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 21.4.0
16+
*/
17+
public interface IJeiGrindstoneRecipe {
18+
/**
19+
* Get the inputs that go into the top slot of the Grindstone.
20+
*
21+
* @since 21.4.0
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 21.4.0
30+
*/
31+
@Unmodifiable
32+
List<ItemStack> getBottomInputs();
33+
34+
/**
35+
* Get the outputs of the Grindstone recipe.
36+
*
37+
* @since 21.4.0
38+
*/
39+
@Unmodifiable
40+
List<ItemStack> getOutputs();
41+
42+
/**
43+
* The minimum XP that a player can receive.
44+
*
45+
* @since 21.4.0
46+
*/
47+
int getMinXpReward();
48+
49+
/**
50+
* The maximum XP that a player can receive.
51+
*
52+
* @since 21.4.0
53+
*/
54+
int getMaxXpReward();
55+
56+
/**
57+
* Unique ID for this recipe.
58+
*
59+
* @since 21.4.0
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 21.4.0
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
@@ -44,6 +44,21 @@ public interface IVanillaRecipeFactory {
4444
*/
4545
IJeiAnvilRecipe createAnvilRecipe(List<ItemStack> leftInputs, List<ItemStack> rightInputs, List<ItemStack> outputs, ResourceLocation uid);
4646

47+
/**
48+
* Create a grindstone recipe for the given inputs and output.
49+
* The number of inputs in the top and bottom must match.
50+
*
51+
* @param topInputs The itemStack(s) placed on the top slot.
52+
* @param bottomInputs The itemStack(s) placed on the bottom slot.
53+
* @param outputs The resulting itemStack(s).
54+
* @param minXp The minimum amount of XP that a player can receive.
55+
* @param maxXp The maximum amount of XP that a player can receive.
56+
* @param uid The unique ID for this recipe.
57+
*
58+
* @since 21.4.0
59+
*/
60+
IJeiGrindstoneRecipe createGrindstoneRecipe(List<ItemStack> topInputs, List<ItemStack> bottomInputs, List<ItemStack> outputs, int minXp, int maxXp, ResourceLocation uid);
61+
4762
/**
4863
* Create a new brewing recipe.
4964
* 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,12 +4,15 @@
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.ShapedRecipePattern;
1012
import net.minecraft.world.item.crafting.SmithingRecipe;
1113
import net.minecraft.world.item.crafting.SmithingTransformRecipe;
1214
import net.minecraft.world.item.crafting.SmithingTrimRecipe;
15+
import net.minecraft.world.item.enchantment.Enchantment;
1316

1417
import java.util.List;
1518
import java.util.Optional;
@@ -57,4 +60,9 @@ public List<IJeiBrewingRecipe> getBrewingRecipes(IIngredientManager ingredientMa
5760
public String[] shrinkShapedRecipePattern(List<String> pattern) {
5861
return ShapedRecipePattern.shrink(pattern);
5962
}
63+
64+
@Override
65+
public boolean isItemEnchantable(ItemStack stack, Holder<Enchantment> enchantment) {
66+
return true;
67+
}
6068
}

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.VanillaRecipes;
5757
import mezz.jei.library.plugins.vanilla.crafting.replacers.ShieldDecorationRecipeMaker;
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;
@@ -79,6 +81,7 @@
7981
import net.minecraft.client.gui.screens.inventory.CrafterScreen;
8082
import net.minecraft.client.gui.screens.inventory.CraftingScreen;
8183
import net.minecraft.client.gui.screens.inventory.FurnaceScreen;
84+
import net.minecraft.client.gui.screens.inventory.GrindstoneScreen;
8285
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
8386
import net.minecraft.client.gui.screens.inventory.SmithingScreen;
8487
import net.minecraft.client.gui.screens.inventory.SmokerScreen;
@@ -225,7 +228,8 @@ public void registerCategories(IRecipeCategoryRegistration registration) {
225228
new SmokingFuelCategory(guiHelper, textures),
226229
new BlastingFuelCategory(guiHelper, textures),
227230
new BrewingRecipeCategory(guiHelper),
228-
new AnvilRecipeCategory(guiHelper)
231+
new AnvilRecipeCategory(guiHelper),
232+
new GrindstoneRecipeCategory(guiHelper)
229233
);
230234
}
231235

@@ -289,6 +293,7 @@ public void registerRecipes(IRecipeRegistration registration) {
289293
List<IJeiBrewingRecipe> brewingRecipes = recipeHelper.getBrewingRecipes(ingredientManager, vanillaRecipeFactory, potionBrewing);
290294
brewingRecipes.sort(Comparator.comparingInt(IJeiBrewingRecipe::getBrewingSteps));
291295
registration.addRecipes(RecipeTypes.BREWING, brewingRecipes);
296+
registration.addRecipes(RecipeTypes.GRINDSTONE, GrindstoneRecipeMaker.getGrindstoneRecipes(ingredientManager, recipeHelper));
292297
}
293298

294299
@Override
@@ -301,6 +306,7 @@ public void registerGuiHandlers(IGuiHandlerRegistration registration) {
301306
registration.addRecipeClickArea(SmokerScreen.class, 78, 32, 28, 23, RecipeTypes.SMOKING, RecipeTypes.SMOKING_FUEL);
302307
registration.addRecipeClickArea(BlastFurnaceScreen.class, 78, 32, 28, 23, RecipeTypes.BLASTING, RecipeTypes.BLASTING_FUEL);
303308
registration.addRecipeClickArea(AnvilScreen.class, 102, 48, 22, 15, RecipeTypes.ANVIL);
309+
registration.addRecipeClickArea(GrindstoneScreen.class, 92, 31, 28, 21, RecipeTypes.GRINDSTONE);
304310
registration.addRecipeClickArea(SmithingScreen.class, 68, 49, 22, 15, RecipeTypes.SMITHING);
305311

306312
registration.addGenericGuiContainerHandler(AbstractContainerScreen.class, new InventoryEffectRendererGuiHandler());
@@ -348,6 +354,7 @@ public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
348354
registration.addCraftingStation(RecipeTypes.BLASTING_FUEL, Blocks.BLAST_FURNACE);
349355
registration.addCraftingStation(RecipeTypes.BREWING, Blocks.BREWING_STAND);
350356
registration.addCraftingStation(RecipeTypes.ANVIL, Blocks.ANVIL);
357+
registration.addCraftingStation(RecipeTypes.GRINDSTONE, Blocks.GRINDSTONE);
351358
registration.addCraftingStation(RecipeTypes.SMITHING, Blocks.SMITHING_TABLE);
352359
registration.addCraftingStation(RecipeTypes.COMPOSTING, Blocks.COMPOSTER);
353360
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
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;
@@ -47,6 +48,15 @@ public AnvilRecipe createAnvilRecipe(List<ItemStack> leftInputs, List<ItemStack>
4748
return new AnvilRecipe(List.copyOf(leftInputs), List.copyOf(rightInputs), List.copyOf(outputs), uid);
4849
}
4950

51+
@Override
52+
public GrindstoneRecipe createGrindstoneRecipe(List<ItemStack> topInputs, List<ItemStack> bottomInputs, List<ItemStack> outputs, int minXp, int maxXp, @Nullable ResourceLocation uid) {
53+
ErrorUtil.checkNotEmpty(topInputs, "topInputs");
54+
ErrorUtil.checkNotNull(bottomInputs, "bottomInputs");
55+
ErrorUtil.checkNotEmpty(outputs, "outputs");
56+
57+
return new GrindstoneRecipe(List.copyOf(topInputs), List.copyOf(bottomInputs), List.copyOf(outputs), minXp, maxXp, uid);
58+
}
59+
5060
@Override
5161
public IJeiBrewingRecipe createBrewingRecipe(List<ItemStack> ingredients, ItemStack potionInput, ItemStack potionOutput, ResourceLocation uid) {
5262
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
@@ -302,7 +302,7 @@ private static Stream<IJeiAnvilRecipe> getRepairRecipes(
302302
damagedThreeQuartersSingletonList,
303303
damagedThreeQuartersSingletonList,
304304
List.of(damagedHalf),
305-
ResourceLocation.fromNamespaceAndPath(itemModId, "self_repair." + ingredientIdPath)
305+
ResourceLocation.fromNamespaceAndPath(itemModId, "anvil.self_repair." + ingredientIdPath)
306306
);
307307
consumer.accept(repairWithSame);
308308

@@ -313,7 +313,7 @@ private static Stream<IJeiAnvilRecipe> getRepairRecipes(
313313
List.of(damagedFully),
314314
repairMaterials,
315315
damagedThreeQuartersSingletonList,
316-
ResourceLocation.fromNamespaceAndPath(itemModId, "materials_repair." + ingredientIdPath)
316+
ResourceLocation.fromNamespaceAndPath(itemModId, "anvil.materials_repair." + ingredientIdPath)
317317
);
318318
consumer.accept(repairWithMaterial);
319319
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package mezz.jei.library.plugins.vanilla.grindstone;
2+
3+
import mezz.jei.api.recipe.vanilla.IJeiGrindstoneRecipe;
4+
import net.minecraft.resources.ResourceLocation;
5+
import net.minecraft.world.item.ItemStack;
6+
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Nullable;
8+
import org.jetbrains.annotations.Unmodifiable;
9+
10+
import java.util.List;
11+
12+
public record GrindstoneRecipe(
13+
List<ItemStack> topInputs,
14+
List<ItemStack> bottomInputs,
15+
List<ItemStack> outputs,
16+
int minXpReward,
17+
int maxXpReward,
18+
@Nullable ResourceLocation uid,
19+
boolean isOutputRenderOnly
20+
) implements IJeiGrindstoneRecipe {
21+
22+
public GrindstoneRecipe(
23+
List<ItemStack> topInputs,
24+
List<ItemStack> bottomInputs,
25+
List<ItemStack> outputs,
26+
int minXpReward,
27+
int maxXpReward,
28+
@Nullable ResourceLocation uid) {
29+
this(topInputs, bottomInputs, outputs, minXpReward, maxXpReward, uid, true);
30+
}
31+
32+
@Override
33+
@Unmodifiable
34+
@NotNull
35+
public List<ItemStack> getTopInputs() {
36+
return topInputs;
37+
}
38+
39+
@Override
40+
@Unmodifiable
41+
@NotNull
42+
public List<ItemStack> getBottomInputs() {
43+
return bottomInputs;
44+
}
45+
46+
@Override
47+
@Unmodifiable
48+
@NotNull
49+
public List<ItemStack> getOutputs() {
50+
return outputs;
51+
}
52+
53+
@Override
54+
public int getMinXpReward() {
55+
return minXpReward;
56+
}
57+
58+
@Override
59+
public int getMaxXpReward() {
60+
return maxXpReward;
61+
}
62+
63+
@Override
64+
@Nullable
65+
public ResourceLocation getUid() {
66+
return uid;
67+
}
68+
69+
@Override
70+
@Unmodifiable
71+
public boolean isOutputRenderOnly() {
72+
return isOutputRenderOnly;
73+
}
74+
}

0 commit comments

Comments
 (0)