@Override public IResource getResource(ResourceLocation loc) { if(loc == null) { return null; } try { return Minecraft.getMinecraft().getResourceManager().getResource(loc); } catch(IOException e) { return null; } }
@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); }
@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); }
@Override public List<SectionData> getSections() { return new ArrayList<>(Arrays.asList(BookLoader.GSON .fromJson(resourceToString(getResource(getResourceLocation("index.json"))), SectionData[].class))); }
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 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()); }
public abstract boolean resourceExists(ResourceLocation location);
@Override public ResourceLocation getResourceLocation(String path, boolean safe) { if(path == null) { return safe ? new ResourceLocation("") : null; } if(!path.contains(":")) { String langPath = Minecraft.getMinecraft().getLanguageManager().getCurrentLanguage().getLanguageCode(); String defaultLangPath = "en_US"; ResourceLocation res = new ResourceLocation(location + "/" + langPath + "/" + path); if(resourceExists(res)) { return res; } res = new ResourceLocation(location + "/" + defaultLangPath + "/" + path); if(resourceExists(res)) { return res; } res = new ResourceLocation(location + "/" + path); if(resourceExists(res)) { return res; } return safe ? new ResourceLocation("") : null; } else { ResourceLocation res = new ResourceLocation(path); if(resourceExists(res)) { return res; } return safe ? new ResourceLocation("") : null; } }
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"));
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);
public static void integrate() { INSTANCE.addRepository(new FileRepository(EnderIO.DOMAIN + ":eiobook")); INSTANCE.addTransformer(BookTransformer.IndexTranformer()); }
@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());
@Override public boolean resourceExists(ResourceLocation location) { if(location == null) { return false; } try { Minecraft.getMinecraft().getResourceManager().getResource(location); return true; } catch(IOException e) { return false; } }
@SideOnly(Side.CLIENT) public static void integrate() { TinkerBook.INSTANCE.addRepository(new FileRepository("enderio:book")); TinkerBook.INSTANCE.addTransformer(new OurBookTransformer()); }
public abstract ResourceLocation getResourceLocation(String path, boolean safe);