public override CompoundTag SaveNBT() { CompoundTag nbt = base.SaveNBT(); nbt.PutShort("Age", this.Age); nbt.PutShort("PickupDelay", this.PickupDelay); nbt.PutString("Owner", this.Owner); nbt.PutCompound("Item", NBTIO.WriteItem(this.Item)); return(nbt); }
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 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 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 CompoundTag CompoundTagDeserialize(JObject json) { CompoundTag tag = new CompoundTag(); foreach (KeyValuePair <string, JToken> kv in json) { JToken token = kv.Value; if (token is JValue) { JValue value = (JValue)token; object t = value.Value; if (t is byte) { tag.PutByte(kv.Key, (byte)t); } else if (t is double) { tag.PutDouble(kv.Key, (double)t); } else if (t is float) { tag.PutFloat(kv.Key, (float)t); } else if (t is int) { tag.PutInt(kv.Key, (int)t); } else if (t is long) { tag.PutLong(kv.Key, (long)t); } else if (t is short) { tag.PutShort(kv.Key, (short)t); } else if (t is string) { tag.PutString(kv.Key, (string)t); } } else if (token is JObject) { tag.PutCompound(kv.Key, NBTJsonSerializer.CompoundTagDeserialize((JObject)token)); } else { tag.PutList(NBTJsonSerializer.ListTagDeserialize((JArray)token, kv.Key)); } } return(tag); }
public void DropItem(Item item, Vector3 pos, Vector3 motion = new Vector3(), int delay = 10) { Chunk chunk = this.GetChunk(pos.FloorX, pos.FloorZ); CompoundTag nbt = Entity.CreateEntityNBT(pos, motion); nbt.PutShort("PickupDelay", (short)delay); Entity entity = Entity.CreateEntity("Item", chunk, nbt); if (entity is EntityItem) { ((EntityItem)entity).Item = item; } entity.SpawnToAll(); }
public void Convert() { for (int i = 0; i < this.BlockEntitiesTag.Length; ++i) { CompoundTag tag = this.BlockEntitiesTag[i]; switch (tag.GetString("id")) { case "minecraft:flower_pot": tag.PutShort("item", (short)Util.GetItemIdFromString(tag.GetString("Item")).Item1); tag.PutInt("mData", tag.GetInt("Data")); tag.Remove("Item"); tag.Remove("Data"); break; case "minecraft:sign": string text1 = tag.GetString("Text1").Remove(0, 9); text1 = text1.Remove(text1.Length - 2, 2); string text2 = tag.GetString("Text2").Remove(0, 9); text2 = text2.Remove(text2.Length - 2, 2); string text3 = tag.GetString("Text3").Remove(0, 9); text3 = text3.Remove(text3.Length - 2, 2); string text4 = tag.GetString("Text4").Remove(0, 9); text4 = text4.Remove(text4.Length - 2, 2); string text = $"{text1}\n{text2}\n{text3}\n{text4}"; tag.PutString("Text", text); break; } } for (int i = 0; i < this.SubChunks.Length; ++i) { if (this.SubChunks[i] == null) { continue; } this.SubChunks[i].Convert(); } }