Advertisement
MoonHikari

JEI Intergration Attempt

Apr 16th, 2022
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.09 KB | None | 0 0
  1. package net.mcreator.berrycows;
  2.  
  3. import net.minecraft.util.ResourceLocation;
  4. import net.minecraft.item.ItemStack;
  5.  
  6. import net.mcreator.berrycows.item.PurpleRaspberryItem;
  7. import net.mcreator.berrycows.item.BlueberryMilkItem;
  8. import net.mcreator.berrycows.item.BlueberryItem;
  9. import net.mcreator.berrycows.block.BlueberryBlitzSmoothieBlock;
  10. import net.mcreator.berrycows.block.BerryBlenderBlock;
  11.  
  12. import mezz.jei.api.registration.IRecipeRegistration;
  13. import mezz.jei.api.registration.IRecipeCategoryRegistration;
  14. import mezz.jei.api.registration.IRecipeCatalystRegistration;
  15. import mezz.jei.api.recipe.category.IRecipeCategory;
  16. import mezz.jei.api.ingredients.IIngredients;
  17. import mezz.jei.api.helpers.IJeiHelpers;
  18. import mezz.jei.api.helpers.IGuiHelper;
  19. import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
  20. import mezz.jei.api.gui.drawable.IDrawable;
  21. import mezz.jei.api.gui.IRecipeLayout;
  22. import mezz.jei.api.constants.VanillaTypes;
  23. import mezz.jei.api.IModPlugin;
  24.  
  25. import java.util.List;
  26. import java.util.ArrayList;
  27.  
  28. @mezz.jei.api.JeiPlugin
  29. public class JEIIntegration implements IModPlugin {
  30.     public static IJeiHelpers jeiHelper;
  31.  
  32.     @Override
  33.     public ResourceLocation getPluginUid() {
  34.         return new ResourceLocation("berrycows", "default");
  35.     }
  36.  
  37.     @Override
  38.     public void registerCategories(IRecipeCategoryRegistration registration) {
  39.         jeiHelper = registration.getJeiHelpers();
  40.         registration.addRecipeCategories(new BerryBlenderJeiCategory(jeiHelper.getGuiHelper()));
  41.     }
  42.  
  43.     @Override
  44.     public void registerRecipes(IRecipeRegistration registration) {
  45.         registration.addRecipes(generateBerryBlenderRecipes(), BerryBlenderJeiCategory.Uid);
  46.         // ...
  47.     }
  48.  
  49.     private List<BerryBlenderJeiCategory.BerryBlenderRecipeWrapper> generateBerryBlenderRecipes() {
  50.         List<BerryBlenderJeiCategory.BerryBlenderRecipeWrapper> recipes = new ArrayList<>();
  51.         ArrayList<ItemStack> inputs = new ArrayList<>();
  52.         ArrayList<ItemStack> outputs = new ArrayList<>();
  53.         inputs.add(new ItemStack(BlueberryItem.block)); //slot 0 item
  54.         inputs.add(new ItemStack(PurpleRaspberryItem.block)); //slot 1 item
  55.         inputs.add(new ItemStack(BlueberryMilkItem.block));//slot 2 item
  56.         outputs.add(new ItemStack(BlueberryBlitzSmoothieBlock.block)); //slot 3 item
  57.         // ...
  58.         recipes.add(new BerryBlenderJeiCategory.BerryBlenderRecipeWrapper(inputs, outputs));
  59.         return recipes;
  60.     }
  61.  
  62.     @Override
  63.     public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
  64.         registration.addRecipeCatalyst(new ItemStack(BerryBlenderBlock.block), BerryBlenderJeiCategory.Uid);
  65.     }
  66.  
  67.     public static class BerryBlenderJeiCategory implements IRecipeCategory<BerryBlenderJeiCategory.BerryBlenderRecipeWrapper> {
  68.         private static ResourceLocation Uid = new ResourceLocation("berrycows", "berryblendercategory");
  69.         private static final int input1 = 0; // THE NUMBER = SLOTID
  70.         private static final int input2 = 1; // THE NUMBER = SLOTID
  71.         private static final int input3 = 2; // THE NUMBER = SLOTID
  72.         private static final int output1 = 3; // THE NUMBER = SLOTID
  73.         // ...
  74.         private final String title;
  75.         private final IDrawable background;
  76.  
  77.         public BerryBlenderJeiCategory(IGuiHelper guiHelper) {
  78.             this.title = "Berry Blender";
  79.             this.background = guiHelper.createDrawable(new ResourceLocation("berrycows", "textures/BlenderGuiPng.png"), 0, 0, 645, 295);
  80.         }
  81.  
  82.         @Override
  83.         public ResourceLocation getUid() {
  84.             return Uid;
  85.         }
  86.  
  87.         @Override
  88.         public Class<? extends BerryBlenderRecipeWrapper> getRecipeClass() {
  89.             return BerryBlenderJeiCategory.BerryBlenderRecipeWrapper.class;
  90.         }
  91.  
  92.         @Override
  93.         public String getTitle() {
  94.             return title;
  95.         }
  96.  
  97.         @Override
  98.         public IDrawable getBackground() {
  99.             return background;
  100.         }
  101.  
  102.         @Override
  103.         public IDrawable getIcon() {
  104.             return null;
  105.         }
  106.  
  107.         @Override
  108.         public void setIngredients(BerryBlenderRecipeWrapper recipeWrapper, IIngredients iIngredients) {
  109.             iIngredients.setInputs(VanillaTypes.ITEM, recipeWrapper.getInput());
  110.             iIngredients.setOutputs(VanillaTypes.ITEM, recipeWrapper.getOutput());
  111.         }
  112.  
  113.         @Override
  114.         public void setRecipe(IRecipeLayout iRecipeLayout, BerryBlenderRecipeWrapper recipeWrapper, IIngredients iIngredients) {
  115.             IGuiItemStackGroup stacks = iRecipeLayout.getItemStacks();
  116.             stacks.init(input1, true, 132, 56);
  117.             stacks.init(input2, true, 132, 146);
  118.             stacks.init(input3, true, 132, 236);
  119.             stacks.init(output1, false, 586, 127);
  120.             // ...
  121.             stacks.set(input1, iIngredients.getInputs(VanillaTypes.ITEM).get(0));
  122.             stacks.set(input2, iIngredients.getInputs(VanillaTypes.ITEM).get(1));
  123.             stacks.set(input3, iIngredients.getInputs(VanillaTypes.ITEM).get(2));
  124.             stacks.set(output1, iIngredients.getOutputs(VanillaTypes.ITEM).get(0));
  125.             // ...
  126.         }
  127.  
  128.         public static class BerryBlenderRecipeWrapper {
  129.             private List<ItemStack> input;
  130.             private List<ItemStack> output;
  131.  
  132.             public BerryBlenderRecipeWrapper(List<ItemStack> input, List<ItemStack> output) {
  133.                 this.input = input;
  134.                 this.output = output;
  135.             }
  136.  
  137.             public List<ItemStack> getInput() {
  138.                 return input;
  139.             }
  140.  
  141.             public List<ItemStack> getOutput() {
  142.                 return output;
  143.             }
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement