public int getPageCount(@Nullable GuiBook.AdvancementCache advancementCache) { int pages = 0; for(SectionData section : sections) { section.update(advancementCache); pages += section.isUnlocked(advancementCache) ? section.getPageCount() : 0; } return pages; }
public boolean isUnlocked(GuiBook.AdvancementCache advancementCache) { if(advancementCache == null || requirements == null || requirements.length == 0) { return true; } for(String achievement : requirements) { if(!requirementSatisfied(achievement, advancementCache)) { return false; } } return true; }
public String translate(String string) { return parent.translate(string); }
public SectionData findSection(String name, GuiBook.AdvancementCache advancementCache) { for(SectionData section : sections) { section.update(advancementCache); if(section.name.equals(name.toLowerCase())) { return section.isUnlocked(advancementCache) ? section : null; } } return null; }
@Override public void drawTooltips(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) { if(section != null && isHovered(mouseX, mouseY)) { List<String> text = new ArrayList<>(); text.add(section.getTitle()); if(!section.isUnlocked(parent.advancementCache)) { text.add(TextFormatting.RED + "Locked"); text.add("Requirements:"); text.addAll(Arrays.asList(section.requirements)); } drawHoveringText(text, mouseX, mouseY, fontRenderer); } }
int genPages = (int) Math.ceil(section.getPageCount() * 1.F / ENTRIES_PER_PAGE); pages[i].name = "tableofcontents" + i; TextData[] text = new TextData[i > pages.length - 1 ? ENTRIES_PER_PAGE : section .getPageCount() - (genPages - 1) * ENTRIES_PER_PAGE]; for(int j = 0; j < text.length; j++) { text[j] = new TextData((i * ENTRIES_PER_PAGE + j + 1) + ". " + section.pages.get(i * ENTRIES_PER_PAGE + j) pages[i].content = new ContentTableOfContents(i == 0 ? section.getTitle() : "", text);
SectionData error = new SectionData(); error.name = "errorenous"; PageData page = new PageData(true); section.load(); section.load(); SectionData section = new SectionData(true); section.name = "errorenous"; PageData page = new PageData(true);
public List<SectionData> getVisibleSections(GuiBook.AdvancementCache advancementCache) { List<SectionData> visible = new ArrayList<>(); for(SectionData section : sections) { if(section.isUnlocked(advancementCache) || !section.hideWhenLocked) { visible.add(section); } } return visible; }
@Override public void draw(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) { boolean unlocked = section.isUnlocked(parent.advancementCache); boolean hover = isHovered(mouseX, mouseY); int textW = fontRenderer.getStringWidth(section.getTitle()); int textX = x + WIDTH / 2 - textW / 2; int textY = y + HEIGHT - fontRenderer.FONT_HEIGHT/2; fontRenderer.drawString(section.getTitle(), textX, textY,
@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 int getFirstPageNumber(SectionData section, @Nullable GuiBook.AdvancementCache advancementCache) { int pages = 0; for(SectionData sect : sections) { sect.update(advancementCache); if(section == sect) { return section.isUnlocked(advancementCache) ? pages + 1 : -1; } if(!sect.isUnlocked(advancementCache)) { continue; } pages += sect.getPageCount(); } return -1; }
public PageData findPage(int number, @Nullable GuiBook.AdvancementCache advancementCache) { if(number < 0) { return null; } int pages = 0; for(SectionData section : sections) { section.update(advancementCache); if(!section.isUnlocked(advancementCache)) { continue; } if(pages + section.getPageCount() > number) { return section.pages.get(number - pages); } else { pages += section.getPageCount(); } } return null; }
public int findPageNumber(String location, @Nullable GuiBook.AdvancementCache advancementCache) { location = location.toLowerCase(); int pages = 0; if(!location.contains(".")) { return -1; } String sectionName = location.substring(0, location.indexOf('.')); String pageName = location.substring(location.indexOf('.') + 1); for(SectionData section : sections) { section.update(advancementCache); if(!section.isUnlocked(advancementCache)) { continue; } if(!sectionName.equals(section.name)) { pages += section.getPageCount(); continue; } for(PageData page : section.pages) { if(!pageName.equals(page.name)) { pages++; continue; } return pages + 1; } } return -1; }