Added an NEI Handler for info in the booklet and removed "Press I"-Thing

This commit is contained in:
Ellpeck 2015-10-04 15:24:11 +02:00
parent f42bf35372
commit 9b850658ff
15 changed files with 197 additions and 77 deletions

View file

@ -202,7 +202,7 @@ public class GuiBooklet extends GuiScreen{
protected void mouseClicked(int par1, int par2, int par3){
this.searchField.mouseClicked(par1, par2, par3);
if(par3 == 0){
if(par3 == 0 && this.currentChapter != null){
this.mousePressed = true;
}

View file

@ -114,6 +114,7 @@ public class PageCrafting extends BookletPage{
for(int y = 0; y < height; y++){
ItemStack stack = stacks[y*width+x];
if(stack != null){
stack.stackSize = 1;
if(stack.getItemDamage() == Util.WILDCARD){
stack.setItemDamage(0);
}
@ -151,12 +152,9 @@ public class PageCrafting extends BookletPage{
@Override
public ItemStack[] getItemStacksForPage(){
ItemStack[] stacks = new ItemStack[this.recipes.length];
for(int i = 0; i < stacks.length; i++){
if(this.recipes[i] != null){
stacks[i] = this.recipes[i].getRecipeOutput();
}
if(this.recipes != null && this.recipes.length > 0){
return new ItemStack[]{this.recipes[0].getRecipeOutput()};
}
return stacks;
return null;
}
}

View file

@ -12,18 +12,15 @@ package ellpeck.actuallyadditions.event;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import ellpeck.actuallyadditions.booklet.GuiBooklet;
import ellpeck.actuallyadditions.booklet.InitBooklet;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
import ellpeck.actuallyadditions.util.*;
import ellpeck.actuallyadditions.util.KeyUtil;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.item.Item;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.input.Keyboard;
public class TooltipEvent{
@ -33,26 +30,6 @@ public class TooltipEvent{
@SuppressWarnings("unchecked")
@SubscribeEvent
public void onTooltipEvent(ItemTooltipEvent event){
//Booklet Access
if(event.itemStack != null && !(Minecraft.getMinecraft().currentScreen instanceof GuiBooklet)){
for(BookletPage page : InitBooklet.pagesWithItemStackData){
if(ItemUtil.contains(page.getItemStacksForPage(), event.itemStack, true)){
int keyCode = KeyBinds.keybindOpenBooklet.getKeyCode();
if(ConfigBoolValues.SHOW_BOOKLET_INFO.isEnabled()){
event.toolTip.add(EnumChatFormatting.GOLD+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".keyToSeeRecipe", keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE ? Keyboard.getKeyName(keyCode) : "[NONE]"));
}
if(keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE && Keyboard.isKeyDown(keyCode) && KeyUtil.isAltPressed()){
GuiBooklet book = new GuiBooklet(Minecraft.getMinecraft().currentScreen);
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
Minecraft.getMinecraft().displayGuiScreen(book);
book.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true);
book.openChapter(page.getChapter(), page);
}
break;
}
}
}
//Advanced Item Info
if(event.itemStack.getItem() != null){
if(ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()){

View file

@ -0,0 +1,167 @@
/*
* This file ("BookletInfoRecipeHandler.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.nei;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.booklet.InitBooklet;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.inventory.gui.GuiFurnaceDouble;
import ellpeck.actuallyadditions.util.ItemUtil;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
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.*;
import java.util.List;
public class BookletInfoRecipeHandler extends TemplateRecipeHandler implements INeiRecipeHandler{
public static final String NAME = "actuallyadditions.booklet";
public BookletInfoRecipeHandler(){
RecipeInfo.setGuiOffset(this.getGuiClass(), 0, 0);
}
@Override
public ItemStack getStackForInfo(int page){
return ((CachedInfoStack)this.arecipes.get(page)).theStack;
}
@SuppressWarnings("unchecked")
@Override
public void loadCraftingRecipes(String outputId, Object... results){
if(outputId.equals(NAME) && getClass() == BookletInfoRecipeHandler.class){
for(BookletPage page : InitBooklet.pagesWithItemStackData){
for(ItemStack stack : page.getItemStacksForPage()){
arecipes.add(new CachedInfoStack(stack));
}
}
}
else{
super.loadCraftingRecipes(outputId, results);
}
}
@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);
}
}
}
@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);
}
}
}
@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);
}
for(BookletPage page : InitBooklet.pagesWithItemStackData){
if(ItemUtil.contains(page.getItemStacksForPage(), stack.theStack, true)){
int maxLines = 6;
String aText = page.getChapter().pages[0].getText();
if(aText != null){
List text = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(aText, 165);
for(int i = 0; i < Math.min(maxLines, text.size()); i++){
GuiDraw.drawString(text.get(i)+(i == maxLines-1 && text.size() >= maxLines ? "..." : ""), 0, 18+25+i*(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT+1), 0, false);
}
}
}
}
}
}
@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 void loadTransferRects(){
transferRects.add(new RecipeTransferRect(new Rectangle(0, 18, 165, Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), NAME));
}
@Override
public Class<? extends GuiContainer> getGuiClass(){
return GuiFurnaceDouble.class;
}
@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;
public CachedInfoStack(ItemStack theStack){
this.theStack = theStack;
}
@Override
public PositionedStack getResult(){
if(this.theStack != null){
ItemStack newStack = this.theStack.copy();
newStack.stackSize = 1;
return new PositionedStack(newStack, 0, 0);
}
return null;
}
}
}

View file

@ -42,7 +42,7 @@ public class CoffeeMachineRecipeHandler extends TemplateRecipeHandler implements
}
@Override
public ItemStack getStackForInfo(){
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockCoffeeMachine);
}

View file

@ -38,7 +38,7 @@ public class CompostRecipeHandler extends TemplateRecipeHandler implements INeiR
}
@Override
public ItemStack getStackForInfo(){
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockCompost);
}

View file

@ -36,7 +36,7 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler implements INeiR
}
@Override
public ItemStack getStackForInfo(){
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockGrinder);
}
@ -131,7 +131,7 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler implements INeiR
public static class CrusherDoubleRecipeHandler extends CrusherRecipeHandler{
@Override
public ItemStack getStackForInfo(){
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockGrinderDouble);
}

View file

@ -38,7 +38,7 @@ public class FurnaceDoubleRecipeHandler extends TemplateRecipeHandler implements
}
@Override
public ItemStack getStackForInfo(){
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockFurnaceDouble);
}

View file

@ -36,7 +36,7 @@ public class HairyBallRecipeHandler extends TemplateRecipeHandler implements INe
}
@Override
public ItemStack getStackForInfo(){
public ItemStack getStackForInfo(int page){
//TODO Add Hairy Ball Page
return null;
}

View file

@ -14,5 +14,5 @@ import net.minecraft.item.ItemStack;
public interface INeiRecipeHandler{
ItemStack getStackForInfo();
ItemStack getStackForInfo(int page);
}

View file

@ -56,6 +56,10 @@ public class NEIActuallyAdditionsConfig implements IConfigureNEI{
API.registerRecipeHandler(coffeeMachineRecipeHandler);
API.registerUsageHandler(coffeeMachineRecipeHandler);
BookletInfoRecipeHandler bookletInfoRecipeHandler = new BookletInfoRecipeHandler();
API.registerRecipeHandler(bookletInfoRecipeHandler);
API.registerUsageHandler(bookletInfoRecipeHandler);
API.hideItem(new ItemStack(InitBlocks.blockRice));
API.hideItem(new ItemStack(InitBlocks.blockCanola));
API.hideItem(new ItemStack(InitBlocks.blockFlax));

View file

@ -38,19 +38,20 @@ public class NeiScreenEvents{
int guiLeft = (event.gui.width-xSize)/2;
int guiTop = (event.gui.height-ySize)/2;
this.neiButton = new GuiBooklet.TexturedButton(NEI_BUTTON_ID, guiLeft+xSize-24, guiTop+ySize/2-20, 146, 154, 20, 20){
this.neiButton = new GuiBooklet.TexturedButton(NEI_BUTTON_ID, guiLeft+xSize-24, guiTop+127, 146, 154, 20, 20){
@Override
public void drawButton(Minecraft minecraft, int x, int y){
super.drawButton(minecraft, x, y);
if(this.visible && this.field_146123_n){
this.drawString(Minecraft.getMinecraft().fontRenderer, StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe"), this.xPosition+this.width+5, this.yPosition+this.height/2-Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT/2, StringUtil.DECIMAL_COLOR_WHITE);
String text = StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe");
Minecraft.getMinecraft().fontRenderer.drawString(text, this.xPosition-Minecraft.getMinecraft().fontRenderer.getStringWidth(text)-1, this.yPosition+this.height/2-Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT/2, StringUtil.DECIMAL_COLOR_WHITE, true);
}
}
};
event.buttonList.add(this.neiButton);
IRecipeHandler handler = theGui.getCurrentRecipeHandlers().get(theGui.recipetype);
this.neiButton.visible = handler instanceof INeiRecipeHandler && ((INeiRecipeHandler)handler).getStackForInfo() != null;
this.neiButton.visible = handler instanceof INeiRecipeHandler && ((INeiRecipeHandler)handler).getStackForInfo(theGui.page) != null;
}
}
@ -60,16 +61,16 @@ public class NeiScreenEvents{
GuiRecipe theGui = (GuiRecipe)event.gui;
IRecipeHandler handler = theGui.getCurrentRecipeHandlers().get(theGui.recipetype);
boolean isPage = handler instanceof INeiRecipeHandler && ((INeiRecipeHandler)handler).getStackForInfo() != null;
boolean isPage = handler instanceof INeiRecipeHandler && ((INeiRecipeHandler)handler).getStackForInfo(theGui.page) != null;
this.neiButton.visible = isPage;
if(isPage && event.button.id == NEI_BUTTON_ID){
for(BookletPage page : InitBooklet.pagesWithItemStackData){
if(ItemUtil.contains(page.getItemStacksForPage(), ((INeiRecipeHandler)handler).getStackForInfo(), true)){
if(ItemUtil.contains(page.getItemStacksForPage(), ((INeiRecipeHandler)handler).getStackForInfo(theGui.page), true)){
GuiBooklet book = new GuiBooklet(Minecraft.getMinecraft().currentScreen);
Minecraft.getMinecraft().displayGuiScreen(book);
book.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true);
book.openChapter(page.getChapter(), page);
book.openChapter(page.getChapter(), page.getChapter().pages[0]);
}
}
}

View file

@ -37,7 +37,7 @@ public class TreasureChestRecipeHandler extends TemplateRecipeHandler implements
}
@Override
public ItemStack getStackForInfo(){
public ItemStack getStackForInfo(int page){
return new ItemStack(InitBlocks.blockTreasureChest);
}

View file

@ -1,25 +0,0 @@
/*
* This file ("KeyBinds.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.util;
import cpw.mods.fml.client.registry.ClientRegistry;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard;
public class KeyBinds{
public static KeyBinding keybindOpenBooklet = new KeyBinding("key."+ModUtil.MOD_ID_LOWER+".openBooklet.name", Keyboard.KEY_I, "key."+ModUtil.MOD_ID_LOWER+".category");
public static void init(){
ClientRegistry.registerKeyBinding(keybindOpenBooklet);
}
}

View file

@ -2,10 +2,6 @@
itemGroup.actuallyadditions=Actually Additions
achievement.page.actuallyadditions=Actually Additions
#Keybindings
key.actuallyadditions.category=Actually Additions
key.actuallyadditions.openBooklet.name=Open Booklet in Inventory
#Fluids
fluid.oil=Oil
fluid.canolaoil=Canola Oil
@ -24,6 +20,9 @@ container.nei.actuallyadditions.coffee.maxAmount=Max Amount
container.nei.actuallyadditions.coffee.shift=[SHIFT]!
container.nei.actuallyadditions.coffee.extra.milk=+01:00, -1 Level
container.nei.actuallyadditions.booklet.name=ActAdd Manual
container.nei.actuallyadditions.booklet.header=The <item>Actually Additions Manual<r> reads:
#Blocks
tile.actuallyadditions.blockCompost.name=Compost
tile.actuallyadditions.blockMiscOreBlackQuartz.name=Black Quartz Ore
@ -404,7 +403,6 @@ booklet.actuallyadditions.indexEntry.itemsRF.name=Items that use RF
#Booklet Info
booklet.actuallyadditions.recipeDisabled=The crafting recipe for this item is disabled in the Config File! If you're on a server, ask the server author to enable it in the config. If you're on a client, press the 'Open Config'-Button on the top right and enable the recipe!
booklet.actuallyadditions.clickToSeeRecipe=Click to see more Information
booklet.actuallyadditions.keyToSeeRecipe=Press ALT+%s to see more Information
#Booklet Chapters
booklet.actuallyadditions.chapter.intro.name=An Introduction to ActAdd