Examples of NBTInputStream


Examples of net.lightstone.util.nbt.NBTInputStream

    }

    DataInputStream in = region.getChunkDataInputStream(regionX, regionZ);
    Chunk chunk = new Chunk(x, z);

    NBTInputStream nbt = new NBTInputStream(in, false);
    CompoundTag tag = (CompoundTag) nbt.readTag();
    Map<String, Tag> levelTags = ((CompoundTag) tag.getValue().get("Level")).getValue();

    byte[] tileData = ((ByteArrayTag) levelTags.get("Blocks")).getValue();
    chunk.setTypes(tileData);

    byte[] skyLightData = ((ByteArrayTag) levelTags.get("SkyLight")).getValue();
    byte[] blockLightData = ((ByteArrayTag) levelTags.get("BlockLight")).getValue();
    byte[] metaData = ((ByteArrayTag) levelTags.get("Data")).getValue();

    for (int cx = 0; cx < Chunk.WIDTH; cx++) {
      for (int cz = 0; cz < Chunk.HEIGHT; cz++) {
        for (int cy = 0; cy < Chunk.DEPTH; cy++) {
          boolean mostSignificantNibble = ((cx * Chunk.HEIGHT + cz) * Chunk.DEPTH + cy) % 2 == 1;
          int offset = ((cx * Chunk.HEIGHT + cz) * Chunk.DEPTH + cy) / 2;

          int skyLight, blockLight, meta;
          if (mostSignificantNibble) {
            skyLight = (skyLightData[offset] & 0xF0) >> 4;
            blockLight = (blockLightData[offset] & 0xF0) >> 4;
            meta = (metaData[offset] & 0xF0) >> 4;
          } else {
            skyLight = skyLightData[offset] & 0x0F;
            blockLight = blockLightData[offset] & 0x0F;
            meta = metaData[offset] & 0x0F;
          }

          chunk.setSkyLight(cx, cz, cy, skyLight);
          chunk.setBlockLight(cx, cz, cy, blockLight);
          chunk.setMetaData(cx, cz, cy, meta);
        }
      }
    }
    nbt.close();
    return chunk;
  }
View Full Code Here

Examples of org.jnbt.NBTInputStream

   * @throws IOException
   * @author Corrodias
   */
  protected static Coordinates getSpawn(final File level) throws IOException {
    try {
      final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
      final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
      input.close();

      final Map<String, Tag> originalData =
          ((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
      // This is our map of data. It is an unmodifiable map, for some
      // reason, so we have to make a copy.
View Full Code Here

Examples of org.jnbt.NBTInputStream

   * @author Corrodias
   */
  protected static void setSpawn(final File level, final Coordinates xyz) throws IOException {

    try {
      final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
      final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
      input.close();

      //@formatter:off

            //Note: The Following Information is Old (from 2010), compared to the Data inside a current "level.dat".
            //However, What we look at (SpawnX,Y,Z and RandomSeed) have not changed.
View Full Code Here

Examples of org.jnbt.NBTInputStream

    if (multi) {
      String outPath = file.getParent() + "/players/" + name +".dat";
      out = new File(outPath);
      backupFile(out);
      try {
        NBTInputStream inStream = new NBTInputStream(new FileInputStream(out));
        CompoundTag root = (CompoundTag)inStream.readTag();
        inStream.close();
       
        HashMap<String, Tag> rootMap = new HashMap<String, Tag>(root.getValue());
        ArrayList<Tag> posTag = new ArrayList<Tag>(((ListTag)rootMap.get("Pos")).getValue());
        posTag.set(0, new DoubleTag("x", x));
        posTag.set(1, new DoubleTag("y", 120));
        posTag.set(2, new DoubleTag("z", y));
        rootMap.put("Pos", new ListTag("Pos", DoubleTag.class, posTag));
        root = new CompoundTag("Data", rootMap);
        NBTOutputStream outStream = new NBTOutputStream(new FileOutputStream(out));
        outStream.writeTag(root);
        outStream.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
     
    } else {
      out = file;
      backupFile(out);
      try {
        NBTInputStream inStream = new NBTInputStream(new FileInputStream(out));
        CompoundTag root = (CompoundTag)(((CompoundTag)inStream.readTag()).getValue().get("Data"));
        inStream.close();
       
        HashMap<String, Tag> rootMap = new HashMap<String, Tag>(root.getValue());
        HashMap<String, Tag> playerMap = new HashMap<String, Tag>(((CompoundTag)rootMap.get("Player")).getValue());
        ArrayList<Tag> posTag = new ArrayList<Tag>(((ListTag)playerMap.get("Pos")).getValue());
        posTag.set(0, new DoubleTag("x", x));
View Full Code Here

Examples of org.jnbt.NBTInputStream

  public SaveLoader(File f) {
    file = f;
    players = new ArrayList<MapObjectPlayer>();
    back = new ArrayList<String>();
    try {
      NBTInputStream inStream = new NBTInputStream(new FileInputStream(f));
      CompoundTag root = (CompoundTag) ((CompoundTag)inStream.readTag()).getValue().get("Data");
      inStream.close();
      seed = (Long)(root.getValue().get("RandomSeed").getValue());
      if (root.getValue().get("generatorName") != null) {
        genType = Type.fromMixedCase((String)(root.getValue().get("generatorName").getValue()));
       
        if (genType == Type.CUSTOMIZED)
          generatorOptions = (String)root.getValue().get("generatorOptions").getValue();
      }
      CompoundTag playerTag = (CompoundTag)root.getValue().get("Player");
     
      File playersFolder = new File(f.getParent(), "players");
      boolean multi = (playersFolder.exists() && (playersFolder.listFiles().length > 0));
     
      if (multi)
        Log.i("Multiplayer map detected.");
      else
        Log.i("Singleplayer map detected.");
     
      if (!multi) {
        addPlayer("Player", playerTag);
      } else {
        File[] listing = playersFolder.listFiles();
        for (int i = 0; i < (listing != null ? listing.length : 0); i++) {
          if (listing[i].isFile()) {
            NBTInputStream playerInputStream = new NBTInputStream(new FileInputStream(listing[i]));
            addPlayer(listing[i].getName().split("\\.")[0], (CompoundTag) ((CompoundTag)playerInputStream.readTag()));
            playerInputStream.close();
          }
        }
       
      }
    } catch (Exception e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.