Ejemplo n.º 1
0
        public void SpawnToPlayers(Player player)
        {
            var addEntity = McpeAddEntity.CreateObject();

            addEntity.entityType      = (byte)EntityTypeId;
            addEntity.entityIdSelf    = EntityId;
            addEntity.runtimeEntityId = EntityId;
            addEntity.x          = KnownPosition.X;
            addEntity.y          = KnownPosition.Y;
            addEntity.z          = KnownPosition.Z;
            addEntity.yaw        = KnownPosition.Yaw;
            addEntity.pitch      = KnownPosition.Pitch;
            addEntity.metadata   = GetMetadata();
            addEntity.speedX     = (float)Velocity.X;
            addEntity.speedY     = (float)Velocity.Y;
            addEntity.speedZ     = (float)Velocity.Z;
            addEntity.attributes = GetEntityAttributes();
            player.SendPackage(addEntity);

            SendAttributes(player);

            var BossEvent = McpeBossEvent.CreateObject();

            //BossEvent.WriteSignedVarLong(EntityId);
            BossEvent.bossEntityId = EntityId;
            BossEvent.eventType    = 0;
            //BossEvent.WriteSignedVarLong(0);
            player.SendPackage(BossEvent);
        }
Ejemplo n.º 2
0
Archivo: Entity.cs Proyecto: Eros/MiNET
        public virtual void SpawnEntity()
        {
            Level.AddEntity(this);

            var addEntity = McpeAddEntity.CreateObject();

            addEntity.entityType = EntityTypeId;
            addEntity.entityId   = EntityId;
            addEntity.x          = KnownPosition.X;
            addEntity.y          = KnownPosition.Y;
            addEntity.z          = KnownPosition.Z;
            addEntity.yaw        = KnownPosition.Yaw;
            addEntity.pitch      = KnownPosition.Pitch;
            addEntity.metadata   = GetMetadata();
            addEntity.speedX     = (float)Velocity.X;
            addEntity.speedY     = (float)Velocity.Y;
            addEntity.speedZ     = (float)Velocity.Z;

            Level.RelayBroadcast(addEntity);

            IsSpawned = true;

            //McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject();
            //mcpeSetEntityData.entityId = EntityId;
            //mcpeSetEntityData.metadata = GetMetadata();
            //Level.RelayBroadcast(mcpeSetEntityData);
        }
Ejemplo n.º 3
0
        public virtual void SpawnToPlayers(Player[] players)
        {
            var addEntity = McpeAddEntity.CreateObject();

            addEntity.entityType      = (byte)EntityTypeId;
            addEntity.entityIdSelf    = EntityId;
            addEntity.runtimeEntityId = EntityId;
            addEntity.x        = KnownPosition.X;
            addEntity.y        = KnownPosition.Y;
            addEntity.z        = KnownPosition.Z;
            addEntity.yaw      = KnownPosition.Yaw;
            addEntity.pitch    = KnownPosition.Pitch;
            addEntity.metadata = GetMetadata();
            addEntity.speedX   = (float)Velocity.X;
            addEntity.speedY   = (float)Velocity.Y;
            addEntity.speedZ   = (float)Velocity.Z;
            Level.RelayBroadcast(players, addEntity);

            var msg = addEntity;

            Log.DebugFormat("McpeAddEntity Entity ID: {0}", msg.entityIdSelf);
            Log.DebugFormat("McpeAddEntity Runtime Entity ID: {0}", msg.runtimeEntityId);
            Log.DebugFormat("Entity Type: {0}", msg.entityType);
            Log.DebugFormat("X: {0}", msg.x);
            Log.DebugFormat("Y: {0}", msg.y);
            Log.DebugFormat("Z: {0}", msg.z);
            Log.DebugFormat("Yaw: {0}", msg.yaw);
            Log.DebugFormat("Pitch: {0}", msg.pitch);
            Log.DebugFormat("Velocity X: {0}", msg.speedX);
            Log.DebugFormat("Velocity Y: {0}", msg.speedY);
            Log.DebugFormat("Velocity Z: {0}", msg.speedZ);
            Log.DebugFormat("Metadata: {0}", MetadataDictionary.MetadataToCode(msg.metadata));
        }
Ejemplo n.º 4
0
        public override void HandleMcpeAddEntity(McpeAddEntity message)
        {
            var type = message.entityType.Replace("minecraft:", "");

            if (Enum.TryParse(typeof(EntityType), type, true, out object res))
            {
                SpawnMob(message.runtimeEntityId, Guid.NewGuid(), (EntityType)res, new PlayerLocation(message.x, message.y, message.z, message.headYaw, message.yaw, message.pitch), new Microsoft.Xna.Framework.Vector3(message.speedX, message.speedY, message.speedZ));
            }
            else
            {
                Log.Warn($"Unknown mob: {type}");
            }
        }
Ejemplo n.º 5
0
        public virtual void SpawnToPlayers(Player[] players)
        {
            var addEntity = McpeAddEntity.CreateObject();

            addEntity.entityType = EntityTypeId;
            addEntity.entityId   = EntityId;
            addEntity.x          = KnownPosition.X;
            addEntity.y          = KnownPosition.Y;
            addEntity.z          = KnownPosition.Z;
            addEntity.yaw        = KnownPosition.Yaw;
            addEntity.pitch      = KnownPosition.Pitch;
            addEntity.metadata   = GetMetadata();
            addEntity.speedX     = (float)Velocity.X;
            addEntity.speedY     = (float)Velocity.Y;
            addEntity.speedZ     = (float)Velocity.Z;
            Level.RelayBroadcast(players, addEntity);
        }
