mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-26 21:09:23 +01:00
Added proper JEI Handler for booklet
Added RecipeWrapperWithButton to API
This commit is contained in:
parent
b76d96c303
commit
e130f89296
14 changed files with 109 additions and 11 deletions
|
@ -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<CrusherRecipe> crusherRecipes = new ArrayList<CrusherRecipe>();
|
||||
public static List<BallOfFurReturn> ballOfFurReturnItems = new ArrayList<BallOfFurReturn>();
|
||||
|
|
|
@ -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;
|
||||
|
|
@ -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();
|
||||
}
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("<item>", EnumChatFormatting.BLUE+"").replaceAll("<r>", 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<String> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue