Пример #1
0
  public static NBTTagCompound getCacheCompound() {
    File cache = null;

    try {
      cache = getCacheFile();
    } catch (IOException e) {
      e.printStackTrace();
    }

    if (cache == null) throw new RuntimeException("No cache file!");

    try {
      NBTTagCompound cmp = CompressedStreamTools.readCompressed(new FileInputStream(cache));
      return cmp;
    } catch (IOException e) {
      NBTTagCompound cmp = new NBTTagCompound();

      try {
        CompressedStreamTools.writeCompressed(cmp, new FileOutputStream(cache));
        return getCacheCompound();
      } catch (IOException e1) {
        e1.printStackTrace();
        return null;
      }
    }
  }
Пример #2
0
  public WorldInfo func_75803_c(String p_75803_1_) {
    File var2 = new File(this.field_75808_a, p_75803_1_);
    if (!var2.exists()) {
      return null;
    } else {
      File var3 = new File(var2, "level.dat");
      NBTTagCompound var4;
      NBTTagCompound var5;
      if (var3.exists()) {
        try {
          var4 = CompressedStreamTools.func_74796_a(new FileInputStream(var3));
          var5 = var4.func_74775_l("Data");
          return new WorldInfo(var5);
        } catch (Exception var7) {
          var7.printStackTrace();
        }
      }

      var3 = new File(var2, "level.dat_old");
      if (var3.exists()) {
        try {
          var4 = CompressedStreamTools.func_74796_a(new FileInputStream(var3));
          var5 = var4.func_74775_l("Data");
          return new WorldInfo(var5);
        } catch (Exception var6) {
          var6.printStackTrace();
        }
      }

      return null;
    }
  }
Пример #3
0
  @Override
  public WorldInfo d() {
    File file1 = new File(this.worldDir, "level.dat");
    NBTTagCompound nbttagcompound;
    NBTTagCompound nbttagcompound1;

    if (file1.exists()) {
      try {
        nbttagcompound = CompressedStreamTools.a((InputStream) (new FileInputStream(file1)));
        nbttagcompound1 = nbttagcompound.m("Data");
        return new WorldInfo(nbttagcompound1);
      } catch (Exception exception) {
        exception.printStackTrace();
      }
    }

    file1 = new File(this.worldDir, "level.dat_old");
    if (file1.exists()) {
      try {
        nbttagcompound = CompressedStreamTools.a((InputStream) (new FileInputStream(file1)));
        nbttagcompound1 = nbttagcompound.m("Data");
        return new WorldInfo(nbttagcompound1);
      } catch (Exception exception1) {
        exception1.printStackTrace();
      }
    }

    return null;
  }
Пример #4
0
 public static void injectNBTToFile(File file, NBTTagCompound cmp) {
   try {
     CompressedStreamTools.writeCompressed(cmp, new FileOutputStream(file));
   } catch (IOException e) {
     GuiDevTools.logThrowable(e);
   }
 }
Пример #5
0
 @Override
 public void doCommand(ItemStack duplicator, EntityPlayerMP sender, String[] arguments) {
   try {
     String name = arguments.length == 2 ? arguments[1] : sender.getCommandSenderName();
     File file =
         new File(
             DimensionManager.getCurrentSaveRootDirectory().getPath()
                 + File.separator
                 + "managers"
                 + File.separator
                 + name
                 + ".nbt");
     if (!file.exists()) {
       throw new CommandException("Couldn't access file: " + name + ".nbt");
     }
     NBTTagCompound tagCompound = CompressedStreamTools.read(file);
     duplicator.setTagCompound(unstripBaseNBT(tagCompound));
     CommandBase.getCommandSenderAsPlayer(sender)
         .addChatComponentMessage(
             new ChatComponentText(
                 LocalizationHelper.translateFormatted(
                     "stevesaddons.command.loadSuccess", name + ".nbt")));
   } catch (IOException e) {
     throw new CommandException("stevesaddons.command.loadFailed");
   }
 }
  public GenericStructureInfo structureInfoFromZip(ZipInputStream zipInputStream)
      throws StructureLoadException {
    try {
      String json = null;
      NBTTagCompound worldData = null;

      ZipEntry zipEntry;

      while ((zipEntry = zipInputStream.getNextEntry()) != null) {
        byte[] bytes = completeByteArray(zipInputStream);

        if (bytes != null) {
          if (STRUCTURE_INFO_JSON_FILENAME.equals(zipEntry.getName())) json = new String(bytes);
          else if (WORLD_DATA_NBT_FILENAME.equals(zipEntry.getName()))
            worldData = CompressedStreamTools.func_152457_a(bytes, NBTSizeTracker.field_152451_a);
        }

        zipInputStream.closeEntry();
      }
      zipInputStream.close();

      if (json == null || worldData == null)
        throw new StructureInvalidZipException(json != null, worldData != null);

      GenericStructureInfo genericStructureInfo = registry.createStructureFromJSON(json);
      genericStructureInfo.worldDataCompound = worldData;

      return genericStructureInfo;
    } catch (IOException e) {
      throw new StructureLoadException(e);
    }
  }
