コード例 #1
0
ファイル: ChestUI.cs プロジェクト: wetstreet/Theircraft
    static void SaveData()
    {
        // save to chest
        Instance.Items.Clear();
        Instance.Items.ChangeValueType(TagType.TAG_COMPOUND);

        int count = 0;

        for (int i = 46; i <= 72; i++)
        {
            InventoryItem item = InventorySystem.items[i];
            if (item.id != null)
            {
                TagNodeCompound serializeItem = new TagNodeCompound();
                serializeItem.Add("Count", (TagNodeByte)item.count);
                serializeItem.Add("Damage", (TagNodeShort)item.damage);
                serializeItem.Add("id", (TagNodeString)item.id);
                serializeItem.Add("Slot", (TagNodeByte)(i - 46));
                Instance.Items.Insert(count, serializeItem);

                InventorySystem.items[i].id     = null;
                InventorySystem.items[i].damage = 0;
                InventorySystem.items[i].count  = 0;
            }
        }
    }
コード例 #2
0
ファイル: Item.cs プロジェクト: MinedroidFTW/ForgeCraft
        public TagNodeCompound GetNBTData()
        {
            TagNodeCompound comp = new TagNodeCompound();

            comp.Add("ID", new TagNodeShort(id));
            comp.Add("Count", new TagNodeByte(count));
            comp.Add("Meta", new TagNodeShort(meta));
            comp.Add("Ench", GetEnchantmentNBT());
            return(comp);
        }
コード例 #3
0
        public bool AddTag(TagNode tag, string name)
        {
            if (_tag.ContainsKey(name))
            {
                return(false);
            }

            _tag.Add(name, tag);
            return(true);
        }
コード例 #4
0
ファイル: Item.cs プロジェクト: MinedroidFTW/ForgeCraft
        public static TagNodeList GetEnchantmentNBT(List <Enchantment> enchantments)
        {
            TagNodeCompound compound;
            TagNodeList     list = new TagNodeList(TagType.TAG_COMPOUND);

            foreach (Enchantment ench in enchantments.ToArray())
            {
                compound = new TagNodeCompound();
                compound.Add("id", new TagNodeShort(ench.id));
                compound.Add("lvl", new TagNodeShort(ench.level));
                list.Add(compound);
            }
            return(list);
        }
コード例 #5
0
        /// <summary>
        /// Builds a Level subtree from the current data.
        /// </summary>
        /// <returns>The root node of a Level subtree representing the current data.</returns>
        public virtual TagNode BuildTree()
        {
            TagNodeCompound data = new TagNodeCompound();

            data["Time"]       = new TagNodeLong(_time);
            data["LastPlayed"] = new TagNodeLong(_lastPlayed);

            if (_player != null)
            {
                data["Player"] = _player.BuildTree();
            }

            data["SpawnX"]     = new TagNodeInt(_spawnX);
            data["SpawnY"]     = new TagNodeInt(_spawnY);
            data["SpawnZ"]     = new TagNodeInt(_spawnZ);
            data["SizeOnDisk"] = new TagNodeLong(_sizeOnDisk);
            data["RandomSeed"] = new TagNodeLong(_randomSeed);

            if (_version != null && _version != 0)
            {
                data["version"] = new TagNodeInt(_version ?? 0);
            }

            if (_name != null)
            {
                data["LevelName"] = new TagNodeString(_name);
            }

            if (_raining != null)
            {
                data["raining"] = new TagNodeByte(_raining ?? 0);
            }
            if (_thundering != null)
            {
                data["thundering"] = new TagNodeByte(_thundering ?? 0);
            }
            if (_rainTime != null)
            {
                data["rainTime"] = new TagNodeInt(_rainTime ?? 0);
            }
            if (_thunderTime != null)
            {
                data["thunderTime"] = new TagNodeInt(_thunderTime ?? 0);
            }

            if (_gameType != null)
            {
                data["GameType"] = new TagNodeInt(_gameType ?? 0);
            }
            if (_mapFeatures != null)
            {
                data["MapFeatures"] = new TagNodeByte(_mapFeatures ?? 0);
            }

            TagNodeCompound tree = new TagNodeCompound();

            tree.Add("Data", data);

            return(tree);
        }
コード例 #6
0
        public override bool Process (DataNode dataNode, ConsoleOptions options)
        {
            if (options.Values.Count == 0)
                return false;

            string jsonPath = options.Values[0];
            using (FileStream stream = File.OpenWrite(jsonPath)) {
                using (StreamWriter writer = new StreamWriter(stream)) {
                    if (dataNode is TagDataNode) {
                        TagDataNode tagNode = dataNode as TagDataNode;
                        WriteNbtTag(writer, tagNode.Tag);
                    }
                    else if (dataNode is NbtFileDataNode) {
                        dataNode.Expand();
                        TagNodeCompound root = new TagNodeCompound();

                        foreach (DataNode child in dataNode.Nodes) {
                            TagDataNode childTagNode = child as TagDataNode;
                            if (childTagNode == null)
                                continue;

                            if (childTagNode.Tag != null)
                                root.Add(childTagNode.NodeName, childTagNode.Tag);
                        }

                        WriteNbtTag(writer, root);
                    }
                }
            }

            return true;
        }
コード例 #7
0
ファイル: AnvilChunk.cs プロジェクト: IAAA-Lab/EINA-TO-NBT
        public TagNode BuildTree()
        {
            TagNodeCompound level     = _tree.Root["Level"] as TagNodeCompound;
            TagNodeCompound levelCopy = new TagNodeCompound();

            foreach (KeyValuePair <string, TagNode> node in level)
            {
                levelCopy.Add(node.Key, node.Value);
            }

            TagNodeList sections = new TagNodeList(TagType.TAG_COMPOUND);

            for (int i = 0; i < _sections.Length; i++)
            {
                if (ShouldIncludeSection(_sections[i]))
                {
                    sections.Add(_sections[i].BuildTree());
                }
            }

            levelCopy["Sections"] = sections;

            if (_tileTicks.Count == 0)
            {
                levelCopy.Remove("TileTicks");
            }

            return(levelCopy);
        }
コード例 #8
0
    public static void SaveData(TagNodeList Inventory)
    {
        Inventory.Clear();
        Inventory.ChangeValueType(TagType.TAG_COMPOUND);

        int count = 0;

        for (int i = 0; i < 36; i++)
        {
            InventoryItem item = items[i];
            if (item.id != null)
            {
                TagNodeCompound serializeItem = new TagNodeCompound();
                serializeItem.Add("Count", (TagNodeByte)item.count);
                serializeItem.Add("Damage", (TagNodeShort)item.damage);
                serializeItem.Add("id", (TagNodeString)item.id);
                serializeItem.Add("Slot", (TagNodeByte)i);
                Inventory.Insert(count, serializeItem);
            }
        }
    }
コード例 #9
0
ファイル: AnvilSection.cs プロジェクト: hach-que/Substrate
        private void BuildNbtTree()
        {
            int elements3 = XDIM * YDIM * ZDIM;

            TagNodeByteArray blocks     = new TagNodeByteArray(new byte[elements3]);
            TagNodeByteArray data       = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray skyLight   = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray blockLight = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray addBlocks  = new TagNodeByteArray(new byte[elements3 >> 1]);

            _blocks     = new YZXByteArray(XDIM, YDIM, ZDIM, blocks);
            _data       = new YZXNibbleArray(XDIM, YDIM, ZDIM, data);
            _skyLight   = new YZXNibbleArray(XDIM, YDIM, ZDIM, skyLight);
            _blockLight = new YZXNibbleArray(XDIM, YDIM, ZDIM, blockLight);
            _addBlocks  = new YZXNibbleArray(XDIM, YDIM, ZDIM, addBlocks);

            TagNodeCompound tree = new TagNodeCompound();

            tree.Add("Y", new TagNodeByte(_y));
            tree.Add("Blocks", blocks);
            tree.Add("Data", data);
            tree.Add("SkyLight", skyLight);
            tree.Add("BlockLight", blockLight);
            tree.Add("AddBlocks", addBlocks);

            _tree = tree;
        }
コード例 #10
0
        public static byte[] SerializeNode (TagNode node)
        {
            TagNodeCompound root = new TagNodeCompound();
            root.Add("root", node);
            NbtTree tree = new NbtTree(root);

            using (MemoryStream ms = new MemoryStream()) {
                tree.WriteTo(ms);
                byte[] data = new byte[ms.Length];
                Array.Copy(ms.GetBuffer(), data, ms.Length);

                return data;
            }
        }
コード例 #11
0
        public static byte[] SerializeNode(TagNode node)
        {
            TagNodeCompound root = new TagNodeCompound();

            root.Add("root", node);
            NbtTree tree = new NbtTree(root);

            using (MemoryStream ms = new MemoryStream()) {
                tree.WriteTo(ms);
                byte[] data = new byte[ms.Length];
                Array.Copy(ms.GetBuffer(), data, ms.Length);

                return(data);
            }
        }
コード例 #12
0
ファイル: AnvilSection.cs プロジェクト: hach-que/Substrate
        public TagNode BuildTree()
        {
            TagNodeCompound copy = new TagNodeCompound();

            foreach (KeyValuePair <string, TagNode> node in _tree)
            {
                copy.Add(node.Key, node.Value);
            }

            if (CheckAddBlocksEmpty())
            {
                copy.Remove("AddBlocks");
            }

            return(copy);
        }
