public static NbtMap Load(string filename) { var map = new NbtMap(); var nf = new NBTFile(filename); using (var nbtstr = nf.GetDataInputStream()) { var tree = new NbtTree(nbtstr); var root = tree.Root["map"]; var list = root.ToTagList(); foreach (var tag in list) { var k = tag.ToTagCompound()["k"].ToTagString(); var v = (short)tag.ToTagCompound()["v"].ToTagInt(); if (!map.ContainsKey(v)) { map.Add(v, k); } } return(map); } }
protected override void ExpandCore() { if (_tree == null) { NBTFile file = new NBTFile(_path); _tree = new NbtTree(); _tree.ReadFrom(file.GetDataInputStream(_compressionType)); if (_tree.Root != null) { _container = new CompoundTagContainer(_tree.Root); } } var list = new SortedList <TagKey, TagNode>(); foreach (var item in _tree.Root) { list.Add(new TagKey(item.Key, item.Value.GetTagType()), item.Value); } foreach (TagNode tag in list.Values) { TagDataNode node = TagDataNode.CreateFromTag(tag); if (node != null) { Nodes.Add(node); } } }
public static TagNodeCompound GetLevelDat() { if (levelDat == null) { string path = Path.Combine(savePath, "level.dat"); levelFile = new NBTFile(path); levelTree = new NbtTree(); levelTree.ReadFrom(levelFile.GetDataInputStream()); levelDat = levelTree.Root["Data"] as TagNodeCompound; } return(levelDat); }
public static World Load(string filename) { var nf = new NBTFile(filename); using var nbtstr = nf.GetDataInputStream(); var tree = new NbtTree(nbtstr); var root = tree.Root["Data"].ToTagCompound(); var dataVersion = root["DataVersion"].ToTagInt().Data; return(new World(filename, dataVersion)); }
private bool LoadLevel () { NBTFile nf = new NBTFile(IO.Path.Combine(Path, _levelFile)); Stream nbtstr = nf.GetDataInputStream(); if (nbtstr == null) { return false; } NbtTree tree = new NbtTree(nbtstr); _level = new Level(this); _level = _level.LoadTreeSafe(tree.Root); return _level != null; }
/// <inheritdoc /> public Structure Load(string filename) { var input = new NBTFile(filename); var nbt = new NbtTree(input.GetDataInputStream()).Root; var length = nbt["Length"].ToTagInt().Data; var width = nbt["Width"].ToTagInt().Data; var height = nbt["Height"].ToTagInt().Data; var palette = LoadPalette(nbt); var tiles = LoadTileEntities(nbt); var blocks = LoadBlocks(nbt, palette, length, width, tiles); var entities = LoadEntities(nbt); return(new SchematicStructure(blocks, entities, palette, width, height, length)); }
public static FabricRegistry Load(string filename) { var nf = new NBTFile(filename); using var nbtstr = nf.GetDataInputStream(); var tree = new NbtTree(nbtstr); var version = tree.Root["version"].ToTagInt().Data; var registries = tree.Root["registries"].ToTagCompound(); var blockMap = CreateMap(registries["minecraft:block"]); var blockEntityTypeMap = CreateMap(registries["minecraft:block_entity_type"]); var itemMap = CreateMap(registries["minecraft:item"]); return(new FabricRegistry(version, blockMap, blockEntityTypeMap, itemMap)); }
NbtTree LoadLevelTree(string path) { NBTFile nf = new NBTFile(path); NbtTree tree = null; using (Stream nbtstr = nf.GetDataInputStream()) { if (nbtstr == null) { return(null); } tree = new NbtTree(nbtstr); } return(tree); }
public WorldData(string WorldPath) { _LoadedMods = new List <string>(); BlockIDs = new Dictionary <string, int>(); NBTFile LevelFile = new NBTFile(Path.Combine(WorldPath, "level.dat")); NbtTree LevelTree; using (Stream nbtstr = LevelFile.GetDataInputStream()) { LevelTree = new NbtTree(nbtstr); } _LoadedMods.Add("minecraft"); if (LevelTree.Root.ContainsKey("FML")) { TagNodeList IDList = (TagNodeList)(((TagNodeCompound)LevelTree.Root["FML"])["ItemData"]); TagNodeList ModList = (TagNodeList)(((TagNodeCompound)LevelTree.Root["FML"])["ModList"]); foreach (TagNodeCompound Entry in IDList) { string Key = ((TagNodeString)Entry["K"]).Data.Trim(' ', '', ''); // Non-visible control characters in those last two entries int Value = ((TagNodeInt)Entry["v"]).Data; BlockIDs.Add(Key, Value); } foreach (TagNodeCompound Entry in ModList) { _LoadedMods.Add(((TagNodeString)Entry["ModId"]).Data); } } else { // Load default vanilla stuff here StreamReader TR = new StreamReader(Properties.Resources.BaseIDs); string[] Line; while (!TR.EndOfStream) { Line = TR.ReadLine().Split(' '); BlockIDs.Add(Line[1], int.Parse(Line[0])); } } }
private static NbtFileDataNode TryCreateFrom(string path, CompressionType compressionType) { try { var file = new NBTFile(path); var tree = new NbtTree(); tree.ReadFrom(file.GetDataInputStream(compressionType)); if (tree.Root == null) return null; return new NbtFileDataNode(path, compressionType); } catch { return null; } }
/// <inheritdoc /> public Structure Load(string filename) { var input = new NBTFile(filename); var nbt = new NbtTree(input.GetDataInputStream()).Root; var dataVersion = nbt["DataVersion"].ToTagInt().Data; var author = nbt.ContainsKey("author") ? nbt["author"].ToTagString().Data : null; var size = nbt["size"].ToTagList().Select(node => node.ToTagInt().Data).ToArray(); var width = size[0]; var height = size[1]; var length = size[2]; var palette = LoadPalette(nbt); var blocks = LoadBlocks(nbt, palette); var entities = LoadEntities(nbt); return(new StructureBlockStructure(author, width, height, length, blocks, entities)); }
private bool LoadLevel() { NBTFile nf = new NBTFile(IO.Path.Combine(Path, _levelFile)); NbtTree tree; using (Stream nbtstr = nf.GetDataInputStream()) { if (nbtstr == null) { return(false); } tree = new NbtTree(nbtstr); } _level = new Level(this); _level = _level.LoadTreeSafe(tree.Root); return(_level != null); }
protected override void ExpandCore() { if (_tree == null) { NBTFile file = new NBTFile(_path); _tree = new NbtTree(); _tree.ReadFrom(file.GetDataInputStream(_compressionType)); if (_tree.Root != null) { _container = new CompoundTagContainer(_tree.Root); } } foreach (TagNode tag in _tree.Root.Values) { TagDataNode node = TagDataNode.CreateFromTag(tag); if (node != null) { Nodes.Add(node); } } }
/// <summary> /// Imports a schematic file at the given path and returns in as a <see cref="Schematic"/> object. /// </summary> /// <param name="path">The path to the schematic file.</param> /// <returns>A <see cref="Schematic"/> object containing the decoded schematic file data.</returns> public static Schematic Import(string path) { NBTFile schematicFile = new NBTFile(path); if (!schematicFile.Exists()) { return(null); } Stream nbtStream = schematicFile.GetDataInputStream(); if (nbtStream == null) { return(null); } NbtTree tree = new NbtTree(nbtStream); NbtVerifier v = new NbtVerifier(tree.Root, _schema); if (!v.Verify()) { return(null); } //TagNodeCompound schematic = tree.Root["Schematic"] as TagNodeCompound; TagNodeCompound schematic = tree.Root; int xdim = schematic["Width"].ToTagShort(); int zdim = schematic["Length"].ToTagShort(); int ydim = schematic["Height"].ToTagShort(); Schematic self = new Schematic(xdim, ydim, zdim); // Damnit, schematic is YZX ordering. YZXByteArray schemaBlocks = new YZXByteArray(xdim, ydim, zdim, schematic["Blocks"].ToTagByteArray()); YZXByteArray schemaData = new YZXByteArray(xdim, ydim, zdim, schematic["Data"].ToTagByteArray()); for (int x = 0; x < xdim; x++) { for (int y = 0; y < ydim; y++) { for (int z = 0; z < zdim; z++) { self._blocks[x, y, z] = schemaBlocks[x, y, z]; self._data[x, y, z] = schemaData[x, y, z]; } } } TagNodeList entities = schematic["Entities"] as TagNodeList; foreach (TagNode e in entities) { self._entities.Add(e); } TagNodeList tileEntities = schematic["TileEntities"] as TagNodeList; foreach (TagNode te in tileEntities) { self._tileEntities.Add(te); } self._blockset.Refresh(); return(self); }
private static void RunOptionsAndReturnExitCode(CliOptions opts) { Console.Clear(); var cgui = new ConsoleGui(); var pbBlocks = new ConsoleGuiProgressBar(0, 0, Console.WindowWidth, 0, 1) { ForegroundColor = ConsoleColor.Green, BackgroundColor = ConsoleColor.DarkGray }; var lBlocksTotal = new ConsoleGuiLabel(0, 1, "Total Blocks : {0}"); var lBlocksRemaining = new ConsoleGuiLabel(0, 2, "Remaining Blocks: {0}"); var lBlocksFailed = new ConsoleGuiLabel(0, 3, "Failed Blocks : {0}"); var lStatus = new ConsoleGuiLabel(0, 4, "Status : {0}"); cgui.Add(pbBlocks); cgui.Add(lBlocksTotal); cgui.Add(lBlocksRemaining); cgui.Add(lBlocksFailed); cgui.Add(lStatus); var failed = new List <int>(); var inputMap = NbtMap.Load(opts.InputMap); var outputMap = NbtMap.Load(opts.OutputMap); var inputSchematic = new NBTFile(opts.InputSchematic); var tag = new NbtTree(inputSchematic.GetDataInputStream()).Root; var bLower = tag["Blocks"].ToTagByteArray().Data; var addBlocks = new byte[(bLower.Length >> 1) + 1]; if (tag.ContainsKey("AddBlocks")) { addBlocks = tag["AddBlocks"].ToTagByteArray().Data; } lStatus.Value = "Processing..."; for (var index = 0; index < bLower.Length; index++) { short oldId; if ((index & 1) == 1) { oldId = (short)(((addBlocks[index >> 1] & 0x0F) << 8) + (bLower[index] & 0xFF)); } else { oldId = (short)(((addBlocks[index >> 1] & 0xF0) << 4) + (bLower[index] & 0xFF)); } if (!TranslateId(oldId, inputMap, outputMap, out var newId)) { failed.Add(oldId); } bLower[index] = (byte)(newId & 0xFF); addBlocks[index >> 1] = (byte)(((index & 1) == 1) ? addBlocks[index >> 1] & 0xF0 | (newId >> 8) & 0xF : addBlocks[index >> 1] & 0xF | ((newId >> 8) & 0xF) << 4); // Gui lBlocksTotal.Value = index + 1; lBlocksRemaining.Value = bLower.Length - index - 1; lBlocksFailed.Value = failed.Count; pbBlocks.Value = (float)index / bLower.Length; if (index % 10000 == 0) { cgui.Render(); } } cgui.Render(); tag["Blocks"] = new TagNodeByteArray(bLower); if (!tag.ContainsKey("AddBlocks")) { tag.Add("AddBlocks", new TagNodeByteArray(addBlocks)); } else { tag["AddBlocks"] = new TagNodeByteArray(addBlocks); } lStatus.Value = "Saving..."; cgui.Render(); var schematicFile = new NBTFile(opts.OutputSchematic); using (var nbtStream = schematicFile.GetDataOutputStream()) { if (nbtStream == null) { return; } var tree = new NbtTree(tag, "Schematic"); tree.WriteTo(nbtStream); } lStatus.Value = "Done. Press Enter."; cgui.Render(); Console.WriteLine(); foreach (var i in failed) { Console.WriteLine($"Failed ID: {i}"); } Console.ReadKey(); }