Пример #1
0
  private void func_22181_a(
      File file, ArrayList arraylist, int i, int j, IProgressUpdate iprogressupdate) {
    Collections.sort(arraylist);
    byte abyte0[] = new byte[4096];
    int i1;
    for (Iterator iterator = arraylist.iterator();
        iterator.hasNext();
        iprogressupdate.setLoadingProgress(i1)) {
      ChunkFile chunkfile = (ChunkFile) iterator.next();
      int k = chunkfile.func_22323_b();
      int l = chunkfile.func_22321_c();
      RegionFile regionfile = RegionFileCache.func_22193_a(file, k, l);
      if (!regionfile.func_22202_c(k & 0x1f, l & 0x1f)) {
        try {
          DataInputStream datainputstream =
              new DataInputStream(
                  new GZIPInputStream(new FileInputStream(chunkfile.func_22324_a())));
          DataOutputStream dataoutputstream =
              regionfile.getChunkDataOutputStream(k & 0x1f, l & 0x1f);
          for (int j1 = 0; (j1 = datainputstream.read(abyte0)) != -1; ) {
            dataoutputstream.write(abyte0, 0, j1);
          }

          dataoutputstream.close();
          datainputstream.close();
        } catch (IOException ioexception) {
          ioexception.printStackTrace();
        }
      }
      i++;
      i1 = (int) Math.round((100D * (double) i) / (double) j);
    }

    RegionFileCache.func_22192_a();
  }
Пример #2
0
  /** clears region file references */
  public static synchronized void clearRegionFileReferences() {
    Iterator iterator = regionsByFilename.values().iterator();

    do {
      if (!iterator.hasNext()) {
        break;
      }

      Reference reference = (Reference) iterator.next();

      try {
        RegionFile regionfile = (RegionFile) reference.get();

        if (regionfile != null) {
          regionfile.close();
        }
      } catch (IOException ioexception) {
        ioexception.printStackTrace();
      }
    } while (true);

    regionsByFilename.clear();
  }
Пример #3
0
  private static List<Chunk> loadChunks(String arg) throws Exception {
    File region = new File(arg, "region");
    final List<Chunk> chunks = new ArrayList<>();

    for (File file : region.listFiles()) {
      if (file.getName().endsWith(".mca")) {
        final Point offset = parseMcaFileName(file.getName());

        try (RegionFile rf = new RegionFile(file)) {
          for (int z = 0; z < 32; z++) {
            for (int x = 0; x < 32; x++) {
              if (rf.hasChunk(x, z)) {
                try (NBTStreamReader sr = rf.getChunk(x, z)) {
                  final int xx = x;
                  final int zz = z;

                  new NBTWalker(sr) {
                    boolean inSections;
                    byte y;
                    byte[] blocks;

                    @Override
                    public boolean value(String name, byte value) throws Exception {
                      if ("Y".equals(name)) {
                        y = value;
                      }
                      return super.value(name, value);
                    }

                    @Override
                    public boolean value(String name, byte[] value) throws Exception {
                      if ("Blocks".equals(name)) {
                        blocks = value;
                      }
                      return true;
                    }

                    @Override
                    public boolean list(String name, int length) throws Exception {
                      inSections = "Sections".equals(name);
                      super.list(name, length);
                      return !inSections;
                    }

                    @Override
                    public boolean compound(String name) throws Exception {
                      if (!super.compound(name)) {
                        return false;
                      }

                      if (inSections) {
                        chunks.add(
                            new Chunk(
                                new Vector(offset.getX() * 32 + xx, y, offset.getY() * 32 + zz),
                                blocks));
                      }
                      return true;
                    }
                  };
                }
              }
            }
          }
        }
      }
    }

    return chunks;
  }
Пример #4
0
 /** Returns an output stream for the specified chunk. Args: worldDir, chunkX, chunkZ */
 public static DataOutputStream getChunkOutputStream(File par0File, int par1, int par2) {
   RegionFile regionfile = createOrLoadRegionFile(par0File, par1, par2);
   return regionfile.getChunkDataOutputStream(par1 & 0x1f, par2 & 0x1f);
 }
  /** copies a 32x32 chunk set from par2File to par1File, via AnvilConverterData */
  private void convertChunks(
      File par1File,
      File par2File,
      WorldChunkManager par3WorldChunkManager,
      int par4,
      int par5,
      IProgressUpdate par6IProgressUpdate) {
    try {
      String s = par2File.getName();
      RegionFile regionfile = new RegionFile(par2File);
      RegionFile regionfile1 =
          new RegionFile(
              new File(
                  par1File,
                  (new StringBuilder())
                      .append(s.substring(0, s.length() - ".mcr".length()))
                      .append(".mca")
                      .toString()));

      for (int i = 0; i < 32; i++) {
        for (int j = 0; j < 32; j++) {
          if (!regionfile.isChunkSaved(i, j) || regionfile1.isChunkSaved(i, j)) {
            continue;
          }

          DataInputStream datainputstream = regionfile.getChunkDataInputStream(i, j);

          if (datainputstream == null) {
            System.out.println("Failed to fetch input stream");
          } else {
            NBTTagCompound nbttagcompound = CompressedStreamTools.read(datainputstream);
            datainputstream.close();
            NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("Level");
            AnvilConverterData anvilconverterdata = ChunkLoader.load(nbttagcompound1);
            NBTTagCompound nbttagcompound2 = new NBTTagCompound();
            NBTTagCompound nbttagcompound3 = new NBTTagCompound();
            nbttagcompound2.setTag("Level", nbttagcompound3);
            ChunkLoader.convertToAnvilFormat(
                anvilconverterdata, nbttagcompound3, par3WorldChunkManager);
            DataOutputStream dataoutputstream = regionfile1.getChunkDataOutputStream(i, j);
            CompressedStreamTools.write(nbttagcompound2, dataoutputstream);
            dataoutputstream.close();
          }
        }

        int k = (int) Math.round((100D * (double) (par4 * 1024)) / (double) (par5 * 1024));
        int l =
            (int)
                Math.round((100D * (double) ((i + 1) * 32 + par4 * 1024)) / (double) (par5 * 1024));

        if (l > k) {
          par6IProgressUpdate.setLoadingProgress(l);
        }
      }

      regionfile.close();
      regionfile1.close();
    } catch (IOException ioexception) {
      ioexception.printStackTrace();
    }
  }