ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/jei/RecipeWrapperWithButton.java
Ellpeck f35a041a55 Booklet rework, part 1.
This is an API breaking change, by the way.
2016-11-10 19:50:01 +01:00

73 lines
2.6 KiB
Java

/*
* 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
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.jei;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.inventory.gui.TexturedButton;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import mezz.jei.api.recipe.BlankRecipeWrapper;
import net.minecraft.client.Minecraft;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
public abstract class RecipeWrapperWithButton extends BlankRecipeWrapper{
protected final TexturedButton theButton;
public RecipeWrapperWithButton(){
this.theButton = new TexturedButton(GuiBooklet.RES_LOC_GADGETS, 23782, this.getButtonX(), this.getButtonY(), 0, 0, 20, 20);
}
public abstract int getButtonX();
public abstract int getButtonY();
@Override
public boolean handleClick(Minecraft minecraft, int mouseX, int mouseY, int mouseButton){
if(this.theButton.mousePressed(minecraft, mouseX, mouseY)){
this.theButton.playPressSound(minecraft.getSoundHandler());
IBookletPage page = this.getPage();
if(page != null){
//TODO Fix this
/*GuiBooklet book = new GuiBooklet(Minecraft.getMinecraft().currentScreen, false, true);
Minecraft.getMinecraft().displayGuiScreen(book);
BookletUtils.openIndexEntry(book, page.getChapter().getEntry(), ActuallyAdditionsAPI.BOOKLET_ENTRIES.indexOf(page.getChapter().getEntry())/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true);
BookletUtils.openChapter(book, page.getChapter(), page);*/
return true;
}
}
return false;
}
public abstract IBookletPage getPage();
@Override
public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){
this.theButton.drawButton(minecraft, mouseX, mouseY);
}
@Nullable
@Override
public List<String> getTooltipStrings(int mouseX, int mouseY){
if(this.theButton.isMouseOver()){
return Collections.singletonList(StringUtil.localize("booklet."+ModUtil.MOD_ID+".clickToSeeRecipe"));
}
else{
return Collections.emptyList();
}
}
}