From cebb49555a743635171cccc23618c797925b9a24 Mon Sep 17 00:00:00 2001 From: gigabit101 Date: Thu, 25 Feb 2016 13:17:33 +0000 Subject: [PATCH] Added grinder jei support --- .../compat/jei/RecipeCategoryUids.java | 3 +- .../compat/jei/TechRebornJeiPlugin.java | 14 ++++- .../jei/grinder/GrinderRecipeCategory.java | 59 +++++++++++++++++++ .../jei/grinder/GrinderRecipeHandler.java | 42 +++++++++++++ .../jei/grinder/GrinderRecipeWrapper.java | 33 +++++++++++ .../IndustrialGrinderRecipeCategory.java | 2 +- .../IndustrialGrinderRecipeHandler.java | 2 +- 7 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 src/main/java/techreborn/compat/jei/grinder/GrinderRecipeCategory.java create mode 100644 src/main/java/techreborn/compat/jei/grinder/GrinderRecipeHandler.java create mode 100644 src/main/java/techreborn/compat/jei/grinder/GrinderRecipeWrapper.java diff --git a/src/main/java/techreborn/compat/jei/RecipeCategoryUids.java b/src/main/java/techreborn/compat/jei/RecipeCategoryUids.java index 2010895b0..e3f8272f8 100644 --- a/src/main/java/techreborn/compat/jei/RecipeCategoryUids.java +++ b/src/main/java/techreborn/compat/jei/RecipeCategoryUids.java @@ -10,10 +10,11 @@ public class RecipeCategoryUids { public static final String CENTRIFUGE = "TechReborn.Centrifuge"; public static final String CHEMICAL_REACTOR = "TechReborn.ChemicalReactor"; public static final String FUSION_REACTOR = "TechReborn.FusionReactor"; - public static final String GRINDER = "TechReborn.Grinder"; + public static final String INDUSTRIAL_GRINDER = "TechReborn.IndustrialGrinder"; public static final String IMPLOSION_COMPRESSOR = "TechReborn.ImplosionCompressor"; public static final String INDUSTRIAL_ELECTROLYZER = "TechReborn.IndustrialElectrolyzer"; public static final String INDUSTRIAL_SAWMILL = "TechReborn.IndustrialSawmill"; public static final String ROLLING_MACHINE = "TechReborn.RollingMachine"; public static final String VACUUM_FREEZER = "TechReborn.VacuumFreezer"; + public static final String GRINDER = "TechReborn.Grinder"; } diff --git a/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java b/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java index 01ed4457a..35f8de9ed 100644 --- a/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java +++ b/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java @@ -27,6 +27,8 @@ import techreborn.compat.jei.chemicalReactor.ChemicalReactorRecipeCategory; import techreborn.compat.jei.chemicalReactor.ChemicalReactorRecipeHandler; import techreborn.compat.jei.fusionReactor.FusionReactorRecipeCategory; import techreborn.compat.jei.fusionReactor.FusionReactorRecipeHandler; +import techreborn.compat.jei.grinder.GrinderRecipeCategory; +import techreborn.compat.jei.grinder.GrinderRecipeHandler; import techreborn.compat.jei.implosionCompressor.ImplosionCompressorRecipeCategory; import techreborn.compat.jei.implosionCompressor.ImplosionCompressorRecipeHandler; import techreborn.compat.jei.industrialElectrolyzer.IndustrialElectrolyzerRecipeCategory; @@ -64,7 +66,8 @@ public class TechRebornJeiPlugin extends BlankModPlugin { new IndustrialElectrolyzerRecipeCategory(guiHelper), new IndustrialSawmillRecipeCategory(guiHelper), new RollingMachineRecipeCategory(guiHelper), - new VacuumFreezerRecipeCategory(guiHelper) + new VacuumFreezerRecipeCategory(guiHelper), + new GrinderRecipeCategory(guiHelper) ); registry.addRecipeHandlers( @@ -79,7 +82,8 @@ public class TechRebornJeiPlugin extends BlankModPlugin { new IndustrialElectrolyzerRecipeHandler(jeiHelpers), new IndustrialSawmillRecipeHandler(jeiHelpers), new RollingMachineRecipeHandler(), - new VacuumFreezerRecipeHandler(jeiHelpers) + new VacuumFreezerRecipeHandler(jeiHelpers), + new GrinderRecipeHandler(jeiHelpers) ); registry.addRecipes(RecipeHandler.recipeList); @@ -106,12 +110,14 @@ public class TechRebornJeiPlugin extends BlankModPlugin { registry.addRecipeClickArea(GuiCentrifuge.class, 83, 53, 12, 9, RecipeCategoryUids.CENTRIFUGE); registry.addRecipeClickArea(GuiChemicalReactor.class, 73, 39, 32, 12, RecipeCategoryUids.CHEMICAL_REACTOR); registry.addRecipeClickArea(GuiFusionReactor.class, 111, 34, 27, 19, RecipeCategoryUids.FUSION_REACTOR); - registry.addRecipeClickArea(GuiIndustrialGrinder.class, 50, 35, 25, 16, RecipeCategoryUids.GRINDER); + registry.addRecipeClickArea(GuiIndustrialGrinder.class, 50, 35, 25, 16, RecipeCategoryUids.INDUSTRIAL_GRINDER); registry.addRecipeClickArea(GuiImplosionCompressor.class, 60, 37, 24, 15, RecipeCategoryUids.IMPLOSION_COMPRESSOR); registry.addRecipeClickArea(GuiIndustrialElectrolyzer.class, 72, 37, 33, 14, RecipeCategoryUids.INDUSTRIAL_ELECTROLYZER); registry.addRecipeClickArea(GuiIndustrialSawmill.class, 55, 36, 24, 16, RecipeCategoryUids.INDUSTRIAL_SAWMILL); registry.addRecipeClickArea(GuiRollingMachine.class, 89, 32, 26, 25, RecipeCategoryUids.ROLLING_MACHINE); registry.addRecipeClickArea(GuiVacuumFreezer.class, 78, 36, 24, 16, RecipeCategoryUids.VACUUM_FREEZER); + registry.addRecipeClickArea(GuiGrinder.class, 78, 36, 24, 16, RecipeCategoryUids.GRINDER); + IRecipeTransferRegistry recipeTransferRegistry = registry.getRecipeTransferRegistry(); recipeTransferRegistry.addRecipeTransferHandler(ContainerAlloyFurnace.class, RecipeCategoryUids.ALLOY_SMELTER, 0, 2, 4, 36); @@ -128,6 +134,8 @@ public class TechRebornJeiPlugin extends BlankModPlugin { recipeTransferRegistry.addRecipeTransferHandler(ContainerIndustrialSawmill.class, RecipeCategoryUids.INDUSTRIAL_SAWMILL, 0, 2, 5, 36); recipeTransferRegistry.addRecipeTransferHandler(ContainerRollingMachine.class, RecipeCategoryUids.ROLLING_MACHINE, 0, 9, 11, 36); recipeTransferRegistry.addRecipeTransferHandler(ContainerVacuumFreezer.class, RecipeCategoryUids.VACUUM_FREEZER, 0, 1, 2, 36); + recipeTransferRegistry.addRecipeTransferHandler(ContainerGrinder.class, RecipeCategoryUids.GRINDER, 0, 1, 2, 36); + } private static void addDebugRecipes(IModRegistry registry) { diff --git a/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeCategory.java b/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeCategory.java new file mode 100644 index 000000000..45632e1b2 --- /dev/null +++ b/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeCategory.java @@ -0,0 +1,59 @@ +package techreborn.compat.jei.grinder; + +import mezz.jei.api.IGuiHelper; +import mezz.jei.api.gui.IDrawable; +import mezz.jei.api.gui.IGuiItemStackGroup; +import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.recipe.BlankRecipeCategory; +import mezz.jei.api.recipe.IRecipeWrapper; +import net.minecraft.util.StatCollector; +import techreborn.client.gui.GuiGrinder; +import techreborn.client.gui.GuiVacuumFreezer; +import techreborn.compat.jei.RecipeCategoryUids; +import techreborn.compat.jei.RecipeUtil; + +import javax.annotation.Nonnull; + +public class GrinderRecipeCategory extends BlankRecipeCategory { + private static final int[] INPUT_SLOTS = {0}; + private static final int[] OUTPUT_SLOTS = {1}; + + private final IDrawable background; + private final String title; + + public GrinderRecipeCategory(IGuiHelper guiHelper) { + background = guiHelper.createDrawable(GuiGrinder.texture, 55, 30, 82, 26); + title = StatCollector.translateToLocal("tile.techreborn.grinder.name"); + } + + @Nonnull + @Override + public String getUid() { + return RecipeCategoryUids.GRINDER; + } + + @Nonnull + @Override + public String getTitle() { + return title; + } + + @Nonnull + @Override + public IDrawable getBackground() { + return background; + } + + @Override + public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapper recipeWrapper) { + IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks(); + guiItemStacks.init(INPUT_SLOTS[0], true, 0, 3); + + guiItemStacks.init(OUTPUT_SLOTS[0], false, 60, 4); + + if (recipeWrapper instanceof GrinderRecipeWrapper) { + GrinderRecipeWrapper recipe = (GrinderRecipeWrapper) recipeWrapper; + RecipeUtil.setRecipeItems(recipeLayout, recipe, INPUT_SLOTS, OUTPUT_SLOTS, null, null); + } + } +} diff --git a/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeHandler.java b/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeHandler.java new file mode 100644 index 000000000..38d2a19ac --- /dev/null +++ b/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeHandler.java @@ -0,0 +1,42 @@ +package techreborn.compat.jei.grinder; + +import mezz.jei.api.IJeiHelpers; +import mezz.jei.api.recipe.IRecipeHandler; +import mezz.jei.api.recipe.IRecipeWrapper; +import techreborn.api.recipe.machines.GrinderRecipe; +import techreborn.api.recipe.machines.VacuumFreezerRecipe; +import techreborn.compat.jei.RecipeCategoryUids; + +import javax.annotation.Nonnull; + +public class GrinderRecipeHandler implements IRecipeHandler { + @Nonnull + private final IJeiHelpers jeiHelpers; + + public GrinderRecipeHandler(@Nonnull IJeiHelpers jeiHelpers) { + this.jeiHelpers = jeiHelpers; + } + + @Nonnull + @Override + public Class getRecipeClass() { + return GrinderRecipe.class; + } + + @Nonnull + @Override + public String getRecipeCategoryUid() { + return RecipeCategoryUids.GRINDER; + } + + @Nonnull + @Override + public IRecipeWrapper getRecipeWrapper(@Nonnull GrinderRecipe recipe) { + return new GrinderRecipeWrapper(jeiHelpers, recipe); + } + + @Override + public boolean isRecipeValid(@Nonnull GrinderRecipe recipe) { + return true; + } +} diff --git a/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeWrapper.java b/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeWrapper.java new file mode 100644 index 000000000..c0f5cf530 --- /dev/null +++ b/src/main/java/techreborn/compat/jei/grinder/GrinderRecipeWrapper.java @@ -0,0 +1,33 @@ +package techreborn.compat.jei.grinder; + +import mezz.jei.api.IGuiHelper; +import mezz.jei.api.IJeiHelpers; +import mezz.jei.api.gui.IDrawableAnimated; +import mezz.jei.api.gui.IDrawableStatic; +import net.minecraft.client.Minecraft; +import techreborn.api.recipe.machines.GrinderRecipe; +import techreborn.api.recipe.machines.VacuumFreezerRecipe; +import techreborn.client.gui.GuiGrinder; +import techreborn.client.gui.GuiVacuumFreezer; +import techreborn.compat.jei.BaseRecipeWrapper; + +import javax.annotation.Nonnull; + +public class GrinderRecipeWrapper extends BaseRecipeWrapper { + private final IDrawableAnimated progress; + + public GrinderRecipeWrapper(@Nonnull IJeiHelpers jeiHelpers, @Nonnull GrinderRecipe baseRecipe) { + super(baseRecipe); + IGuiHelper guiHelper = jeiHelpers.getGuiHelper(); + IDrawableStatic progressStatic = guiHelper.createDrawable(GuiGrinder.texture, 176, 14, 20, 11); + + int ticksPerCycle = baseRecipe.tickTime(); + this.progress = guiHelper.createAnimatedDrawable(progressStatic, ticksPerCycle, IDrawableAnimated.StartDirection.LEFT, false); + } + + @Override + public void drawAnimations(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight) { + super.drawAnimations(minecraft, recipeWidth, recipeHeight); + progress.draw(minecraft, 25, 7); + } +} diff --git a/src/main/java/techreborn/compat/jei/industrialGrinder/IndustrialGrinderRecipeCategory.java b/src/main/java/techreborn/compat/jei/industrialGrinder/IndustrialGrinderRecipeCategory.java index c400b1620..e5a429719 100644 --- a/src/main/java/techreborn/compat/jei/industrialGrinder/IndustrialGrinderRecipeCategory.java +++ b/src/main/java/techreborn/compat/jei/industrialGrinder/IndustrialGrinderRecipeCategory.java @@ -36,7 +36,7 @@ public class IndustrialGrinderRecipeCategory extends BlankRecipeCategory { @Nonnull @Override public String getUid() { - return RecipeCategoryUids.GRINDER; + return RecipeCategoryUids.INDUSTRIAL_GRINDER; } @Nonnull diff --git a/src/main/java/techreborn/compat/jei/industrialGrinder/IndustrialGrinderRecipeHandler.java b/src/main/java/techreborn/compat/jei/industrialGrinder/IndustrialGrinderRecipeHandler.java index 9e34f7f85..430f84c37 100644 --- a/src/main/java/techreborn/compat/jei/industrialGrinder/IndustrialGrinderRecipeHandler.java +++ b/src/main/java/techreborn/compat/jei/industrialGrinder/IndustrialGrinderRecipeHandler.java @@ -25,7 +25,7 @@ public class IndustrialGrinderRecipeHandler implements IRecipeHandler