/// <summary> /// Builds a Player subtree from the current data. /// </summary> /// <returns>The root node of a Player subtree representing the current data.</returns> public virtual new 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["Dimension"] = new TagNodeInt(_dimension); tree["Sleeping"] = new TagNodeByte(_sleeping); tree["SleepTimer"] = new TagNodeShort(_sleepTimer); if (_spawnX != null && _spawnY != null && _spawnZ != null) { tree["SpawnX"] = new TagNodeInt(_spawnX ?? 0); tree["SpawnY"] = new TagNodeInt(_spawnY ?? 0); tree["SpawnZ"] = new TagNodeInt(_spawnZ ?? 0); } if (_world != null) { tree["World"] = new TagNodeString(_world); } tree["Inventory"] = _inventory.BuildTree(); return(tree); }
/// <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); }
/// <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 override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["EntityId"] = new TagNodeString(_entityID); tree["Delay"] = new TagNodeShort(_delay); if (_maxDelay != null) { tree["MaxSpawnDelay"] = new TagNodeShort(_maxDelay ?? 0); } if (_minDelay != null) { tree["MinSpawnDelay"] = new TagNodeShort(_minDelay ?? 0); } if (_spawnCount != null) { tree["SpawnCount"] = new TagNodeShort(_spawnCount ?? 0); } if (_spawnRange != null) { tree["SpawnRange"] = new TagNodeShort(_spawnRange ?? 0); } if (_maxNearbyEnemies != null) { tree["MaxNearbyEnemies"] = new TagNodeShort(_maxNearbyEnemies ?? 0); } if (_requiredPlayerRange != null) { tree["RequiredPlayerRange"] = new TagNodeShort(_requiredPlayerRange ?? 0); } if (_maxExperience != null) { tree["MaxExperience"] = new TagNodeInt(_maxExperience ?? 0); } if (_remainingExperience != null) { tree["RemainingExperience"] = new TagNodeInt(_remainingExperience ?? 0); } if (_experienceRegenTick != null) { tree["ExperienceRegenTick"] = new TagNodeInt(_experienceRegenTick ?? 0); } if (_experienceRegenRate != null) { tree["ExperienceRegenRate"] = new TagNodeInt(_experienceRegenRate ?? 0); } if (_experienceRegenAmount != null) { tree["ExperienceRegenAmount"] = new TagNodeInt(_experienceRegenAmount ?? 0); } if (_spawnData != null && _spawnData.Count > 0) { tree["SpawnData"] = _spawnData; } return(tree); }
/// <summary> /// Builds an Entity subtree from the current data. /// </summary> /// <returns>The root node of an Entity subtree representing the current data.</returns> public virtual new TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["id"] = new TagNodeString(_id); return(tree); }
public override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["Command"] = new TagNodeString(_command); return(tree); }
public override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["EntityId"] = new TagNodeString(_entityID); tree["Delay"] = new TagNodeShort(_delay); return(tree); }
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); }
public override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["Owner"] = new TagNodeString(_owner); tree["Sitting"] = new TagNodeByte((byte)(_sitting ? 1 : 0)); tree["Angry"] = new TagNodeByte((byte)(_angry ? 1 : 0)); return(tree); }
public override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["Text1"] = new TagNodeString(_text1); tree["Text2"] = new TagNodeString(_text2); tree["Text3"] = new TagNodeString(_text3); tree["Text4"] = new TagNodeString(_text4); return(tree); }
/// <summary> /// Builds a Tile Entity subtree from the current data. /// </summary> /// <returns>The root node of a Tile Entity subtree representing the current data.</returns> public virtual TagNode BuildTree() { TagNodeCompound tree = new TagNodeCompound(); tree["id"] = new TagNodeString(_id); tree["x"] = new TagNodeInt(_x); tree["y"] = new TagNodeInt(_y); tree["z"] = new TagNodeInt(_z); return(tree); }
public override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["EntityId"] = new TagNodeString(_entityID); tree["Delay"] = new TagNodeShort(_delay); tree["MaxSpawnDelay"] = new TagNodeShort(_maxDelay); tree["MinSpawnDelay"] = new TagNodeShort(_minDelay); tree["SpawnCount"] = new TagNodeShort(_spawnCount); tree["SpawnData"] = _spawnData.BuildTree(); return(tree); }
public override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["Dir"] = new TagNodeByte((byte)_dir); tree["Motive"] = new TagNodeString(_motive); tree["TileX"] = new TagNodeInt(_xTile); tree["TileY"] = new TagNodeInt(_yTile); tree["TileZ"] = new TagNodeInt(_zTile); return(tree); }
/// <summary> /// Builds a Tile Entity subtree from the current data. /// </summary> /// <returns>The root node of a Tile Entity subtree representing the current data.</returns> public virtual TagNode BuildTree() { TagNodeCompound tree = new TagNodeCompound(); tree["id"] = new TagNodeString(_id); tree["x"] = new TagNodeInt(_x); tree["y"] = new TagNodeInt(_y); tree["z"] = new TagNodeInt(_z); if (_source != null) { tree.MergeFrom(_source); } return(tree); }
public static bool ContainerTranslator(TagNodeCompound Target, List <LanguageItem> Source) { LanguageItem target = null; bool flag = false; foreach (LanguageItem c in Source) { if (c.Info == Target["x"].ToTagInt().Data + "," + Target["y"].ToTagInt().Data + "," + Target["z"].ToTagInt().Data) { target = c; break; } } if (target == null) { return(false); } Container o = target.Original as Container; Container t = target.Translated as Container; if (Target.ContainsKey("RecordItem")) { return(ItemTranslator(Target["RecordItem"].ToTagCompound(), o.Items[0], t.Items[0])); } else { TagNodeList Items = Target["Items"].ToTagList(); foreach (TagNode item in Items) { for (int i = 0; i < o.Items.Count; i++) { if (ItemTranslator(item.ToTagCompound(), o.Items[i], t.Items[i])) { flag = true; goto Next; } } } Next: if (Target.ContainsKey("CustomName") && t.CustomName != "") { Target["CustomName"] = new TagNodeString(t.CustomName); flag = true; } if (Target.ContainsKey("Lock") && t.Lock != "") { Target["Lock"] = new TagNodeString(t.Lock); flag = true; } } return(flag); }
public static bool SignTranslator(TagNodeCompound Target, List <LanguageItem> Source) { string data1 = Target["Text1"].ToTagString().Data; string data2 = Target["Text2"].ToTagString().Data; string data3 = Target["Text3"].ToTagString().Data; string data4 = Target["Text4"].ToTagString().Data; Sign sign = null; foreach (LanguageItem item in Source) { Sign ori = item.Original as Sign; if (ori.Line1 == data1 && ori.Line2 == data2 && ori.Line3 == data3 && ori.Line4 == data4) { sign = item.Translated as Sign; break; } } if (sign != null) { if (sign.Line1 != "" || sign.Line2 != "" || sign.Line3 != "" || sign.Line4 != "") { if (sign.Line1 == "") { sign.Line1 = "{\"text\":\"\"}"; } if (sign.Line2 == "") { sign.Line2 = "{\"text\":\"\"}"; } if (sign.Line3 == "") { sign.Line3 = "{\"text\":\"\"}"; } if (sign.Line4 == "") { sign.Line4 = "{\"text\":\"\"}"; } Target["Text1"] = new TagNodeString(sign.Line1); Target["Text2"] = new TagNodeString(sign.Line2); Target["Text3"] = new TagNodeString(sign.Line3); Target["Text4"] = new TagNodeString(sign.Line4); return(true); } } return(false); }
public static bool CommandBlockTranslator(TagNodeCompound Target, List <LanguageItem> Source) { string cmd = Target["Command"].ToTagString().Data; string c = cmd.Split(' ')[0].Replace("/", ""); if (c == "me" || c == "title" || c == "tellraw" || c == "say") { LanguageItem languageItem = null; foreach (LanguageItem item in Source) { if (cmd == item.Original as string) { languageItem = item; break; } } if (languageItem != null && languageItem.Translated as string != "") { Target["Command"] = new TagNodeString(languageItem.Translated as string); return(true); } } return(false); }
public override TagNode BuildTree() { TagNodeCompound tree = base.BuildTree() as TagNodeCompound; if (CustomName != null) { tree["CustomName"] = new TagNodeString(CustomName); } tree["Base"] = new TagNodeInt((int)BaseColor); if (Patterns.Length != 0) { tree["Patterns"] = new TagNodeList( TagType.TAG_COMPOUND, Patterns.Select(x => new TagNodeCompound() { { "Color", new TagNodeInt((int)x.Color) }, { "Pattern", new TagNodeString(x.Pattern) } }).ToList <TagNode>() ); } return(tree); }
/// <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); }
/// <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); }
/// <summary> /// 保存所有修改到 Region 文件 /// </summary> internal void saveAll() { // 缓存变量 RegionFile lastRegion = null; NbtTree lastTree = null; TagNodeList lastTileEntities = null; int lastChunkX = -1; int lastChunkZ = -1; // 遍历命令方块列表 foreach (var commandBlock in this.CommandBlocks) { // 如果需要保存 if (commandBlock.edit) { // 读取目标区块的 TileEntities if (lastRegion == commandBlock.region && commandBlock.chunkX == lastChunkX && commandBlock.chunkZ == lastChunkZ) { // 如果 region chunk 都没变 则触发缓存 继续用上次的 TileEntities } else { if (lastRegion != null) { // 保存之前的修改到文件 using (var stream = lastRegion.GetChunkDataOutputStream(lastChunkX, lastChunkZ)) { lastTree.WriteTo(stream); } } // 打开 Region 文件 lastRegion = commandBlock.region; // 打开目标 Chunk lastTree = new NbtTree(); lastTree.ReadFrom(lastRegion.GetChunkDataInputStream(commandBlock.chunkX, commandBlock.chunkZ)); // Level var level = lastTree.Root["Level"] as TagNodeCompound; // TileEntities lastTileEntities = level["TileEntities"] as TagNodeList; // 保存区块位置 lastChunkX = commandBlock.chunkX; lastChunkZ = commandBlock.chunkZ; } // 遍历 TileEntity 列表 foreach (TagNodeCompound tileEntity in lastTileEntities) { // 当前 TileEntity 的坐标 int x = int.Parse(tileEntity["x"].ToString()); int y = int.Parse(tileEntity["y"].ToString()); int z = int.Parse(tileEntity["z"].ToString()); // 如果坐标一致 if (x == commandBlock.x && y == commandBlock.y && z == commandBlock.z) { // 修改 Command tileEntity["Command"] = new TagNodeString(commandBlock.command); // 输出调试信息 // System.Diagnostics.Debug.WriteLine("Save" + commandBlock); // 设置 CommandBlock 的保存标记 commandBlock.edit = false; break; } } } } if (lastRegion != null) { // 保存之前的修改到文件 using (var str = lastRegion.GetChunkDataOutputStream(lastChunkX, lastChunkZ)) { lastTree.WriteTo(str); } } }
/// <summary> /// Builds a Player subtree from the current data. /// </summary> /// <returns>The root node of a Player subtree representing the current data.</returns> public virtual new 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["Dimension"] = new TagNodeInt(_dimension); tree["Sleeping"] = new TagNodeByte(_sleeping); tree["SleepTimer"] = new TagNodeShort(_sleepTimer); if (_spawnX != null && _spawnY != null && _spawnZ != null) { tree["SpawnX"] = new TagNodeInt(_spawnX ?? 0); tree["SpawnY"] = new TagNodeInt(_spawnY ?? 0); tree["SpawnZ"] = new TagNodeInt(_spawnZ ?? 0); } else { tree.Remove("SpawnX"); tree.Remove("SpawnY"); tree.Remove("SpawnZ"); } if (_world != null) { tree["World"] = new TagNodeString(_world); } if (_foodLevel != null) { tree["foodLevel"] = new TagNodeInt(_foodLevel ?? 0); } if (_foodTickTimer != null) { tree["foodTickTimer"] = new TagNodeInt(_foodTickTimer ?? 0); } if (_foodExhaustion != null) { tree["foodExhaustionLevel"] = new TagNodeFloat(_foodExhaustion ?? 0); } if (_foodSaturation != null) { tree["foodSaturation"] = new TagNodeFloat(_foodSaturation ?? 0); } if (_xpP != null) { tree["XpP"] = new TagNodeFloat(_xpP ?? 0); } if (_xpLevel != null) { tree["XpLevel"] = new TagNodeInt(_xpLevel ?? 0); } if (_xpTotal != null) { tree["XpTotal"] = new TagNodeInt(_xpTotal ?? 0); } if (_score != null) { tree["Score"] = new TagNodeInt(_score ?? 0); } if (_gameType != null) { tree["PlayerGameType"] = new TagNodeInt((int)(_gameType ?? PlayerGameType.Survival)); } if (AbilitiesSet()) { TagNodeCompound pb = new TagNodeCompound(); pb["flying"] = new TagNodeByte(_abilities.Flying ? (byte)1 : (byte)0); pb["instabuild"] = new TagNodeByte(_abilities.InstantBuild ? (byte)1 : (byte)0); pb["mayfly"] = new TagNodeByte(_abilities.MayFly ? (byte)1 : (byte)0); pb["invulnerable"] = new TagNodeByte(_abilities.Invulnerable ? (byte)1 : (byte)0); pb["mayBuild"] = new TagNodeByte(_abilities.MayBuild ? (byte)1 : (byte)0); pb["walkSpeed"] = new TagNodeFloat(_abilities.WalkSpeed); pb["flySpeed"] = new TagNodeFloat(_abilities.FlySpeed); tree["abilities"] = pb; } tree["Inventory"] = _inventory.BuildTree(); tree["EnderItems"] = _enderItems.BuildTree(); return(tree); }
public TagStringDataNode(TagNodeString tag) : base(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 (EntityTyped 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(); }
public static bool EntityTranslator(TagNodeCompound Target, List <LanguageItem> Source) { bool result = false; if (Target.ContainsKey("CustomName")) { string name = Target["CustomName"].ToTagString().Data; foreach (LanguageItem item in Source) { if ((item.Original as Entity).CustomName == name && name != "" && name != null) { Entity tra = item.Translated as Entity; if (tra.CustomName == "") { break; } Target["CustomName"] = new TagNodeString(tra.CustomName); result = true; } } } if (Target["id"].ToTagString().Data.ToLower().Contains("item")) { foreach (LanguageItem e in Source) { for (int i = 0; i < 6; i++) { if (Target.ContainsKey("Item") && ItemTranslator(Target["Item"].ToTagCompound(), (e.Original as Entity).Equipments[i], (e.Translated as Entity).Equipments[i])) { result = true; goto Next; } } } Next :; } else if (Target.ContainsKey("ArmorItems") || Target.ContainsKey("HandItems")) { TagNodeList list = Target["ArmorItems"].ToTagList(); bool b1 = false, b2 = false, b3 = false, b4 = false; foreach (LanguageItem e in Source) { if (list.Count > 0 && ItemTranslator(list[0].ToTagCompound(), (e.Original as Entity).Equipments[5], (e.Translated as Entity).Equipments[0])) { b1 = true; } if (list.Count > 1 && ItemTranslator(list[1].ToTagCompound(), (e.Original as Entity).Equipments[4], (e.Translated as Entity).Equipments[1])) { b2 = true; } if (list.Count > 2 && ItemTranslator(list[2].ToTagCompound(), (e.Original as Entity).Equipments[3], (e.Translated as Entity).Equipments[2])) { b3 = true; } if (list.Count > 3 && ItemTranslator(list[3].ToTagCompound(), (e.Original as Entity).Equipments[2], (e.Translated as Entity).Equipments[3])) { b4 = true; } if (b1 && b2 && b3 && b4) { goto Next; } } Next: TagNodeList list2 = Target["HandItems"].ToTagList(); bool b5 = false, b6 = false; foreach (LanguageItem e in Source) { if (list2.Count > 0 && ItemTranslator(list2[0].ToTagCompound(), (e.Original as Entity).Equipments[0], (e.Translated as Entity).Equipments[0])) { b5 = true; } if (list2.Count > 1 && ItemTranslator(list2[1].ToTagCompound(), (e.Original as Entity).Equipments[1], (e.Translated as Entity).Equipments[1])) { b6 = true; } if (b5 && b6) { goto End; } } End : result = result ? true : b1 || b2 || b3 || b4 || b5 || b6; } else if (Target.ContainsKey("Equipment")) { TagNodeList list = Target["Equipment"].ToTagList(); bool b1 = false, b2 = false, b3 = false, b4 = false, b5 = false; foreach (LanguageItem e in Source) { if (list.Count > 0 && ItemTranslator(list[0].ToTagCompound(), (e.Original as Entity).Equipments[0], (e.Translated as Entity).Equipments[0])) { b1 = true; } if (list.Count > 1 && ItemTranslator(list[1].ToTagCompound(), (e.Original as Entity).Equipments[2], (e.Translated as Entity).Equipments[1])) { b2 = true; } if (list.Count > 2 && ItemTranslator(list[2].ToTagCompound(), (e.Original as Entity).Equipments[3], (e.Translated as Entity).Equipments[1])) { b3 = true; } if (list.Count > 3 && ItemTranslator(list[3].ToTagCompound(), (e.Original as Entity).Equipments[4], (e.Translated as Entity).Equipments[1])) { b4 = true; } if (list.Count > 4 && ItemTranslator(list[4].ToTagCompound(), (e.Original as Entity).Equipments[5], (e.Translated as Entity).Equipments[1])) { b5 = true; } if (b1 && b2 && b3 && b4 && b5) { goto End; } } End: result = result ? true : b1 || b2 || b3 || b4 || b5; } return(result); }
public override bool Matches(TagCompoundDataNode container, List <TagDataNode> matchedNodes) { TagDataNode childNode = GetChild(container, Name); TagNodeString data = LookupTag <TagNodeString>(container, Name); if (data == null) { return(false); } switch (Operator) { case StringOperator.Equals: if (data.ToTagString().Data != Value) { return(false); } break; case StringOperator.NotEquals: if (data.ToTagString().Data == Value) { return(false); } break; case StringOperator.Contains: if (!data.ToTagString().Data.Contains(Value)) { return(false); } break; case StringOperator.NotContains: if (data.ToTagString().Data.Contains(Value)) { return(false); } break; case StringOperator.StartsWith: if (!data.ToTagString().Data.StartsWith(Value)) { return(false); } break; case StringOperator.EndsWith: if (!data.ToTagString().Data.EndsWith(Value)) { return(false); } break; case StringOperator.Any: break; default: return(false); } if (!matchedNodes.Contains(childNode)) { matchedNodes.Add(childNode); } return(true); }
private static bool FixSpawnData(TagNodeCompound spawnData) { if (!spawnData.ContainsKey("potionValue") && !spawnData.ContainsKey("Potion")) { return(false); } int damage = 0; spawnData["id"] = new TagNodeString("minecraft:potion"); if (spawnData.ContainsKey("potionValue")) { damage = spawnData["potionValue"].ToTagInt(); spawnData.Remove("potionValue"); } if (!spawnData.ContainsKey("Potion")) { spawnData["Potion"] = new TagNodeCompound(); } TagNodeCompound potion = spawnData["Potion"].ToTagCompound(); if (!potion.ContainsKey("tag")) { potion["tag"] = new TagNodeCompound(); } TagNodeCompound tag = potion["tag"].ToTagCompound(); if (!potion.ContainsKey("Count")) { potion["Count"] = new TagNodeByte(1); } if (potion.ContainsKey("Damage")) { if (damage == 0) { damage = potion["Damage"].ToTagInt(); } potion.Remove("Damage"); } potion["id"] = new TagNodeString(ItemInfo.SplashPotion.NameID); if (damage != 0) { string potionEffect = PotionEffects[damage & 15]; string potionPrefix = ""; if ((damage & 32) == 32) { potionPrefix = "strong_"; } else if ((damage & 64) == 64) { potionPrefix = "long_"; } if (potionPrefix == "strong_" && (potionEffect == "fire_resistance" || potionEffect == "night_vision" || potionEffect == "weakness" || potionEffect == "slowness" || potionEffect == "water_breating" || potionEffect == "invisibility")) { tag["Potion"] = new TagNodeString("minecraft:" + potionEffect); } else if (potionPrefix == "long_" && (potionEffect == "healing" || potionEffect == "harming")) { tag["Potion"] = new TagNodeString("minecraft:" + potionEffect); } else { tag["Potion"] = new TagNodeString("minecraft:" + potionPrefix + potionEffect); } } return(true); }
public static bool ItemTranslator(TagNodeCompound Target, Item O, Item T) { if (!Target.ContainsKey("tag") || O == null || T == null) { return(false); } TagNodeCompound tag = Target["tag"].ToTagCompound(); string name = "", lore = ""; bool t = false; if (O is Book && T is Book) { Book bo = O as Book, bt = T as Book; string title = ""; string[] pages; lore = T.Lore == "" ? O.Lore : T.Lore; title = bt.Title == "" ? bo.Title : bt.Title; pages = (bt.Pages == "" ? bo.Pages : bt.Pages).Split('\n'); if (tag.ContainsKey("display")) { TagNodeCompound display = tag["display"].ToTagCompound(); if (display.ContainsKey("Lore")) { if (!CheckLore(display, O)) { goto Next; } List <TagNode> nodes = new List <TagNode>(); foreach (string str in lore.Split('\n')) { nodes.Add(new TagNodeString(str.Replace("\r", ""))); } display["Lore"] = new TagNodeList(TagType.TAG_STRING, nodes); t = true; } } Next: if (tag.ContainsKey("title") && tag["title"].ToTagString().Data == bo.Title) { tag["title"] = new TagNodeString(bt.Title); t = true; } if (tag.ContainsKey("pages")) { TagNodeList Pages = tag["pages"].ToTagList(); string pagestr = ""; foreach (TagNodeString s in Pages) { pagestr += "\n" + s.Data; } if (pagestr.Length != 0) { pagestr = pagestr.Substring(1); } if (pagestr == bo.Pages) { List <TagNode> result = new List <TagNode>(); foreach (string s in pages) { result.Add(new TagNodeString(s)); } tag["pages"] = new TagNodeList(TagType.TAG_STRING, result); t = true; } } } else { if (!tag.ContainsKey("display")) { return(false); } TagNodeCompound compound = tag["display"].ToTagCompound(); if (T.Name == "") { name = O.Name; } else { name = T.Name; } if (T.Lore == "") { lore = O.Lore; } else { lore = T.Lore; } if (compound.ContainsKey("Name") || compound.ContainsKey("Lore")) { if (compound.ContainsKey("Lore") && !CheckLore(compound, O)) { return(false); } if (compound.ContainsKey("Name")) { if (compound["Name"].ToTagString().Data == O.Name) { compound["Name"] = new TagNodeString(name); t = true; } else { return(false); } } if (compound.ContainsKey("Lore")) { if (CheckLore(compound, O)) { List <TagNode> nodes = new List <TagNode>(); foreach (string str in lore.Split('\n')) { nodes.Add(new TagNodeString(str.Replace("\r", ""))); } compound["Lore"] = new TagNodeList(TagType.TAG_STRING, nodes); t = true; } else { return(false); } } t = true; } } return(t); }