Ejemplo n.º 1
0
  private static void writeNBT(NBTTagCompound tag, File file) {
    try {
      // create file/folders if they don;t exist..
      if (!file.getParentFile().exists()) file.getParentFile().mkdirs();

      // make temp file
      File temp = new File(file.getPath() + "_tmp");
      if (temp.exists()) temp.delete();

      // write temp file
      DataOutputStream stream =
          new DataOutputStream(new GZIPOutputStream(new FileOutputStream(temp)));
      try {
        NBTBase.writeNamedTag(tag, stream);
      } finally {
        stream.close();
      }

      // change from temp to real
      if (file.exists()) {
        file.delete();
      }

      if (file.exists()) {
        throw new IOException("Failed to delete " + file);
      } else {
        temp.renameTo(file);
      }
    } catch (Exception e) {
      OutputHandler.SOP("Writing NBT to " + file + " failed");
    }
  }
Ejemplo n.º 2
0
 private static void saveWorldCompound() {
   try {
     DataOutputStream dout = new DataOutputStream(new FileOutputStream(worldSaveFile));
     NBTBase.writeNamedTag(worldCompound, dout);
     dout.close();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
 // ICLIENTSTATE
 @Override
 public void writeData(DataOutputStream data) throws IOException {
   NBTTagCompound nbt = new NBTTagCompound();
   for (int i = 0; i < fluids.length; ++i) {
     NBTTagCompound nbttagcompound = new NBTTagCompound();
     if (fluids[i] != null) nbttagcompound.setString("FluidName", fluids[i].getName());
     nbt.setTag("fluidStack[" + i + "]", nbttagcompound);
   }
   NBTBase.writeNamedTag(nbt, data);
 }