2020-09-09 16:48:43 +02:00
|
|
|
package de.ellpeck.actuallyadditions.booklet.misc;
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2017-11-02 22:49:53 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-11-10 19:50:01 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
2016-11-10 21:07:15 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
2016-11-10 19:50:01 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
2016-11-11 18:55:32 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
2020-09-09 16:48:43 +02:00
|
|
|
import de.ellpeck.actuallyadditions.booklet.gui.GuiEntry;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.gui.GuiMainPage;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.gui.GuiPage;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.ItemUtil;
|
2016-11-10 21:07:15 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2016-11-10 19:50:01 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2017-11-02 22:49:53 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-11-12 15:48:24 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public final class BookletUtils {
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static IBookletPage findFirstPageForStack(ItemStack stack) {
|
|
|
|
for (IBookletPage page : ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA) {
|
2017-11-02 22:49:53 +01:00
|
|
|
List<ItemStack> stacks = NonNullList.create();
|
2016-11-11 18:55:32 +01:00
|
|
|
page.getItemStacksForPage(stacks);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (stacks != null && !stacks.isEmpty()) {
|
|
|
|
for (ItemStack pageStack : stacks) {
|
|
|
|
if (ItemUtil.areItemsEqual(pageStack, stack, true)) { return page; }
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-11-10 21:07:15 +01:00
|
|
|
|
2016-11-12 15:48:24 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static GuiPage createBookletGuiFromPage(GuiScreen previousScreen, IBookletPage page) {
|
2016-11-10 21:07:15 +01:00
|
|
|
GuiMainPage mainPage = new GuiMainPage(previousScreen);
|
|
|
|
|
|
|
|
IBookletChapter chapter = page.getChapter();
|
2016-11-12 12:26:36 +01:00
|
|
|
GuiEntry entry = new GuiEntry(previousScreen, mainPage, chapter.getEntry(), chapter, "", false);
|
2016-11-10 21:07:15 +01:00
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
return createPageGui(previousScreen, entry, page);
|
|
|
|
}
|
|
|
|
|
2016-11-12 15:48:24 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static GuiPage createPageGui(GuiScreen previousScreen, GuiBookletBase parentPage, IBookletPage page) {
|
2016-11-10 23:37:40 +01:00
|
|
|
IBookletChapter chapter = page.getChapter();
|
|
|
|
|
2016-11-10 22:06:58 +01:00
|
|
|
IBookletPage[] allPages = chapter.getAllPages();
|
2016-11-11 18:55:32 +01:00
|
|
|
int pageIndex = chapter.getPageIndex(page);
|
2016-11-10 22:06:58 +01:00
|
|
|
IBookletPage page1;
|
|
|
|
IBookletPage page2;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (page.shouldBeOnLeftSide()) {
|
2016-11-10 22:06:58 +01:00
|
|
|
page1 = page;
|
2019-05-02 09:10:29 +02:00
|
|
|
page2 = pageIndex >= allPages.length - 1 ? null : allPages[pageIndex + 1];
|
|
|
|
} else {
|
|
|
|
page1 = pageIndex <= 0 ? null : allPages[pageIndex - 1];
|
2016-11-10 22:06:58 +01:00
|
|
|
page2 = page;
|
|
|
|
}
|
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
return new GuiPage(previousScreen, parentPage, page1, page2);
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
2016-11-12 13:54:49 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static IBookletPage getBookletPageById(String id) {
|
|
|
|
if (id != null) {
|
|
|
|
for (IBookletChapter chapter : ActuallyAdditionsAPI.ALL_CHAPTERS) {
|
|
|
|
for (IBookletPage page : chapter.getAllPages()) {
|
|
|
|
if (id.equals(page.getIdentifier())) { return page; }
|
2016-11-12 13:54:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|