mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-03-19 01:48:12 +00:00
Fix JEI integration for MC 1.21
- Use the client side registry access (possible now that we've moved JEI to the client). - Generate unique ids for JEI recipes.
This commit is contained in:
parent
28f75a0687
commit
efd9a0f315
@ -19,6 +19,8 @@ import mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter;
|
||||
import mezz.jei.api.registration.IAdvancedRegistration;
|
||||
import mezz.jei.api.registration.ISubtypeRegistration;
|
||||
import mezz.jei.api.runtime.IJeiRuntime;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
@ -44,7 +46,7 @@ public class JEIComputerCraft implements IModPlugin {
|
||||
|
||||
@Override
|
||||
public void registerAdvanced(IAdvancedRegistration registry) {
|
||||
registry.addRecipeManagerPlugin(new RecipeResolver());
|
||||
registry.addRecipeManagerPlugin(new RecipeResolver(getRegistryAccess()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,7 +54,7 @@ public class JEIComputerCraft implements IModPlugin {
|
||||
var registry = runtime.getRecipeManager();
|
||||
|
||||
// Register all turtles/pocket computers (not just vanilla upgrades) as upgrades on JEI.
|
||||
var upgradeItems = RecipeModHelpers.getExtraStacks(RecipeModHelpers.getEmptyRegistryAccess());
|
||||
var upgradeItems = RecipeModHelpers.getExtraStacks(getRegistryAccess());
|
||||
if (!upgradeItems.isEmpty()) {
|
||||
runtime.getIngredientManager().addIngredientsAtRuntime(VanillaTypes.ITEM_STACK, upgradeItems);
|
||||
}
|
||||
@ -99,4 +101,8 @@ public class JEIComputerCraft implements IModPlugin {
|
||||
* Distinguishes disks by colour.
|
||||
*/
|
||||
private static final IIngredientSubtypeInterpreter<ItemStack> diskSubtype = (stack, ctx) -> Integer.toString(DiskItem.getColour(stack));
|
||||
|
||||
private static RegistryAccess getRegistryAccess() {
|
||||
return Minecraft.getInstance().level.registryAccess();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
package dan200.computercraft.client.integration.jei;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.shared.integration.RecipeModHelpers;
|
||||
import dan200.computercraft.shared.integration.UpgradeRecipeGenerator;
|
||||
import dan200.computercraft.shared.pocket.items.PocketComputerItem;
|
||||
import dan200.computercraft.shared.turtle.items.TurtleItem;
|
||||
@ -14,6 +13,7 @@ import mezz.jei.api.recipe.IFocus;
|
||||
import mezz.jei.api.recipe.RecipeType;
|
||||
import mezz.jei.api.recipe.advanced.IRecipeManagerPlugin;
|
||||
import mezz.jei.api.recipe.category.IRecipeCategory;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
@ -22,8 +22,19 @@ import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import java.util.List;
|
||||
|
||||
class RecipeResolver implements IRecipeManagerPlugin {
|
||||
private static final ResourceLocation RECIPE_ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "upgrade");
|
||||
private final UpgradeRecipeGenerator<RecipeHolder<CraftingRecipe>> resolver = new UpgradeRecipeGenerator<>(x -> new RecipeHolder<>(RECIPE_ID, x), RecipeModHelpers.getEmptyRegistryAccess());
|
||||
private final UpgradeRecipeGenerator<RecipeHolder<CraftingRecipe>> resolver;
|
||||
|
||||
/**
|
||||
* We need to generate unique ids for each recipe, as JEI will attempt to deduplicate them otherwise.
|
||||
*/
|
||||
private int nextId = 0;
|
||||
|
||||
RecipeResolver(HolderLookup.Provider registries) {
|
||||
resolver = new UpgradeRecipeGenerator<>(
|
||||
x -> new RecipeHolder<>(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "upgrade_" + nextId++), x),
|
||||
registries
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> List<RecipeType<?>> getRecipeTypes(IFocus<V> focus) {
|
||||
@ -60,7 +71,7 @@ class RecipeResolver implements IRecipeManagerPlugin {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({ "unchecked", "rawtypes", "UnusedVariable" })
|
||||
private static <T, U> List<T> cast(RecipeType<U> ignoredType, List<U> from) {
|
||||
return (List) from;
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import dan200.computercraft.shared.util.DataComponentUtil;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@ -77,18 +76,6 @@ public final class RecipeModHelpers {
|
||||
return upgradeItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* A temporary function to denote places where we need a {@link HolderLookup.Provider} within our recipe mods, but
|
||||
* don't have access to one.
|
||||
*
|
||||
* @return The empty recipe mod access.
|
||||
* @deprecated We should get the registry access from a more sensible place.
|
||||
*/
|
||||
@Deprecated
|
||||
public static HolderLookup.Provider getEmptyRegistryAccess() {
|
||||
return RegistryAccess.EMPTY;
|
||||
}
|
||||
|
||||
static <T> void forEachRegistry(HolderLookup.Provider registries, ResourceKey<Registry<T>> registry, Consumer<Holder.Reference<T>> consumer) {
|
||||
registries.lookup(registry).map(HolderLookup::listElements).orElse(Stream.empty()).forEach(consumer);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user