Some more booklet work

This commit is contained in:
Ellpeck 2016-11-11 21:07:18 +01:00
parent 81584c2fb1
commit c85a3c72a1
5 changed files with 48 additions and 14 deletions

View file

@ -33,7 +33,7 @@ public abstract class GuiBooklet extends GuiBookletBase{
public static final ResourceLocation RES_LOC_GADGETS = AssetUtil.getBookletGuiLocation("guiBookletGadgets");
public GuiScreen previousScreen;
protected GuiBookletBase parentPage;
public GuiBookletBase parentPage;
private GuiButton buttonLeft;
private GuiButton buttonRight;

View file

@ -93,6 +93,33 @@ public class GuiEntry extends GuiBooklet{
}
@Override
public boolean hasPageLeftButton(){
return this.entryPage > 0;
}
@Override
public void onPageLeftButtonPressed(){
this.mc.displayGuiScreen(new GuiEntry(this.previousScreen, this.parentPage, this.entry, this.entryPage-1));
}
@Override
public boolean hasPageRightButton(){
if(!this.chapters.isEmpty()){
IBookletChapter lastChap = this.chapters.get(this.chapters.size()-1);
if(lastChap != null){
int lastPage = calcEntryPage(this.entry, lastChap);
return this.entryPage < lastPage;
}
}
return false;
}
@Override
public void onPageRightButtonPressed(){
this.mc.displayGuiScreen(new GuiEntry(this.previousScreen, this.parentPage, this.entry, this.entryPage+1));
}
@Override
public boolean hasBackButton(){
return true;

View file

@ -32,19 +32,16 @@ public class GuiMainPage extends GuiBooklet{
public void initGui(){
super.initGui();
for(int x = 0; x < 2; x++){
for(int y = 0; y < BUTTONS_PER_PAGE; y++){
int id = y+x*BUTTONS_PER_PAGE;
if(ActuallyAdditionsAPI.BOOKLET_ENTRIES.size() > id){
IBookletEntry entry = ActuallyAdditionsAPI.BOOKLET_ENTRIES.get(id);
this.buttonList.add(new EntryButton(id, this.guiLeft+14+x*142, this.guiTop+11+y*16, 115, 10, entry.getLocalizedNameWithFormatting(), null));
for(int i = 0; i < BUTTONS_PER_PAGE; i++){
if(ActuallyAdditionsAPI.BOOKLET_ENTRIES.size() > i){
IBookletEntry entry = ActuallyAdditionsAPI.BOOKLET_ENTRIES.get(i);
this.buttonList.add(new EntryButton(i, this.guiLeft+156, this.guiTop+11+i*16, 115, 10, entry.getLocalizedNameWithFormatting(), null));
}
else{
return;
}
}
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException{

View file

@ -13,7 +13,9 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiMainPage;
import de.ellpeck.actuallyadditions.mod.booklet.misc.BookletUtils;
import de.ellpeck.actuallyadditions.mod.inventory.gui.*;
import de.ellpeck.actuallyadditions.mod.items.ItemBooklet;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.entity.player.EntityPlayer;
@ -169,7 +171,14 @@ public class GuiHandler implements IGuiHandler{
case CLOUD:
return new GuiSmileyCloud(tile, x, y, z, world);
case BOOK:
if(ItemBooklet.forcedPage != null){
GuiBooklet gui = BookletUtils.createBookletGuiFromPage(null, ItemBooklet.forcedPage);
ItemBooklet.forcedPage = null;
return gui;
}
else{
return new GuiMainPage(null);
}
case DIRECTIONAL_BREAKER:
return new GuiDirectionalBreaker(player.inventory, tile);
case RANGED_COLLECTOR:

View file

@ -35,14 +35,15 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemBooklet extends ItemBase implements IHudDisplay{
//TODO Fix this
//@SideOnly(Side.CLIENT)
//public static EntrySet forcedEntry;
@SideOnly(Side.CLIENT)
public static IBookletPage forcedPage;
public ItemBooklet(String name){
super(name);
@ -56,11 +57,11 @@ public class ItemBooklet extends ItemBase implements IHudDisplay{
if(player.isSneaking()){
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
ItemStack blockStack = new ItemStack(block, 1, block.getMetaFromState(state));
ItemStack blockStack = new ItemStack(block, 1, block.damageDropped(state));
IBookletPage page = BookletUtils.findFirstPageForStack(blockStack);
if(page != null){
if(world.isRemote){
//forcedEntry = new EntrySet(page, page.getChapter(), page.getChapter().getEntry(), ActuallyAdditionsAPI.BOOKLET_ENTRIES.indexOf(page.getChapter().getEntry())/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1);
forcedPage = page;
}
this.onItemRightClick(stack, world, player, hand);
return EnumActionResult.SUCCESS;