コード例 #13
0
ファイル: JsonOperation.cs プロジェクト: Faustvii/NBTExplorer
        public override bool Process(DataNode dataNode, ConsoleOptions options)
        {
            if (options.Values.Count == 0)
            {
                return(false);
            }

            var jsonPath = options.Values[0];

            using (var stream = File.OpenWrite(jsonPath))
            {
                using (var writer = new StreamWriter(stream))
                {
                    if (dataNode is TagDataNode)
                    {
                        var tagNode = dataNode as TagDataNode;
                        WriteNbtTag(writer, tagNode.Tag);
                    }
                    else if (dataNode is NbtFileDataNode)
                    {
                        dataNode.Expand();
                        var root = new TagNodeCompound();

                        foreach (var child in dataNode.Nodes)
                        {
                            var childTagNode = child as TagDataNode;
                            if (childTagNode == null)
                            {
                                continue;
                            }

                            if (childTagNode.Tag != null)
                            {
                                root.Add(childTagNode.NodeName, childTagNode.Tag);
                            }
                        }

                        WriteNbtTag(writer, root);
                    }
                }
            }

            return(true);
        }
コード例 #14
0
ファイル: Map.cs プロジェクト: whatupdave/Substrate
        /// <summary>
        /// Builds a Map subtree from the current data.
        /// </summary>
        /// <returns>The root node of a Map subtree representing the current data.</returns>
        public virtual TagNode BuildTree()
        {
            TagNodeCompound data = new TagNodeCompound();

            data["scale"]     = new TagNodeByte(_scale);
            data["dimension"] = new TagNodeByte(_dimension);
            data["height"]    = new TagNodeShort(_height);
            data["width"]     = new TagNodeShort(_width);
            data["xCenter"]   = new TagNodeInt(_x);
            data["zCenter"]   = new TagNodeInt(_z);

            data["colors"] = new TagNodeByteArray(_colors);

            if (_source != null)
            {
                data.MergeFrom(_source);
            }

            TagNodeCompound tree = new TagNodeCompound();

            tree.Add("data", data);

            return(tree);
        }
コード例 #15
0
        /// <inheritdoc/>
        public TagNode BuildTree()
        {
            TagNodeCompound tree = new TagNodeCompound();

            tree["id"]     = new TagNodeShort(_id);
            tree["Count"]  = new TagNodeByte(_count);
            tree["Damage"] = new TagNodeShort(_damage);

            TagNodeCompound tagtree = new TagNodeCompound();

            if (_enchantments.Count > 0)
            {
                TagNodeList enchList = new TagNodeList(TagType.TAG_COMPOUND);
                foreach (Enchantment e in _enchantments)
                {
                    enchList.Add(e.BuildTree());
                }

                tagtree["ench"] = enchList;

                if (_source != null && _source.ContainsKey("tag"))
                {
                    tagtree.MergeFrom(_source["tag"].ToTagCompound());
                }
            }
            if (_storedEnchantments.Count > 0)
            {
                TagNodeList storedEnchList = new TagNodeList(TagType.TAG_COMPOUND);
                foreach (Enchantment e in _storedEnchantments)
                {
                    storedEnchList.Add(e.BuildTree());
                }

                tagtree["StoredEnchantments"] = storedEnchList;

                if (_source != null && _source.ContainsKey("tag"))
                {
                    tagtree.MergeFrom(_source["tag"].ToTagCompound());
                }
            }

            if (_name != null || _lore != null || _color != 0)
            {
                TagNodeCompound displayTag = new TagNodeCompound();
                if (_color != 0)
                {
                    displayTag.Add("color", new TagNodeInt(_color));
                }
                if (_name != null)
                {
                    displayTag.Add("Name", new TagNodeString(_name));
                }
                if (_lore != null)
                {
                    List <TagNode> LoreList = new List <TagNode>();
                    string[]       lores    = _lore.Split('\n');
                    foreach (string lore in lores)
                    {
                        LoreList.Add(new TagNodeString(lore));
                    }
                    displayTag.Add("Lore", new TagNodeList(TagType.TAG_STRING, LoreList));
                }
                tagtree["display"] = displayTag;
            }

            if (tagtree.Count > 0)
            {
                tree["tag"] = tagtree;
            }

            if (_source != null)
            {
                tree.MergeFrom(_source);
            }

            return(tree);
        }
