示例#1
0
  public static void registerModInJar(String modid, File jar) {
    try {
      ZipFile zipfile = new ZipFile(jar);
      Enumeration enumeration = zipfile.entries();
      while (enumeration.hasMoreElements()) {
        ZipEntry zipentry = (ZipEntry) enumeration.nextElement();
        String fileName = zipentry.getName();
        Path path1 = Paths.get(fileName);
        Path path2 = Paths.get("assets", modid, "books");

        if (path1.startsWith(path2)) {
          try {
            String json = IOUtils.toString(zipfile.getInputStream(zipentry));
            BookData data =
                BookRegistry.register(GsonClientHelper.getGson().fromJson(json, BookData.class));
            ELogger.log(
                Level.INFO,
                "Successfully loaded in the book with the unique identifier: "
                    + data.uniqueName
                    + " for the language: "
                    + data.language);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }

      zipfile.close();
    } catch (Exception e) {
    }
  }
示例#2
0
 public static void registerItemStack(String identifier, ItemStack stack) {
   if (stack == null)
     ELogger.log(
         Level.WARN,
         "A book with the identifier "
             + identifier
             + " could not be registered as the stack was null");
   else if (getDataInFirstLanguage(identifier) == null) {
     ELogger.log(
         Level.WARN,
         "A book with the identifier " + identifier + " could not be found in any language");
   } else {
     stackToIdentifier.put(stack, identifier);
     markAllLanguagesAsNoCreative(identifier);
     ELogger.log(
         Level.WARN,
         "Successfully registered "
             + stack.getDisplayName()
             + " as a book that will open the identifier "
             + identifier);
   }
 }
示例#3
0
  public static void registerModInDev(String modid, File source) {
    File path = FileHelper.getDevAssetsForModPath(source.getParentFile(), modid, "books");
    if (!path.exists()) {
      path.mkdir();
    }

    Collection<File> files = FileUtils.listFiles(path, new String[] {"json"}, true);
    for (File file : files) {
      try {
        String json = FileUtils.readFileToString(file);
        BookData data =
            BookRegistry.register(GsonClientHelper.getGson().fromJson(json, BookData.class));
        ELogger.log(
            Level.INFO,
            "Successfully loaded in the book with the unique identifier: "
                + data.uniqueName
                + " for the language: "
                + data.language);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }