Exemple #1
0
 public Item SetNamedTag(CompoundTag nbt)
 {
     nbt.Name       = "";
     this.cachedNBT = nbt;
     this.tags      = NBTIO.WriteTag(nbt);
     return(this);
 }
Exemple #2
0
        public void SpawnTo(Player player)
        {
            BlockEntityDataPacket pk = new BlockEntityDataPacket
            {
                Position = new BlockCoordinate3D((int)this.X, (int)this.Y, (int)this.Z),
                Namedtag = NBTIO.WriteTag(this.SpawnCompound(), NBTEndian.LITTLE_ENDIAN, true)
            };

            player.SendPacket(pk);
        }
Exemple #3
0
        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)));
        }
Exemple #4
0
        public byte[] GetBytes()
        {
            using (BinaryStream stream = new BinaryStream())
            {
                int sendChunk = 16;

                for (int i = 15; i >= 0; i--)
                {
                    if (this.SubChunks[i].IsEnpty)
                    {
                        sendChunk = i;
                    }
                    else
                    {
                        break;
                    }
                }

                stream.WriteByte((byte)sendChunk);
                for (int i = 0; i < sendChunk; ++i)
                {
                    stream.WriteBytes(this.SubChunks[i].GetBytes());
                }

                byte[] b1 = new byte[512];
                Buffer.BlockCopy(this.HeightMap, 0, b1, 0, 512);
                stream.WriteBytes(b1);
                stream.WriteBytes(this.Biomes);
                stream.WriteByte(0);
                stream.WriteSVarInt(0); //TODO Extra Data

                foreach (KeyValuePair <BlockCoordinate3D, BlockEntity> blockEntity in this.BlockEntities)
                {
                    BlockEntitySpawnable s = blockEntity.Value as BlockEntitySpawnable;
                    stream.WriteBytes(NBTIO.WriteTag(s?.SpawnCompound(), NBTEndian.LITTLE_ENDIAN, true));
                }

                return(stream.ToArray());
            }
        }
        public void WriteItem(Item item)
        {
            if (item == null || item.ID == 0)
            {
                this.WriteSVarInt(0);
                return;
            }

            this.WriteSVarInt(item.ID);
            int auxValue = ((item.Damage & 0x7fff) << 8) | (item.Count & 0xff);

            this.WriteSVarInt(auxValue);
            byte[] nbt = new byte[0];
            if (item.NamedTag.Count != 0)
            {
                CompoundTag tag = (CompoundTag)item.NamedTag.Clone();
                tag.Name = "";
                nbt      = NBTIO.WriteTag(tag);
            }

            this.WriteLShort((ushort)nbt.Length);
            this.WriteBytes(nbt);

            string[] canPlaceOn = item.CanPlaceOn;
            this.WriteSVarInt(canPlaceOn.Length);
            for (int i = 0; i < canPlaceOn.Length; ++i)
            {
                this.WriteString(canPlaceOn[i]);
            }

            string[] canDestroy = item.CanDestroy;
            this.WriteSVarInt(canDestroy.Length);
            for (int i = 0; i < canDestroy.Length; ++i)
            {
                this.WriteString(canDestroy[i]);
            }
        }
        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);
        }