-
-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump min JEI version to 19.10.0.126 and add support for searching by …
…our aliases in JEI (#8218)
- Loading branch information
1 parent
2911cfe
commit e7d6f44
Showing
13 changed files
with
145 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/additions/java/mekanism/additions/client/recipe_viewer/jei/AdditionsJEI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package mekanism.additions.client.recipe_viewer.jei; | ||
|
||
import mekanism.additions.client.recipe_viewer.aliases.AdditionsAliasMapping; | ||
import mekanism.additions.common.MekanismAdditions; | ||
import mekanism.client.recipe_viewer.jei.JEIAliasHelper; | ||
import mezz.jei.api.IModPlugin; | ||
import mezz.jei.api.JeiPlugin; | ||
import mezz.jei.api.registration.IIngredientAliasRegistration; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@JeiPlugin | ||
public class AdditionsJEI implements IModPlugin { | ||
|
||
@NotNull | ||
@Override | ||
public ResourceLocation getPluginUid() { | ||
//Note: Can't use MekanismTools.rl, as JEI needs this in the constructor and the class may not be loaded yet. | ||
// we can still reference the modid though because of constant inlining | ||
return ResourceLocation.fromNamespaceAndPath(MekanismAdditions.MODID, "jei_plugin"); | ||
} | ||
|
||
@Override | ||
public void registerIngredientAliases(@NotNull IIngredientAliasRegistration registration) { | ||
new AdditionsAliasMapping().addAliases(new JEIAliasHelper(registration)); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/datagen/generated/mekanism/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/java/mekanism/client/recipe_viewer/jei/JEIAliasHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package mekanism.client.recipe_viewer.jei; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import mekanism.api.chemical.ChemicalStack; | ||
import mekanism.api.providers.IChemicalProvider; | ||
import mekanism.api.providers.IFluidProvider; | ||
import mekanism.api.text.IHasTranslationKey; | ||
import mekanism.client.recipe_viewer.alias.RVAliasHelper; | ||
import mekanism.common.Mekanism; | ||
import mekanism.common.util.RegistryUtils; | ||
import mezz.jei.api.constants.VanillaTypes; | ||
import mezz.jei.api.ingredients.IIngredientType; | ||
import mezz.jei.api.neoforge.NeoForgeTypes; | ||
import mezz.jei.api.registration.IIngredientAliasRegistration; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.ItemLike; | ||
import net.neoforged.neoforge.fluids.FluidStack; | ||
import net.neoforged.neoforge.fluids.FluidType; | ||
|
||
public class JEIAliasHelper implements RVAliasHelper<ItemStack, FluidStack, ChemicalStack> { | ||
|
||
private static final Function<ItemStack, String> ITEM_TO_STRING = stack -> stack.getItem().toString(); | ||
private static final Function<FluidStack, String> FLUID_TO_STRING = stack -> RegistryUtils.getName(stack.getFluid()).toString(); | ||
private static final Function<ChemicalStack, String> CHEMICAL_TO_STRING = stack -> stack.getChemical().getRegistryName().toString(); | ||
|
||
private final IIngredientAliasRegistration registration; | ||
|
||
public JEIAliasHelper(IIngredientAliasRegistration registration) { | ||
this.registration = registration; | ||
} | ||
|
||
@Override | ||
public ItemStack ingredient(ItemLike itemLike) { | ||
return new ItemStack(itemLike); | ||
} | ||
|
||
@Override | ||
public ItemStack ingredient(ItemStack item) { | ||
return item; | ||
} | ||
|
||
@Override | ||
public FluidStack ingredient(IFluidProvider fluidProvider) { | ||
return fluidProvider.getFluidStack(FluidType.BUCKET_VOLUME); | ||
} | ||
|
||
@Override | ||
public FluidStack ingredient(FluidStack fluid) { | ||
return fluid; | ||
} | ||
|
||
@Override | ||
public ChemicalStack ingredient(IChemicalProvider chemicalProvider) { | ||
return chemicalProvider.getStack(FluidType.BUCKET_VOLUME); | ||
} | ||
|
||
@Override | ||
public void addItemAliases(List<ItemStack> stacks, IHasTranslationKey... aliases) { | ||
addAliases(VanillaTypes.ITEM_STACK, stacks, ITEM_TO_STRING, aliases); | ||
} | ||
|
||
@Override | ||
public void addFluidAliases(List<FluidStack> stacks, IHasTranslationKey... aliases) { | ||
addAliases(NeoForgeTypes.FLUID_STACK, stacks, FLUID_TO_STRING, aliases); | ||
} | ||
|
||
@Override | ||
public void addChemicalAliases(List<ChemicalStack> stacks, IHasTranslationKey... aliases) { | ||
addAliases(MekanismJEI.TYPE_CHEMICAL, stacks, CHEMICAL_TO_STRING, aliases); | ||
} | ||
|
||
private <INGREDIENT> void addAliases(IIngredientType<INGREDIENT> type, List<INGREDIENT> stacks, Function<INGREDIENT, String> ingredientToString, | ||
IHasTranslationKey... aliases) { | ||
if (aliases.length == 0) { | ||
Mekanism.logger.warn("Expected to have at least one alias for ingredients of type: {}. Ingredients: {}", type.getUid(), stacks.stream() | ||
.map(ingredientToString) | ||
.collect(Collectors.joining(", ")) | ||
); | ||
} else { | ||
List<String> aliasesAsString = Arrays.stream(aliases) | ||
.map(IHasTranslationKey::getTranslationKey) | ||
.toList(); | ||
registration.addAliases(type, stacks, aliasesAsString); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters