public BlockTileEntities(IDataArray3 blocks, TagNodeList tileEntities) { _blocks = blocks; _tileEntities = tileEntities; BuildTileEntityCache(); }
public Item(TagNodeCompound item) { if (!item.ContainsKey("tag")) { return; } TagNodeCompound tag = item["tag"].ToTagCompound(); if (!tag.ContainsKey("display")) { return; } TagNodeCompound display = tag["display"].ToTagCompound(); if (display.Keys.Contains("Name")) { Name = display["Name"].ToTagString().Data; } if (display.Keys.Contains("Lore")) { TagNodeList l = display["Lore"].ToTagList(); for (int k = 0; k < l.Count; k++) { Lore += l[k].ToTagString().Data.Replace("Line" + (k + 1) + ":", "") + "\n"; } if (Lore.Length > 0) { Lore = Lore.Substring(0, Lore.Length - 1); } } }
public BlockTileEntities(BlockTileEntities bte) { _blocks = bte._blocks; _tileEntities = bte._tileEntities; BuildTileEntityCache(); }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> overlay on top of Alpha-specific units of data. /// </summary> /// <param name="blocks">An array of Block IDs.</param> /// <param name="data">An array of data nibbles.</param> /// <param name="blockLight">An array of block light nibbles.</param> /// <param name="skyLight">An array of sky light nibbles.</param> /// <param name="heightMap">An array of height map values.</param> /// <param name="tileEntities">A list of tile entities corresponding to blocks in this collection.</param> /// <param name="tileTicks">A list of tile ticks corresponding to blocks in this collection.</param> public AlphaBlockCollection( IDataArray3 blocks, IDataArray3 data, IDataArray3 blockLight, IDataArray3 skyLight, IDataArray2 heightMap, TagNodeList tileEntities, TagNodeList tileTicks) { _blocks = blocks; _data = data; _blockLight = blockLight; _skyLight = skyLight; _heightMap = heightMap; _tileEntities = tileEntities; _tileTicks = tileTicks; if (_tileTicks == null) { _tileTicks = new TagNodeList(TagType.TAG_COMPOUND); } _xdim = _blocks.XDim; _ydim = _blocks.YDim; _zdim = _blocks.ZDim; Refresh(); }
public static void Save() { TagNodeList Pos = playerData.Root["Pos"] as TagNodeList; Pos[0] = (TagNodeDouble)PlayerController.instance.transform.position.x; Pos[1] = (TagNodeDouble)PlayerController.instance.transform.position.y; Pos[2] = (TagNodeDouble)PlayerController.instance.transform.position.z; TagNodeList Rotation = playerData.Root["Rotation"] as TagNodeList; Rotation[0] = (TagNodeFloat)(-PlayerController.instance.transform.localEulerAngles.y); Rotation[1] = (TagNodeFloat)PlayerController.instance.camera.localEulerAngles.x; InventorySystem.SaveData(playerData.Root["Inventory"] as TagNodeList); using (Stream stream = playerFile.GetDataOutputStream()) { playerData.WriteTo(stream); } foreach (KeyValuePair <Vector2Int, NbtTree> kvPair in chunkDictNBT) { int chunkX = kvPair.Key.x; int chunkZ = kvPair.Key.y; int regionX = GetRegionCoordinate(chunkX); int regionZ = GetRegionCoordinate(chunkZ); RegionFile region = GetRegion(regionX, regionZ); int _x = chunkX - regionX * 32; int _z = chunkZ - regionZ * 32; using (Stream stream = region.GetChunkDataOutputStream(_x, _z)) { kvPair.Value.WriteTo(stream); } } }
public BlockTileTicks(IDataArray3 blocks, TagNodeList tileTicks) { _blocks = blocks; _tileTicks = tileTicks; BuildTileTickCache(); }
/// <summary> /// Attempt to load an Entity subtree into the <see cref="Entity"/> without validation. /// </summary> /// <param name="tree">The root node of an Entity subtree.</param> /// <returns>The <see cref="Entity"/> returns itself on success, or null if the tree was unparsable.</returns> public Entity LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null) { return(null); } TagNodeList pos = ctree["Pos"].ToTagList(); _pos = new Vector3(); _pos.X = pos[0].ToTagDouble(); _pos.Y = pos[1].ToTagDouble(); _pos.Z = pos[2].ToTagDouble(); TagNodeList motion = ctree["Motion"].ToTagList(); _motion = new Vector3(); _motion.X = motion[0].ToTagDouble(); _motion.Y = motion[1].ToTagDouble(); _motion.Z = motion[2].ToTagDouble(); TagNodeList rotation = ctree["Rotation"].ToTagList(); _rotation = new Orientation(); _rotation.Yaw = rotation[0].ToTagFloat(); _rotation.Pitch = rotation[1].ToTagFloat(); _fire = ctree["Fire"].ToTagShort(); _air = ctree["Air"].ToTagShort(); _onGround = ctree["OnGround"].ToTagByte(); return(this); }
/// <summary> /// Builds an Entity subtree from the current data. /// </summary> /// <returns>The root node of an Entity subtree representing the current data.</returns> public TagNode BuildTree() { TagNodeCompound tree = new TagNodeCompound(); TagNodeList pos = new TagNodeList(TagType.TAG_DOUBLE); pos.Add(new TagNodeDouble(_pos.X)); pos.Add(new TagNodeDouble(_pos.Y)); pos.Add(new TagNodeDouble(_pos.Z)); tree["Pos"] = pos; TagNodeList motion = new TagNodeList(TagType.TAG_DOUBLE); motion.Add(new TagNodeDouble(_motion.X)); motion.Add(new TagNodeDouble(_motion.Y)); motion.Add(new TagNodeDouble(_motion.Z)); tree["Motion"] = motion; TagNodeList rotation = new TagNodeList(TagType.TAG_FLOAT); rotation.Add(new TagNodeFloat((float)_rotation.Yaw)); rotation.Add(new TagNodeFloat((float)_rotation.Pitch)); tree["Rotation"] = rotation; tree["FallDistance"] = new TagNodeFloat(_fallDistance); tree["Fire"] = new TagNodeShort(_fire); tree["Air"] = new TagNodeShort(_air); tree["OnGround"] = new TagNodeByte(_onGround); return(tree); }
public BlockTileTicks(BlockTileTicks bte) { _blocks = bte._blocks; _tileTicks = bte._tileTicks; BuildTileTickCache(); }
/// <inheritdoc/> public Item LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null) { return(null); } _enchantments.Clear(); _id = ctree["id"].ToTagString(); _count = ctree["Count"].ToTagByte(); _damage = ctree["Damage"].ToTagShort(); if (ctree.ContainsKey("tag")) { TagNodeCompound tagtree = ctree["tag"].ToTagCompound(); if (tagtree.ContainsKey("ench")) { TagNodeList enchList = tagtree["ench"].ToTagList(); foreach (TagNode tag in enchList) { _enchantments.Add(new Enchantment().LoadTree(tag)); } } } _source = ctree.Copy() as TagNodeCompound; return(this); }
public BlockTileEntities(XZYByteArray blocks, TagNodeList tileEntities) { _blocks = blocks; _tileEntities = tileEntities; BuildTileEntityCache(); }
public static NBTChunk LoadChunk(int chunkX, int chunkZ) { UnityEngine.Profiling.Profiler.BeginSample("ChunkChecker.Update"); key.Set(chunkX, chunkZ); if (!chunkDict.ContainsKey(key)) { TagNodeCompound Chunk = GetChunkNode(chunkX, chunkZ); if (Chunk != null) { TagNodeCompound Level = Chunk["Level"] as TagNodeCompound; TagNodeList Sections = Level["Sections"] as TagNodeList; NBTChunk chunk = ChunkPool.GetChunk(); chunk.SetData(chunkX, chunkZ, Sections); chunkDict.Add(key, chunk); } } UnityEngine.Profiling.Profiler.EndSample(); if (chunkDict.ContainsKey(key)) { return(chunkDict[key]); } return(null); }
/// <inheritdoc/> public TagNode BuildTree() { TagNodeCompound tree = new TagNodeCompound(); tree["id"] = new TagNodeString(_id); tree["Count"] = new TagNodeByte(_count); tree["Damage"] = new TagNodeShort(_damage); if (_enchantments.Count > 0) { TagNodeList enchList = new TagNodeList(TagType.TAG_COMPOUND); foreach (Enchantment e in _enchantments) { enchList.Add(e.BuildTree()); } TagNodeCompound tagtree = new TagNodeCompound(); tagtree["ench"] = enchList; if (_source != null && _source.ContainsKey("tag")) { tagtree.MergeFrom(_source["tag"].ToTagCompound()); } tree["tag"] = tagtree; } if (_source != null) { tree.MergeFrom(_source); } return(tree); }
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); }
/// <summary> /// Loads the Chunk from an NBT tree rooted at the given TagValue node. /// </summary> /// <param name="tree">Root node of an NBT tree.</param> /// <returns>A reference to the current Chunk, or null if the tree is unparsable.</returns> public Chunk LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null) { return(null); } _tree = new NbtTree(ctree); TagNodeCompound level = _tree.Root["Level"] as TagNodeCompound; _blocks = new XZYByteArray(XDIM, YDIM, ZDIM, level["Blocks"] as TagNodeByteArray); _data = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["Data"] as TagNodeByteArray); _blockLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["BlockLight"] as TagNodeByteArray); _skyLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["SkyLight"] as TagNodeByteArray); _heightMap = new ZXByteArray(XDIM, ZDIM, level["HeightMap"] as TagNodeByteArray); _entities = level["Entities"] as TagNodeList; _tileEntities = level["TileEntities"] as TagNodeList; if (level.ContainsKey("TileTicks")) { _tileTicks = level["TileTicks"] as TagNodeList; } else { _tileTicks = new TagNodeList(TagType.TAG_COMPOUND); } // List-type patch up if (_entities.Count == 0) { level["Entities"] = new TagNodeList(TagType.TAG_COMPOUND); _entities = level["Entities"] as TagNodeList; } if (_tileEntities.Count == 0) { level["TileEntities"] = new TagNodeList(TagType.TAG_COMPOUND); _tileEntities = level["TileEntities"] as TagNodeList; } if (_tileTicks.Count == 0) { level["TileTicks"] = new TagNodeList(TagType.TAG_COMPOUND); _tileTicks = level["TileTicks"] as TagNodeList; } _cx = level["xPos"].ToTagInt(); _cz = level["zPos"].ToTagInt(); _blockManager = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities, _tileTicks); _entityManager = new EntityCollection(_entities); return(this); }
/// <inheritdoc/> public Item LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null) { return(null); } _enchantments.Clear(); _id = ctree["id"].ToTagShort(); _count = ctree["Count"].ToTagByte(); _damage = ctree["Damage"].ToTagShort(); if (ctree.ContainsKey("tag")) { TagNodeCompound tagtree = ctree["tag"].ToTagCompound(); if (tagtree.ContainsKey("ench")) { TagNodeList enchList = tagtree["ench"].ToTagList(); foreach (TagNode tag in enchList) { _enchantments.Add(new Enchantment().LoadTree(tag)); } } if (tagtree.ContainsKey("StoredEnchantments")) { TagNodeList storedEnchList = tagtree["StoredEnchantments"].ToTagList(); foreach (TagNode tag in storedEnchList) { _storedEnchantments.Add(new Enchantment().LoadTree(tag)); } } if (tagtree.ContainsKey("display")) { TagNodeCompound displaytree = tagtree["display"].ToTagCompound(); _color = displaytree["color"].ToTagInt(); _name = displaytree["Name"].ToTagString(); TagNodeList loreList = displaytree["Lore"].ToTagList(); string str = ""; foreach (TagNode tag in loreList) { str += tag.ToTagString() + "\n"; } str = str.Substring(0, str.Length - 1); // get rid of last \n _lore = str; } } _source = ctree.Copy() as TagNodeCompound; return(this); }
public override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["AttackTime"] = new TagNodeShort(_attackTime); tree["DeathTime"] = new TagNodeShort(_deathTime); tree["Health"] = new TagNodeShort(_health); tree["HurtTime"] = new TagNodeShort(_hurtTime); tree["CanPickUpLoot"] = new TagNodeByte(_canPickUpLoot); tree["PersistenceRequired"] = new TagNodeByte(_persistenceRequired); tree["CustomName"] = new TagNodeString(_customName); tree["CustomNameVisible"] = new TagNodeByte(_customNameVisible); if (_activeEffects != null) { TagNodeList effects = new TagNodeList(TagType.TAG_COMPOUND); foreach (ActiveEffects effect in _activeEffects) { if (!effect.IsValid) { continue; } TagNodeCompound ae = new TagNodeCompound(); ae["Id"] = new TagNodeByte((byte)effect.Id); ae["Amplifier"] = new TagNodeByte((byte)effect.Amplifier); ae["Duration"] = new TagNodeInt(effect.Duration); ae["Ambient"] = new TagNodeByte(effect.Ambient ? (byte)1 : (byte)0); effects.Add(ae); } tree["ActiveEffects"] = effects; } if (_equipment != null) { TagNodeList equipment = new TagNodeList(TagType.TAG_COMPOUND); foreach (Item item in _equipment) { equipment.Add(item.BuildTree()); } tree["Equipment"] = equipment; } if (_dropChances != null) { TagNodeList dropChances = new TagNodeList(TagType.TAG_FLOAT); foreach (float dc in _dropChances) { dropChances.Add(new TagNodeFloat(dc)); } tree["DropChances"] = dropChances; } return(tree); }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> overlay on top of Alpha-specific units of data. /// </summary> /// <param name="blocks">An array of Block IDs.</param> /// <param name="data">An array of data nibbles.</param> /// <param name="blockLight">An array of block light nibbles.</param> /// <param name="skyLight">An array of sky light nibbles.</param> /// <param name="heightMap">An array of height map values.</param> /// <param name="tileEntities">A list of tile entities corresponding to blocks in this collection.</param> public AlphaBlockCollection( IDataArray3 blocks, IDataArray3 data, IDataArray3 blockLight, IDataArray3 skyLight, IDataArray2 heightMap, TagNodeList tileEntities) : this(blocks, data, blockLight, skyLight, heightMap, tileEntities, null) { }
public static Vector3 GetPlayerRot() { TagNodeCompound player = GetPlayerData(); TagNodeList Pos = player["Rotation"] as TagNodeList; TagNodeFloat y = Pos[0] as TagNodeFloat; TagNodeFloat x = Pos[1] as TagNodeFloat; Vector3 rot = new Vector3(0, y, x); return(rot); }
public void LoadEnchantmentNBT(TagNodeList list) { TagNodeCompound compound; foreach (TagNode tag in list) { compound = tag.ToTagCompound(); enchantments.Add(new Enchantment(compound["id"].ToTagShort().Data, compound["lvl"].ToTagShort().Data)); } }
private void BuildConditional() { TagNodeCompound level = _tree.Root["Level"] as TagNodeCompound; if (_tileTicks != _blockManager.TileTicks && _blockManager.TileTicks.Count > 0) { _tileTicks = _blockManager.TileTicks; level["TileTicks"] = _tileTicks; } }
public void SetData(int _x, int _z, TagNodeList sections) { x = _x; z = _z; globalX = x * 16; globalZ = z * 16; Sections = sections; gameObject.name = "chunk (" + x + "," + z + ")"; transform.localPosition = new Vector3(x * 16, 0, z * 16); ClearData(); }
public static Vector3 GetPlayerPos() { TagNodeCompound player = GetPlayerData(); TagNodeList Pos = player["Pos"] as TagNodeList; TagNodeDouble x = Pos[0] as TagNodeDouble; TagNodeDouble y = Pos[1] as TagNodeDouble; TagNodeDouble z = Pos[2] as TagNodeDouble; Vector3 pos = new Vector3((float)x, (float)y, (float)z); return(pos); }
/// <inheritdoc/> public TagNode BuildTree() { TagNodeList list = new TagNodeList(TagType.TAG_COMPOUND); foreach (KeyValuePair <int, Item> item in _items) { TagNodeCompound itemtree = item.Value.BuildTree() as TagNodeCompound; itemtree["Slot"] = new TagNodeByte((byte)item.Key); list.Add(itemtree); } return(list); }
/// <summary> /// Create an empty, exportable schematic of given dimensions. /// </summary> /// <param name="xdim">The length of the X-dimension in blocks.</param> /// <param name="ydim">The length of the Y-dimension in blocks.</param> /// <param name="zdim">The length of the Z-dimension in blocks.</param> public Schematic(int xdim, int ydim, int zdim) { _blocks = new XZYByteArray(xdim, ydim, zdim); _data = new XZYNibbleArray(xdim, ydim, zdim); _blockLight = new XZYNibbleArray(xdim, ydim, zdim); _skyLight = new XZYNibbleArray(xdim, ydim, zdim); _heightMap = new ZXByteArray(xdim, zdim); _entities = new TagNodeList(TagType.TAG_COMPOUND); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _blockset = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities); _entityset = new EntityCollection(_entities); }
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); }
public static bool CheckLore(TagNodeCompound compound, Item O) { TagNodeList list = compound["Lore"].ToTagList(); string[] split = O.Lore.Split('\n'); for (int i = 0; i < list.Count && i < split.Length; i++) { if (list[i].ToTagString().Data != split[i].Replace("\r", "")) { return(false); } } return(true); }
public static void GetBlockData(int x, int y, int z, ref byte blockType, ref byte blockData) { UnityEngine.Profiling.Profiler.BeginSample("GetBlockData"); int chunkX = Mathf.FloorToInt(x / 16f); int chunkY = Mathf.FloorToInt(y / 16f); int chunkZ = Mathf.FloorToInt(z / 16f); int xInChunk = x - chunkX * 16; int yInChunk = y - chunkY * 16; int zInChunk = z - chunkZ * 16; NBTChunk chunk = GetChunk(chunkX, chunkZ); if (chunk != null) { chunk.GetBlockData(xInChunk, y, zInChunk, ref blockType, ref blockData); } else { UnityEngine.Profiling.Profiler.BeginSample("GetChunkNode"); TagNodeCompound Chunk = GetChunkNode(chunkX, chunkZ); UnityEngine.Profiling.Profiler.EndSample(); if (Chunk != null) { UnityEngine.Profiling.Profiler.BeginSample("GetBlockData new block"); TagNodeCompound Level = Chunk["Level"] as TagNodeCompound; TagNodeList Sections = Level["Sections"] as TagNodeList; if (chunkY < Sections.Count) { TagNodeCompound section = Sections[chunkY] as TagNodeCompound; TagNodeByteArray Blocks = section["Blocks"] as TagNodeByteArray; byte[] blocks = new byte[4096]; Buffer.BlockCopy(Blocks, 0, blocks, 0, 4096); int blockPos = yInChunk * 16 * 16 + zInChunk * 16 + xInChunk; blockType = blocks[blockPos]; TagNodeByteArray Data = section["Data"] as TagNodeByteArray; byte[] data = Data.Data; blockData = GetNibble(data, blockPos); } UnityEngine.Profiling.Profiler.EndSample(); } } UnityEngine.Profiling.Profiler.EndSample(); }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> of a given dimension. /// </summary> /// <param name="xdim">The length of the X-dimension of the collection.</param> /// <param name="ydim">The length of the Y-dimension of the collection.</param> /// <param name="zdim">The length of the Z-dimension of the collection.</param> public AlphaBlockCollection(int xdim, int ydim, int zdim) { _blocks = new XZYByteArray(xdim, ydim, zdim); _data = new XZYNibbleArray(xdim, ydim, zdim); _blockLight = new XZYNibbleArray(xdim, ydim, zdim); _skyLight = new XZYNibbleArray(xdim, ydim, zdim); _heightMap = new ZXByteArray(xdim, zdim); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _xdim = xdim; _ydim = ydim; _zdim = zdim; Refresh(); }
public override TileEntity LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null || base.LoadTree(tree) == null) { return(null); } TagNodeList items = ctree["Items"].ToTagList(); _items = new ItemCollection(_CAPACITY).LoadTree(items); return(this); }
public override TypedEntity LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null || base.LoadTree(tree) == null) { return(null); } TagNodeList items = ctree["Items"].ToTagList(); _items = _items.LoadTree(items); return(this); }
private static void SerializeList (TagNodeList tag, StringBuilder str, int level) { if (tag.Count == 0) { str.Append("[ ]"); return; } str.AppendLine(); AddLine(str, "[", level); IEnumerator<TagNode> en = tag.GetEnumerator(); bool first = true; while (en.MoveNext()) { if (!first) { str.Append(","); } TagNode item = en.Current; if (item.GetTagType() == TagType.TAG_COMPOUND) { SerializeCompound(item as TagNodeCompound, str, level + 1); } else if (item.GetTagType() == TagType.TAG_LIST) { SerializeList(item as TagNodeList, str, level + 1); } else { if (!first) { str.AppendLine(); } Indent(str, level + 1); if (item.GetTagType() == TagType.TAG_INT_ARRAY) { SerializeIntArray(item as TagNodeIntArray, str, level); } else if (item.GetTagType() == TagType.TAG_BYTE_ARRAY) { SerializeByteArray(item as TagNodeByteArray, str, level); } else { SerializeScaler(item, str); } } first = false; } str.AppendLine(); Add(str, "]", level); }
public override TagNodeList GetNBTData() { TagNodeCompound comp; Item item; TagNodeList list = new TagNodeList(TagType.TAG_COMPOUND); for (int i = 0; i < Size; i++) { item = items[i]; if (item != null && item.id != -1) { comp = item.GetNBTData(); comp.Add("Slot", new TagNodeByte((byte)i)); list.Add(comp); } } return list; }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> overlay on top of Alpha-specific units of data. /// </summary> /// <param name="blocks">An array of Block IDs.</param> /// <param name="data">An array of data nibbles.</param> /// <param name="blockLight">An array of block light nibbles.</param> /// <param name="skyLight">An array of sky light nibbles.</param> /// <param name="heightMap">An array of height map values.</param> /// <param name="tileEntities">A list of tile entities corresponding to blocks in this collection.</param> public AlphaBlockCollection( XZYByteArray blocks, XZYNibbleArray data, XZYNibbleArray blockLight, XZYNibbleArray skyLight, ZXByteArray heightMap, TagNodeList tileEntities) { _blocks = blocks; _data = data; _blockLight = blockLight; _skyLight = skyLight; _heightMap = heightMap; _tileEntities = tileEntities; _xdim = _blocks.XDim; _ydim = _blocks.YDim; _zdim = _blocks.ZDim; Refresh(); }
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); } }
public TagListDataNode(TagNodeList tag) : base(tag) { _container = new ListTagContainer(tag, res => IsDataModified = true); }
private INBTTag readTagPlod(TagNodeType type, string name) { /* There are 3 types of nodes in a NBT file, namely TAG_LIST, TAG_COMPOUND and the base TAG_TYPEs. * * The difference between the data types and TAG_LIST and TAG_COMPOUND is both TAG_LIST and TAG_COMPOUND requires * additional reading methodology to effectively read the whole file. * * First, on a TAG_LIST container type, the nodes are sequentially read WITHOUT the name tag because virtually, it is a * custom data type array. * * Unlike TAG_LISTs, a TAG_COMPOUND container type requires the nodes to be read again by readTagHead() for n times * (listing will only stop if it were to see a TAG_END node) because this container type contains heterogeneous * mix of primitive data types. * * Lastly, if it is a base type data node, it will be directly read by the Read(BinaryReader, TagNodeType) method. * * In a nutshell, this method will read the value (payload) of a node depending on the type of the node. */ // check the tag type of the node switch (type) { // type is a TAG_LIST case TagNodeType.TAG_LIST: { // get the common TAG_TYPE of the list byte _tagType = NBTReader.Read(this._bRead, TagNodeType.TAG_BYTE); // then get the total number of items stored in that list int _tagCout = NBTReader.Read(this._bRead, TagNodeType.TAG_INT); // after getting those values, create a TagNodeList (basically a List) that will // hold the succeeding tag values. TagNodeList _assetsList = new TagNodeList(name, (TagNodeType)_tagType); // loop-it according to the total count of the list for (int i = 0; i < _tagCout; i++) { // read the data then immediately add it on the list _assetsList.Add((INBTTag)readTagPlod((TagNodeType)_tagType, "")); } // finally, return _assetsList to the parent method return _assetsList; } // type is a TAG_COMPOUND case TagNodeType.TAG_COMPOUND: { // create a TagNodeList (basically a Dictionary) that will hold the succeeding tag values. TagNodeListNamed _assetsMaps = new TagNodeListNamed(name); // yes, this is an intentional infinite loop >:) do { // read a tag node INBTTag _nodeMap = readTagHead(); // if tag node is not TAG_END, meaning there is more to add if (_nodeMap.Type != TagNodeType.TAG_END) { // add the _nodeMap into the list _assetsMaps.Add(_nodeMap.Name, _nodeMap); } // otherwise else { // break the loop *\o/* break; } } while (true); // return the list containing the newly read nodes to the parent method return _assetsMaps; } // tag is a primitive data type default: { // read the node according to the type of the node (the method Read() will handle the payload processing) return new TagNode(type, name, Read(this._bRead, type)); } } }
public TagListDataNode(TagNodeList tag) : base(tag) { _container = new ListTagContainer(tag); }
/// <summary> /// Exports the <see cref="Schematic"/> object to a schematic file. /// </summary> /// <param name="path">The path to write out the schematic file to.</param> public void Export(string path) { int xdim = _blockset.XDim; int ydim = _blockset.YDim; int zdim = _blockset.ZDim; byte[] blockData = new byte[xdim * ydim * zdim]; byte[] dataData = new byte[xdim * ydim * zdim]; YZXByteArray schemaBlocks = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, blockData); YZXByteArray schemaData = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, dataData); TagNodeList entities = new TagNodeList(TagType.TAG_COMPOUND); TagNodeList tileEntities = new TagNodeList(TagType.TAG_COMPOUND); for (int x = 0; x < xdim; x++) { for (int z = 0; z < zdim; z++) { for (int y = 0; y < ydim; y++) { AlphaBlock block = _blockset.GetBlock(x, y, z); schemaBlocks[x, y, z] = (byte)block.ID; schemaData[x, y, z] = (byte)block.Data; TileEntity te = block.GetTileEntity(); if (te != null) { te.X = x; te.Y = y; te.Z = z; tileEntities.Add(te.BuildTree()); } } } } foreach (TypedEntity e in _entityset) { entities.Add(e.BuildTree()); } TagNodeCompound schematic = new TagNodeCompound(); schematic["Width"] = new TagNodeShort((short)xdim); schematic["Length"] = new TagNodeShort((short)zdim); schematic["Height"] = new TagNodeShort((short)ydim); schematic["Entities"] = entities; schematic["TileEntities"] = tileEntities; schematic["Materials"] = new TagNodeString("Alpha"); schematic["Blocks"] = new TagNodeByteArray(blockData); schematic["Data"] = new TagNodeByteArray(dataData); NBTFile schematicFile = new NBTFile(path); Stream nbtStream = schematicFile.GetDataOutputStream(); if (nbtStream == null) { return; } NbtTree tree = new NbtTree(schematic, "Schematic"); tree.WriteTo(nbtStream); nbtStream.Close(); }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> overlay on top of Alpha-specific units of data. /// </summary> /// <param name="blocks">An array of Block IDs.</param> /// <param name="data">An array of data nibbles.</param> /// <param name="blockLight">An array of block light nibbles.</param> /// <param name="skyLight">An array of sky light nibbles.</param> /// <param name="heightMap">An array of height map values.</param> /// <param name="tileEntities">A list of tile entities corresponding to blocks in this collection.</param> /// <param name="tileTicks">A list of tile ticks corresponding to blocks in this collection.</param> public AlphaBlockCollection( IDataArray3 blocks, IDataArray3 data, IDataArray3 blockLight, IDataArray3 skyLight, IDataArray2 heightMap, TagNodeList tileEntities, TagNodeList tileTicks) { _blocks = blocks; _data = data; _blockLight = blockLight; _skyLight = skyLight; _heightMap = heightMap; _tileEntities = tileEntities; _tileTicks = tileTicks; if (_tileTicks == null) _tileTicks = new TagNodeList(TagType.TAG_COMPOUND); _xdim = _blocks.XDim; _ydim = _blocks.YDim; _zdim = _blocks.ZDim; Refresh(); }
public ListTagContainer(TagNodeList tag) { _tag = tag; }
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; }
public override void LoadNBTData(TagNodeList list) { try { TagNodeCompound comp; byte slot; for (int i = 0; i < list.Count; i++) { comp = list[i].ToTagCompound(); slot = comp["Slot"].ToTagByte(); if (slot < 0 || slot > Size - 1) continue; if (items[slot] == null) items[slot] = Item.Nothing; items[slot].LoadNBTData(comp); } } catch { Logger.Log("NBT data is invalid."); } }
public ListTagContainer (TagNodeList tag, Action<bool> modifyHandler) { _tag = tag; }
internal static void AddTagToNode(TreeNode node, int descriptionIndex, TagType type) { TagNode tag = GetTagNode(node); if (tag == null) return; if (tag.GetTagType() != TagType.TAG_COMPOUND && tag.GetTagType() != TagType.TAG_LIST) return; if (tag.GetTagType() == TagType.TAG_LIST && tag.ToTagList().ValueType != type && tag.ToTagList().Count > 0) return; TagNode newNode = null; switch (type) { case TagType.TAG_BYTE: newNode = new TagNodeByte(); break; case TagType.TAG_SHORT: newNode = new TagNodeShort(); break; case TagType.TAG_INT: newNode = new TagNodeInt(); break; case TagType.TAG_LONG: newNode = new TagNodeLong(); break; case TagType.TAG_FLOAT: newNode = new TagNodeFloat(); break; case TagType.TAG_DOUBLE: newNode = new TagNodeDouble(); break; case TagType.TAG_BYTE_ARRAY: newNode = new TagNodeByteArray(); break; case TagType.TAG_STRING: newNode = new TagNodeString(); break; case TagType.TAG_LIST: newNode = new TagNodeList(TagType.TAG_BYTE); break; case TagType.TAG_COMPOUND: newNode = new TagNodeCompound(); break; case TagType.TAG_INT_ARRAY: newNode = new TagNodeIntArray(); break; } if (tag is TagNodeCompound) { TagNodeCompound ctag = tag as TagNodeCompound; EditValue form = new EditValue(""); foreach (string key in ctag.Keys) { form.InvalidNames.Add(key); } if (form.ShowDialog() != DialogResult.OK) return; ctag.Add(form.NodeName, newNode); TreeNode tnode = NodeFromTag(newNode, descriptionIndex, form.NodeName); node.Nodes.Add(tnode); tnode.TreeView.SelectedNode = tnode; tnode.Expand(); } else if (tag is TagNodeList) { var ltag = tag as TagNodeList; if (ltag.ValueType != type) ltag.ChangeValueType(type); ltag.Add(newNode); TreeNode tnode = NodeFromTag(newNode, descriptionIndex); node.Nodes.Add(tnode); tnode.TreeView.SelectedNode = tnode; tnode.Expand(); } node.Text = GetNodeText(node); TreeNode baseNode = BaseNode(node); if (baseNode != null) { (baseNode.Tag as DataNode).Modified = true; } }
/// <summary> /// Constructs a default <see cref="TagNodeList"/> satisfying the constraints of this node. /// </summary> /// <returns>A <see cref="TagNodeList"/> with a sensible default value. If a length is specified, default child <see cref="TagNode"/> objects of the necessary type will be created and added to the <see cref="TagNodeList"/>.</returns> public override TagNode BuildDefaultTree () { if (_length == 0) { return new TagNodeList(_type); } TagNodeList list = new TagNodeList(_type); for (int i = 0; i < _length; i++) { list.Add(_subschema.BuildDefaultTree()); } return list; }
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); } }
public abstract void LoadNBTData(TagNodeList list);