TBroski

MCreator JEI Integration Working *PROOF*

Jun 10th, 2020
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.34 KB | None | 0 0
  1. /**
  2.  * This mod element is always locked. Enter your code in the methods below.
  3.  * If you don't need some of these methods, you can remove them as they
  4.  * are overrides of the base class JeitestModElements.ModElement.
  5.  *
  6.  * You can register new events in this class too.
  7.  *
  8.  * As this class is loaded into mod element list, it NEEDS to extend
  9.  * ModElement class. If you remove this extend statement or remove the
  10.  * constructor, the compilation will fail.
  11.  *
  12.  * If you want to make a plain independent class, create it in
  13.  * "Workspace" -> "Source" menu.
  14.  *
  15.  * If you change workspace package, modid or prefix, you will need
  16.  * to manually adapt this file to these changes or remake it.
  17. */
  18. package net.mcreator.jeitest;
  19.  
  20. import mezz.jei.api.IModPlugin;
  21. import mezz.jei.api.constants.VanillaTypes;
  22. import mezz.jei.api.gui.IRecipeLayout;
  23. import mezz.jei.api.gui.drawable.IDrawable;
  24. import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
  25. import mezz.jei.api.helpers.IGuiHelper;
  26. import mezz.jei.api.helpers.IJeiHelpers;
  27. import mezz.jei.api.ingredients.IIngredients;
  28. import mezz.jei.api.recipe.category.IRecipeCategory;
  29. import mezz.jei.api.registration.IRecipeCatalystRegistration;
  30. import mezz.jei.api.registration.IRecipeCategoryRegistration;
  31. import mezz.jei.api.registration.IRecipeRegistration;
  32. import net.minecraft.item.ItemStack;
  33. import net.minecraft.item.Items;
  34. import net.minecraft.util.ResourceLocation;
  35.  
  36. import net.mcreator.jeitest.block.InfuseBenchBlock;
  37.  
  38. import java.util.ArrayList;
  39. import java.util.List;
  40.  
  41. @mezz.jei.api.JeiPlugin
  42. public class MyJeiPlugin implements IModPlugin {
  43.  
  44.     public static IJeiHelpers jeiHelper;
  45.  
  46.     @Override
  47.     public ResourceLocation getPluginUid() {
  48.         return new ResourceLocation("jeitest","default");
  49.     }
  50.  
  51.     @Override
  52.     public void registerCategories(IRecipeCategoryRegistration registration) {
  53.         jeiHelper = registration.getJeiHelpers();
  54.  
  55.         registration.addRecipeCategories(new InfuseJeiCategory(jeiHelper.getGuiHelper()));
  56.     }
  57.  
  58.     @Override
  59.     public void registerRecipes(IRecipeRegistration registration) {
  60.  
  61.         registration.addRecipes(generateInfuseRecipes(), InfuseJeiCategory.Uid);
  62.  
  63.     }
  64.  
  65.     private List<InfuseJeiCategory.InfuseRecipeWrapper> generateInfuseRecipes() {
  66.         List<InfuseJeiCategory.InfuseRecipeWrapper> recipes = new ArrayList<>();
  67.         recipes.add(new InfuseJeiCategory.InfuseRecipeWrapper(new ItemStack(Items.DIRT), new ItemStack(Items.DIAMOND)));
  68.         return recipes;
  69.     }
  70.  
  71.     @Override
  72.     public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
  73.         registration.addRecipeCatalyst(new ItemStack(InfuseBenchBlock.block), InfuseJeiCategory.Uid);
  74.     }
  75.  
  76.     public static class InfuseJeiCategory implements IRecipeCategory<InfuseJeiCategory.InfuseRecipeWrapper>
  77.     {
  78.         private static ResourceLocation Uid = new ResourceLocation("jeitest", "infusebench");
  79.         private static final int input1 = 0;
  80.         private static final int output1 = 1;
  81.         private final String title;
  82.         private final IDrawable background;
  83.         private final IDrawable icon;
  84.         public InfuseJeiCategory(IGuiHelper guiHelper)
  85.         {
  86.             this.title = "Infusion Bench";
  87.             this.background = guiHelper.createDrawable(new ResourceLocation("jeitest", "textures/infuse_bench_gui.png"), 0, 0, 176, 116);
  88.             this.icon = guiHelper.createDrawable(new ResourceLocation("jeitest", "textures/blocks/jeitestbench.png"), 0, 0, 16, 16);
  89.         }
  90.  
  91.         @Override
  92.         public ResourceLocation getUid() {
  93.             return Uid;
  94.         }
  95.  
  96.         @Override
  97.         public Class<? extends InfuseRecipeWrapper> getRecipeClass() {
  98.             return InfuseJeiCategory.InfuseRecipeWrapper.class;
  99.         }
  100.  
  101.         @Override
  102.         public String getTitle() {
  103.             return title;
  104.         }
  105.  
  106.         @Override
  107.         public IDrawable getBackground() {
  108.             return background;
  109.         }
  110.  
  111.         @Override
  112.         public IDrawable getIcon() {
  113.             return null;
  114.         }
  115.  
  116.         @Override
  117.         public void setIngredients(InfuseRecipeWrapper infuseRecipeWrapper, IIngredients iIngredients) {
  118.             iIngredients.setInput(VanillaTypes.ITEM, infuseRecipeWrapper.getStack0());
  119.             iIngredients.setOutput(VanillaTypes.ITEM, infuseRecipeWrapper.getStack1());
  120.         }
  121.  
  122.         @Override
  123.         public void setRecipe(IRecipeLayout iRecipeLayout, InfuseRecipeWrapper infuseRecipeWrapper, IIngredients iIngredients) {
  124.             IGuiItemStackGroup stacks = iRecipeLayout.getItemStacks();
  125.  
  126.             stacks.init(input1, true, 37, 32);
  127.             stacks.init(output1, false, 118, 28);
  128.  
  129.             stacks.set(0, iIngredients.getInputs(VanillaTypes.ITEM).get(0));
  130.             stacks.set(1, iIngredients.getOutputs(VanillaTypes.ITEM).get(0));
  131.         }
  132.  
  133.  
  134.         public static class InfuseRecipeWrapper {
  135.  
  136.             private ItemStack item0;
  137.             private ItemStack item1;
  138.  
  139.             public InfuseRecipeWrapper(ItemStack item0, ItemStack item1) {
  140.                 this.item0 = item0;
  141.                 this.item1 = item1;
  142.             }
  143.  
  144.  
  145.             public ItemStack getStack0() {
  146.                 return item0;
  147.             }
  148.  
  149.             public ItemStack getStack1() {
  150.                 return item1;
  151.             }
  152.         }
  153.     }
  154. }
Add Comment
Please, Sign In to add comment