コード例 #16
0
        /// <summary>
        /// Builds a Level subtree from the current data.
        /// </summary>
        /// <returns>The root node of a Level subtree representing the current data.</returns>
        public virtual TagNode BuildTree()
        {
            TagNodeCompound data = new TagNodeCompound();

            data["Time"]       = new TagNodeLong(_time);
            data["LastPlayed"] = new TagNodeLong(_lastPlayed);

            if (_player != null)
            {
                data["Player"] = _player.BuildTree();
            }

            data["SpawnX"]     = new TagNodeInt(_spawnX);
            data["SpawnY"]     = new TagNodeInt(_spawnY);
            data["SpawnZ"]     = new TagNodeInt(_spawnZ);
            data["SizeOnDisk"] = new TagNodeLong(_sizeOnDisk);
            data["RandomSeed"] = new TagNodeLong(_randomSeed);

            if (_version != null && _version != 0)
            {
                data["version"] = new TagNodeInt(_version ?? 0);
            }

            if (_name != null)
            {
                data["LevelName"] = new TagNodeString(_name);
            }

            if (_generator != null)
            {
                data["generatorName"] = new TagNodeString(_generator);
            }

            if (_raining != null)
            {
                data["raining"] = new TagNodeByte(_raining ?? 0);
            }
            if (_thundering != null)
            {
                data["thundering"] = new TagNodeByte(_thundering ?? 0);
            }
            if (_rainTime != null)
            {
                data["rainTime"] = new TagNodeInt(_rainTime ?? 0);
            }
            if (_thunderTime != null)
            {
                data["thunderTime"] = new TagNodeInt(_thunderTime ?? 0);
            }

            if (_gameType != null)
            {
                data["GameType"] = new TagNodeInt(_gameType ?? 0);
            }
            if (_mapFeatures != null)
            {
                data["MapFeatures"] = new TagNodeByte(_mapFeatures ?? 0);
            }
            if (_hardcore != null)
            {
                data["hardcore"] = new TagNodeByte(_hardcore ?? 0);
            }

            if (_generatorOptions != null)
            {
                data["generatorOptions"] = new TagNodeString(_generatorOptions);
            }
            if (_generatorVersion != null)
            {
                data["generatorVersion"] = new TagNodeInt(_generatorVersion ?? 0);
            }
            if (_allowCommands != null)
            {
                data["allowCommands"] = new TagNodeByte(_allowCommands ?? 0);
            }
            if (_initialized != null)
            {
                data["initialized"] = new TagNodeByte(_initialized ?? 0);
            }
            if (_DayTime != null)
            {
                data["DayTime"] = new TagNodeLong(_DayTime ?? 0);
            }
            TagNodeCompound gr = new TagNodeCompound();

            gr["commandBlockOutput"] = new TagNodeString(_gameRules.CommandBlockOutput ? "true" : "false");
            gr["doFireTick"]         = new TagNodeString(_gameRules.DoFireTick ? "true" : "false");
            gr["doMobLoot"]          = new TagNodeString(_gameRules.DoMobLoot ? "true" : "false");
            gr["doMobSpawning"]      = new TagNodeString(_gameRules.DoMobSpawning ? "true" : "false");
            gr["doTileDrops"]        = new TagNodeString(_gameRules.DoTileDrops ? "true" : "false");
            gr["keepInventory"]      = new TagNodeString(_gameRules.KeepInventory ? "true" : "false");
            gr["mobGriefing"]        = new TagNodeString(_gameRules.MobGriefing ? "true" : "false");
            data["GameRules"]        = gr;

            if (_source != null)
            {
                data.MergeFrom(_source);
            }

            TagNodeCompound tree = new TagNodeCompound();

            tree.Add("Data", data);

            return(tree);
        }
コード例 #17
0
ファイル: Level.cs プロジェクト: default0/Substrate
        /// <summary>
        /// Builds a Level subtree from the current data.
        /// </summary>
        /// <returns>The root node of a Level subtree representing the current data.</returns>
        public virtual TagNode BuildTree()
        {
            TagNodeCompound data = new TagNodeCompound();

            data["Time"]       = new TagNodeLong(_time);
            data["LastPlayed"] = new TagNodeLong(_lastPlayed);

            if (_player != null)
            {
                data["Player"] = _player.BuildTree();
            }

            data["SpawnX"]     = new TagNodeInt(_spawnX);
            data["SpawnY"]     = new TagNodeInt(_spawnY);
            data["SpawnZ"]     = new TagNodeInt(_spawnZ);
            data["SizeOnDisk"] = new TagNodeLong(_sizeOnDisk);
            data["RandomSeed"] = new TagNodeLong(_randomSeed);

            if (_version != null && _version != 0)
            {
                data["version"] = new TagNodeInt(_version ?? 0);
            }

            if (_name != null)
            {
                data["LevelName"] = new TagNodeString(_name);
            }

            if (_raining != null)
            {
                data["raining"] = new TagNodeByte(_raining ?? 0);
            }
            if (_thundering != null)
            {
                data["thundering"] = new TagNodeByte(_thundering ?? 0);
            }
            if (_rainTime != null)
            {
                data["rainTime"] = new TagNodeInt(_rainTime ?? 0);
            }
            if (_thunderTime != null)
            {
                data["thunderTime"] = new TagNodeInt(_thunderTime ?? 0);
            }

            if (_gameType != null)
            {
                data["GameType"] = new TagNodeInt(_gameType ?? 0);
            }
            if (_mapFeatures != null)
            {
                data["MapFeatures"] = new TagNodeByte(_mapFeatures ?? 0);
            }
            if (_hardcore != null)
            {
                data["hardcore"] = new TagNodeByte(_hardcore ?? 0);
            }

            if (_generatorName != null)
            {
                data["generatorName"] = new TagNodeString(_generatorName);
            }
            if (_generatorOptions != null)
            {
                data["generatorOptions"] = new TagNodeString(_generatorOptions.GetGeneratorOptions());
            }
            else
            {
                data["generatorOptions"] = new TagNodeString("");
            }
            if (_difficulty != null)
            {
                data["Difficulty"] = new TagNodeByte(_difficulty ?? 0);
            }
            if (_difficultyLocked != null)
            {
                data["DifficultyLocked"] = new TagNodeByte(_difficultyLocked ?? 0);
            }
            if (_allowCommands != null)
            {
                data["allowCommands"] = new TagNodeByte(_allowCommands ?? 0);
            }


            if (_source != null)
            {
                data.MergeFrom(_source);
            }

            TagNodeCompound tree = new TagNodeCompound();

            tree.Add("Data", data);

            return(tree);
        }
コード例 #18
0
ファイル: Item.cs プロジェクト: Shade2010/ForgeCraft
        public static byte[] GetEnchantmentNBTData(List<Enchantment> enchantments)
        {
            if (enchantments.Count < 1) return new byte[0];

            NbtTree nbt = new NbtTree();
            TagNodeList list = new TagNodeList(TagType.TAG_COMPOUND);

            TagNodeCompound compound;
            foreach (Enchantment ench in enchantments.ToArray())
            {
                compound = new TagNodeCompound();
                compound.Add("id", new TagNodeShort(ench.id));
                compound.Add("lvl", new TagNodeShort(ench.level));
                list.Add(compound);
            }

            nbt.Root.Add("ench", list);

            using (MemoryStream ms = new MemoryStream())
            {
                nbt.WriteTo(ms);
                return ms.ToArray().Compress(Ionic.Zlib.CompressionLevel.BestCompression, CompressionType.GZip);
            }
        }
コード例 #19
0
        private void BuildNBTTree()
        {
            int elements2 = XDIM * ZDIM;
            int elements3 = elements2 * YDIM;

            TagNodeByteArray blocks     = new TagNodeByteArray(new byte[elements3]);
            TagNodeByteArray data       = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray blocklight = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray skylight   = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray heightMap  = new TagNodeByteArray(new byte[elements2]);

            _blocks     = new XZYByteArray(XDIM, YDIM, ZDIM, blocks);
            _data       = new XZYNibbleArray(XDIM, YDIM, ZDIM, data);
            _blockLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, blocklight);
            _skyLight   = new XZYNibbleArray(XDIM, YDIM, ZDIM, skylight);
            _heightMap  = new ZXByteArray(XDIM, ZDIM, heightMap);

            _entities     = new TagNodeList(TagType.TAG_COMPOUND);
            _tileEntities = new TagNodeList(TagType.TAG_COMPOUND);

            TagNodeCompound level = new TagNodeCompound();

            level.Add("Blocks", blocks);
            level.Add("Data", data);
            level.Add("SkyLight", blocklight);
            level.Add("BlockLight", skylight);
            level.Add("HeightMap", heightMap);
            level.Add("Entities", _entities);
            level.Add("TileEntities", _tileEntities);
            level.Add("LastUpdate", new TagNodeLong(Timestamp()));
            level.Add("xPos", new TagNodeInt(_cx));
            level.Add("zPos", new TagNodeInt(_cz));
            level.Add("TerrainPopulated", new TagNodeByte());

            _tree = new NbtTree();
            _tree.Root.Add("Level", level);

            _blockManager  = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities);
            _entityManager = new EntityCollection(_entities);
        }
