From c85a3c72a1ed82b6d714f371a05a12e0b5d5e36d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 11 Nov 2016 21:07:18 +0100 Subject: [PATCH] Some more booklet work --- .../mod/booklet/gui/GuiBooklet.java | 2 +- .../mod/booklet/gui/GuiEntry.java | 27 +++++++++++++++++++ .../mod/booklet/gui/GuiMainPage.java | 11 +++----- .../mod/inventory/GuiHandler.java | 11 +++++++- .../mod/items/ItemBooklet.java | 11 ++++---- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiBooklet.java index 6dde68818..6f7744d6b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiBooklet.java @@ -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; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiEntry.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiEntry.java index 86970417f..9a731f480 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiEntry.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiEntry.java @@ -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; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiMainPage.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiMainPage.java index e7d63e050..eaca29af9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiMainPage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/gui/GuiMainPage.java @@ -32,18 +32,15 @@ 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 diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/GuiHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/GuiHandler.java index b62c92d05..29a7b81c0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/GuiHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/GuiHandler.java @@ -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: - return new GuiMainPage(null); + 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: diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java index 33236fbe5..db817c383 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java @@ -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;