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; }
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; }
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; }
@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); } }
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 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; }
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; }
@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)); } } }
@Override public void draw(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) { boolean unlocked = section.isUnlocked(parent.advancementCache); boolean hover = isHovered(mouseX, mouseY);