Fix some bugs with the NEI Integration of the Booklet

This commit is contained in:
Ellpeck 2015-11-27 16:44:39 +01:00
parent 7cb73187c4
commit be21628161
11 changed files with 81 additions and 106 deletions

View file

@ -431,6 +431,21 @@ public class BookletUtils{
}
}
public static ArrayList<BookletPage> getPagesForStack(ItemStack stack){
ArrayList<BookletPage> possiblePages = new ArrayList<BookletPage>();
for(BookletPage page : InitBooklet.pagesWithItemStackData){
if(ItemUtil.contains(page.getItemStacksForPage(), stack, true)){
possiblePages.add(page);
}
}
return possiblePages;
}
public static BookletPage getFirstPageForStack(ItemStack stack){
ArrayList<BookletPage> pages = getPagesForStack(stack);
return pages.isEmpty() ? null : pages.get(0);
}
public static class TexturedButton extends GuiButton{
public int texturePosX;

View file

@ -16,7 +16,6 @@ import ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapterCoffee;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapterCrusher;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapterReconstructor;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch;
import ellpeck.actuallyadditions.booklet.page.*;
@ -56,7 +55,7 @@ public class InitBooklet{
//Getting Started
chapterIntro = new BookletChapter("intro", entryGettingStarted, new ItemStack(InitItems.itemLexicon), new PageTextOnly(1), new PageTextOnly(2), new PageTextOnly(3));
new BookletChapter("bookTutorial", entryGettingStarted, new ItemStack(InitItems.itemLexicon), new PageTextOnly(1), new PageTextOnly(2), new PageCrafting(3, ItemCrafting.recipeBook));
new BookletChapterReconstructor("crystals", entryGettingStarted, new ItemStack(InitBlocks.blockAtomicReconstructor), new PageTextOnly(1).addTextReplacement("<rf>", ConfigIntValues.RECONSTRUCTOR_BASE_ENERGY_USE.getValue()), new PageTextOnly(2), new PagePicture(3, "pageAtomicReconstructor", 0).setNoText(), new PageTextOnly(4), new PageCrafting(5, BlockCrafting.recipeAtomicReconstructor).setNoText(), new PageCrafting(6, ItemCrafting.recipeLens).setNoText()).setSpecial();
new BookletChapter("crystals", entryGettingStarted, new ItemStack(InitBlocks.blockAtomicReconstructor), new PageTextOnly(1).addTextReplacement("<rf>", ConfigIntValues.RECONSTRUCTOR_BASE_ENERGY_USE.getValue()), new PageTextOnly(2), new PagePicture(3, "pageAtomicReconstructor", 0).setNoText(), new PageTextOnly(4), new PageCrafting(5, BlockCrafting.recipeAtomicReconstructor).setNoText(), new PageCrafting(6, ItemCrafting.recipeLens).setNoText(), new PageCrafting(7, MiscCrafting.recipesCrystals).setNoText(), new PageCrafting(8, MiscCrafting.recipesCrystalBlocks).setNoText(), new PageReconstructor(9, ReconstructorRecipeHandler.mainPageRecipes).setNoText()).setSpecial();
new BookletChapter("coalGen", entryGettingStarted, new ItemStack(InitBlocks.blockCoalGenerator), new PageCrafting(1, BlockCrafting.recipeCoalGen).addTextReplacement("<rf>", ConfigIntValues.COAL_GEN_ENERGY_PRODUCED.getValue()));
new BookletChapter("craftingIngs", entryGettingStarted, new ItemStack(InitItems.itemMisc, 1, TheMiscItems.COIL.ordinal()), new PageTextOnly(1), new PageCrafting(2, ItemCrafting.recipeCoil).setNoText(), new PageCrafting(3, ItemCrafting.recipeCoilAdvanced).setNoText(), new PageCrafting(4, BlockCrafting.recipeCase).setNoText(), new PageCrafting(5, BlockCrafting.recipeStoneCase).setNoText(), new PageCrafting(6, BlockCrafting.recipeEnderPearlBlock).setNoText(), new PageCrafting(7, BlockCrafting.recipeEnderCase).setNoText(), new PageCrafting(8, ItemCrafting.recipeRing).setNoText(), new PageCrafting(9, ItemCrafting.recipeKnifeHandle).setNoText(), new PageCrafting(10, ItemCrafting.recipeKnifeBlade).setNoText(), new PageCrafting(11, ItemCrafting.recipeKnife).setNoText(), new PageCrafting(12, ItemCrafting.recipeDough).setNoText(), new PageCrafting(13, ItemCrafting.recipeRiceDough).setNoText(), new PageCrafting(14, BlockCrafting.recipeIronCase).setNoText()).setImportant();

View file

@ -1,52 +0,0 @@
/*
* This file ("BookletChapterReconstructor.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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015 Ellpeck
*/
package ellpeck.actuallyadditions.booklet.chapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.booklet.page.PageCrafting;
import ellpeck.actuallyadditions.booklet.page.PageReconstructor;
import ellpeck.actuallyadditions.crafting.MiscCrafting;
import ellpeck.actuallyadditions.recipe.ReconstructorRecipeHandler;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
public class BookletChapterReconstructor extends BookletChapter{
public BookletChapterReconstructor(String unlocalizedName, BookletEntry entry, ItemStack displayStack, BookletPage... pages){
super(unlocalizedName, entry, displayStack, getPages(pages));
}
@SuppressWarnings("unchecked")
private static BookletPage[] getPages(BookletPage... pages){
ArrayList<BookletPage> allPages = new ArrayList<BookletPage>();
allPages.addAll(Arrays.asList(pages));
allPages.add(new PageCrafting(allPages.size()+1, MiscCrafting.recipesCrystals){
@Override
public ItemStack[] getItemStacksForPage(){
return new ItemStack[0];
}
}.setNoText());
allPages.add(new PageCrafting(allPages.size()+1, MiscCrafting.recipesCrystalBlocks){
@Override
public ItemStack[] getItemStacksForPage(){
return new ItemStack[0];
}
}.setNoText());
allPages.add(new PageReconstructor(allPages.size()+1, ReconstructorRecipeHandler.mainPageRecipes).setNoText());
return allPages.toArray(new BookletPage[allPages.size()]);
}
}

View file

@ -14,7 +14,6 @@ import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.GuiBooklet;
import ellpeck.actuallyadditions.booklet.InitBooklet;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.util.ItemUtil;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import net.minecraft.client.Minecraft;
@ -143,17 +142,14 @@ public class BookletPage{
}
if(checkAndTransfer){
for(BookletPage page : InitBooklet.pagesWithItemStackData){
if(ItemUtil.contains(page.getItemStacksForPage(), stack, true)){
list.add(EnumChatFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe"));
BookletPage page = BookletUtils.getFirstPageForStack(stack);
if(page != null){
list.add(EnumChatFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe"));
if(mousePressed){
BookletUtils.openIndexEntry(gui, page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true);
BookletUtils.openChapter(gui, page.getChapter(), page);
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
break;
if(mousePressed){
BookletUtils.openIndexEntry(gui, page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true);
BookletUtils.openChapter(gui, page.getChapter(), page);
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
}
}

View file

@ -14,6 +14,7 @@ import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.InitBooklet;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
@ -28,6 +29,7 @@ import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class NEIBookletRecipe extends TemplateRecipeHandler implements INEIRecipeHandler{
@ -39,8 +41,8 @@ public class NEIBookletRecipe extends TemplateRecipeHandler implements INEIRecip
}
@Override
public ItemStack getStackForInfo(int page){
return ((CachedInfoStack)this.arecipes.get(page)).theStack;
public BookletPage getPageForInfo(int page){
return ((CachedInfoStack)this.arecipes.get(page)).thePage;
}
@Override
@ -53,8 +55,15 @@ public class NEIBookletRecipe extends TemplateRecipeHandler implements INEIRecip
public void loadCraftingRecipes(String outputId, Object... results){
if(outputId.equals(NAME) && getClass() == NEIBookletRecipe.class){
for(BookletPage page : InitBooklet.pagesWithItemStackData){
for(ItemStack stack : page.getItemStacksForPage()){
arecipes.add(new CachedInfoStack(stack));
ItemStack[] stacks = page.getItemStacksForPage();
//So that you don't see things like Mashed Food more than once
ArrayList<ItemStack> nonDoubleStacks = new ArrayList<ItemStack>();
for(ItemStack stack : stacks){
if(!ItemUtil.contains(nonDoubleStacks, stack, true)){
arecipes.add(new CachedInfoStack(stack, page));
nonDoubleStacks.add(stack);
}
}
}
}
@ -66,22 +75,20 @@ public class NEIBookletRecipe extends TemplateRecipeHandler implements INEIRecip
@SuppressWarnings("unchecked")
@Override
public void loadCraftingRecipes(ItemStack result){
for(BookletPage page : InitBooklet.pagesWithItemStackData){
if(ItemUtil.contains(page.getItemStacksForPage(), result, true)){
CachedInfoStack theRecipe = new CachedInfoStack(result);
arecipes.add(theRecipe);
}
ArrayList<BookletPage> allPages = BookletUtils.getPagesForStack(result);
for(BookletPage page : allPages){
CachedInfoStack theRecipe = new CachedInfoStack(result, page);
arecipes.add(theRecipe);
}
}
@SuppressWarnings("unchecked")
@Override
public void loadUsageRecipes(ItemStack ingredient){
for(BookletPage page : InitBooklet.pagesWithItemStackData){
if(ItemUtil.contains(page.getItemStacksForPage(), ingredient, true)){
CachedInfoStack theRecipe = new CachedInfoStack(ingredient);
arecipes.add(theRecipe);
}
ArrayList<BookletPage> allPages = BookletUtils.getPagesForStack(ingredient);
for(BookletPage page : allPages){
CachedInfoStack theRecipe = new CachedInfoStack(ingredient, page);
arecipes.add(theRecipe);
}
}
@ -104,19 +111,15 @@ public class NEIBookletRecipe extends TemplateRecipeHandler implements INEIRecip
GuiDraw.drawString((String)header.get(i), 0, 18+i*(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT+1), 0, false);
}
for(BookletPage page : InitBooklet.pagesWithItemStackData){
if(ItemUtil.contains(page.getItemStacksForPage(), stack.theStack, true)){
int maxLines = 6;
BookletChapter chapter = page.getChapter();
String aText = (chapter.pages[0] instanceof PagePicture && chapter.pages.length > 1 ? chapter.pages[1] : chapter.pages[0]).getText();
List text = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(aText != null ? aText : EnumChatFormatting.DARK_RED+StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".booklet.noText"), 165);
for(int i = 0; i < Math.min(maxLines, text.size()); i++){
GuiDraw.drawString(text.get(i)+(i == maxLines-1 && text.size() > maxLines ? EnumChatFormatting.RESET+""+EnumChatFormatting.BLACK+"..." : ""), 0, 18+25+i*(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT+1), 0, false);
}
break;
}
int maxLines = 5;
BookletChapter chapter = stack.thePage.getChapter();
String aText = (chapter.pages[0] instanceof PagePicture && chapter.pages.length > 1 ? chapter.pages[1] : chapter.pages[0]).getText();
List text = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(aText != null ? aText : EnumChatFormatting.DARK_RED+StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".booklet.noText"), 165);
for(int i = 0; i < Math.min(maxLines, text.size()); i++){
GuiDraw.drawString(text.get(i)+(i == maxLines-1 && text.size() > maxLines ? EnumChatFormatting.RESET+""+EnumChatFormatting.BLACK+"..." : ""), 0, 18+25+i*(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT+1), 0, false);
}
GuiDraw.drawString(EnumChatFormatting.GOLD+chapter.getLocalizedName(), 0, 95, 0, false);
GuiDraw.drawString(EnumChatFormatting.GOLD+"Page "+stack.thePage.getID(), 0, 105, 0, false);
}
}
@ -150,9 +153,11 @@ public class NEIBookletRecipe extends TemplateRecipeHandler implements INEIRecip
public class CachedInfoStack extends CachedRecipe{
public ItemStack theStack;
public BookletPage thePage;
public CachedInfoStack(ItemStack theStack){
public CachedInfoStack(ItemStack theStack, BookletPage thePage){
this.theStack = theStack;
this.thePage = thePage;
}
@Override

View file

@ -16,6 +16,8 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.blocks.InitBlocks;
import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import ellpeck.actuallyadditions.inventory.gui.GuiCoffeeMachine;
import ellpeck.actuallyadditions.items.InitItems;
@ -42,8 +44,8 @@ public class NEICoffeeMachineRecipe extends TemplateRecipeHandler implements INE
}
@Override
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockCoffeeMachine);
public BookletPage getPageForInfo(int page){
return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockCoffeeMachine));
}
@Override

View file

@ -16,6 +16,8 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.blocks.InitBlocks;
import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.items.metalists.TheMiscItems;
@ -38,8 +40,8 @@ public class NEICompostRecipe extends TemplateRecipeHandler implements INEIRecip
}
@Override
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockCompost);
public BookletPage getPageForInfo(int page){
return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockCompost));
}
@Override

View file

@ -15,6 +15,8 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.blocks.InitBlocks;
import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.inventory.gui.GuiGrinder;
import ellpeck.actuallyadditions.recipe.CrusherRecipeRegistry;
import ellpeck.actuallyadditions.util.ItemUtil;
@ -36,8 +38,8 @@ public class NEICrusherRecipe extends TemplateRecipeHandler implements INEIRecip
}
@Override
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockGrinder);
public BookletPage getPageForInfo(int page){
return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockGrinder));
}
@Override
@ -131,8 +133,8 @@ public class NEICrusherRecipe extends TemplateRecipeHandler implements INEIRecip
public static class Double extends NEICrusherRecipe{
@Override
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockGrinderDouble);
public BookletPage getPageForInfo(int page){
return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockGrinderDouble));
}
@Override

