public void WriteRawFileTest() { ListTag list = new ListTag(Data.NBTTagType.BYTE); list.Name = "listTag"; list.Add(new ByteTag(0xff)); list.Add(new ByteTag(0x00)); list.Add(new ByteTag(0xff)); CompoundTag tag = new CompoundTag(); tag.PutBool("bool", true); tag.PutByte("byte", 0xff); tag.PutShort("short", 0x7fff); tag.PutInt("int", 0x7fffffff); tag.PutLong("long", 0x7fffffffffffffff); tag.PutFloat("float", 0.0001f); tag.PutDouble("double", 0.00000001d); tag.PutString("string", "Hello NBT"); tag.PutByteArray("byte[]", ArrayUtils.CreateArray <byte>(100, 0xff)); tag.PutIntArray("int[]", ArrayUtils.CreateArray <int>(100, 0x7fffffff)); tag.PutLongArray("long[]", ArrayUtils.CreateArray <long>(100, 0x7fffffffffffffff)); tag.PutList(list); NBTIO.WriteRawFile(Path + "\\" + "raw.nbt", tag); }
public void NBTJsonSerializerTests_DeserializeTest() { ListTag list = new ListTag("list", NBTTagType.INT); list.Add(new IntTag(12345)); list.Add(new IntTag(67890)); CompoundTag subTag = new CompoundTag(); subTag.PutBool("bool", true); subTag.PutByte("byte", 123); CompoundTag tag = new CompoundTag(); tag.PutBool("bool", true); tag.PutByte("byte", 123); tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200)); tag.PutShort("short", 12345); tag.PutInt("int", 12345678); tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200)); tag.PutLong("long", 123456789123456); tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200)); tag.PutFloat("float", 12.3456f); tag.PutDouble("double", 12.3456789); tag.PutList(list); tag.PutCompound("com", subTag); JObject json = NBTJsonSerializer.Serialize(tag); Console.WriteLine(NBTJsonSerializer.Serialize(NBTJsonSerializer.Deserialize(json)).ToString()); }
public void NBTIOTests_WriteGZFileTest() { ListTag list = new ListTag("list", NBTTagType.COMPOUND); list.Add(new CompoundTag().PutInt("c1", 123)); list.Add(new CompoundTag().PutLong("c2", 123456)); CompoundTag subTag = new CompoundTag(); subTag.PutBool("bool", true); subTag.PutByte("byte", 123); CompoundTag tag = new CompoundTag(); tag.PutBool("bool", true); tag.PutByte("byte", 123); tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200)); tag.PutShort("short", 12345); tag.PutInt("int", 12345678); tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200)); tag.PutLong("long", 123456789123456); tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200)); tag.PutFloat("float", 12.3456f); tag.PutDouble("double", 12.3456789); tag.PutList(list); tag.PutCompound("com", subTag); NBTIO.WriteGZIPFile(Environment.CurrentDirectory + "\\test2.nbt", tag); }
internal static ListTag ListTagDeserialize(JArray json, string key = "") { ListTag tag = new ListTag(key, NBTTagType.BYTE); foreach (JToken token in json) { if (token is JValue) { JValue value = (JValue)token; object t = value.Value; if (t is byte) { tag.ListTagType = NBTTagType.BYTE; tag.Add(new ByteTag((byte)t)); } else if (t is double) { tag.ListTagType = NBTTagType.DOUBLE; tag.Add(new DoubleTag((double)t)); } else if (t is float) { tag.ListTagType = NBTTagType.FLOAT; tag.Add(new FloatTag((float)t)); } else if (t is int) { tag.ListTagType = NBTTagType.INT; tag.Add(new IntTag((int)t)); } else if (t is long) { tag.ListTagType = NBTTagType.LONG; tag.Add(new LongTag((long)t)); } else if (t is short) { tag.ListTagType = NBTTagType.SHORT; tag.Add(new ShortTag((short)t)); } else if (t is string) { tag.ListTagType = NBTTagType.STRING; tag.Add(new StringTag((string)t)); } } else if (token is JObject) { tag.Add(NBTJsonSerializer.CompoundTagDeserialize((JObject)token)); } else { tag.Add(NBTJsonSerializer.ListTagDeserialize((JArray)token)); } } return(tag); }
public virtual void SaveNBT() { ListTag pos = new ListTag("Pos", NBTTagType.FLOAT); pos.Add(new FloatTag(this.X)); pos.Add(new FloatTag(this.Y)); pos.Add(new FloatTag(this.Z)); this.NamedTag.PutList(pos); ListTag rotation = new ListTag("Rotation", NBTTagType.FLOAT); rotation.Add(new FloatTag(this.Yaw)); rotation.Add(new FloatTag(this.Pitch)); this.NamedTag.PutList(rotation); }
public Item SetLore(params string[] lores) { if (lores == null || lores.Length < 1) { this.ClearLore(); } else { CompoundTag tag; if (this.HasTags) { tag = this.GetNamedTag(); } else { tag = new CompoundTag(); } ListTag list = new ListTag("Lore", NBTTagType.STRING); for (int i = 0; i < lores.Length; ++i) { list.Add(new StringTag(lores[i])); } if (tag.Exist("display")) { tag.GetCompound("display").PutList(list); } else { tag.PutCompound("display", new CompoundTag("display").PutList(list)); } this.SetNamedTag(tag); } return(this); }
public void NBTIOTests_Test3() { this.namedTag = new CompoundTag(); this.namedTag.PutList(new ListTag("Attributes", NBTTagType.COMPOUND)); this.namedTag.PutList(new ListTag("Pos", NBTTagType.FLOAT)); this.namedTag.PutList(new ListTag("Rotation", NBTTagType.FLOAT)); this.namedTag.PutInt("PlayerGameMode", 0); this.namedTag.PutInt("PlayerLevel", 0); this.namedTag.PutFloat("PlayerLevelProgress", 0f); if (!this.namedTag.Exist("Inventory")) { ListTag initItems = new ListTag("Inventory", NBTTagType.COMPOUND); for (int i = 0; i < 36; ++i) { initItems.Add(NBTIO.WriteItem(Item.Get(0), i)); } this.namedTag.PutList(initItems); } ListTag items = this.namedTag.GetList("Inventory"); for (int i = 0; i < 36; ++i) { Item item = NBTIO.ReadItem((CompoundTag)items[i]); } NBTIO.WriteGZIPFile(Environment.CurrentDirectory + "\\test3.nbt", this.namedTag); Console.WriteLine(NBTIO.ReadGZIPFile(Environment.CurrentDirectory + "\\test3.nbt")); }
public PlayerInventory(Player player) : base(player, 36) { if (!player.NamedTag.Exist("Inventory")) { ListTag initItems = new ListTag("Inventory", NBTTagType.COMPOUND); for (int i = 0; i < this.Size; ++i) { initItems.Add(NBTIO.WriteItem(Item.Get(0, 0, 0), i)); } player.NamedTag.PutList(initItems); } ListTag items = player.NamedTag.GetList("Inventory"); for (int i = 0; i < this.Size; ++i) { Item item = NBTIO.ReadItem((CompoundTag)items[i]); this.SetItem(i, item, false); } this.PlayerCursorInventory = new PlayerCursorInventory(player); this.PlayerEnderChestInventory = new PlayerEnderChestInventory(player); this.CraftingGridInventory = new CraftingGridInventory(player); }
public override void SaveNBT() { ListTag inventory = new ListTag("EnderChestInventory", NBTTagType.COMPOUND); for (int i = 0; i < this.Size; ++i) { inventory.Add(NBTIO.WriteItem(this.GetItem(i), i)); } this.Player.NamedTag.PutList(inventory); }
public virtual CompoundTag SaveNBT() { CompoundTag nbt = new CompoundTag(); ListTag list = new ListTag(this.Name, NBTTagType.COMPOUND); for (int i = 0; i < this.Size; ++i) { list.Add(NBTIO.WriteItem(this.GetItem(i), i)); } nbt.PutList(list); return(nbt); }
public static CompoundTag WriteItem(Item item, int slot = -1) { CompoundTag nbt = new CompoundTag() .PutShort("id", (short)item.ID) .PutShort("damage", (short)item.Damage) .PutByte("count", (byte)item.Count); if (slot != -1) { nbt.PutByte("slot", (byte)slot); } if (item.NamedTag.Count != 0) { nbt.PutCompound("tag", item.NamedTag); } string[] canPlaceOn = item.CanPlaceOn; if (canPlaceOn.Length > 0) { ListTag list = new ListTag("CanPlaceOn", NBTTagType.STRING); for (int i = 0; i < canPlaceOn.Length; ++i) { list.Add(new StringTag(canPlaceOn[i])); } nbt.PutList(list); } string[] canDestroy = item.CanDestroy; if (canDestroy.Length > 0) { ListTag list = new ListTag("CanDestroy", NBTTagType.STRING); for (int i = 0; i < canDestroy.Length; ++i) { list.Add(new StringTag(canDestroy[i])); } nbt.PutList(list); } return(nbt); }
public EntityArmorInventory(EntityLiving entity) : base(entity) { if (!entity.NamedTag.Exist("Armor")) { ListTag newTag = new ListTag("Armor", NBTTagType.COMPOUND); for (int i = 0; i < this.Size; ++i) { newTag.Add(NBTIO.WriteItem(Item.Get(0, 0, 0), i)); } entity.NamedTag.PutList(newTag); } ListTag items = entity.NamedTag.GetList("Armor"); for (int i = 0; i < this.Size; ++i) { Item item = NBTIO.ReadItem((CompoundTag)items[i]); this.SetItem(i, item, false); } }
public EntityOffhandInventory(EntityLiving holder) : base(holder) { if (!holder.NamedTag.Exist("Offhand")) { ListTag newTag = new ListTag("Offhand", NBTTagType.COMPOUND); for (int i = 0; i < this.Size; ++i) { newTag.Add(NBTIO.WriteItem(Item.Get(0, 0, 0))); } holder.NamedTag.PutList(newTag); } ListTag items = holder.NamedTag.GetList("Offhand"); for (int i = 0; i < this.Size; ++i) { Item item = NBTIO.ReadItem((CompoundTag)items[i]); this.SetItem(i, item, false); } }
public virtual void LoadNBT(CompoundTag nbt) { if (!nbt.Exist(this.Name)) { ListTag list = new ListTag(this.Name, NBTTagType.COMPOUND); for (int i = 0; i < this.Size; ++i) { list.Add(NBTIO.WriteItem(Item.Get(0, 0, 0))); } nbt.PutList(list); } ListTag items = nbt.GetList(this.Name); for (int i = 0; i < this.Size; ++i) { Item item = NBTIO.ReadItem((CompoundTag)items[i]); this.SetItem(i, item, false); } }
public ChestInventory(BlockEntityChest holder) : base(holder) { if (!holder.NamedTag.Exist("Items")) { ListTag initItems = new ListTag("Items", NBTTagType.COMPOUND); for (int i = 0; i < this.Size; ++i) { initItems.Add(NBTIO.WriteItem(Item.Get(0, 0, 0), i)); } holder.NamedTag.PutList(initItems); } ListTag items = holder.NamedTag.GetList("Items"); for (int i = 0; i < this.Size; ++i) { Item item = NBTIO.ReadItem((CompoundTag)items[i]); this.SetItem(i, item, false); } }
public Item AddLore(params string[] lores) { if (lores == null || lores.Length < 1) { return(this); } if (!this.HasTags || this.GetLore().Length < 1) { this.SetLore(lores); return(this); } CompoundTag tag = this.GetNamedTag(); ListTag list = tag.GetCompound("display").GetList("Lore"); for (int i = 0; i < lores.Length; ++i) { list.Add(new StringTag(lores[i])); } this.SetNamedTag(tag); return(this); }
public PlayerEnderChestInventory(Player player) : base(null) { this.Player = player; if (!player.NamedTag.Exist("EnderChestInventory")) { ListTag newTag = new ListTag("EnderChestInventory", NBTTagType.COMPOUND); for (int i = 0; i < this.Size; ++i) { newTag.Add(NBTIO.WriteItem(Item.Get(0, 0, 0))); } player.NamedTag.PutList(newTag); } ListTag items = player.NamedTag.GetList("EnderChestInventory"); for (int i = 0; i < this.Size; ++i) { Item item = NBTIO.ReadItem((CompoundTag)items[i]); this.SetItem(i, item, false); } }
private ListTag ConvertSections(ListTag sections) { ListTag list = new ListTag("Sections", NBTTagType.COMPOUND); foreach (Tag sectionTag in sections.Tags) { if (sectionTag is CompoundTag) { CheckCancel(); if (((CompoundTag)sectionTag).Exist("Palette")) { list.Add(ConvertSection(sectionTag)); } else { return(null); } } } return(list); }
protected override void OnPropertyChanged(string propertyName) { base.OnPropertyChanged(propertyName); if (propertyName == "SelectedViewPicModel") { if (SelectedViewPicModel != null) { BigPictureUrl = SelectedViewPicModel.ImageUrl; var model = _listPostilInfoModel.FirstOrDefault(t => t._id == SelectedViewPicModel.PostilId); if (model == null) { return; } PostilTitle = model.Title; PostilTime = model.CreateTime; PostilFounder = model.PostilUser; PublicOrPrivate = model.IsPublic ? "公开" : "不公开"; ListTag.Clear(); foreach (var tag in model.Tags) { ListTag.Add(new TagInfoModel { Name = $" {tag} " }); } } else { BigPictureUrl = null; PostilTitle = ""; PostilTime = DateTime.MinValue; PostilFounder = ""; PublicOrPrivate = ""; ListTag.Clear(); } } }
public override CompoundTag SerializeChunk(Chunk chunk) { CompoundTag tag = new CompoundTag(); tag.PutInt("xPos", chunk.X); tag.PutInt("zPos", chunk.Z); tag.PutLong("LastUpdate", chunk.LastUpdate); tag.PutByte("LightPopulated", chunk.LightPopulated); tag.PutByte("TerrainPopulated", chunk.TerrainPopulated); tag.PutByte("V", chunk.V); tag.PutLong("InhabitedTime", chunk.InhabitedTime); tag.PutByteArray("Biomes", chunk.Biomes); int[] cast = new int[256]; chunk.HeightMap.CopyTo(cast, 0); tag.PutIntArray("HeightMap", cast); ListTag sections = new ListTag("Sections", NBTTagType.COMPOUND); SubChunk[] subChunks = chunk.SubChunks; for (int i = 0; i < subChunks.Length; ++i) { if (subChunks[i] == null) { continue; } CompoundTag data = new CompoundTag(); data.PutByte("Y", (byte)i); byte[] blocks = new byte[subChunks[i].BlockDatas.Length]; for (int j = 0; j < subChunks[i].BlockDatas.Length; ++j) { blocks[j] = (byte)subChunks[i].BlockDatas[j]; } data.PutByteArray("Blocks", blocks); data.PutByteArray("Data", subChunks[i].MetaDatas.ArrayData); data.PutByteArray("BlockLight", subChunks[i].BlockLight); data.PutByteArray("SkyLight", subChunks[i].SkyLight); sections.Add(data); } tag.PutList(sections); ListTag entitiesTag = new ListTag("Entities", NBTTagType.COMPOUND); CompoundTag[] entities = chunk.EntitiesTag; for (int i = 0; i < entities.Length; ++i) { entitiesTag.Add(entities[i]); } tag.PutList(entitiesTag); ListTag blockEntitiesTag = new ListTag("TileEntities", NBTTagType.COMPOUND); CompoundTag[] blockEntities = chunk.BlockEntitiesTag; for (int i = 0; i < blockEntities.Length; ++i) { blockEntitiesTag.Add(blockEntities[i]); } tag.PutList(blockEntitiesTag); return(new CompoundTag().PutCompound("", new CompoundTag().PutCompound("Level", tag))); }
public CompoundTag NBTSerialize(Chunk chunk) { CompoundTag tag = new CompoundTag("Level"); tag.PutInt("xPos", chunk.X); //Chunk X tag.PutInt("zPos", chunk.Z); //Chunk Z tag.PutLong("LastUpdate", chunk.LastUpdate); //Last Save Tick tag.PutByte("LightPopulated", chunk.LightPopulated ? (byte)1 : (byte)0); // tag.PutByte("TerrainPopulated", chunk.TerrainPopulated ? (byte)1 : (byte)0); // tag.PutByte("V", 1); //Version tag.PutLong("InhabitedTime", chunk.InhabitedTime); tag.PutByteArray("Biomes", chunk.Biomes); int[] cast = new int[256]; chunk.HeightMap.CopyTo(cast, 0); tag.PutIntArray("HeightMap", cast); ListTag sections = new ListTag("Sections", NBTTagType.COMPOUND); SubChunk[] subChunks = chunk.SubChunks; for (int i = 0; i < subChunks.Length; ++i) { if (subChunks[i].IsEnpty) { continue; } CompoundTag data = new CompoundTag(); data.PutByte("Y", (byte)i); data.PutIntArray("Blocks", subChunks[i].BlockDatas); data.PutByteArray("Data", subChunks[i].MetaDatas.ArrayData); data.PutByteArray("SkyLight", subChunks[i].SkyLights.ArrayData); data.PutByteArray("BlockLight", subChunks[i].BlockLigths.ArrayData); sections.Add(data); } tag.PutList(sections); ListTag entitiesTag = new ListTag("Entities", NBTTagType.COMPOUND); Entity[] entities = chunk.GetEntities(); for (int i = 0; i < entities.Length; ++i) { if (entities[i].IsPlayer) { continue; } entitiesTag.Add(entities[i].SaveNBT()); } tag.PutList(entitiesTag); ListTag blockEntitiesTag = new ListTag("TileEntities", NBTTagType.COMPOUND); BlockEntity[] blockEntities = chunk.GetBlockEntities(); for (int i = 0; i < blockEntities.Length; ++i) { blockEntitiesTag.Add(blockEntities[i].SaveNBT()); } tag.PutList(blockEntitiesTag); CompoundTag outTag = new CompoundTag(""); outTag.PutCompound(tag.Name, tag); return(outTag); }