コード例 #20
0
ファイル: Item.cs プロジェクト: Cazzar/ForgeCraft
 public static TagNodeList GetEnchantmentNBT(List<Enchantment> enchantments)
 {
     TagNodeCompound compound;
     TagNodeList list = new TagNodeList(TagType.TAG_COMPOUND);
     foreach (Enchantment ench in enchantments.ToArray())
     {
         compound = new TagNodeCompound();
         compound.Add("id", new TagNodeShort(ench.id));
         compound.Add("lvl", new TagNodeShort(ench.level));
         list.Add(compound);
     }
     return list;
 }
コード例 #21
0
ファイル: Chunk.cs プロジェクト: Cazzar/ForgeCraft
        public void Save(World w)
        {
            try
            {
                string path = CreatePath(w, x, z, true);
                string file = CreatePath(w, x, z);
                if (!Directory.Exists(path)) Directory.CreateDirectory(path);

                NbtTree nbt = new NbtTree();
                nbt.Root.Add("Generated", new TagNodeByte((byte)(generated ? 1 : 0)));
                nbt.Root.Add("Populated", new TagNodeByte((byte)(populated ? 1 : 0)));
                nbt.Root.Add("Blocks", new TagNodeByteArray(blocks));
                nbt.Root.Add("Meta", new TagNodeByteArray(meta));
                nbt.Root.Add("BlockLight", new TagNodeByteArray(Light));
                nbt.Root.Add("SkyLight", new TagNodeByteArray(SkyL));
                nbt.Root.Add("HeightMap", new TagNodeByteArray(heightMap));
                nbt.Root.Add("HeightMapPrec", new TagNodeByteArray(precipitationHeightMap.ToByteArray()));
                TagNodeList nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                TagNodeCompound nbtCompound;
                lock (extra)
                    foreach (KeyValuePair<int, ushort> kvp in extra)
                    {
                        nbtCompound = new TagNodeCompound();
                        nbtCompound.Add("Pos", new TagNodeInt(kvp.Key));
                        nbtCompound.Add("Value", new TagNodeShort((short)kvp.Value));
                        nbtList.Add(nbtCompound);
                    }
                nbt.Root.Add("Extra", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                List<Physics.Check> physChecks = w.physics.GetChunkChecks(x, z);
                foreach (Physics.Check check in physChecks)
                {
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_INT) { new TagNodeInt(check.x), new TagNodeInt(check.y), new TagNodeInt(check.z) });
                    nbtCompound.Add("Meta", new TagNodeByte(check.meta));
                    nbtCompound.Add("Time", new TagNodeShort(check.time));
                    nbtList.Add(nbtCompound);
                }
                nbt.Root.Add("Physics", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                List<Entity> entities = Entities; TagNodeCompound nbtCompound2;
                foreach (Entity e in entities)
                {
                    if (e.isPlayer) continue;
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Motion", new TagNodeList(TagType.TAG_DOUBLE) { new TagNodeDouble(e.velocity[0]), new TagNodeDouble(e.velocity[1]), new TagNodeDouble(e.velocity[2]) });
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_DOUBLE) { new TagNodeDouble(e.pos.x), new TagNodeDouble(e.pos.y), new TagNodeDouble(e.pos.z) });
                    nbtCompound.Add("Rotation", new TagNodeList(TagType.TAG_FLOAT) { new TagNodeFloat(e.rot[0]), new TagNodeFloat(e.rot[1]) });
                    nbtCompound.Add("Type", new TagNodeByte((byte)e.Type));
                    nbtCompound.Add("Age", new TagNodeInt(e.age));
                    nbtCompound.Add("OnGround", new TagNodeByte(e.onground));
                    nbtCompound.Add("Health", new TagNodeShort(e.Health));
                    nbtCompound2 = new TagNodeCompound();
                    switch (e.Type)
                    {
                        case EntityType.AI:
                            nbtCompound2.Add("Type", new TagNodeByte(e.ai.type));
                            break;
                        case EntityType.Object:
                            nbtCompound2.Add("Type", new TagNodeByte(e.obj.type));
                            break;
                        case EntityType.Item:
                            nbtCompound2.Add("ID", new TagNodeShort(e.I.id));
                            nbtCompound2.Add("Count", new TagNodeByte(e.I.count));
                            nbtCompound2.Add("Meta", new TagNodeShort(e.I.meta));
                            break;
                    }
                    nbtCompound.Add("Data", nbtCompound2);
                    nbtList.Add(nbtCompound);
                }
                nbt.Root.Add("Entities", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                foreach (Container c in GetContainers(w))
                {
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Type", new TagNodeByte((byte)c.Type));
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_INT) { new TagNodeInt((int)c.Pos.x), new TagNodeInt((int)c.Pos.y), new TagNodeInt((int)c.Pos.z) });
                    nbtCompound.Add("Items", c.GetNBTData());
                    nbtList.Add(nbtCompound);
                    //Console.WriteLine("SAVED CONTAINER @ " + (int)c.Pos.x + "," + (int)c.Pos.y + "," + (int)c.Pos.z + " @ " + x + "," + z);
                }
                nbt.Root.Add("Containers", nbtList);

                try
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        nbt.WriteTo(ms);
                        byte[] bytes = ms.ToArray().Compress(CompressionLevel.BestCompression, CompressionType.GZip);
                        using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write))
                            fs.Write(bytes, 0, bytes.Length);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogToFile("Error saving chunk at " + x + "," + z + "!");
                    Logger.LogErrorToFile(ex);
                }

                this._dirty = false;
                //Console.WriteLine("SAVED " + x + " " + z);
            }
            catch (Exception ex) { Logger.LogError(ex); }
        }
