public static void init() { BookLoader.registerPageType(ContentMaterial.ID, ContentMaterial.class); BookLoader.registerPageType(ContentModifier.ID, ContentModifier.class); BookLoader.registerPageType(ContentModifierFortify.ID, ContentModifierFortify.class); BookLoader.registerPageType(ContentTool.ID, ContentTool.class); BookLoader.registerPageType(ContentSingleStatMultMaterial.ID, ContentSingleStatMultMaterial.class); BookLoader.registerPageType(ContentImageText2.ID, ContentImageText2.class); INSTANCE.addRepository(new FileRepository(Util.resource("book"))); INSTANCE.addTransformer(new ToolSectionTransformer()); INSTANCE.addTransformer(new MaterialSectionTransformer()); INSTANCE.addTransformer(new ModifierSectionTransformer()); INSTANCE.addTransformer(new BowMaterialSectionTransformer()); INSTANCE.addTransformer(BookTransformer.IndexTranformer()); } }
public class ItemTinkerBook extends Item { public ItemTinkerBook() { this.setCreativeTab(TinkerRegistry.tabGeneral); this.setMaxStackSize(1); } @Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack itemStack = playerIn.getHeldItem(handIn); if(worldIn.isRemote) { TinkerBook.INSTANCE.openGui(itemStack); } return new ActionResult<>(EnumActionResult.SUCCESS, itemStack); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { if(I18n.canTranslate(super.getUnlocalizedName(stack) + ".tooltip")) { tooltip.addAll(LocUtils.getTooltips(TextFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip"))); } } }
protected void processPage(BookData book, ContentListing listing, PageData page) { if(!page.getTitle().equals("hidden")) { listing.addEntry(book.translate(page.getTitle()), page); } } }
RenderHelper.disableStandardItemLighting(); int fullPageCount = book.getFullPageCount(advancementCache); if((page < fullPageCount - 1 || fullPageCount % 2 != 0) && page < fullPageCount) { drawModalRectWithCustomSizedTexture(width / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE); nextArrow.visible = page < book.getFullPageCount(advancementCache) - (book.getPageCount(advancementCache) % 2 != 0 ? 0 : 1); backArrow.visible = oldPage >= -1; nextArrow.x = width / 2 + 165; indexArrow.visible = book.findSection("index") != null && (page - 1) * 2 + 2 > book.findSection("index") .getPageCount(); public void actionPerformed(GuiButton button) { if(button instanceof GuiBookmark) { openPage(book.findPageNumber(((GuiBookmark) button).data.page, advancementCache)); int fullPageCount = book.getFullPageCount(advancementCache); if(page > fullPageCount - (fullPageCount % 2 != 0 ? 0 : 1)) { page = fullPageCount - 1; openPage(book.findPageNumber("index.page1")); PageData page = this.page == 0 ? book.findPage(0, advancementCache) : book.findPage((this.page - 1) * 2 + 1, advancementCache); page = book.findPage((this.page - 1) * 2 + 2, advancementCache);
/** * Adds a book to the loader, and returns a reference object * Be warned that the returned BookData object is not immediately populated, and is instead populated when the resources are loaded/reloaded * * @param name The name of the book, modid: will be automatically appended to the front of the name unless that is already added * @param appendIndex Whether an index should be added to the front of the book using a BookTransformer * @param appendContentTable Whether a table of contents should be added to the front of each section using a BookTransformer * @param repositories All the repositories the book will load the sections from * @return The book object, not immediately populated */ public static BookData registerBook(String name, boolean appendIndex, boolean appendContentTable, BookRepository... repositories) { BookData info = new BookData(repositories); books.put(name.contains(":") ? name : Loader.instance().activeModContainer().getModId() + ":" + name, info); if(appendIndex) { info.addTransformer(BookTransformer.IndexTranformer()); } if(appendContentTable) { info.addTransformer(BookTransformer.contentTableTransformer()); } return info; }
public PageData findPage(String location, @Nullable GuiBook.AdvancementCache advancementCache) { return findPage(findPageNumber(location, advancementCache)); }
public int findPageNumber(String location) { return findPageNumber(location, null); }
public PageData findPage(int number) { return findPage(number, null); }
public int getFirstPageNumber(SectionData section) { return getFirstPageNumber(section, null); }
public SectionData findSection(String name) { return findSection(name, null); }
public GuiBookEditor(@Nullable BookData book) { if(book == null) { book = new BookData(); } innerUi = new GuiBook(book, null); innerUi.mc = Minecraft.getMinecraft(); innerUi._setPage(-1); }
@Override public void processCommand(GuiBook book, String param) { int pageNum = book.book.findPageNumber(param); if(pageNum >= 0) { book.openPage(pageNum, returner); } } }
public PageData findPage(String location) { return findPage(location, null); }
@Override public void mouseClicked(int mouseX, int mouseY, int mouseButton) { if(mouseButton == 0 && section != null && section.isUnlocked(parent.advancementCache) && isHovered(mouseX, mouseY)) { parent.openPage(parent.book.getFirstPageNumber(section, parent.advancementCache)); } } }
public static void integrate() { INSTANCE.addRepository(new FileRepository(EnderIO.DOMAIN + ":eiobook")); INSTANCE.addTransformer(BookTransformer.IndexTranformer()); }
@Override public void transform(BookData book, SectionData data) { ContentListing listing = new ContentListing(); listing.title = book.translate(sectionName); PageData listingPage = new PageData(true); listingPage.name = sectionName; listingPage.source = data.source; listingPage.parent = data; listingPage.content = listing; data.pages.forEach(sectionPage -> processPage(book, listing, sectionPage)); if(listing.hasEntries()) { listingPage.load(); data.pages.add(0, listingPage); } }
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(@Nonnull World worldIn, @Nonnull EntityPlayer playerIn, @Nonnull EnumHand handIn) { ItemStack itemStack = playerIn.getHeldItem(handIn); if (worldIn.isRemote) { EioBook.INSTANCE.openGui(itemStack); } return new ActionResult<>(EnumActionResult.SUCCESS, itemStack); }
public GuiBook(BookData book, @Nullable ItemStack item) { this.book = book; this.item = item; this.mc = Minecraft.getMinecraft(); this.fontRenderer = mc.fontRenderer; init(); advancementCache = new AdvancementCache(); this.mc.player.connection.getAdvancementManager().setListener(advancementCache); openPage(book.findPageNumber(BookHelper.getSavedPage(item), advancementCache)); }
private void buildPages() { leftElements.clear(); rightElements.clear(); if(page == -1) { return; } if(page == 0) { PageData page = book.findPage(0, advancementCache); if(page != null) { page.content.build(book, rightElements, false); } } else { PageData leftPage = book.findPage((page - 1) * 2 + 1, advancementCache); PageData rightPage = book.findPage((page - 1) * 2 + 2, advancementCache); if(leftPage != null) { leftPage.content.build(book, leftElements, false); } if(rightPage != null) { rightPage.content.build(book, rightElements, true); } } for(BookElement element : leftElements) { element.parent = this; } for(BookElement element : rightElements) { element.parent = this; } }
@SideOnly(Side.CLIENT) public static void integrate() { TinkerBook.INSTANCE.addRepository(new FileRepository("enderio:book")); TinkerBook.INSTANCE.addTransformer(new OurBookTransformer()); }