View file

@ -16,6 +16,8 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.blocks.InitBlocks;
import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.inventory.gui.GuiFurnaceDouble;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
@ -38,8 +40,8 @@ public class NEIFurnaceDoubleRecipe extends TemplateRecipeHandler implements INE
}
@Override
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockFurnaceDouble);
public BookletPage getPageForInfo(int page){
return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockFurnaceDouble));
}
@Override

View file

@ -15,6 +15,8 @@ import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.recipe.HairyBallHandler;
import ellpeck.actuallyadditions.util.ModUtil;
@ -37,8 +39,8 @@ public class NEIHairyBallRecipe extends TemplateRecipeHandler implements INEIRec
}
@Override
public ItemStack getStackForInfo(int page){
return new ItemStack(InitItems.itemHairyBall);
public BookletPage getPageForInfo(int page){
return BookletUtils.getFirstPageForStack(new ItemStack(InitItems.itemHairyBall));
}
@Override

View file

@ -16,6 +16,8 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.blocks.InitBlocks;
import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.recipe.TreasureChestHandler;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
@ -37,8 +39,8 @@ public class NEITreasureChestRecipe extends TemplateRecipeHandler implements INE
}
@Override
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockTreasureChest);
public BookletPage getPageForInfo(int page){
return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockTreasureChest));
}
@Override