@Override public void load() { BookRepository repo = parent.source; if(data == null || data.isEmpty()) { return; } ResourceLocation location = repo.getResourceLocation(data); if(location != null && repo.resourceExists(location)) { ContentStructure structure = BookLoader.GSON .fromJson(repo.resourceToString(repo.getResource(location)), ContentStructure.class); structure.parent = parent; structure.load(); this.size = structure.size; this.structure = structure.structure; this.text = structure.text; } }
@Override public void load() { if(name == null) { name = "section" + parent.unnamedSectionCounter++; } name = name.toLowerCase(); if(!data.equals("no-load")) { IResource pagesInfo = source.getResource(source.getResourceLocation(data)); if(pagesInfo != null) { String data = source.resourceToString(pagesInfo); if(!data.isEmpty()) { try { pages = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(data, PageData[].class))); } catch(Exception e) { pages = new ArrayList<>(); PageData pdError = new PageData(true); pdError.name = "errorrenous"; pdError.content = new ContentError("Failed to load section " + name + ".", e); pages.add(pdError); } } } } for(PageData page : pages) { page.parent = this; page.source = source; page.load(); } icon.location = source.getResourceLocation(icon.file, true); }
public NonNullList<ItemStack> getItems() { if(itemListLocation != null && source.resourceExists(itemListLocation)) { try { ItemsList itemsList = BookLoader.GSON .fromJson(source.resourceToString(source.getResource(itemListLocation)), ItemsList.class); NonNullList<ItemStack> items = NonNullList.<ItemStack> withSize(itemsList.items.length, ItemStack.EMPTY); for(int i = 0; i < itemsList.items.length; i++) { items.set(i, itemsList.items[i].getItem()); } this.action = itemsList.action; return items; } catch(Exception ignored) { } } return NonNullList.<ItemStack> withSize(1, getItem()); }
@Override public void swap(BookRepository source, DataLocation object) { object.location = object.file == "$BLOCK_ATLAS" ? TextureMap.LOCATION_BLOCKS_TEXTURE : source .getResourceLocation(object.file, true); } }.getClass());
public abstract String resourceToString(IResource resource, boolean skipCommments); }
public abstract boolean resourceExists(ResourceLocation location);
IResource pageInfo = source.getResource(source.getResourceLocation(data)); if(pageInfo != null) { String data = source.resourceToString(pageInfo); if(!data.isEmpty()) { Class<? extends PageContent> ctype = BookLoader.getPageType(type);
@Override public void swap(BookRepository source, ItemStackData object) { object.source = source; object.itemListLocation = source.getResourceLocation(object.itemList); if(object.itemListLocation != null) { object.id = "->itemList"; } } }.getClass());
List<SectionData> repoContents = repo.getSections(); sections.addAll(repoContents); ResourceLocation appearanceLocation = repo.getResourceLocation("appearance.json"); if(repo.resourceExists(appearanceLocation)) { try { appearance = BookLoader.GSON .fromJson(repo.resourceToString(repo.getResource(appearanceLocation)), AppearanceData.class); } catch(Exception e) { e.printStackTrace(); ResourceLocation itemLinkLocation = repo.getResourceLocation("items.json"); if(repo.resourceExists(itemLinkLocation)) { try { itemLinks = new ArrayList<>(Arrays.asList(BookLoader.GSON .fromJson(repo.resourceToString(repo.getResource(itemLinkLocation)), ItemStackData.ItemLink[].class))); } catch(Exception e) { e.printStackTrace(); ResourceLocation languageLocation = repo.getResourceLocation("language.lang"); if(repo.resourceExists(languageLocation)) { try { BufferedReader br = new BufferedReader(new InputStreamReader(repo.getResource(languageLocation) .getInputStream(), "UTF-8"));
public abstract ResourceLocation getResourceLocation(String path, boolean safe);