|
1 | | -//package dev.compactmods.machines.compat.jei; |
2 | | -// |
3 | | -//import dev.compactmods.machines.api.CompactMachinesApi; |
4 | | -//import dev.compactmods.machines.api.room.CompactMachines.roomApi(); |
5 | | -//import dev.compactmods.machines.CompactMachines; |
6 | | -//import dev.compactmods.machines.machine.Machines; |
7 | | -//import dev.compactmods.machines.shrinking.Shrinking; |
8 | | -//import mezz.jei.api.IModPlugin; |
9 | | -//import mezz.jei.api.JeiPlugin; |
10 | | -//import mezz.jei.api.constants.VanillaTypes; |
11 | | -//import mezz.jei.api.registration.IRecipeRegistration; |
12 | | -//import mezz.jei.api.registration.ISubtypeRegistration; |
13 | | -//import net.minecraft.network.chat.Component; |
14 | | -//import net.minecraft.resources.ResourceLocation; |
15 | | -//import net.minecraft.world.item.ItemStack; |
16 | | -//import net.neoforged.neoforge.server.ServerLifecycleHooks; |
17 | | -// |
18 | | -//@JeiPlugin |
19 | | -//public class CompactMachinesJeiPlugin implements IModPlugin { |
20 | | -// @Override |
21 | | -// public ResourceLocation getPluginUid() { |
22 | | -// return CompactMachinesApi.modRL("main"); |
23 | | -// } |
24 | | -// |
25 | | -// @Override |
26 | | -// public void registerRecipes(IRecipeRegistration registration) { |
27 | | -// final var ingManager = registration.getIngredientManager(); |
28 | | -// |
29 | | -// registration.addIngredientInfo( |
30 | | -// Machines.Items.unboundColored(CompactMachines.BRAND_MACHINE_COLOR), |
31 | | -// VanillaTypes.ITEM_STACK, |
32 | | -// Component.translatable("jei.compactmachines.machines")); |
33 | | -// |
34 | | -// // Add all known template JEI infos |
35 | | -// CompactMachines.roomApi().getTemplates(ServerLifecycleHooks.getCurrentServer()) |
36 | | -// .entrySet() |
37 | | -// .stream() |
38 | | -// .map(t -> Machines.Items.forNewRoom(t.getKey().location(), t.getValue())) |
39 | | -// .forEach(t -> registration.addIngredientInfo(t, VanillaTypes.ITEM_STACK, Component.translatable("jei.compactmachines.machines"))); |
40 | | -// |
41 | | -// registration.addIngredientInfo( |
42 | | -// new ItemStack(Shrinking.PERSONAL_SHRINKING_DEVICE.get()), |
43 | | -// VanillaTypes.ITEM_STACK, |
44 | | -// Component.translatable("jei.compactmachines.shrinking_device")); |
45 | | -// } |
46 | | -// |
47 | | -// @Override |
48 | | -// public void registerItemSubtypes(ISubtypeRegistration registration) { |
49 | | -// registration.registerSubtypeInterpreter(Machines.Items.UNBOUND_MACHINE.get(), |
50 | | -// (ingredient, context) -> { |
51 | | -// // return (ingredient.has(ROOM_TEMPLATE) ? ub.getTemplateId(ingredient).toString() : ""); |
52 | | -// return ""; |
53 | | -// }); |
54 | | -// } |
55 | | -//} |
| 1 | +package dev.compactmods.machines.compat.jei; |
| 2 | + |
| 3 | +import dev.compactmods.machines.CompactMachinesCommon; |
| 4 | +import dev.compactmods.machines.api.CompactMachines; |
| 5 | +import dev.compactmods.machines.api.component.CMDataComponents; |
| 6 | +import dev.compactmods.machines.api.machine.MachineConstants; |
| 7 | +import dev.compactmods.machines.api.room.template.RoomTemplateHelper; |
| 8 | +import dev.compactmods.machines.machine.Machines; |
| 9 | +import dev.compactmods.machines.shrinking.Shrinking; |
| 10 | +import mezz.jei.api.IModPlugin; |
| 11 | +import mezz.jei.api.JeiPlugin; |
| 12 | +import mezz.jei.api.constants.VanillaTypes; |
| 13 | +import mezz.jei.api.ingredients.IIngredientType; |
| 14 | +import mezz.jei.api.ingredients.subtypes.ISubtypeInterpreter; |
| 15 | +import mezz.jei.api.ingredients.subtypes.UidContext; |
| 16 | +import mezz.jei.api.registration.IRecipeRegistration; |
| 17 | +import mezz.jei.api.registration.ISubtypeRegistration; |
| 18 | +import net.minecraft.network.chat.Component; |
| 19 | +import net.minecraft.resources.ResourceLocation; |
| 20 | +import net.minecraft.tags.TagKey; |
| 21 | +import net.minecraft.world.item.Item; |
| 22 | +import net.minecraft.world.item.ItemStack; |
| 23 | +import net.minecraft.world.item.crafting.Ingredient; |
| 24 | +import net.neoforged.neoforge.server.ServerLifecycleHooks; |
| 25 | +import org.jetbrains.annotations.NotNull; |
| 26 | +import org.jetbrains.annotations.Nullable; |
| 27 | + |
| 28 | +import javax.annotation.ParametersAreNonnullByDefault; |
| 29 | +import javax.annotation.ParametersAreNullableByDefault; |
| 30 | + |
| 31 | +@JeiPlugin |
| 32 | +public class CompactMachinesJeiPlugin implements IModPlugin { |
| 33 | + @Override |
| 34 | + public ResourceLocation getPluginUid() { |
| 35 | + return CompactMachines.modRL("main"); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public void registerRecipes(IRecipeRegistration registration) { |
| 40 | + registration.addIngredientInfo( |
| 41 | + Machines.Items.unboundColored(CompactMachinesCommon.BRAND_MACHINE_COLOR), |
| 42 | + VanillaTypes.ITEM_STACK, |
| 43 | + Component.translatable("jei.compactmachines.machines")); |
| 44 | + |
| 45 | + // Add all known template JEI infos |
| 46 | + RoomTemplateHelper.getTemplateHolders(ServerLifecycleHooks.getCurrentServer().registryAccess()) |
| 47 | + .map(Machines.Items::forNewRoom) |
| 48 | + .forEach(t -> registration.addIngredientInfo(t, VanillaTypes.ITEM_STACK, |
| 49 | + Component.translatable("jei.compactmachines.machines"))); |
| 50 | + |
| 51 | + registration.addIngredientInfo( |
| 52 | + new ItemStack(Shrinking.PERSONAL_SHRINKING_DEVICE.get()), |
| 53 | + VanillaTypes.ITEM_STACK, |
| 54 | + Component.translatable("jei.compactmachines.shrinking_device")); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + @ParametersAreNonnullByDefault |
| 59 | + public void registerItemSubtypes(ISubtypeRegistration registration) { |
| 60 | + registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Machines.Items.UNBOUND_MACHINE.get(), |
| 61 | + new ISubtypeInterpreter<>() { |
| 62 | + @Override |
| 63 | + public @Nullable Object getSubtypeData(ItemStack ingredient, UidContext context) { |
| 64 | + return ingredient.get(CMDataComponents.ROOM_TEMPLATE_ID); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) { |
| 69 | + return ""; |
| 70 | + } |
| 71 | + }); |
| 72 | + } |
| 73 | +} |
0 commit comments