Ejemplo n.º 6
0
        private static void OnMcpeAddEntity(Package message)
        {
            McpeAddEntity msg = (McpeAddEntity)message;

            Log.DebugFormat("Entity ID: {0}", msg.entityId);
            Log.DebugFormat("Entity Type: {0}", msg.entityType);
            Log.DebugFormat("X: {0}", msg.x);
            Log.DebugFormat("Y: {0}", msg.y);
            Log.DebugFormat("Z: {0}", msg.z);
            Log.DebugFormat("Yaw: {0}", msg.yaw);
            Log.DebugFormat("Pitch: {0}", msg.pitch);
            Log.DebugFormat("Velocity X: {0}", msg.speedX);
            Log.DebugFormat("Velocity Y: {0}", msg.speedY);
            Log.DebugFormat("Velocity Z: {0}", msg.speedZ);
            Log.DebugFormat("Velocity Z: {0}", msg.metadata);
            //Log.DebugFormat("Links count: {0}", msg.links);
        }
Ejemplo n.º 7
0
        public override void SpawnToPlayers(Player[] players)
        {
            //McpeUpdateBlockSynced updateBlock = McpeUpdateBlockSynced.CreateObject();
            //updateBlock.coordinates = _original.Coordinates;
            //updateBlock.blockRuntimeId = 0;
            //updateBlock.blockPriority = 3;
            //updateBlock.dataLayerId = 0;
            //updateBlock.unknown0 = EntityId;
            //updateBlock.unknown1 = 1;

            //Level.RelayBroadcast(players, updateBlock);

            //base.SpawnToPlayers(players);

            foreach (var player in players)
            {
                McpeUpdateBlockSynced updateBlock = McpeUpdateBlockSynced.CreateObject();
                updateBlock.coordinates    = _original.Coordinates;
                updateBlock.blockRuntimeId = 0;
                updateBlock.blockPriority  = 3;
                updateBlock.dataLayerId    = 0;
                updateBlock.unknown0       = EntityId;
                updateBlock.unknown1       = 1;

                var addEntity = McpeAddEntity.CreateObject();
                addEntity.entityType      = (byte)EntityTypeId;
                addEntity.entityIdSelf    = EntityId;
                addEntity.runtimeEntityId = EntityId;
                addEntity.x          = KnownPosition.X;
                addEntity.y          = KnownPosition.Y;
                addEntity.z          = KnownPosition.Z;
                addEntity.pitch      = KnownPosition.Pitch;
                addEntity.yaw        = KnownPosition.Yaw;
                addEntity.headYaw    = KnownPosition.HeadYaw;
                addEntity.metadata   = GetMetadata();
                addEntity.speedX     = Velocity.X;
                addEntity.speedY     = Velocity.Y;
                addEntity.speedZ     = Velocity.Z;
                addEntity.attributes = GetEntityAttributes();

                player.SendPacket(updateBlock);
                player.SendPacket(addEntity);
            }
        }
Ejemplo n.º 8
0
 public virtual void SpawnToPlayer(Player player, PlayerLocation pl, int x, int z)
 {
     {
         var addEntity = McpeAddEntity.CreateObject();
         addEntity.entityType      = (byte)EntityType.Slime;
         addEntity.entityIdSelf    = EntityId;
         addEntity.runtimeEntityId = EntityId;
         addEntity.x          = pl.X + x + 0.5f;
         addEntity.y          = pl.Y - 2;
         addEntity.z          = pl.Z + z + 0.5f;
         addEntity.yaw        = 0;
         addEntity.pitch      = 0;
         addEntity.metadata   = GetMetadata();
         addEntity.speedX     = 0;
         addEntity.speedY     = 0;
         addEntity.speedZ     = 0;
         addEntity.attributes = GetEntityAttributes();
         player.SendPackage(addEntity);
     }
 }
Ejemplo n.º 9
0
Archivo: Entity.cs Proyecto: oas/MiNET
        public virtual void SpawnToPlayers(Player[] players)
        {
            var addEntity = McpeAddEntity.CreateObject();

            addEntity.entityType      = (byte)EntityTypeId;
            addEntity.entityIdSelf    = EntityId;
            addEntity.runtimeEntityId = EntityId;
            addEntity.x          = KnownPosition.X;
            addEntity.y          = KnownPosition.Y;
            addEntity.z          = KnownPosition.Z;
            addEntity.yaw        = KnownPosition.Yaw;
            addEntity.pitch      = KnownPosition.Pitch;
            addEntity.metadata   = GetMetadata();
            addEntity.speedX     = Velocity.X;
            addEntity.speedY     = Velocity.Y;
            addEntity.speedZ     = Velocity.Z;
            addEntity.attributes = GetEntityAttributes();

            Level.RelayBroadcast(players, addEntity);
        }
