Skip to content

Commit fafaf1d

Browse files
committed
Add helpers for checking matches on our recipes using the vanilla system
1 parent 3539ba7 commit fafaf1d

File tree

116 files changed

+881
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+881
-253
lines changed

src/api/java/mekanism/api/recipes/ChemicalCrystallizerRecipe.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
import mekanism.api.chemical.ChemicalStack;
88
import mekanism.api.chemical.merged.BoxedChemicalStack;
99
import mekanism.api.recipes.ingredients.ChemicalStackIngredient;
10+
import mekanism.api.recipes.vanilla_input.SingleBoxedChemicalInput;
1011
import net.minecraft.core.Holder;
12+
import net.minecraft.core.HolderLookup;
1113
import net.minecraft.core.registries.Registries;
1214
import net.minecraft.resources.ResourceLocation;
1315
import net.minecraft.world.item.Item;
1416
import net.minecraft.world.item.ItemStack;
1517
import net.minecraft.world.item.crafting.RecipeType;
18+
import net.minecraft.world.level.Level;
1619
import net.neoforged.neoforge.registries.DeferredHolder;
1720
import org.jetbrains.annotations.Contract;
1821
import org.jetbrains.annotations.NotNull;
@@ -25,7 +28,7 @@
2528
* @apiNote Chemical Crystallizers can process this recipe type.
2629
*/
2730
@NothingNullByDefault
28-
public abstract class ChemicalCrystallizerRecipe extends MekanismRecipe implements Predicate<@NotNull BoxedChemicalStack> {
31+
public abstract class ChemicalCrystallizerRecipe extends MekanismRecipe<SingleBoxedChemicalInput> implements Predicate<@NotNull BoxedChemicalStack> {
2932

3033
private static final Holder<Item> CHEMICAL_CRYSTALLIZER = DeferredHolder.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "chemical_crystallizer"));
3134

@@ -50,6 +53,21 @@ public abstract class ChemicalCrystallizerRecipe extends MekanismRecipe implemen
5053
*/
5154
public abstract List<ItemStack> getOutputDefinition();
5255

56+
@NotNull
57+
@Override
58+
public ItemStack assemble(SingleBoxedChemicalInput input, HolderLookup.Provider provider) {
59+
if (!isIncomplete() && test(input.chemical())) {
60+
return getOutput(input.chemical());
61+
}
62+
return ItemStack.EMPTY;
63+
}
64+
65+
@Override
66+
public boolean matches(SingleBoxedChemicalInput input, Level level) {
67+
//Don't match incomplete recipes or ones that don't match
68+
return !isIncomplete() && test(input.chemical());
69+
}
70+
5371
@Override
5472
public abstract boolean test(BoxedChemicalStack chemicalStack);
5573

src/api/java/mekanism/api/recipes/ChemicalDissolutionRecipe.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@
44
import java.util.function.BiPredicate;
55
import mekanism.api.MekanismAPI;
66
import mekanism.api.annotations.NothingNullByDefault;
7+
import mekanism.api.chemical.gas.Gas;
78
import mekanism.api.chemical.gas.GasStack;
89
import mekanism.api.chemical.merged.BoxedChemicalStack;
910
import mekanism.api.recipes.ingredients.GasStackIngredient;
1011
import mekanism.api.recipes.ingredients.ItemStackIngredient;
12+
import mekanism.api.recipes.vanilla_input.SingleItemChemicalRecipeInput;
1113
import net.minecraft.core.Holder;
1214
import net.minecraft.core.registries.Registries;
1315
import net.minecraft.resources.ResourceLocation;
1416
import net.minecraft.world.item.Item;
1517
import net.minecraft.world.item.ItemStack;
1618
import net.minecraft.world.item.crafting.RecipeType;
19+
import net.minecraft.world.level.Level;
1720
import net.neoforged.neoforge.registries.DeferredHolder;
1821
import org.jetbrains.annotations.Contract;
1922
import org.jetbrains.annotations.NotNull;
2023

