2015-10-04 15:24:11 +02:00
|
|
|
/*
|
2015-12-30 22:02:15 +01:00
|
|
|
* This file ("NEIBookletRecipe.java") is part of the Actually Additions Mod for Minecraft.
|
2015-10-04 15:24:11 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-10-04 15:24:11 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-10-04 15:24:11 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.nei;
|
2015-10-04 15:24:11 +02:00
|
|
|
|
|
|
|
import codechicken.lib.gui.GuiDraw;
|
|
|
|
import codechicken.nei.PositionedStack;
|
|
|
|
import codechicken.nei.recipe.RecipeInfo;
|
|
|
|
import codechicken.nei.recipe.TemplateRecipeHandler;
|
2016-01-05 14:57:50 +01:00
|
|
|
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.booklet.INEIRecipeHandler;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.page.PagePicture;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2015-10-04 15:24:11 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import java.awt.*;
|
2015-11-27 16:44:39 +01:00
|
|
|
import java.util.ArrayList;
|
2015-10-04 15:24:11 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2015-11-27 15:22:44 +01:00
|
|
|
public class NEIBookletRecipe extends TemplateRecipeHandler implements INEIRecipeHandler{
|
2015-10-04 15:24:11 +02:00
|
|
|
|
|
|
|
public static final String NAME = "actuallyadditions.booklet";
|
|
|
|
|
2015-11-27 15:22:44 +01:00
|
|
|
public NEIBookletRecipe(){
|
2015-10-04 15:24:11 +02:00
|
|
|
RecipeInfo.setGuiOffset(this.getGuiClass(), 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-27 16:44:39 +01:00
|
|
|
public BookletPage getPageForInfo(int page){
|
|
|
|
return ((CachedInfoStack)this.arecipes.get(page)).thePage;
|
2015-10-04 15:24:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 19:55:28 +02:00
|
|
|
@Override
|
|
|
|
public void loadTransferRects(){
|
|
|
|
transferRects.add(new RecipeTransferRect(new Rectangle(0, 18, 165, Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), NAME));
|
|
|
|
}
|
|
|
|
|
2015-10-04 15:24:11 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(String outputId, Object... results){
|
2015-11-27 15:22:44 +01:00
|
|
|
if(outputId.equals(NAME) && getClass() == NEIBookletRecipe.class){
|
2016-01-05 14:57:50 +01:00
|
|
|
for(BookletPage page : ActuallyAdditionsAPI.bookletPagesWithItemStackData){
|
2015-11-27 16:44:39 +01:00
|
|
|
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);
|
|
|
|
}
|
2015-10-04 15:24:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
super.loadCraftingRecipes(outputId, results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(ItemStack result){
|
2015-11-27 16:44:39 +01:00
|
|
|
ArrayList<BookletPage> allPages = BookletUtils.getPagesForStack(result);
|
|
|
|
for(BookletPage page : allPages){
|
|
|
|
CachedInfoStack theRecipe = new CachedInfoStack(result, page);
|
|
|
|
arecipes.add(theRecipe);
|
2015-10-04 15:24:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void loadUsageRecipes(ItemStack ingredient){
|
2015-11-27 16:44:39 +01:00
|
|
|
ArrayList<BookletPage> allPages = BookletUtils.getPagesForStack(ingredient);
|
|
|
|
for(BookletPage page : allPages){
|
|
|
|
CachedInfoStack theRecipe = new CachedInfoStack(ingredient, page);
|
|
|
|
arecipes.add(theRecipe);
|
2015-10-04 15:24:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGuiTexture(){
|
|
|
|
return ModUtil.MOD_ID_LOWER+":textures/gui/guiFurnaceDouble.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOverlayIdentifier(){
|
|
|
|
return NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawExtras(int recipe){
|
|
|
|
CachedInfoStack stack = (CachedInfoStack)this.arecipes.get(recipe);
|
|
|
|
if(stack.theStack != null){
|
|
|
|
List header = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".booklet.header").replaceAll("<item>", EnumChatFormatting.BLUE+"").replaceAll("<r>", EnumChatFormatting.BLACK+""), 165);
|
|
|
|
for(int i = 0; i < header.size(); i++){
|
|
|
|
GuiDraw.drawString((String)header.get(i), 0, 18+i*(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT+1), 0, false);
|
|
|
|
}
|
|
|
|
|
2015-11-27 16:44:39 +01:00
|
|
|
int maxLines = 5;
|
2016-01-05 14:57:50 +01:00
|
|
|
IBookletChapter chapter = stack.thePage.getChapter();
|
|
|
|
String aText = (chapter.getPages()[0] instanceof PagePicture && chapter.getPages().length > 1 ? chapter.getPages()[1] : chapter.getPages()[0]).getText();
|
2015-11-27 16:44:39 +01:00
|
|
|
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);
|
2015-10-04 15:24:11 +02:00
|
|
|
}
|
2015-11-27 16:48:01 +01:00
|
|
|
GuiDraw.drawString(EnumChatFormatting.ITALIC+chapter.getLocalizedName(), 0, 97, 0, false);
|
|
|
|
GuiDraw.drawString(EnumChatFormatting.ITALIC+"Page "+stack.thePage.getID(), 0, 107, 0, false);
|
2015-10-04 15:24:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 19:55:28 +02:00
|
|
|
@Override
|
|
|
|
public Class<? extends GuiContainer> getGuiClass(){
|
2015-10-13 05:39:58 +02:00
|
|
|
return null;
|
2015-10-05 19:55:28 +02:00
|
|
|
}
|
|
|
|
|
2015-10-04 15:24:11 +02:00
|
|
|
@Override
|
|
|
|
public void drawBackground(int recipe){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawForeground(int recipe){
|
|
|
|
GL11.glColor4f(1F, 1F, 1F, 1F);
|
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
|
|
this.drawExtras(recipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int recipiesPerPage(){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getRecipeName(){
|
|
|
|
return StringUtil.localize("container.nei."+NAME+".name");
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CachedInfoStack extends CachedRecipe{
|
|
|
|
|
|
|
|
public ItemStack theStack;
|
2015-11-27 16:44:39 +01:00
|
|
|
public BookletPage thePage;
|
2015-10-04 15:24:11 +02:00
|
|
|
|
2015-11-27 16:44:39 +01:00
|
|
|
public CachedInfoStack(ItemStack theStack, BookletPage thePage){
|
2015-10-04 15:24:11 +02:00
|
|
|
this.theStack = theStack;
|
2015-11-27 16:44:39 +01:00
|
|
|
this.thePage = thePage;
|
2015-10-04 15:24:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PositionedStack getResult(){
|
|
|
|
if(this.theStack != null){
|
|
|
|
ItemStack newStack = this.theStack.copy();
|
|
|
|
newStack.stackSize = 1;
|
|
|
|
return new PositionedStack(newStack, 0, 0);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|