Пример #7
0
  public void writeToFile(boolean unloadInstances) {
    try {

      NBTTagCompound data = new NBTTagCompound();

      Collection playerDataCl = grid.values();
      Iterator it = playerDataCl.iterator();

      while (it.hasNext()) {
        BlockDataPoint bdp = (BlockDataPoint) it.next();
        data.setTag("" + bdp.hash, bdp.writeToNBT());
      }

      String saveFolder =
          CoroUtilFile.getWorldSaveFolderPath()
              + CoroUtilFile.getWorldFolderName()
              + "epoch"
              + File.separator;

      // Write out to file
      if (!(new File(saveFolder).exists())) (new File(saveFolder)).mkdirs();
      FileOutputStream fos =
          new FileOutputStream(
              saveFolder + "EpochBlockDataDim_" + world.provider.dimensionId + ".dat");
      CompressedStreamTools.writeCompressed(data, fos);
      fos.close();

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Пример #8
0
  @Override
  public void a(WorldInfo worldinfo) {
    NBTTagCompound nbttagcompound = worldinfo.a();
    NBTTagCompound nbttagcompound1 = new NBTTagCompound();

    nbttagcompound1.a("Data", (NBTBase) nbttagcompound);

    try {
      File file1 = new File(this.worldDir, "level.dat_new");
      File file2 = new File(this.worldDir, "level.dat_old");
      File file3 = new File(this.worldDir, "level.dat");

      CompressedStreamTools.a(nbttagcompound1, (OutputStream) (new FileOutputStream(file1)));
      if (file2.exists()) {
        file2.delete();
      }

      file3.renameTo(file2);
      if (file3.exists()) {
        file3.delete();
      }

      file1.renameTo(file3);
      if (file1.exists()) {
        file1.delete();
      }
    } catch (Exception exception) {
      exception.printStackTrace();
    }
  }
Пример #9
0
 @SideOnly(Side.CLIENT)
 public void func_75806_a(String p_75806_1_, String p_75806_2_) {
   File var3 = new File(this.field_75808_a, p_75806_1_);
   if (var3.exists()) {
     File var4 = new File(var3, "level.dat");
     if (var4.exists()) {
       try {
         NBTTagCompound var5 = CompressedStreamTools.func_74796_a(new FileInputStream(var4));
         NBTTagCompound var6 = var5.func_74775_l("Data");
         var6.func_74778_a("LevelName", p_75806_2_);
         CompressedStreamTools.func_74799_a(var5, new FileOutputStream(var4));
       } catch (Exception var7) {
         var7.printStackTrace();
       }
     }
   }
 }
Пример #10
0
 public static void injectNBTToFile(NBTTagCompound cmp) {
   try {
     File f = getCacheFile();
     CompressedStreamTools.writeCompressed(cmp, new FileOutputStream(f));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Пример #11
0
  public static NBTTagCompound getCacheCompound(File file) {
    if (file == null) throw new RuntimeException("No cache file!");

    try {
      NBTTagCompound cmp = CompressedStreamTools.readCompressed(new FileInputStream(file));
      return cmp;
    } catch (IOException e) {
      NBTTagCompound cmp = new NBTTagCompound();

      try {
        CompressedStreamTools.writeCompressed(cmp, new FileOutputStream(file));
        return getCacheCompound(file);
      } catch (IOException e1) {
        GuiDevTools.logThrowable(e1);
        return null;
      }
    }
  }
Пример #12
0
 public static NBTTagCompound readNBT(File file) throws IOException {
   if (!file.exists()) {
     return null;
   }
   FileInputStream in = new FileInputStream(file);
   NBTTagCompound tag;
   try {
     tag = CompressedStreamTools.readCompressed(in);
   } catch (ZipException e) {
     if (e.getMessage().equals("Not in GZIP format")) {
       tag = CompressedStreamTools.read(file);
     } else {
       throw e;
     }
   }
   in.close();
   return tag;
 }
Пример #13
0
 private static NBTTagCompound readNBT(File file) {
   try {
     NBTTagCompound nbt = CompressedStreamTools.readCompressed(new FileInputStream(file));
     return nbt;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
 public static void writeNBTTagCompound(NBTTagCompound tag, DataOutputStream data)
     throws IOException {
   if (tag == null) {
     data.writeShort(-1);
   } else {
     byte[] var3 = CompressedStreamTools.compress(tag);
     data.writeShort((short) var3.length);
     data.write(var3);
   }
 }
Пример #15
0
 @Override
 public void writeSpawnData(ByteBuf buffer) {
   try {
     byte[] b = CompressedStreamTools.compress(spell.writeToNBT());
     buffer.writeInt(b.length);
     buffer.writeBytes(b);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 public static NBTTagCompound readNBTTagCompound(DataInputStream data) throws IOException {
   short legth = data.readShort();
   if (legth < 0) {
     return null;
   } else {
     byte[] array = new byte[legth];
     data.readFully(array);
     return CompressedStreamTools.decompress(array);
   }
 }
Пример #17
0
  protected NBTTagCompound readNBTTagCompound(DataInputStream data) throws IOException {

    short length = data.readShort();

    if (length < 0) return null;
    else {
      byte[] compressed = new byte[length];
      data.readFully(compressed);
      return CompressedStreamTools.decompress(compressed);
    }
  }
Пример #18
0
  public static void readPacket(byte data[]) {
    ByteArrayInputStream stream = new ByteArrayInputStream(data);
    stream.skip(1); // data[0] identifies this as NBT-encoded BWR recipes. The rest is the NBT.

    try {
      NBTTagCompound tag = CompressedStreamTools.readCompressed(stream);
      readTag(tag);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #19
0
  protected void writeNBTTagCompound(NBTTagCompound nbttagcompound, DataOutputStream data)
      throws IOException {

    if (nbttagcompound == null) {
      data.writeShort(-1);
    } else {
      byte[] compressed = CompressedStreamTools.compress(nbttagcompound);
      data.writeShort((short) compressed.length);
      data.write(compressed);
    }
  }
Пример #20
0
  public static NBTTagCompound getNBTFromBase64(String elementString) {
    byte[] nbtBytes = DatatypeConverter.parseBase64Binary(elementString);

    try {
      return CompressedStreamTools.func_152457_a(nbtBytes, NBTSizeTracker.field_152451_a);
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
Пример #21
0
  public static String getBase64FromNBT(NBTTagCompound compound) {
    byte[] worldDataByteArray;

    try {
      worldDataByteArray = CompressedStreamTools.compress(compound);
      return DatatypeConverter.printBase64Binary(worldDataByteArray);
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
Пример #22
0
 @Override
 public void readSpawnData(ByteBuf additionalData) {
   try {
     byte[] b = new byte[additionalData.readInt()];
     additionalData.readBytes(b);
     NBTTagCompound tag = CompressedStreamTools.decompress(b);
     spell = Spell.createFromNBT(tag);
     setSpell(spell);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Пример #23
0
  public static NBTTagCompound readNBTTagCompound(ByteBuf fullBuffer) throws IOException {
    short short1 = fullBuffer.readShort(); // par0DataInput.readShort();

    if (short1 < 0) {
      return null;
    } else {
      byte[] abyte = new byte[short1];
      fullBuffer.readBytes(abyte);
      return CompressedStreamTools.func_152457_a(abyte, new NBTSizeTracker(2097152L));
      // return CompressedStreamTools.decompress(abyte);
    }
  }
Пример #24
0
 public static Schematic loadSchematic(String file, World world) {
   Schematic schematic = null;
   InputStream is =
       SchematicManager.class.getResourceAsStream(
           "/assets/" + TechWorld.ID.toLowerCase() + "/schematics/" + file + ".schematic");
   try {
     NBTTagCompound comp = CompressedStreamTools.readCompressed(is);
     schematic = Schematic.loadSchematic(comp, world);
   } catch (IOException e) {
     TechWorld.logging.severe(e.toString());
   }
   return schematic;
 }
  // api
  public PacketNEIRecipe(NBTTagCompound recipe) throws IOException {
    ByteBuf data = Unpooled.buffer();

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream outputStream = new DataOutputStream(bytes);

    data.writeInt(this.getPacketID());

    CompressedStreamTools.writeCompressed(recipe, outputStream);
    data.writeBytes(bytes.toByteArray());

    this.configureWrite(data);
  }
  public NBTTagCompound loadPlayerDataOld(String player) {
    File saveDir = this.getSaveDir();
    String filename = player;
    if (player.isEmpty()) {
      filename = "noplayername";
    }

    filename = filename + ".dat";

    File e;
    try {
      e = new File(saveDir, filename);
      if (e.exists()) {
        NBTTagCompound comp = CompressedStreamTools.readCompressed(new FileInputStream(e));
        e.delete();
        e = new File(saveDir, filename + "_old");
        if (e.exists()) {
          e.delete();
        }

        return comp;
      }
    } catch (Exception var7) {
      LogWriter.except(var7);
    }

    try {
      e = new File(saveDir, filename + "_old");
      if (e.exists()) {
        return CompressedStreamTools.readCompressed(new FileInputStream(e));
      }
    } catch (Exception var6) {
      LogWriter.except(var6);
    }

    return new NBTTagCompound();
  }
Пример #27
0
  // CanaryMod: Added player.dat by UUID getter
  public NBTTagCompound b(UUID uuid) {
    NBTTagCompound nbttagcompound = null;

    try {
      File file1 = new File(this.globalPlayerFilesDir, uuid.toString() + ".dat");

      if (file1.exists() && file1.isFile()) {
        nbttagcompound = CompressedStreamTools.a((InputStream) (new FileInputStream(file1)));
      }
    } catch (Exception exception) {
      a.warn("Failed to load player data for " + uuid.toString());
    }

    return nbttagcompound;
  }
Пример #28
0
  @RPC(RPCSide.CLIENT)
  public void downloadBlueprintToClient(BlueprintId id, byte[] data) {
    try {
      NBTTagCompound nbt = CompressedStreamTools.func_152457_a(data, NBTSizeTracker.field_152451_a);
      BlueprintBase bpt = BlueprintBase.loadBluePrint(nbt);
      bpt.setData(data);
      bpt.id = id;

      BuildCraftBuilders.clientDB.add(bpt);
      setCurrentPage(BuildCraftBuilders.clientDB.getPage(pageId));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #29
0
  // CanaryMod enable writing dat files from player name and a given base tag
  // This is a copy of this.a(EntityPlayer and might need adjustments accordingly!)
  // TODO UUID
  public void writePlayerNbt(UUID uuid, CanaryCompoundTag tag) {
    try {
      NBTTagCompound nbttagcompound = tag.getHandle();

      File file1 = new File(this.worldDir, uuid.toString() + ".dat.tmp");
      File file2 = new File(this.worldDir, uuid.toString() + ".dat");

      CompressedStreamTools.a(nbttagcompound, (OutputStream) (new FileOutputStream(file1)));
      if (file2.exists()) {
        file2.delete();
      }
      file1.renameTo(file2);
    } catch (Exception exception) {
      a.warn("Failed to save player data for " + uuid.toString());
    }
  }
Пример #30
0
  public static DataContainer readDataFromRegion(DataInputStream stream) throws IOException {
    if (stream == null) {
      return null;
    }
    NBTTagCompound data = CompressedStreamTools.read(stream);

    // Checks are based on AnvilChunkLoader#checkedReadChunkFromNBT

    if (!data.hasKey(NbtDataUtil.CHUNK_DATA_LEVEL, NbtDataUtil.TAG_COMPOUND)) {
      return null;
    }
    NBTTagCompound level = data.getCompoundTag(NbtDataUtil.CHUNK_DATA_LEVEL);
    if (!level.hasKey(NbtDataUtil.CHUNK_DATA_SECTIONS, NbtDataUtil.TAG_LIST)) {
      return null;
    }
    return NbtTranslator.getInstance().translateFrom(level);
  }