2124
@NothingNullByDefault
22-
public abstract class ChemicalDissolutionRecipe extends MekanismRecipe implements BiPredicate<@NotNull ItemStack, @NotNull GasStack> {
25+
public abstract class ChemicalDissolutionRecipe extends MekanismRecipe<SingleItemChemicalRecipeInput<Gas, GasStack>>
26+
implements BiPredicate<@NotNull ItemStack, @NotNull GasStack> {
2327

2428
private static final Holder<Item> CHEMICAL_DISSOLUTION_CHAMBER = DeferredHolder.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "chemical_dissolution_chamber"));
2529

@@ -51,6 +55,12 @@ public abstract class ChemicalDissolutionRecipe extends MekanismRecipe implement
5155
@Override
5256
public abstract boolean test(ItemStack itemStack, GasStack gasStack);
5357

58+
@Override
59+
public boolean matches(SingleItemChemicalRecipeInput<Gas, GasStack> input, Level level) {
60+
//Don't match incomplete recipes or ones that don't match
61+
return !isIncomplete() && test(input.item(), input.chemical());
62+
}
63+
5464
/**
5565
* For JEI, gets the output representations to display.
5666
*

src/api/java/mekanism/api/recipes/CombinerRecipe.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import net.minecraft.resources.ResourceLocation;
1212
import net.minecraft.world.item.Item;
1313
import net.minecraft.world.item.ItemStack;
14+
import net.minecraft.world.item.crafting.RecipeInput;
1415
import net.minecraft.world.item.crafting.RecipeType;
16+
import net.minecraft.world.level.Level;
1517
import net.neoforged.neoforge.registries.DeferredHolder;
1618
import org.jetbrains.annotations.Contract;
1719
import org.jetbrains.annotations.NotNull;
@@ -26,7 +28,7 @@
2628
* @apiNote Combiners and Combining Factories can process this recipe type.
2729
*/
2830
@NothingNullByDefault
29-
public abstract class CombinerRecipe extends MekanismRecipe implements BiPredicate<@NotNull ItemStack, @NotNull ItemStack> {
31+
public abstract class CombinerRecipe extends MekanismRecipe<RecipeInput> implements BiPredicate<@NotNull ItemStack, @NotNull ItemStack> {
3032

3133
private static final Holder<Item> COMBINER = DeferredHolder.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "combiner"));
3234

@@ -43,6 +45,30 @@ public abstract class CombinerRecipe extends MekanismRecipe implements BiPredica
4345
*/
4446
public abstract ItemStackIngredient getExtraInput();
4547

48+
@NotNull
49+
@Override
50+
public ItemStack assemble(RecipeInput input, HolderLookup.Provider provider) {
51+
if (!isIncomplete() && input.size() == 2) {
52+
ItemStack mainInput = input.getItem(0);
53+
ItemStack extraInput = input.getItem(1);
54+
if (test(mainInput, extraInput)) {
55+
return getOutput(mainInput, extraInput);
56+
}
57+
}
58+
return ItemStack.EMPTY;
59+
}
60+
61+
@Override
62+
public boolean matches(RecipeInput input, Level level) {
63+
//Don't match incomplete recipes or ones that don't match
64+
return !isIncomplete() && input.size() == 2 && test(input.getItem(0), input.getItem(1));
65+
}
66+
67+
@Override
68+
public boolean canCraftInDimensions(int width, int height) {
69+
return width * height > 1;
70+
}
71+
4672
/**
4773
* Gets a new output based on the given inputs.
4874
*

src/api/java/mekanism/api/recipes/ElectrolysisRecipe.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import mekanism.api.chemical.gas.GasStack;
99
import mekanism.api.math.FloatingLong;
1010
import mekanism.api.recipes.ingredients.FluidStackIngredient;
11+
import mekanism.api.recipes.vanilla_input.SingleFluidRecipeInput;
1112
import net.minecraft.core.Holder;
1213
import net.minecraft.core.registries.Registries;
1314
import net.minecraft.resources.ResourceLocation;
1415
import net.minecraft.world.item.Item;
1516
import net.minecraft.world.item.ItemStack;
1617
import net.minecraft.world.item.crafting.RecipeType;
18+
import net.minecraft.world.level.Level;
1719
import net.neoforged.neoforge.fluids.FluidStack;
1820
import net.neoforged.neoforge.registries.DeferredHolder;
1921
import org.jetbrains.annotations.Contract;
@@ -29,7 +31,7 @@
2931
* @apiNote Electrolytic Separators can process this recipe type.
3032
*/
3133
@NothingNullByDefault
32-
public abstract class ElectrolysisRecipe extends MekanismRecipe implements Predicate<@NotNull FluidStack> {
34+
public abstract class ElectrolysisRecipe extends MekanismRecipe<SingleFluidRecipeInput> implements Predicate<@NotNull FluidStack> {
3335

3436
private static final Holder<Item> ELECTROLYTIC_SEPARATOR = DeferredHolder.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "electrolytic_separator"));
3537

