public static Item Get(int id, int damage, int count, byte[] nbt) { Item item = Item.Get(id, damage, count); CompoundTag tag = new CompoundTag(); if (nbt != null && nbt.Length > 0) { tag = NBTIO.ReadTag(nbt); } item.NamedTag = tag; return(item); }
public CompoundTag GetNamedTag() { if (!this.HasTags) { return(new CompoundTag()); } if (this.cachedNBT == null) { this.cachedNBT = NBTIO.ReadTag(this.tags); } if (this.cachedNBT != null) { this.cachedNBT.Name = ""; } return(this.cachedNBT); }
public void NBTIOTests_Test4() { /*this.namedTag = new CompoundTag(); * Item item = Item.Get(10); * item.SetCustomName("Test"); * this.namedTag.PutCompound("Item", NBTIO.WriteItem(item)); * * byte[] buffer = NBTIO.WriteTag(this.namedTag); * Console.WriteLine(NBTIO.ReadTag(buffer));*/ string tags = "0a0000090400656e63680a01000000020200696412000203006c766c01000000"; byte[] t = tags.Chunks(2).Select(x => Convert.ToByte(new string(x.ToArray()), 16)).ToArray(); CompoundTag com = NBTIO.ReadTag(t); Console.WriteLine(com); Console.WriteLine(""); Console.WriteLine(NBTIO.ReadTag(NBTIO.WriteTag(com))); }
public Item ReadItem() { int id = this.ReadSVarInt(); if (id == 0) { return(Item.Get(BlockIDs.AIR, 0, 0)); } int auxValue = this.ReadSVarInt(); int data = auxValue >> 8; if (data == short.MaxValue) { data = -1; } int cnt = auxValue & 0xff; int nbtLen = this.ReadLShort(); byte[] nbt = new byte[0]; if (nbtLen < ushort.MaxValue) { nbt = this.ReadBytes(nbtLen); } else if (nbtLen == ushort.MaxValue) { int count = (int)this.ReadUVarInt(); int tmpOffset = this.Offset; for (int i = 0; i < count; i++) { byte[] buf = this.ReadBytes(); CompoundTag tag = NBTIO.ReadTag(buf, out int offset, NBTEndian.LITTLE_ENDIAN, true); nbt = NBTIO.WriteTag(tag); this.Offset = tmpOffset + offset; } } Item item = Item.Get(id, data, cnt, nbt); int canPlaceOn = this.ReadSVarInt(); if (canPlaceOn > 0) { for (int i = 0; i < canPlaceOn; ++i) { item.AddCanPlaceOn(this.ReadString()); } } int canDestroy = this.ReadSVarInt(); if (canDestroy > 0) { for (int i = 0; i < canDestroy; ++i) { item.AddCanDestroy(this.ReadString()); } } return(item); }