From e130f89296fe1e5da90bb105ca0a08e07857879a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 17 Jan 2016 01:09:36 +0100 Subject: [PATCH] Added proper JEI Handler for booklet Added RecipeWrapperWithButton to API --- .../api/ActuallyAdditionsAPI.java | 2 +- .../integration}/INEIRecipeHandler.java | 2 +- .../integration/RecipeWrapperWithButton.java | 73 +++++++++++++++++++ .../jei/booklet/BookletRecipeCategory.java | 4 +- .../mod/jei/booklet/BookletRecipeWrapper.java | 30 ++++++-- .../mod/nei/NEIBookletRecipe.java | 1 + .../mod/nei/NEICoffeeMachineRecipe.java | 1 + .../mod/nei/NEICompostRecipe.java | 1 + .../mod/nei/NEICrusherRecipe.java | 1 + .../mod/nei/NEIFurnaceDoubleRecipe.java | 1 + .../mod/nei/NEIHairyBallRecipe.java | 1 + .../mod/nei/NEIReconstructorRecipe.java | 1 + .../mod/nei/NEIScreenEvents.java | 1 + .../mod/nei/NEITreasureChestRecipe.java | 1 + 14 files changed, 109 insertions(+), 11 deletions(-) rename src/main/java/de/ellpeck/actuallyadditions/{mod/nei => api/integration}/INEIRecipeHandler.java (92%) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/api/integration/RecipeWrapperWithButton.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 9806c98aa..bd53a91e8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -28,7 +28,7 @@ public class ActuallyAdditionsAPI{ public static final String MOD_ID = "ActuallyAdditions"; public static final String API_ID = MOD_ID+"API"; - public static final String API_VERSION = "5"; + public static final String API_VERSION = "6"; public static List crusherRecipes = new ArrayList(); public static List ballOfFurReturnItems = new ArrayList(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/INEIRecipeHandler.java b/src/main/java/de/ellpeck/actuallyadditions/api/integration/INEIRecipeHandler.java similarity index 92% rename from src/main/java/de/ellpeck/actuallyadditions/mod/nei/INEIRecipeHandler.java rename to src/main/java/de/ellpeck/actuallyadditions/api/integration/INEIRecipeHandler.java index 223b8de07..97b851ef1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/INEIRecipeHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/integration/INEIRecipeHandler.java @@ -8,7 +8,7 @@ * © 2016 Ellpeck */ -package de.ellpeck.actuallyadditions.mod.nei; +package de.ellpeck.actuallyadditions.api.integration; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/integration/RecipeWrapperWithButton.java b/src/main/java/de/ellpeck/actuallyadditions/api/integration/RecipeWrapperWithButton.java new file mode 100644 index 000000000..8abd9bbce --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/api/integration/RecipeWrapperWithButton.java @@ -0,0 +1,73 @@ +/* + * This file ("RecipeWrapperWithButton.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.api.integration; + +import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; +import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; +import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet; +import de.ellpeck.actuallyadditions.mod.booklet.button.TexturedButton; +import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import de.ellpeck.actuallyadditions.mod.util.StringUtil; +import net.minecraft.client.Minecraft; + +/** + * Make a JEI Recipe Wrapper extend this to make a button show up on the page + * You still need to make it implement IRecipeWrapper! + */ +public abstract class RecipeWrapperWithButton{ + + protected TexturedButton theButton; + + public RecipeWrapperWithButton(){ + this.theButton = new TexturedButton(23782, 0, 84, 146, 154, 20, 20){ + @Override + public void drawButton(Minecraft minecraft, int x, int y){ + super.drawButton(minecraft, x, y); + if(this.visible && this.hovered){ + String text = StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe"); + Minecraft.getMinecraft().fontRendererObj.drawString(text, this.xPosition-Minecraft.getMinecraft().fontRendererObj.getStringWidth(text)-1, this.yPosition+this.height/2-Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT/2, StringUtil.DECIMAL_COLOR_WHITE, true); + } + } + }; + } + + /** + * Handles a click. Return this on IRecipeWrapper's handleClick() method + */ + public boolean handleClick(Minecraft mc, int mouseX, int mouseY){ + if(this.theButton.mousePressed(mc, mouseX, mouseY)){ + this.theButton.playPressSound(mc.getSoundHandler()); + + BookletPage page = this.getPage(); + if(page != null){ + GuiBooklet book = new GuiBooklet(Minecraft.getMinecraft().currentScreen, false, true); + Minecraft.getMinecraft().displayGuiScreen(book); + BookletUtils.openIndexEntry(book, page.getChapter().getEntry(), ActuallyAdditionsAPI.bookletEntries.indexOf(page.getChapter().getEntry())/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true); + BookletUtils.openChapter(book, page.getChapter(), page); + return true; + } + } + return false; + } + + /** + * Updates the button's rendering. Call this on IRecipeWrapper's drawInfo() method + */ + public void updateButton(Minecraft mc, int mouseX, int mouseY){ + this.theButton.drawButton(mc, mouseX, mouseY); + } + + /** + * The booklet page that will be opened when clicking the button + */ + public abstract BookletPage getPage(); +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/booklet/BookletRecipeCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/booklet/BookletRecipeCategory.java index f103cf149..fc456a852 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/booklet/BookletRecipeCategory.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/booklet/BookletRecipeCategory.java @@ -27,7 +27,7 @@ public class BookletRecipeCategory implements IRecipeCategory{ private IDrawable background; public BookletRecipeCategory(IGuiHelper helper){ - this.background = helper.createBlankDrawable(150, 256); + this.background = helper.createBlankDrawable(160, 100); } @Nonnull @@ -63,7 +63,7 @@ public class BookletRecipeCategory implements IRecipeCategory{ if(recipeWrapper instanceof BookletRecipeWrapper){ BookletRecipeWrapper wrapper = (BookletRecipeWrapper)recipeWrapper; - recipeLayout.getItemStacks().init(0, true, 62, 23); + recipeLayout.getItemStacks().init(0, true, 62, -3); recipeLayout.getItemStacks().set(0, Arrays.asList(wrapper.thePage.getItemStacksForPage())); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/booklet/BookletRecipeWrapper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/booklet/BookletRecipeWrapper.java index eca11683c..ce8124033 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/booklet/BookletRecipeWrapper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/booklet/BookletRecipeWrapper.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.jei.booklet; import com.google.common.collect.ImmutableList; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; +import de.ellpeck.actuallyadditions.api.integration.RecipeWrapperWithButton; import de.ellpeck.actuallyadditions.mod.booklet.page.PagePicture; import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; @@ -26,7 +27,7 @@ import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; -public class BookletRecipeWrapper implements IRecipeWrapper{ +public class BookletRecipeWrapper extends RecipeWrapperWithButton implements IRecipeWrapper{ public BookletPage thePage; @@ -56,22 +57,27 @@ public class BookletRecipeWrapper implements IRecipeWrapper{ @Override public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight){ - int yOffset = 30; + } + + @Override + public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){ List header = minecraft.fontRendererObj.listFormattedStringToWidth(StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".booklet.header").replaceAll("", EnumChatFormatting.BLUE+"").replaceAll("", EnumChatFormatting.BLACK+""), 150); for(int i = 0; i < header.size(); i++){ - minecraft.fontRendererObj.drawString((String)header.get(i), 0, yOffset+18+i*(minecraft.fontRendererObj.FONT_HEIGHT+1), 0, false); + minecraft.fontRendererObj.drawString((String)header.get(i), 0, 17+i*(minecraft.fontRendererObj.FONT_HEIGHT+1), 0, false); } - int maxLines = 5; + int maxLines = 4; IBookletChapter chapter = this.thePage.getChapter(); String aText = (chapter.getPages()[0] instanceof PagePicture && chapter.getPages().length > 1 ? chapter.getPages()[1] : chapter.getPages()[0]).getText(); List text = minecraft.fontRendererObj.listFormattedStringToWidth(aText != null ? aText : EnumChatFormatting.DARK_RED+StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".booklet.noText"), 150); for(int i = 0; i < Math.min(maxLines, text.size()); i++){ - minecraft.fontRendererObj.drawString(text.get(i)+(i == maxLines-1 && text.size() > maxLines ? EnumChatFormatting.RESET+""+EnumChatFormatting.BLACK+"..." : ""), 0, yOffset+18+25+i*(minecraft.fontRendererObj.FONT_HEIGHT+1), 0, false); + minecraft.fontRendererObj.drawString(text.get(i)+(i == maxLines-1 && text.size() > maxLines ? EnumChatFormatting.RESET+""+EnumChatFormatting.BLACK+"..." : ""), 0, 16+25+i*(minecraft.fontRendererObj.FONT_HEIGHT+1), 0, false); } - minecraft.fontRendererObj.drawString(EnumChatFormatting.ITALIC+chapter.getLocalizedName(), 0, yOffset+97, 0, false); - minecraft.fontRendererObj.drawString(EnumChatFormatting.ITALIC+"Page "+this.thePage.getID(), 0, yOffset+107, 0, false); + minecraft.fontRendererObj.drawString(EnumChatFormatting.ITALIC+chapter.getLocalizedName(), 25, 85, 0, false); + minecraft.fontRendererObj.drawString(EnumChatFormatting.ITALIC+"Page "+this.thePage.getID(), 25, 95, 0, false); + + this.updateButton(minecraft, mouseX, mouseY); } @Override @@ -84,4 +90,14 @@ public class BookletRecipeWrapper implements IRecipeWrapper{ 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 this.thePage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIBookletRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIBookletRecipe.java index dcffa7320..ccefcd865 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIBookletRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIBookletRecipe.java @@ -17,6 +17,7 @@ import codechicken.nei.recipe.TemplateRecipeHandler; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; import de.ellpeck.actuallyadditions.mod.booklet.page.PagePicture; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICoffeeMachineRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICoffeeMachineRecipe.java index f2adf5b5a..2bcbe51eb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICoffeeMachineRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICoffeeMachineRecipe.java @@ -17,6 +17,7 @@ import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.api.recipe.coffee.CoffeeBrewing; import de.ellpeck.actuallyadditions.api.recipe.coffee.CoffeeIngredient; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICompostRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICompostRecipe.java index fc7eab9e5..b1ab6a3af 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICompostRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICompostRecipe.java @@ -16,6 +16,7 @@ import codechicken.nei.PositionedStack; import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; import de.ellpeck.actuallyadditions.mod.items.InitItems; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICrusherRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICrusherRecipe.java index 23e12ffd9..293bb981d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICrusherRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEICrusherRecipe.java @@ -16,6 +16,7 @@ import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIFurnaceDoubleRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIFurnaceDoubleRecipe.java index fd65dcc97..c6c862a6e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIFurnaceDoubleRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIFurnaceDoubleRecipe.java @@ -16,6 +16,7 @@ import codechicken.nei.PositionedStack; import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFurnaceDouble; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIHairyBallRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIHairyBallRecipe.java index f25599559..287f8bf2c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIHairyBallRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIHairyBallRecipe.java @@ -17,6 +17,7 @@ import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.api.recipe.BallOfFurReturn; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; import de.ellpeck.actuallyadditions.mod.items.InitItems; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIReconstructorRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIReconstructorRecipe.java index 2abe18254..c2a107ee8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIReconstructorRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIReconstructorRecipe.java @@ -16,6 +16,7 @@ import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.api.recipe.LensNoneRecipe; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIScreenEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIScreenEvents.java index 99f2729ac..3cbf8c8d3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIScreenEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEIScreenEvents.java @@ -14,6 +14,7 @@ import codechicken.nei.recipe.GuiRecipe; import codechicken.nei.recipe.IRecipeHandler; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils; import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet; import de.ellpeck.actuallyadditions.mod.booklet.button.TexturedButton; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEITreasureChestRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEITreasureChestRecipe.java index 58486bd8d..c0990ff50 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEITreasureChestRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/nei/NEITreasureChestRecipe.java @@ -17,6 +17,7 @@ import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.integration.INEIRecipeHandler; import de.ellpeck.actuallyadditions.api.recipe.TreasureChestLoot; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils;