From 2189dde1a092f3d611fc4586ef2041ea85f06ddf Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 17 Jan 2016 15:09:59 +0100 Subject: [PATCH] JEI Crusher --- .../mod/jei/JEIActuallyAdditionsPlugin.java | 9 +- .../coffee/CoffeeMachineRecipeWrapper.java | 16 +-- .../jei/crusher/CrusherRecipeCategory.java | 82 +++++++++++++ .../mod/jei/crusher/CrusherRecipeHandler.java | 43 +++++++ .../mod/jei/crusher/CrusherRecipeWrapper.java | 111 ++++++++++++++++++ 5 files changed, 252 insertions(+), 9 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeCategory.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeHandler.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeWrapper.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java index c5b3ac905..a89d9f1b7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java @@ -15,6 +15,8 @@ import de.ellpeck.actuallyadditions.mod.jei.booklet.BookletRecipeCategory; import de.ellpeck.actuallyadditions.mod.jei.booklet.BookletRecipeHandler; import de.ellpeck.actuallyadditions.mod.jei.coffee.CoffeeMachineRecipeCategory; import de.ellpeck.actuallyadditions.mod.jei.coffee.CoffeeMachineRecipeHandler; +import de.ellpeck.actuallyadditions.mod.jei.crusher.CrusherRecipeCategory; +import de.ellpeck.actuallyadditions.mod.jei.crusher.CrusherRecipeHandler; import mezz.jei.api.*; @JEIPlugin @@ -36,16 +38,19 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin{ public void register(IModRegistry registry){ registry.addRecipeCategories( new BookletRecipeCategory(this.helpers.getGuiHelper()), - new CoffeeMachineRecipeCategory(this.helpers.getGuiHelper()) + new CoffeeMachineRecipeCategory(this.helpers.getGuiHelper()), + new CrusherRecipeCategory(this.helpers.getGuiHelper()) ); registry.addRecipeHandlers( new BookletRecipeHandler(), - new CoffeeMachineRecipeHandler() + new CoffeeMachineRecipeHandler(), + new CrusherRecipeHandler() ); registry.addRecipes(ActuallyAdditionsAPI.bookletPagesWithItemStackData); registry.addRecipes(ActuallyAdditionsAPI.coffeeMachineIngredients); + registry.addRecipes(ActuallyAdditionsAPI.crusherRecipes); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineRecipeWrapper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineRecipeWrapper.java index 7b2215f3f..faa60310c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineRecipeWrapper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineRecipeWrapper.java @@ -72,19 +72,21 @@ public class CoffeeMachineRecipeWrapper extends RecipeWrapperWithButton implemen @Override public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight){ - if(this.theIngredient.getExtraText() != null){ - Minecraft.getMinecraft().fontRendererObj.drawString(StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".coffee.special")+":", 2, 4, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); - Minecraft.getMinecraft().fontRendererObj.drawString(this.theIngredient.getExtraText(), 2, 16, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); - } - if(this.theIngredient.maxAmplifier > 0){ - Minecraft.getMinecraft().fontRendererObj.drawString(StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".coffee.maxAmount")+": "+this.theIngredient.maxAmplifier, 2, 28, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); - } } @Override public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){ this.updateButton(minecraft, mouseX, mouseY); + + if(this.theIngredient.getExtraText() != null){ + minecraft.fontRendererObj.drawString(StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".coffee.special")+":", 2, 4, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); + minecraft.fontRendererObj.drawString(this.theIngredient.getExtraText(), 2, 16, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); + } + + if(this.theIngredient.maxAmplifier > 0){ + minecraft.fontRendererObj.drawString(StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".coffee.maxAmount")+": "+this.theIngredient.maxAmplifier, 2, 28, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); + } } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeCategory.java new file mode 100644 index 000000000..d00501956 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeCategory.java @@ -0,0 +1,82 @@ +/* + * This file ("CrusherRecipeCategor.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense/ + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.jei.crusher; + +import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import de.ellpeck.actuallyadditions.mod.util.StringUtil; +import mezz.jei.api.IGuiHelper; +import mezz.jei.api.gui.IDrawable; +import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.recipe.IRecipeCategory; +import mezz.jei.api.recipe.IRecipeWrapper; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; +import java.util.List; + +public class CrusherRecipeCategory implements IRecipeCategory{ + + public static final String NAME = "actuallyadditions.crushing"; + + private IDrawable background; + + public CrusherRecipeCategory(IGuiHelper helper){ + this.background = helper.createDrawable(AssetUtil.getGuiLocation("guiGrinder"), 60, 13, 56, 79); + } + + @Nonnull + @Override + public String getUid(){ + return NAME; + } + + @Nonnull + @Override + public String getTitle(){ + return StringUtil.localize("container.nei."+NAME+".name"); + } + + @Nonnull + @Override + public IDrawable getBackground(){ + return this.background; + } + + @Override + public void drawExtras(Minecraft minecraft){ + + } + + @Override + public void drawAnimations(Minecraft minecraft){ + + } + + @Override + public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapper recipeWrapper){ + if(recipeWrapper instanceof CrusherRecipeWrapper){ + CrusherRecipeWrapper wrapper = (CrusherRecipeWrapper)recipeWrapper; + + recipeLayout.getItemStacks().init(0, true, 19, 7); + recipeLayout.getItemStacks().set(0, wrapper.theRecipe.getRecipeInputs()); + + recipeLayout.getItemStacks().init(1, true, 7, 55); + recipeLayout.getItemStacks().set(1, wrapper.theRecipe.getRecipeOutputOnes()); + + List outputTwos = wrapper.theRecipe.getRecipeOutputTwos(); + if(outputTwos != null && !outputTwos.isEmpty()){ + recipeLayout.getItemStacks().init(2, true, 31, 55); + recipeLayout.getItemStacks().set(2, outputTwos); + } + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeHandler.java new file mode 100644 index 000000000..698e59d7a --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeHandler.java @@ -0,0 +1,43 @@ +/* + * This file ("CrusherRecipeHandler.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense/ + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.jei.crusher; + +import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; +import mezz.jei.api.recipe.IRecipeHandler; +import mezz.jei.api.recipe.IRecipeWrapper; + +import javax.annotation.Nonnull; + +public class CrusherRecipeHandler implements IRecipeHandler{ + + @Nonnull + @Override + public Class getRecipeClass(){ + return CrusherRecipe.class; + } + + @Nonnull + @Override + public String getRecipeCategoryUid(){ + return CrusherRecipeCategory.NAME; + } + + @Nonnull + @Override + public IRecipeWrapper getRecipeWrapper(@Nonnull CrusherRecipe recipe){ + return new CrusherRecipeWrapper(recipe); + } + + @Override + public boolean isRecipeValid(@Nonnull CrusherRecipe recipe){ + return true; + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeWrapper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeWrapper.java new file mode 100644 index 000000000..a668c2c1b --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeWrapper.java @@ -0,0 +1,111 @@ +/* + * This file ("CrusherRecipeWrapper.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense/ + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.jei.crusher; + +import com.google.common.collect.ImmutableList; +import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; +import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; +import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; +import de.ellpeck.actuallyadditions.mod.jei.RecipeWrapperWithButton; +import de.ellpeck.actuallyadditions.mod.util.StringUtil; +import mezz.jei.api.recipe.IRecipeWrapper; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public class CrusherRecipeWrapper extends RecipeWrapperWithButton implements IRecipeWrapper{ + + public CrusherRecipe theRecipe; + + public CrusherRecipeWrapper(CrusherRecipe recipe){ + this.theRecipe = recipe; + } + + @Override + public List getInputs(){ + return this.theRecipe.getRecipeInputs(); + } + + @Override + public List getOutputs(){ + List list = new ArrayList(); + list.addAll(this.theRecipe.getRecipeOutputOnes()); + + List outputTwos = this.theRecipe.getRecipeOutputTwos(); + if(outputTwos != null && !outputTwos.isEmpty()){ + list.addAll(outputTwos); + } + + return list; + } + + @Override + public List getFluidInputs(){ + return ImmutableList.of(); + } + + @Override + public List getFluidOutputs(){ + return ImmutableList.of(); + } + + @Override + public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight){ + + } + + @Override + public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){ + this.updateButton(minecraft, mouseX, mouseY); + + List outputTwos = this.theRecipe.getRecipeOutputTwos(); + if(outputTwos != null && !outputTwos.isEmpty()){ + minecraft.fontRendererObj.drawString(this.theRecipe.outputTwoChance+"%", 60, 60, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); + } + } + + @Override + public void drawAnimations(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight){ + + } + + @Nullable + @Override + public List getTooltipStrings(int mouseX, int mouseY){ + return null; + } + + @Override + public boolean handleClick(@Nonnull Minecraft minecraft, int mouseX, int mouseY, int mouseButton){ + return this.handleClick(minecraft, mouseX, mouseY); + } + + @Override + public BookletPage getPage(){ + return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockGrinder)); + } + + @Override + public int getButtonX(){ + return -5; + } + + @Override + public int getButtonY(){ + return 26; + } +}