コード例 #22
0
ファイル: Item.cs プロジェクト: Cazzar/ForgeCraft
 public TagNodeCompound GetNBTData()
 {
     TagNodeCompound comp = new TagNodeCompound();
     comp.Add("ID", new TagNodeShort(id));
     comp.Add("Count", new TagNodeByte(count));
     comp.Add("Meta", new TagNodeShort(meta));
     comp.Add("Ench", GetEnchantmentNBT());
     return comp;
 }
コード例 #23
0
ファイル: AnvilChunk.cs プロジェクト: IAAA-Lab/EINA-TO-NBT
        private void BuildNBTTree()
        {
            int elements2 = XDIM * ZDIM;

            _sections = new AnvilSection[16];
            TagNodeList sections = new TagNodeList(TagType.TAG_COMPOUND);

            for (int i = 0; i < _sections.Length; i++)
            {
                _sections[i] = new AnvilSection(i);
                sections.Add(_sections[i].BuildTree());
            }

            FusedDataArray3[] blocksBA     = new FusedDataArray3[_sections.Length];
            YZXNibbleArray[]  dataBA       = new YZXNibbleArray[_sections.Length];
            YZXNibbleArray[]  skyLightBA   = new YZXNibbleArray[_sections.Length];
            YZXNibbleArray[]  blockLightBA = new YZXNibbleArray[_sections.Length];

            for (int i = 0; i < _sections.Length; i++)
            {
                blocksBA[i]     = new FusedDataArray3(_sections[i].AddBlocks, _sections[i].Blocks);
                dataBA[i]       = _sections[i].Data;
                skyLightBA[i]   = _sections[i].SkyLight;
                blockLightBA[i] = _sections[i].BlockLight;
            }

            _blocks     = new CompositeDataArray3(blocksBA);
            _data       = new CompositeDataArray3(dataBA);
            _skyLight   = new CompositeDataArray3(skyLightBA);
            _blockLight = new CompositeDataArray3(blockLightBA);

            TagNodeIntArray heightMap = new TagNodeIntArray(new int[elements2]);

            _heightMap = new ZXIntArray(XDIM, ZDIM, heightMap);

            TagNodeByteArray biomes = new TagNodeByteArray(new byte[elements2]);

            _biomes = new ZXByteArray(XDIM, ZDIM, biomes);
            for (int x = 0; x < XDIM; x++)
            {
                for (int z = 0; z < ZDIM; z++)
                {
                    _biomes[x, z] = BiomeType.Default;
                }
            }

            _entities     = new TagNodeList(TagType.TAG_COMPOUND);
            _tileEntities = new TagNodeList(TagType.TAG_COMPOUND);
            _tileTicks    = new TagNodeList(TagType.TAG_COMPOUND);

            TagNodeCompound level = new TagNodeCompound();

            level.Add("Sections", sections);
            level.Add("HeightMap", heightMap);
            level.Add("Biomes", biomes);
            level.Add("Entities", _entities);
            level.Add("TileEntities", _tileEntities);
            level.Add("TileTicks", _tileTicks);
            level.Add("LastUpdate", new TagNodeLong(Timestamp()));
            level.Add("xPos", new TagNodeInt(_cx));
            level.Add("zPos", new TagNodeInt(_cz));
            level.Add("TerrainPopulated", new TagNodeByte());

            _tree = new NbtTree();
            _tree.Root.Add("Level", level);

            _blockManager  = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities);
            _entityManager = new EntityCollection(_entities);
        }
