Package org.jnbt

Examples of org.jnbt.CompoundTag


   * @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.
      final Map<String, Tag> newData = new LinkedHashMap<String, Tag>(originalData);
      // .get() a couple of values, just to make sure we're dealing with a
      // valid level file, here. Good for debugging, too.
View Full Code Here


   */
  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.

            /* <editor-fold defaultstate="collapsed" desc="structure">
             * Structure:
             *
             *TAG_Compound("Data"): World data.
             *  * TAG_Long("Time"): Stores the current "time of day" in ticks. There are 20 ticks per real-life second, and 24000 ticks per Minecraft day, making the day length 20 minutes. 0 appears to be sunrise, 12000 sunset and 24000 sunrise again.
             *  * TAG_Long("LastPlayed"): Stores the Unix time stamp (in milliseconds) when the player saved the game.
             *  * TAG_Compound("Player"): Player entity information. See Entity Format and Mob Entity Format for details. Has additional elements:
             *    o TAG_List("Inventory"): Each TAG_Compound in this list defines an item the player is carrying, holding, or wearing as armor.
             *      + TAG_Compound: Inventory item data
             *        # TAG_Short("id"): Item or Block ID.
             *         # TAG_Short("Damage"): The amount of wear each item has suffered. 0 means undamaged. When the Damage exceeds the item's durability, it breaks and disappears. Only tools and armor accumulate damage normally.
             *        # TAG_Byte("Count"): Number of items stacked in this inventory slot. Any item can be stacked, including tools, armor, and vehicles. Range is 1-255. Values above 127 are not displayed in-game.
             *        # TAG_Byte("Slot"): Indicates which inventory slot this item is in.
             *    o TAG_Int("Score"): Current score, doesn't appear to be implemented yet. Always 0.
             *  * TAG_Int("SpawnX"): X coordinate of the player's spawn position. Default is 0.
             *  * TAG_Int("SpawnY"): Y coordinate of the player's spawn position. Default is 64.
             *  * TAG_Int("SpawnZ"): Z coordinate of the player's spawn position. Default is 0.
             *  * TAG_Byte("SnowCovered"): 1 enables, 0 disables, see Winter Mode
             *  * TAG_Long("SizeOnDisk"): Estimated size of the entire world in bytes.
             *  * TAG_Long("RandomSeed"): Random number providing the Random Seed for the terrain.
             * </editor-fold>
             */

            //@formatter:on

      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.
      final Map<String, Tag> newData = new LinkedHashMap<String, Tag>(originalData);

      // .get() a couple of values, just to make sure we're dealing with a valid level file, here. Good for debugging, too.
      @SuppressWarnings("unused")
      final IntTag spawnX = (IntTag) newData.get("SpawnX"); // we never use these... Its only here for potential debugging.
      @SuppressWarnings("unused")
      final IntTag spawnY = (IntTag) newData.get("SpawnY"); // but whatever... so I (Morlok8k) suppressed these warnings.
      @SuppressWarnings("unused")
      final IntTag spawnZ = (IntTag) newData.get("SpawnZ"); // I don't want to remove existing code, either by myself (Morlok8k) or Corrodias

      newData.put("SpawnX", new IntTag("SpawnX", xyz.getX()));    // pulling the data out of the Coordinates,
      newData.put("SpawnY", new IntTag("SpawnY", xyz.getY()));    // and putting it into our IntTag's
      newData.put("SpawnZ", new IntTag("SpawnZ", xyz.getZ()));

      // Again, we can't modify the data map in the old Tag, so we have to make a new one.
      final CompoundTag newDataTag = new CompoundTag("Data", newData);
      final Map<String, Tag> newTopLevelMap = new HashMap<String, Tag>(1);
      newTopLevelMap.put("Data", newDataTag);
      final CompoundTag newTopLevelTag = new CompoundTag("", newTopLevelMap);

      final NBTOutputStream output = new NBTOutputStream(new FileOutputStream(level));
      output.writeTag(newTopLevelTag);
      output.close();
    } catch (final ClassCastException ex) {
View Full Code Here

      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));
        posTag.set(1, new DoubleTag("y", 120));
        posTag.set(2, new DoubleTag("z", y));
        rootMap.put("Player", new CompoundTag("Player", playerMap));
        playerMap.put("Pos", new ListTag("Pos", DoubleTag.class, posTag));
        root = new CompoundTag("Data", rootMap);
        HashMap<String, Tag> base = new HashMap<String, Tag>();
        base.put("Data", root);
        root = new CompoundTag("Base", base);
        NBTOutputStream outStream = new NBTOutputStream(new FileOutputStream(out));
        outStream.writeTag(root);
        outStream.close();
      } catch (Exception e) {
        e.printStackTrace();
View Full Code Here

    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)
View Full Code Here

TOP

Related Classes of org.jnbt.CompoundTag

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.