Package net.lightstone.util.nbt

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

TOP

Related Classes of net.lightstone.util.nbt.NBTInputStream

Copyright © 2018 www.massapicom. 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.