コード例 #24
0
ファイル: Chunk.cs プロジェクト: MinedroidFTW/ForgeCraft
        public void Save(World w)
        {
            try
            {
                string path = CreatePath(w, x, z, true);
                string file = CreatePath(w, x, z);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                NbtTree nbt = new NbtTree();
                nbt.Root.Add("Generated", new TagNodeByte((byte)(generated ? 1 : 0)));
                nbt.Root.Add("Populated", new TagNodeByte((byte)(populated ? 1 : 0)));
                nbt.Root.Add("Blocks", new TagNodeByteArray(blocks));
                nbt.Root.Add("Meta", new TagNodeByteArray(meta));
                nbt.Root.Add("BlockLight", new TagNodeByteArray(Light));
                nbt.Root.Add("SkyLight", new TagNodeByteArray(SkyL));
                nbt.Root.Add("HeightMap", new TagNodeByteArray(heightMap));
                nbt.Root.Add("HeightMapPrec", new TagNodeByteArray(precipitationHeightMap.ToByteArray()));
                TagNodeList     nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                TagNodeCompound nbtCompound;
                lock (extra)
                    foreach (KeyValuePair <int, ushort> kvp in extra)
                    {
                        nbtCompound = new TagNodeCompound();
                        nbtCompound.Add("Pos", new TagNodeInt(kvp.Key));
                        nbtCompound.Add("Value", new TagNodeShort((short)kvp.Value));
                        nbtList.Add(nbtCompound);
                    }
                nbt.Root.Add("Extra", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                List <Physics.Check> physChecks = w.physics.GetChunkChecks(x, z);
                foreach (Physics.Check check in physChecks)
                {
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_INT)
                    {
                        new TagNodeInt(check.x), new TagNodeInt(check.y), new TagNodeInt(check.z)
                    });
                    nbtCompound.Add("Meta", new TagNodeByte(check.meta));
                    nbtCompound.Add("Time", new TagNodeShort(check.time));
                    nbtList.Add(nbtCompound);
                }
                nbt.Root.Add("Physics", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                List <Entity> entities = Entities; TagNodeCompound nbtCompound2;
                foreach (Entity e in entities)
                {
                    if (e.isPlayer)
                    {
                        continue;
                    }
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Motion", new TagNodeList(TagType.TAG_DOUBLE)
                    {
                        new TagNodeDouble(e.velocity[0]), new TagNodeDouble(e.velocity[1]), new TagNodeDouble(e.velocity[2])
                    });
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_DOUBLE)
                    {
                        new TagNodeDouble(e.pos.x), new TagNodeDouble(e.pos.y), new TagNodeDouble(e.pos.z)
                    });
                    nbtCompound.Add("Rotation", new TagNodeList(TagType.TAG_FLOAT)
                    {
                        new TagNodeFloat(e.rot[0]), new TagNodeFloat(e.rot[1])
                    });
                    nbtCompound.Add("Type", new TagNodeByte((byte)e.Type));
                    nbtCompound.Add("Age", new TagNodeInt(e.age));
                    nbtCompound.Add("OnGround", new TagNodeByte(e.onground));
                    nbtCompound.Add("Health", new TagNodeShort(e.Health));
                    nbtCompound2 = new TagNodeCompound();
                    switch (e.Type)
                    {
                    case EntityType.AI:
                        nbtCompound2.Add("Type", new TagNodeByte(e.ai.type));
                        break;

                    case EntityType.Object:
                        nbtCompound2.Add("Type", new TagNodeByte(e.obj.type));
                        break;

                    case EntityType.Item:
                        nbtCompound2.Add("ID", new TagNodeShort(e.I.id));
                        nbtCompound2.Add("Count", new TagNodeByte(e.I.count));
                        nbtCompound2.Add("Meta", new TagNodeShort(e.I.meta));
                        break;
                    }
                    nbtCompound.Add("Data", nbtCompound2);
                    nbtList.Add(nbtCompound);
                }
                nbt.Root.Add("Entities", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                foreach (Container c in GetContainers(w))
                {
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Type", new TagNodeByte((byte)c.Type));
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_INT)
                    {
                        new TagNodeInt((int)c.Pos.x), new TagNodeInt((int)c.Pos.y), new TagNodeInt((int)c.Pos.z)
                    });
                    nbtCompound.Add("Items", c.GetNBTData());
                    nbtList.Add(nbtCompound);
                    //Console.WriteLine("SAVED CONTAINER @ " + (int)c.Pos.x + "," + (int)c.Pos.y + "," + (int)c.Pos.z + " @ " + x + "," + z);
                }
                nbt.Root.Add("Containers", nbtList);

                try
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        nbt.WriteTo(ms);
                        byte[] bytes = ms.ToArray().Compress(CompressionLevel.BestCompression, CompressionType.GZip);
                        using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write))
                            fs.Write(bytes, 0, bytes.Length);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogToFile("Error saving chunk at " + x + "," + z + "!");
                    Logger.LogErrorToFile(ex);
                }

                this._dirty = false;
                //Console.WriteLine("SAVED " + x + " " + z);
            }
            catch (Exception ex) { Logger.LogError(ex); }
        }