@@ -48,6 +50,12 @@ public abstract class ElectrolysisRecipe extends MekanismRecipe implements Predi
4850
@Override
4951
public abstract boolean test(FluidStack fluidStack);
5052

53+
@Override
54+
public boolean matches(SingleFluidRecipeInput input, Level level) {
55+
//Don't match incomplete recipes or ones that don't match
56+
return !isIncomplete() && test(input.fluid());
57+
}
58+
5159
/**
5260
* Gets a new output based on the given input.
5361
*

src/api/java/mekanism/api/recipes/FluidToFluidRecipe.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import mekanism.api.MekanismAPI;
66
import mekanism.api.annotations.NothingNullByDefault;
77
import mekanism.api.recipes.ingredients.FluidStackIngredient;
8+
import mekanism.api.recipes.vanilla_input.SingleFluidRecipeInput;
89
import net.minecraft.core.Holder;
910
import net.minecraft.core.registries.Registries;
1011
import net.minecraft.resources.ResourceLocation;
1112
import net.minecraft.world.item.Item;
1213
import net.minecraft.world.item.ItemStack;
1314
import net.minecraft.world.item.crafting.RecipeType;
15+
import net.minecraft.world.level.Level;
1416
import net.neoforged.neoforge.fluids.FluidStack;
1517
import net.neoforged.neoforge.registries.DeferredHolder;
1618
import org.jetbrains.annotations.Contract;
@@ -24,13 +26,19 @@
2426
* @apiNote Thermal Evaporation Towers can process this recipe type.
2527
*/
2628
@NothingNullByDefault
27-
public abstract class FluidToFluidRecipe extends MekanismRecipe implements Predicate<@NotNull FluidStack> {
29+
public abstract class FluidToFluidRecipe extends MekanismRecipe<SingleFluidRecipeInput> implements Predicate<@NotNull FluidStack> {
2830

2931
private static final Holder<Item> THERMAL_EVAPORATION_CONTROLLER = DeferredHolder.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "thermal_evaporation_controller"));
3032

3133
@Override
3234
public abstract boolean test(FluidStack fluidStack);
3335

36+
@Override
37+
public boolean matches(SingleFluidRecipeInput input, Level level) {
38+
//Don't match incomplete recipes or ones that don't match
39+
return !isIncomplete() && test(input.fluid());
40+
}
41+
3442
/**
3543
* Gets the input ingredient.
3644
*/

src/api/java/mekanism/api/recipes/ItemStackToEnergyRecipe.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import net.minecraft.world.item.Item;
1313
import net.minecraft.world.item.ItemStack;
1414
import net.minecraft.world.item.crafting.RecipeType;
15+
import net.minecraft.world.item.crafting.SingleRecipeInput;
16+
import net.minecraft.world.level.Level;
1517
import net.neoforged.neoforge.registries.DeferredHolder;
1618
import org.jetbrains.annotations.NotNull;
1719

@@ -23,13 +25,19 @@
2325
* @apiNote Energy conversion recipes can be used in any slots in Mekanism machines that are able to convert items into energy.
2426
*/
2527
@NothingNullByDefault
26-
public abstract class ItemStackToEnergyRecipe extends MekanismRecipe implements Predicate<@NotNull ItemStack> {
28+
public abstract class ItemStackToEnergyRecipe extends MekanismRecipe<SingleRecipeInput> implements Predicate<@NotNull ItemStack> {
2729

2830
private static final Holder<Item> ENERGY_TABLET = DeferredHolder.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "energy_tablet"));
2931

