Esempio n. 1
0
 public void beforeReadEntityFromNBT(NBTTagCompound tags) {
   if (player.worldObj.isRemote) return;
   NBTTagCompound customData = new NBTTagCompound();
   try {
     // Load the data
     File file = new File(FlansModHandler.getSaveDirectory(player.worldObj), "Flan.dat");
     customData = CompressedStreamTools.readCompressed(new FileInputStream(file));
     // Fill the unlocks list
     NBTTagList unlocks = customData.getTagList("Unlocks");
     for (int i = 0; i < unlocks.tagCount(); ++i) {
       NBTTagString string = (NBTTagString) unlocks.tagAt(i);
       FlansMod.blueprintsUnlocked = new ArrayList<PlaneType>();
       FlansMod.blueprintsUnlocked.add(PlaneType.getPlane(string.toString()));
     }
     NBTTagList vehicleUnlocks = customData.getTagList("VehicleUnlocks");
     for (int i = 0; i < vehicleUnlocks.tagCount(); ++i) {
       NBTTagString string = (NBTTagString) vehicleUnlocks.tagAt(i);
       FlansMod.vehicleBlueprintsUnlocked = new ArrayList<VehicleType>();
       FlansMod.vehicleBlueprintsUnlocked.add(VehicleType.getVehicle(string.toString()));
     }
     FlansMod.doneTutorial = customData.getBoolean("DoneTutorial");
   } catch (IOException ioexception) {
     System.out.println("Failed to read data for Flan's mod. Using defaults.");
   }
 }
Esempio n. 2
0
 public NBTTagCompound loadAnim(String name) {
   File file = new File(animDirectory, name + ".dat");
   try {
     return (NBTTagCompound)
         CompressedStreamTools.readCompressed(new FileInputStream(file)).getTag("main");
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
 public static void load() {
   if (DATAFILE.exists()) {
     try {
       mainData = CompressedStreamTools.readCompressed(new FileInputStream(DATAFILE));
     } catch (FileNotFoundException e) {
       OutputHandler.SOP("Failed in reading file: " + DATAFILE.getName());
       e.printStackTrace();
     } catch (IOException e) {
       OutputHandler.SOP("Failed in reading file: " + DATAFILE.getName());
       e.printStackTrace();
     }
   } else {
     mainData = new NBTTagCompound();
     save();
   }
 }
Esempio n. 4
0
  public AnimFactory loadAnim(File file) {
    try {
      NBTTagCompound list =
          (NBTTagCompound)
              CompressedStreamTools.readCompressed(new FileInputStream(file)).getTag("main");
      if (list != null) {

        AnimFactory anim = new AnimFactory(list);
        anims.put(anim.getId(), anim);
      } else return null;
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
Esempio n. 5
0
  private static boolean isChunkSavedPopulated(World world, int chunkX, int chunkZ) {
    File saveFolder = COWorldConfig.getWorldConfig(world).dimensionDir;
    DataInputStream stream = RegionFileCache.getChunkInputStream(saveFolder, chunkX, chunkZ);

    if (stream != null) {
      try {
        NBTTagCompound ex = CompressedStreamTools.read(stream);

        if (ex.hasKey("Level") && ex.getCompoundTag("Level").getBoolean("TerrainPopulated")) {
          return true;
        }
      } catch (IOException var6) {;
      }
    }

    return false;
  }
  public static void save() {
    if (!DATAFILE.exists()) {
      DATAFILE.mkdirs();
    }

    File var1 = new File(ForgeEssentials.FEDIR, DATAFILENAME + "_tmp_.dat");
    try {
      CompressedStreamTools.writeCompressed(mainData, new FileOutputStream(var1));
    } catch (FileNotFoundException e) {
      OutputHandler.SOP("Failed in writing file: " + DATAFILE.getName());
      e.printStackTrace();
    } catch (IOException e) {
      OutputHandler.SOP("Failed in writing file: " + DATAFILE.getName());
      e.printStackTrace();
    }

    if (DATAFILE.exists()) {
      DATAFILE.delete();
    }

    var1.renameTo(DATAFILE);
  }
Esempio n. 7
0
  public void afterWriteEntityToNBT(NBTTagCompound tags) {
    if (player.worldObj.isRemote) return;
    NBTTagCompound customData = new NBTTagCompound();
    NBTTagList unlocks = new NBTTagList();
    for (PlaneType type : FlansMod.blueprintsUnlocked) {
      unlocks.appendTag(new NBTTagString("Plane", type.shortName));
    }
    customData.setTag("Unlocks", unlocks);
    NBTTagList vehicleUnlocks = new NBTTagList();
    for (VehicleType type : FlansMod.vehicleBlueprintsUnlocked) {
      vehicleUnlocks.appendTag(new NBTTagString("Vehicle", type.shortName));
    }
    customData.setTag("VehicleUnlocks", vehicleUnlocks);
    customData.setBoolean("DoneTutorial", FlansMod.doneTutorial);

    // Store the data
    try {
      File file = new File(FlansModHandler.getSaveDirectory(player.worldObj), "Flan.dat");
      CompressedStreamTools.writeCompressed(customData, new FileOutputStream(file));
    } catch (IOException ioexception) {
      ioexception.printStackTrace();
      throw new RuntimeException("Failed to create data for Flan's mod.");
    }
  }