Ejemplo n.º 10
0
		public virtual void SpawnToPlayer(Player player)
		{
			var addEntity = McpeAddEntity.CreateObject();
			addEntity.entityType = EntityTypeId;
			addEntity.entityId = EntityId;
			addEntity.x = KnownPosition.X;
			addEntity.y = KnownPosition.Y;
			addEntity.z = KnownPosition.Z;
			addEntity.yaw = KnownPosition.Yaw;
			addEntity.pitch = KnownPosition.Pitch;
			addEntity.metadata = GetMetadata();
			addEntity.speedX = (float) Velocity.X;
			addEntity.speedY = (float) Velocity.Y;
			addEntity.speedZ = (float) Velocity.Z;
			player.SendPackage(addEntity);

			//McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject();
			//mcpeSetEntityData.entityId = EntityId;
			//mcpeSetEntityData.metadata = GetMetadata();
			//mcpeSetEntityData.Encode();
			//player.SendPackage(mcpeSetEntityData);
		}
Ejemplo n.º 11
0
 public override void HandleMcpeAddEntity(McpeAddEntity message)
 {
 }
 public abstract void HandleMcpeAddEntity(McpeAddEntity message);
Ejemplo n.º 13
0
        /// <summary>
        ///     Handles the specified package.
        /// </summary>
        /// <param name="message">The package.</param>
        /// <param name="senderEndpoint">The sender's endpoint.</param>
        private void HandlePackage(Package message, IPEndPoint senderEndpoint)
        {
            if (typeof(McpeBatch) == message.GetType())
            {
                Log.Debug("Processing Batch package");
                McpeBatch batch = (McpeBatch)message;

                var messages = new List <Package>();

                // Get bytes
                byte[] payload = batch.payload;
                // Decompress bytes

                MemoryStream stream = new MemoryStream(payload);
                if (stream.ReadByte() != 0x78)
                {
                    throw new InvalidDataException("Incorrect ZLib header. Expected 0x78");
                }
                stream.ReadByte();
                using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
                {
                    // Get actual package out of bytes
                    MemoryStream destination = new MemoryStream();
                    defStream2.CopyTo(destination);
                    destination.Position = 0;
                    NbtBinaryReader reader = new NbtBinaryReader(destination, true);
                    do
                    {
                        int    len            = reader.ReadInt32();
                        byte[] internalBuffer = reader.ReadBytes(len);
                        messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer));
                    } while (destination.Position < destination.Length);                     // throw new Exception("Have more data");
                }
                foreach (var msg in messages)
                {
                    HandlePackage(msg, senderEndpoint);
                    msg.PutPool();
                }
                return;
            }

            TraceReceive(message);

            if (typeof(UnknownPackage) == message.GetType())
            {
                return;
            }

            if (typeof(McpeDisconnect) == message.GetType())
            {
                McpeDisconnect msg = (McpeDisconnect)message;
                Log.InfoFormat("Disconnect {1}: {0}", msg.message, Username);
                SendDisconnectionNotification();
                StopClient();
                return;
            }

            if (typeof(ConnectedPing) == message.GetType())
            {
                ConnectedPing msg = (ConnectedPing)message;
                SendConnectedPong(msg.sendpingtime);
                return;
            }

            if (typeof(McpeFullChunkData) == message.GetType())
            {
                //McpeFullChunkData msg = (McpeFullChunkData) message;
                //ChunkColumn chunk = ClientUtils.DecocedChunkColumn(msg.chunkData);
                //if (chunk != null)
                //{
                //	Log.DebugFormat("Chunk X={0}", chunk.x);
                //	Log.DebugFormat("Chunk Z={0}", chunk.z);

                //	//ClientUtils.SaveChunkToAnvil(chunk);
                //}
                return;
            }

            if (typeof(ConnectionRequestAccepted) == message.GetType())
            {
                Thread.Sleep(50);
                SendNewIncomingConnection();
                //_connectedPingTimer = new Timer(state => SendConnectedPing(), null, 1000, 1000);
                Thread.Sleep(50);
                SendLogin(Username);
                return;
            }

            if (typeof(McpeSetSpawnPosition) == message.GetType())
            {
                McpeSetSpawnPosition msg = (McpeSetSpawnPosition)message;
                _spawn        = new Vector3(msg.x, msg.y, msg.z);
                _level.SpawnX = (int)_spawn.X;
                _level.SpawnY = (int)_spawn.Y;
                _level.SpawnZ = (int)_spawn.Z;

                return;
            }

            if (typeof(McpeStartGame) == message.GetType())
            {
                McpeStartGame msg = (McpeStartGame)message;
                _entityId        = msg.entityId;
                _spawn           = new Vector3(msg.x, msg.y, msg.z);
                _level.LevelName = "Default";
                _level.Version   = 19133;
                _level.GameType  = msg.gamemode;

                //ClientUtils.SaveLevel(_level);

                return;
            }

            if (typeof(McpeTileEvent) == message.GetType())
            {
                McpeTileEvent msg = (McpeTileEvent)message;
                Log.DebugFormat("X: {0}", msg.x);
                Log.DebugFormat("Y: {0}", msg.y);
                Log.DebugFormat("Z: {0}", msg.z);
                Log.DebugFormat("Case 1: {0}", msg.case1);
                Log.DebugFormat("Case 2: {0}", msg.case2);
                return;
            }
            if (typeof(McpeAddEntity) == message.GetType())
            {
                McpeAddEntity msg = (McpeAddEntity)message;
                Log.DebugFormat("Entity ID: {0}", msg.entityId);
                Log.DebugFormat("Entity Type: {0}", msg.entityType);
                Log.DebugFormat("X: {0}", msg.x);
                Log.DebugFormat("Y: {0}", msg.y);
                Log.DebugFormat("Z: {0}", msg.z);
                Log.DebugFormat("Yaw: {0}", msg.yaw);
                Log.DebugFormat("Pitch: {0}", msg.pitch);
                Log.DebugFormat("Velocity X: {0}", msg.speedX);
                Log.DebugFormat("Velocity Y: {0}", msg.speedY);
                Log.DebugFormat("Velocity Z: {0}", msg.speedZ);
                //Log.DebugFormat("Metadata: {0}", msg.metadata.ToString());
                //Log.DebugFormat("Links count: {0}", msg.links);

                return;
            }
            if (typeof(McpeSetEntityData) == message.GetType())
            {
                McpeSetEntityData msg = (McpeSetEntityData)message;
                Log.DebugFormat("Entity ID: {0}", msg.entityId);
                MetadataDictionary metadata = msg.metadata;
                Log.DebugFormat("Metadata: {0}", metadata.ToString());
                return;
            }

            if (typeof(McpeMovePlayer) == message.GetType())
            {
                //McpeMovePlayer msg = (McpeMovePlayer) message;
                //Log.DebugFormat("Entity ID: {0}", msg.entityId);

                //CurrentLocation = new PlayerLocation(msg.x, msg.y + 10, msg.z);
                //SendMcpeMovePlayer();
                return;
            }

            if (typeof(McpeUpdateBlock) == message.GetType())
            {
                McpeUpdateBlock msg = (McpeUpdateBlock)message;
                Log.DebugFormat("No of Blocks: {0}", msg.blocks.Count);
                return;
            }

            if (typeof(McpeLevelEvent) == message.GetType())
            {
                McpeLevelEvent msg = (McpeLevelEvent)message;
                Log.DebugFormat("Event ID: {0}", msg.eventId);
                Log.DebugFormat("X: {0}", msg.x);
                Log.DebugFormat("Y: {0}", msg.y);
                Log.DebugFormat("Z: {0}", msg.z);
                Log.DebugFormat("Data: {0}", msg.data);
                return;
            }

            if (typeof(McpeContainerSetContent) == message.GetType())
            {
                McpeContainerSetContent msg = (McpeContainerSetContent)message;
                Log.DebugFormat("Window ID: 0x{0:x2}, Count: {1}", msg.windowId, msg.slotData.Count);
                var slots = msg.slotData.GetValues();

                foreach (var entry in slots)
                {
                    MetadataSlot slot = (MetadataSlot)entry;
                    //Log.DebugFormat(" - Id: {0}, Metadata: {1}, Count: {2}", slot.Value.Item.Id, slot.Value.Item.Metadata, slot.Value.Count);
                }
                return;
            }

            if (typeof(McpeCraftingData) == message.GetType())
            {
                string fileName = Path.GetTempPath() + "Recipes_" + Guid.NewGuid() + ".txt";
                Log.Info("Writing recipes to filename: " + fileName);
                FileStream file = File.OpenWrite(fileName);

                McpeCraftingData   msg    = (McpeCraftingData)message;
                IndentedTextWriter writer = new IndentedTextWriter(new StreamWriter(file));

                writer.WriteLine("static RecipeManager()");
                writer.WriteLine("{");
                writer.Indent++;
                writer.WriteLine("Recipes = new Recipes");
                writer.WriteLine("{");
                writer.Indent++;

                foreach (Recipe recipe in msg.recipes)
                {
                    ShapelessRecipe shapelessRecipe = recipe as ShapelessRecipe;
                    if (shapelessRecipe != null)
                    {
                        writer.WriteLine(string.Format("new ShapelessRecipe(new ItemStack(ItemFactory.GetItem({0}, {1}), {2}),", shapelessRecipe.Result.Id, shapelessRecipe.Result.Metadata, shapelessRecipe.Result.Count));
                        writer.Indent++;
                        writer.WriteLine("new List<ItemStack>");
                        writer.WriteLine("{");
                        writer.Indent++;
                        foreach (var itemStack in shapelessRecipe.Input)
                        {
                            writer.WriteLine(string.Format("new ItemStack(ItemFactory.GetItem({0}, {1}), {2}),", itemStack.Id, itemStack.Metadata, itemStack.Count));
                        }
                        writer.Indent--;
                        writer.WriteLine("}),");
                        writer.Indent--;

                        continue;
                    }

                    ShapedRecipe shapedRecipe = recipe as ShapedRecipe;
                    if (shapedRecipe != null)
                    {
                        writer.WriteLine(string.Format("new ShapedRecipe({0}, {1}, new ItemStack(ItemFactory.GetItem({2}, {3}), {4}),", shapedRecipe.Width, shapedRecipe.Height, shapedRecipe.Result.Id, shapedRecipe.Result.Metadata, shapedRecipe.Result.Count));
                        writer.Indent++;
                        writer.WriteLine("new Item[]");
                        writer.WriteLine("{");
                        writer.Indent++;
                        foreach (Item item in shapedRecipe.Input)
                        {
                            writer.WriteLine(string.Format("ItemFactory.GetItem({0}, {1}),", item.Id, item.Metadata));
                        }
                        writer.Indent--;
                        writer.WriteLine("}),");
                        writer.Indent--;

                        continue;
                    }
                }

                writer.WriteLine("};");
                writer.Indent--;
                writer.WriteLine("}");
                writer.Indent--;

                writer.Flush();

                file.Close();
                Environment.Exit(0);
                return;
            }
        }
