コード例 #1
0
    @Override
    public void run() {

      for (String s : imageURLs) {
        LogHelper.info("Checking Image: " + s);
        if (!checkExistence(s)) if (downloadImage(s)) reloadRequired = true;
        if (checkExistence(s)) {
          try {
            URL url = new URL(s);
            String fileName = url.getFile();

            BufferedImage bi = ImageIO.read(new File(getImagesFolder(), fileName));
            downloadedImages.put(
                s,
                new CustomResourceLocation(
                    fileName.substring(fileName.indexOf("/") + 1), bi.getWidth(), bi.getHeight()));
          } catch (MalformedURLException e) {
            LogHelper.error("Image Read Failed");
            e.printStackTrace();
          } catch (IOException e) {
            LogHelper.error("Image Read Failed");
            e.printStackTrace();
          }
        }
      }

      isFinished = true;
    }
コード例 #2
0
  private static void addRSPack(boolean refreash) {
    File rspack = new File(getConfigFolder(), "/resources");
    if (!rspack.exists()) return;

    if (!Arrays.asList(rspack.list()).contains("pack.mcmeta")) {
      try {
        JsonWriter writer = new JsonWriter(new FileWriter(new File(rspack, "pack.mcmeta")));
        writer.beginObject();
        writer.name("pack");
        writer.beginObject();
        writer.name("pack_format").value(1);
        writer.name("description").value("Draconic Evolution GUI Images");
        writer.endObject();
        writer.endObject();
        writer.close();
      } catch (IOException e) {
        LogHelper.error("Error creating pack.mcmeta");
        e.printStackTrace();
      }
    }

    Field f =
        ReflectionHelper.findField(Minecraft.class, "defaultResourcePacks", "field_110449_ao");
    f.setAccessible(true);
    try {
      List defaultResourcePacks = (List) f.get(Minecraft.getMinecraft());
      defaultResourcePacks.add(new FolderResourcePack(rspack));

      f.set(Minecraft.getMinecraft(), defaultResourcePacks);
      LogHelper.info("RS Added");
      if (refreash) Minecraft.getMinecraft().refreshResources();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
 private static boolean checkExistence(String urlS) {
   try {
     URL url = new URL(urlS);
     String fileName = url.getFile();
     return Arrays.asList(getImagesFolder().list())
         .contains(fileName.substring(fileName.indexOf("/") + 1));
   } catch (MalformedURLException e) {
     LogHelper.error("Unable to check files existence. Invalid URL: " + urlS);
     e.printStackTrace();
     return false;
   }
 }
コード例 #4
0
    private static boolean downloadImage(String urlString) {
      try {
        URL url = new URL(urlString);
        String fileName = url.getFile();

        LogHelper.info("Downloading Image " + fileName);

        File dll = new File(getImagesFolder(), fileName);

        InputStream is = url.openStream();
        OutputStream os = new FileOutputStream(dll);

        ByteStreams.copy(is, os);

        is.close();
        os.close();

      } catch (IOException e) {
        LogHelper.error("Download Failed");
        e.printStackTrace();
        return false;
      }
      return true;
    }