3032
@Override
3133
public abstract boolean test(ItemStack itemStack);
3234

35+
@Override
36+
public boolean matches(SingleRecipeInput input, Level level) {
37+
//Don't match incomplete recipes or ones that don't match
38+
return !isIncomplete() && test(input.item());
39+
}
40+
3341
/**
3442
* Gets the input ingredient.
3543
*/

src/api/java/mekanism/api/recipes/ItemStackToFluidRecipe.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import mekanism.api.annotations.NothingNullByDefault;
66
import mekanism.api.recipes.ingredients.ItemStackIngredient;
77
import net.minecraft.world.item.ItemStack;
8+
import net.minecraft.world.item.crafting.SingleRecipeInput;
9+
import net.minecraft.world.level.Level;
810
import net.neoforged.neoforge.fluids.FluidStack;
911
import org.jetbrains.annotations.Contract;
1012
import org.jetbrains.annotations.NotNull;
@@ -22,11 +24,17 @@
2224
* </ul>
2325
*/
2426
@NothingNullByDefault
25-
public abstract class ItemStackToFluidRecipe extends MekanismRecipe implements Predicate<@NotNull ItemStack> {
27+
public abstract class ItemStackToFluidRecipe extends MekanismRecipe<SingleRecipeInput> implements Predicate<@NotNull ItemStack> {
2628

2729
@Override
2830
public abstract boolean test(ItemStack itemStack);
2931

32+
@Override
33+
public boolean matches(SingleRecipeInput input, Level level) {
34+
//Don't match incomplete recipes or ones that don't match
35+
return !isIncomplete() && test(input.item());
36+
}
37+
3038
/**
3139
* Gets the input ingredient.
3240
*/

src/api/java/mekanism/api/recipes/ItemStackToItemStackRecipe.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.minecraft.core.HolderLookup;
99
import net.minecraft.world.item.ItemStack;
1010
import net.minecraft.world.item.crafting.RecipeType;
11+
import net.minecraft.world.item.crafting.SingleRecipeInput;
12+
import net.minecraft.world.level.Level;
1113
import org.jetbrains.annotations.Contract;
1214
import org.jetbrains.annotations.NotNull;
1315

@@ -24,7 +26,7 @@
2426
* </ul>
2527
*/
2628
@NothingNullByDefault
27-
public abstract class ItemStackToItemStackRecipe extends MekanismRecipe implements Predicate<@NotNull ItemStack> {
29+
public abstract class ItemStackToItemStackRecipe extends MekanismRecipe<SingleRecipeInput> implements Predicate<@NotNull ItemStack> {
2830

2931
protected final RecipeType<ItemStackToItemStackRecipe> recipeType;
3032

@@ -35,6 +37,21 @@ public ItemStackToItemStackRecipe(RecipeType<ItemStackToItemStackRecipe> recipeT
3537
@Override
3638
public abstract boolean test(ItemStack input);
3739

40+
@NotNull
41+
@Override
42+
public ItemStack assemble(SingleRecipeInput input, HolderLookup.Provider provider) {
43+
if (!isIncomplete() && test(input.item())) {
44+
return getOutput(input.item());
45+
}
46+
return ItemStack.EMPTY;
47+
}
48+
49+
@Override
50+
public boolean matches(SingleRecipeInput input, Level level) {
51+
//Don't match incomplete recipes or ones that don't match
52+
return !isIncomplete() && test(input.item());
53+
}
54+
3855
/**
3956
* Gets the input ingredient.
4057
*/

src/api/java/mekanism/api/recipes/MekanismRecipe.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
package mekanism.api.recipes;
22

3-
import mekanism.api.inventory.IgnoredIInventory;
43
import net.minecraft.core.HolderLookup;
54
import net.minecraft.world.item.ItemStack;
65
import net.minecraft.world.item.crafting.Recipe;
7-
import net.minecraft.world.level.Level;
6+
import net.minecraft.world.item.crafting.RecipeInput;
87
import org.jetbrains.annotations.NotNull;
98

109
/**
1110
* Base class for helping wrap our recipes into IRecipes.
1211
*/
13-
public abstract class MekanismRecipe implements Recipe<IgnoredIInventory> {//TODO: Should we make implementations override equals and hashcode?
14-
15-
@Override
16-
public boolean matches(@NotNull IgnoredIInventory inv, @NotNull Level world) {
17-
//TODO - 1.21: Decide if we ever want to make use of this method, as with the changes in 1.21 to allow for extending RecipeInput
18-
// instead of Container, we potentially could implement this even for things that don't use items
19-
//Default to not being able to match incomplete recipes though
20-
return !isIncomplete();
21-
}
12+
public abstract class MekanismRecipe<INPUT extends RecipeInput> implements Recipe<INPUT> {
13+
//TODO: Should we make implementations override equals and hashcode?
2214

2315
@Override
2416
public boolean isSpecial() {
@@ -33,7 +25,7 @@ public boolean isSpecial() {
3325

3426
@NotNull
3527
@Override
36-
public ItemStack assemble(@NotNull IgnoredIInventory inv, @NotNull HolderLookup.Provider provider) {
28+
public ItemStack assemble(@NotNull INPUT input, @NotNull HolderLookup.Provider provider) {
3729
return ItemStack.EMPTY;
3830
}
3931

src/api/java/mekanism/api/recipes/PressurizedReactionRecipe.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
import mekanism.api.annotations.NothingNullByDefault;
77
import mekanism.api.chemical.gas.GasStack;
88
import mekanism.api.math.FloatingLong;
9-
import mekanism.api.recipes.ingredients.GasStackIngredient;
109
import mekanism.api.recipes.ingredients.FluidStackIngredient;
10+
import mekanism.api.recipes.ingredients.GasStackIngredient;
1111
import mekanism.api.recipes.ingredients.ItemStackIngredient;
12+
import mekanism.api.recipes.vanilla_input.ReactionRecipeInput;
1213
import net.minecraft.core.Holder;
1314
import net.minecraft.core.registries.Registries;
1415
import net.minecraft.resources.ResourceLocation;
1516
import net.minecraft.world.item.Item;
1617
import net.minecraft.world.item.ItemStack;
1718
import net.minecraft.world.item.crafting.RecipeType;
19+
import net.minecraft.world.level.Level;
1820
import net.neoforged.neoforge.common.util.TriPredicate;
1921
import net.neoforged.neoforge.fluids.FluidStack;
2022
import net.neoforged.neoforge.registries.DeferredHolder;
@@ -35,7 +37,7 @@
3537
* @apiNote Pressurized Reaction Chambers can process this recipe type.
3638
*/
3739
@NothingNullByDefault
38-
public abstract class PressurizedReactionRecipe extends MekanismRecipe implements TriPredicate<@NotNull ItemStack, @NotNull FluidStack, @NotNull GasStack> {
40+
public abstract class PressurizedReactionRecipe extends MekanismRecipe<ReactionRecipeInput> implements TriPredicate<@NotNull ItemStack, @NotNull FluidStack, @NotNull GasStack> {
3941

4042
private static final Holder<Item> PRESSURIZED_REACTION_CHAMBER = DeferredHolder.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, "pressurized_reaction_chamber"));
4143

@@ -67,6 +69,12 @@ public abstract class PressurizedReactionRecipe extends MekanismRecipe implement
6769
@Override
6870
public abstract boolean test(ItemStack solid, FluidStack liquid, GasStack gas);
6971

72+
@Override
73+
public boolean matches(ReactionRecipeInput input, Level level) {
74+
//Don't match incomplete recipes or ones that don't match
75+
return !isIncomplete() && test(input.item(), input.fluid(), input.gas());
76+
}
77+
7078
/**
7179
* For JEI, gets the output representations to display.
7280
*

0 commit comments

Comments
 (0)