Ejemplo n.º 14
0
        public override void SpawnEntity()
        {
            lock (_spawnSync)
            {
                if (IsSpawned)
                {
                    throw new Exception("Invalid state. Tried to spawn projectile more than one time.");
                }


                Level.AddEntity(this);

                IsSpawned = true;

                if (Shooter == null)
                {
                    var addEntity = McpeAddEntity.CreateObject();
                    addEntity.entityType = EntityTypeId;
                    addEntity.entityId   = EntityId;
                    addEntity.x          = KnownPosition.X;
                    addEntity.y          = KnownPosition.Y;
                    addEntity.z          = KnownPosition.Z;
                    addEntity.yaw        = KnownPosition.Yaw;
                    addEntity.pitch      = KnownPosition.Pitch;
                    addEntity.metadata   = GetMetadata();
                    addEntity.speedX     = (float)Velocity.X;
                    addEntity.speedY     = (float)Velocity.Y;
                    addEntity.speedZ     = (float)Velocity.Z;

                    Level.RelayBroadcast(addEntity);

                    McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject();
                    mcpeSetEntityData.entityId = EntityId;
                    mcpeSetEntityData.metadata = GetMetadata();
                    Level.RelayBroadcast(mcpeSetEntityData);
                }
                else
                {
                    {
                        var addEntity = McpeAddEntity.CreateObject();
                        addEntity.entityType = EntityTypeId;
                        addEntity.entityId   = EntityId;
                        addEntity.x          = KnownPosition.X;
                        addEntity.y          = KnownPosition.Y;
                        addEntity.z          = KnownPosition.Z;
                        addEntity.yaw        = KnownPosition.Yaw;
                        addEntity.pitch      = KnownPosition.Pitch;
                        addEntity.metadata   = GetMetadata();
                        addEntity.speedX     = (float)Velocity.X;
                        addEntity.speedY     = (float)Velocity.Y;
                        addEntity.speedZ     = (float)Velocity.Z;

                        Level.RelayBroadcast(Shooter, addEntity);

                        McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject();
                        mcpeSetEntityData.entityId = EntityId;
                        mcpeSetEntityData.metadata = GetMetadata();
                        Level.RelayBroadcast(Shooter, mcpeSetEntityData);
                    }
                    {
                        MetadataDictionary metadata = GetMetadata();
                        metadata[17] = new MetadataLong(0);

                        var addEntity = McpeAddEntity.CreateObject();
                        addEntity.entityType = EntityTypeId;
                        addEntity.entityId   = EntityId;
                        addEntity.x          = KnownPosition.X;
                        addEntity.y          = KnownPosition.Y;
                        addEntity.z          = KnownPosition.Z;
                        addEntity.yaw        = KnownPosition.Yaw;
                        addEntity.pitch      = KnownPosition.Pitch;
                        addEntity.metadata   = metadata;
                        addEntity.speedX     = (float)Velocity.X;
                        addEntity.speedY     = (float)Velocity.Y;
                        addEntity.speedZ     = (float)Velocity.Z;

                        Shooter.SendPackage(addEntity);

                        McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject();
                        mcpeSetEntityData.entityId = EntityId;
                        mcpeSetEntityData.metadata = metadata;
                        Shooter.SendPackage(mcpeSetEntityData);
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public virtual void HandleMcpeAddEntity(McpeAddEntity message)
 {
 }
Ejemplo n.º 16
0
        public override void SpawnEntity()
        {
            Level.AddEntity(this);

            if (Shooter == null)
            {
                var addEntity = McpeAddEntity.CreateObject();
                addEntity.entityType = EntityTypeId;
                addEntity.entityId   = EntityId;
                addEntity.x          = KnownPosition.X;
                addEntity.y          = KnownPosition.Y;
                addEntity.z          = KnownPosition.Z;
                addEntity.yaw        = KnownPosition.Yaw;
                addEntity.pitch      = KnownPosition.Pitch;
                //addEntity.metadata = GetMetadata();
                addEntity.speedX = (float)Velocity.X;
                addEntity.speedY = (float)Velocity.Y;
                addEntity.speedZ = (float)Velocity.Z;

                Level.RelayBroadcast(addEntity);

                IsSpawned = true;

                McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject();
                mcpeSetEntityData.entityId = EntityId;
                mcpeSetEntityData.metadata = GetMetadata();
                Level.RelayBroadcast(mcpeSetEntityData);
            }
            else
            {
                {
                    var addEntity = McpeAddEntity.CreateObject();
                    addEntity.entityType = EntityTypeId;
                    addEntity.entityId   = EntityId;
                    addEntity.x          = KnownPosition.X;
                    addEntity.y          = KnownPosition.Y;
                    addEntity.z          = KnownPosition.Z;
                    addEntity.yaw        = KnownPosition.Yaw;
                    addEntity.pitch      = KnownPosition.Pitch;
                    //addEntity.metadata = GetMetadata();
                    addEntity.speedX = (float)Velocity.X;
                    addEntity.speedY = (float)Velocity.Y;
                    addEntity.speedZ = (float)Velocity.Z;

                    Level.RelayBroadcast(Shooter, addEntity);

                    McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject();
                    mcpeSetEntityData.entityId = EntityId;
                    mcpeSetEntityData.metadata = GetMetadata();
                    Level.RelayBroadcast(Shooter, mcpeSetEntityData);
                }
                {
                    MetadataDictionary metadata = GetMetadata();
                    metadata[17] = new MetadataLong(0);

                    var addEntity = McpeAddEntity.CreateObject();
                    addEntity.entityType = EntityTypeId;
                    addEntity.entityId   = EntityId;
                    addEntity.x          = KnownPosition.X;
                    addEntity.y          = KnownPosition.Y;
                    addEntity.z          = KnownPosition.Z;
                    addEntity.yaw        = KnownPosition.Yaw;
                    addEntity.pitch      = KnownPosition.Pitch;
                    //addEntity.metadata = metadata;
                    addEntity.speedX = (float)Velocity.X;
                    addEntity.speedY = (float)Velocity.Y;
                    addEntity.speedZ = (float)Velocity.Z;

                    Shooter.SendPackage(addEntity);

                    McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject();
                    mcpeSetEntityData.entityId = EntityId;
                    mcpeSetEntityData.metadata = metadata;
                    Shooter.SendPackage(mcpeSetEntityData);
                }
            }
        }
Ejemplo n.º 17
0
        public override void HandleMcpeAddEntity(McpeAddEntity message)
        {
            if (Client.IsEmulator)
            {
                return;
            }

            if (!Client.Entities.ContainsKey(message.entityIdSelf))
            {
                var entity = new Entity(message.entityType, null);
                entity.EntityId      = message.runtimeEntityId;
                entity.KnownPosition = new PlayerLocation(message.x, message.y, message.z, message.yaw, message.yaw, message.pitch);
                entity.Velocity      = new Vector3(message.speedX, message.speedY, message.speedZ);
                Client.Entities.TryAdd(entity.EntityId, entity);
            }

            Log.DebugFormat("McpeAddEntity Entity ID: {0}", message.entityIdSelf);
            Log.DebugFormat("McpeAddEntity Runtime Entity ID: {0}", message.runtimeEntityId);
            Log.DebugFormat("Entity Type: {0}", message.entityType);
            Log.DebugFormat("X: {0}", message.x);
            Log.DebugFormat("Y: {0}", message.y);
            Log.DebugFormat("Z: {0}", message.z);
            Log.DebugFormat("Yaw: {0}", message.yaw);
            Log.DebugFormat("Pitch: {0}", message.pitch);
            Log.DebugFormat("Velocity X: {0}", message.speedX);
            Log.DebugFormat("Velocity Y: {0}", message.speedY);
            Log.DebugFormat("Velocity Z: {0}", message.speedZ);
            Log.DebugFormat("Metadata: {0}", Client.MetadataToCode(message.metadata));
            Log.DebugFormat("Links count: {0}", message.links?.Count);

            if (message.metadata.Contains(0))
            {
                long?value = ((MetadataLong)message.metadata[0])?.Value;
                if (value != null)
                {
                    long dataValue = (long)value;
                    Log.Debug($"Bit-array datavalue: dec={dataValue} hex=0x{dataValue:x2}, bin={Convert.ToString(dataValue, 2)}b ");
                }
            }

            if (Log.IsDebugEnabled)
            {
                foreach (var attribute in message.attributes)
                {
                    Log.Debug($"Entity attribute {attribute}");
                }
            }

            Log.DebugFormat("Links count: {0}", message.links);

            if (Log.IsDebugEnabled && Client._mobWriter != null)
            {
                Client._mobWriter.WriteLine("Entity Type: {0}", message.entityType);
                Client._mobWriter.Indent++;
                Client._mobWriter.WriteLine("Metadata: {0}", Client.MetadataToCode(message.metadata));
                Client._mobWriter.Indent--;
                Client._mobWriter.WriteLine();
                Client._mobWriter.Flush();
            }

            if (message.entityType == "minecraft:horse")
            {
                var     id  = message.runtimeEntityId;
                Vector3 pos = new Vector3(message.x, message.y, message.z);
                Task.Run(BotHelpers.DoWaitForSpawn(Client))
                .ContinueWith(t => Task.Delay(3000).Wait())
                //.ContinueWith(task =>
                //{
                //	Log.Warn("Sending jump for player");

                //	McpeInteract action = McpeInteract.CreateObject();
                //	action.targetRuntimeEntityId = id;
                //	action.actionId = (int) 3;
                //	SendPackage(action);
                //})
                //.ContinueWith(t => Task.Delay(2000).Wait())
                //.ContinueWith(task =>
                //{
                //	for (int i = 0; i < 10; i++)
                //	{
                //		Log.Warn("Mounting horse");

                //		McpeInventoryTransaction transaction = McpeInventoryTransaction.CreateObject();
                //		transaction.transaction = new Transaction()
                //		{
                //			TransactionType = McpeInventoryTransaction.TransactionType.ItemUseOnEntity,
                //			TransactionRecords = new List<TransactionRecord>(),
                //			EntityId = id,
                //			ActionType = 0,
                //			Slot = 0,
                //			Item = new ItemAir(),
                //			//Item = new ItemBlock(new Cobblestone()) { Count = 64 },
                //			Position = BlockCoordinates.Zero,
                //			FromPosition = CurrentLocation,
                //			ClickPosition = pos,
                //		};

                //		SendPackage(transaction);
                //		Thread.Sleep(4000);
                //	}

                //})
                .ContinueWith(task =>
                {
                    Log.Warn("Sending sneak for player");

                    McpePlayerAction action = McpePlayerAction.CreateObject();
                    action.runtimeEntityId  = Client.EntityId;
                    action.actionId         = (int)PlayerAction.StartSneak;
                    Client.SendPacket(action);
                })
                .ContinueWith(t => Task.Delay(2000).Wait())
                .ContinueWith(task =>
                {
                    Log.Warn("Sending transaction for horse");

                    var transaction         = McpeInventoryTransaction.CreateObject();
                    transaction.transaction = new ItemUseOnEntityTransaction()
                    {
                        TransactionRecords = new List <TransactionRecord>(),
                        EntityId           = id,
                        ActionType         = 0,
                        Slot          = 0,
                        Item          = new ItemAir(),
                        FromPosition  = Client.CurrentLocation,
                        ClickPosition = pos,
                    };

                    Client.SendPacket(transaction);
                });
            }
        }
Ejemplo n.º 18
0
Archivo: Level.cs Proyecto: wgaox/MiNET
        public void AddEntity(Entity entity)
        {
            lock (Entities)
            {
                EntityManager.AddEntity(null, entity);

                if (!Entities.Contains(entity))
                {
                    Entities.Add(entity);
                }
                else
                {
                    throw new Exception("Entity existed in the players list when it should not");
                }

                if (entity is ItemEntity)
                {
                    ItemEntity itemEntity = (ItemEntity)entity;

                    Random random = new Random();

                    float f  = 0.7F;
                    float xr = (float)(random.NextDouble() * f + (1.0F - f) * 0.5D);
                    float yr = (float)(random.NextDouble() * f + (1.0F - f) * 0.5D);
                    float zr = (float)(random.NextDouble() * f + (1.0F - f) * 0.5D);

                    RelayBroadcast(new McpeAddItemEntity()
                    {
                        entityId = itemEntity.EntityId,
                        item     = itemEntity.GetMetadataSlot(),
                        x        = itemEntity.KnownPosition.X + xr,
                        y        = itemEntity.KnownPosition.Y + yr,
                        z        = itemEntity.KnownPosition.Z + zr,
                    });
                }
                else
                {
                    var addEntity = new McpeAddEntity
                    {
                        entityType = entity.EntityTypeId,
                        entityId   = entity.EntityId,
                        x          = entity.KnownPosition.X,
                        y          = entity.KnownPosition.Y,
                        z          = entity.KnownPosition.Z,
                        yaw        = entity.KnownPosition.Yaw,
                        pitch      = entity.KnownPosition.Pitch,
                        metadata   = entity.GetMetadata()
                    };
                    {
                        double dx = entity.Velocity.X;
                        double dy = entity.Velocity.Y;
                        double dz = entity.Velocity.Z;
                        //double maxVelocity = 3.92d;

                        //if (dx < -maxVelocity)
                        //{
                        //	dx = -maxVelocity;
                        //}

                        //if (dy < -maxVelocity)
                        //{
                        //	dy = -maxVelocity;
                        //}

                        //if (dz < -maxVelocity)
                        //{
                        //	dz = -maxVelocity;
                        //}

                        //if (dx > maxVelocity)
                        //{
                        //	dx = maxVelocity;
                        //}

                        //if (dy > maxVelocity)
                        //{
                        //	dy = maxVelocity;
                        //}

                        //if (dz > maxVelocity)
                        //{
                        //	dz = maxVelocity;
                        //}

                        //addEntity.speedX = (short)(dx * 8000.0d);
                        //addEntity.speedY = (short)(dy * 8000.0d);
                        //addEntity.speedZ = (short)(dz * 8000.0d);
                        addEntity.speedX = (float)(dx);
                        addEntity.speedY = (float)(dy);
                        addEntity.speedZ = (float)(dz);
                    }

                    RelayBroadcast(addEntity);

                    RelayBroadcast(new McpeSetEntityData
                    {
                        entityId = entity.EntityId,
                        metadata = entity.GetMetadata(),
                    });
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     Handles the specified package.
        /// </summary>
        /// <param name="message">The package.</param>
        /// <param name="senderEndpoint">The sender's endpoint.</param>
        private void HandlePackage(Package message, IPEndPoint senderEndpoint)
        {
            if (typeof(McpeBatch) == message.GetType())
            {
                McpeBatch batch = (McpeBatch)message;

                var messages = new List <Package>();

                // Get bytes
                byte[] payload = batch.payload;
                // Decompress bytes

                MemoryStream stream = new MemoryStream(payload);
                if (stream.ReadByte() != 0x78)
                {
                    throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
                }
                stream.ReadByte();
                using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
                {
                    // Get actual package out of bytes
                    MemoryStream destination = new MemoryStream();
                    defStream2.CopyTo(destination);
                    byte[] internalBuffer = destination.ToArray();
                    messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer));
                }
                foreach (var msg in messages)
                {
                    HandlePackage(msg, senderEndpoint);
                }
                return;
            }

            TraceReceive(message);

            if (typeof(UnknownPackage) == message.GetType())
            {
                return;
            }

            if (typeof(McpeDisconnect) == message.GetType())
            {
                McpeDisconnect msg = (McpeDisconnect)message;
                Log.Debug(msg.message);
                StopServer();
                return;
            }

            if (typeof(ConnectedPing) == message.GetType())
            {
                ConnectedPing msg = (ConnectedPing)message;
                SendConnectedPong(msg.sendpingtime);
                return;
            }

            if (typeof(McpeFullChunkData) == message.GetType())
            {
                McpeFullChunkData msg   = (McpeFullChunkData)message;
                ChunkColumn       chunk = ClientUtils.DecocedChunkColumn(msg.chunkData);
                if (chunk != null)
                {
                    Log.DebugFormat("Chunk X={0}", chunk.x);
                    Log.DebugFormat("Chunk Z={0}", chunk.z);

                    ClientUtils.SaveChunkToAnvil(chunk);
                }
                return;
            }

            if (typeof(ConnectionRequestAccepted) == message.GetType())
            {
                Thread.Sleep(50);
                SendNewIncomingConnection();
                var t1 = new Timer(state => SendConnectedPing(), null, 2000, 5000);
                Thread.Sleep(50);
                SendLogin("Client12");
                return;
            }

            if (typeof(McpeSetSpawnPosition) == message.GetType())
            {
                McpeSetSpawnPosition msg = (McpeSetSpawnPosition)message;
                _spawn        = new Vector3(msg.x, msg.y, msg.z);
                _level.SpawnX = (int)_spawn.X;
                _level.SpawnY = (int)_spawn.Y;
                _level.SpawnZ = (int)_spawn.Z;

                return;
            }

            if (typeof(McpeStartGame) == message.GetType())
            {
                McpeStartGame msg = (McpeStartGame)message;
                _entityId        = msg.entityId;
                _spawn           = new Vector3(msg.x, msg.y, msg.z);
                _level.LevelName = "Default";
                _level.Version   = 19133;
                _level.GameType  = msg.gamemode;

                ClientUtils.SaveLevel(_level);

                return;
            }

            if (typeof(McpeTileEvent) == message.GetType())
            {
                McpeTileEvent msg = (McpeTileEvent)message;
                Log.DebugFormat("X: {0}", msg.x);
                Log.DebugFormat("Y: {0}", msg.y);
                Log.DebugFormat("Z: {0}", msg.z);
                Log.DebugFormat("Case 1: {0}", msg.case1);
                Log.DebugFormat("Case 2: {0}", msg.case2);
                return;
            }
            if (typeof(McpeAddEntity) == message.GetType())
            {
                McpeAddEntity msg = (McpeAddEntity)message;
                Log.DebugFormat("Entity ID: {0}", msg.entityId);
                Log.DebugFormat("Entity Type: {0}", msg.entityType);
                Log.DebugFormat("X: {0}", msg.x);
                Log.DebugFormat("Y: {0}", msg.y);
                Log.DebugFormat("Z: {0}", msg.z);
                Log.DebugFormat("Yaw: {0}", msg.yaw);
                Log.DebugFormat("Pitch: {0}", msg.pitch);
                Log.DebugFormat("Velocity X: {0}", msg.speedX);
                Log.DebugFormat("Velocity Y: {0}", msg.speedY);
                Log.DebugFormat("Velocity Z: {0}", msg.speedZ);
                Log.DebugFormat("Metadata: {0}", msg.metadata.ToString());
                Log.DebugFormat("Links count: {0}", msg.links);

                return;
            }
            if (typeof(McpeSetEntityData) == message.GetType())
            {
                McpeSetEntityData msg = (McpeSetEntityData)message;
                Log.DebugFormat("Entity ID: {0}", msg.entityId);
                MetadataDictionary metadata = msg.metadata;
                Log.DebugFormat("Metadata: {0}", metadata.ToString());
                return;
            }

            if (typeof(McpeMovePlayer) == message.GetType())
            {
                McpeMovePlayer msg = (McpeMovePlayer)message;
                Log.DebugFormat("Entity ID: {0}", msg.entityId);

                _currentLocation = new PlayerLocation(msg.x, msg.y + 10, msg.z);
                SendMcpeMovePlayer();
                return;
            }

            if (typeof(McpeUpdateBlock) == message.GetType())
            {
                McpeUpdateBlock msg = (McpeUpdateBlock)message;
                Log.DebugFormat("No of Blocks: {0}", msg.blocks.Count);
                return;
            }

            if (typeof(McpeLevelEvent) == message.GetType())
            {
                McpeLevelEvent msg = (McpeLevelEvent)message;
                Log.DebugFormat("Event ID: {0}", msg.eventId);
                Log.DebugFormat("X: {0}", msg.x);
                Log.DebugFormat("Y: {0}", msg.y);
                Log.DebugFormat("Z: {0}", msg.z);
                Log.DebugFormat("Data: {0}", msg.data);
                return;
            }
        }