internal void Read(BinaryReader reader)
        {
            Utils.VerifyVersion(reader.ReadByte(), SaveVersionConstants.ENTITY_CREATION_DATA);

            entityClass = new Value <int>(reader.ReadInt32());

            id       = new Value <int>(reader.ReadInt32());
            lifetime = new Value <float>(reader.ReadSingle());

            pos = new Vector3D <float> {
                x = new Value <float>(reader.ReadSingle()),
                y = new Value <float>(reader.ReadSingle()),
                z = new Value <float>(reader.ReadSingle())
            };

            rot = new Vector3D <float> {
                x = new Value <float>(reader.ReadSingle()),
                y = new Value <float>(reader.ReadSingle()),
                z = new Value <float>(reader.ReadSingle())
            };

            onGround = new Value <bool>(reader.ReadBoolean());

            bodyDamage = new BodyDamage(reader);

            if (reader.ReadBoolean())
            {
                stats = new EntityStats(reader);
            }

            deathTime = new Value <short>(reader.ReadInt16());

            if (reader.ReadBoolean())
            {
                int tileEntityType = reader.ReadInt32();
                lootContainer = TileEntity.Instantiate((TileEntityType)(tileEntityType));
                lootContainer.Read(reader);
            }

            homePosition = new Vector3D <int> {
                x = new Value <int>(reader.ReadInt32()),
                y = new Value <int>(reader.ReadInt32()),
                z = new Value <int>(reader.ReadInt32())
            };
            homeRange = new Value <short>(reader.ReadInt16());

            spawnerSource = (EnumSpawnerSource)reader.ReadByte();

            if (entityClass.Get() == Utils.GetMonoHash("item"))
            {
                belongsPlayerId = new Value <int>(reader.ReadInt32());
                itemStack.Read(reader);

                reader.ReadSByte();
            }

            else if (entityClass.Get() == Utils.GetMonoHash("fallingBlock"))
            {
                blockValue  = new Value <uint>(reader.ReadUInt32());
                textureFull = new Value <long>(reader.ReadInt64());
            }

            else if (entityClass.Get() == Utils.GetMonoHash("fallingTree"))
            {
                blockPosition = new Vector3D <int> {
                    x = new Value <int>(reader.ReadInt32()),
                    y = new Value <int>(reader.ReadInt32()),
                    z = new Value <int>(reader.ReadInt32())
                };

                fallTreeDir = new Vector3D <float> {
                    x = new Value <float>(reader.ReadSingle()),
                    y = new Value <float>(reader.ReadSingle()),
                    z = new Value <float>(reader.ReadSingle())
                };
            }

            else if ((entityClass.Get() == Utils.GetMonoHash("playerMale")) || (entityClass.Get() == Utils.GetMonoHash("playerFemale")))
            {
                holdingItem = new ItemValue(reader);
                teamNumber  = new Value <byte>(reader.ReadByte());
                entityName  = new Value <string>(reader.ReadString());
                skinTexture = new Value <string>(reader.ReadString());

                if (reader.ReadBoolean())
                {
                    playerProfile = PlayerProfile.Read(reader);
                }
                else
                {
                    playerProfile = null;
                }
            }

            //num2
            ushort entityDataLength = reader.ReadUInt16();

            if (entityDataLength > 0)
            {
                byte[] buffer = reader.ReadBytes(entityDataLength);
                entityData = new MemoryStream(buffer);
            }

            if (reader.ReadBoolean())
            {
                int tileEntityType = reader.ReadInt32();
                traderData = (TileEntityTrader)TileEntity.Instantiate((TileEntityType)(tileEntityType));
                traderData.Read(reader);
            }
        }
Example #2
0
        public void Read(BinaryReader reader)
        {
            entityCreationDataVersion = new Value <byte>(reader.ReadByte());
            entityClass = new Value <int>(reader.ReadInt32());

            id       = new Value <int>(reader.ReadInt32());
            lifetime = new Value <float>(reader.ReadSingle());

            pos   = new Vector3D <float>();
            pos.x = new Value <float>(reader.ReadSingle());
            pos.y = new Value <float>(reader.ReadSingle());
            pos.z = new Value <float>(reader.ReadSingle());

            rot   = new Vector3D <float>();
            rot.x = new Value <float>(reader.ReadSingle());
            rot.y = new Value <float>(reader.ReadSingle());
            rot.z = new Value <float>(reader.ReadSingle());

            onGround = new Value <bool>(reader.ReadBoolean());

            bodyDamage = new BodyDamage();
            bodyDamage.Read(reader);

            bool isStatsNotNull = reader.ReadBoolean();

            if (isStatsNotNull)
            {
                stats = new EntityStats();
                stats.Read(reader);
            }

            deathTime = new Value <int>((int)reader.ReadInt16());


            bool tileEntityNotNull = reader.ReadBoolean();

            if (tileEntityNotNull)
            {
                type          = new Value <int>(reader.ReadInt32());
                lootContainer = TileEntity.Instantiate((TileEntityType)(type.Get()));
                lootContainer.Read(reader);
            }

            homePosition   = new Vector3D <int>();
            homePosition.x = new Value <int>(reader.ReadInt32());
            homePosition.y = new Value <int>(reader.ReadInt32());
            homePosition.z = new Value <int>(reader.ReadInt32());

            unknownD      = new Value <int>((int)reader.ReadInt16());
            spawnerSource = (EnumSpawnerSource)reader.ReadByte();

            if (entityClass.Get() == Utils.GetMonoHash("item"))
            {
                belongsPlayerId = new Value <int>(reader.ReadInt32());
                itemStack.Read(reader);

                reader.ReadSByte();
            }

            else if (entityClass.Get() == Utils.GetMonoHash("fallingBlock"))
            {
                blockValueRawData = new Value <uint>(reader.ReadUInt32());
            }

            else if (entityClass.Get() == Utils.GetMonoHash("fallingTree"))
            {
                blockPosition   = new Vector3D <int>();
                blockPosition.x = new Value <int>(reader.ReadInt32());
                blockPosition.y = new Value <int>(reader.ReadInt32());
                blockPosition.z = new Value <int>(reader.ReadInt32());

                fallTreeDir   = new Vector3D <float>();
                fallTreeDir.x = new Value <float>(reader.ReadSingle());
                fallTreeDir.y = new Value <float>(reader.ReadSingle());
                fallTreeDir.z = new Value <float>(reader.ReadSingle());
            }

            else if ((entityClass.Get() == Utils.GetMonoHash("playerMale")) || (entityClass.Get() == Utils.GetMonoHash("playerFemale")))
            {
                holdingItem = new ItemValue();
                holdingItem.Read(reader);
                teamNumber  = new Value <int>((int)reader.ReadByte());
                entityName  = new Value <string>(reader.ReadString());
                skinTexture = new Value <string>(reader.ReadString());

                bool isPlayerProfileNotNull = reader.ReadBoolean();
                if (isPlayerProfileNotNull)
                {
                    playerProfile = PlayerProfile.Read(reader);
                }
                else
                {
                    playerProfile = null;
                }
            }

            //num2
            int entityDataLength = (int)reader.ReadUInt16();

            if (entityDataLength > 0)
            {
                byte[] buffer = reader.ReadBytes(entityDataLength);
                entityData = new MemoryStream(buffer);
            }

            isTraderEntity = new Value <bool>(reader.ReadBoolean());
        }