예제 #1
0
        public override void HandlePacket(MinecraftServer server, MinecraftClient client)
        {
            var target = server.EntityManager.GetEntity(TargetId);
            if (target == null || 
                server.EntityManager.GetEntityWorld(target) != server.EntityManager.GetEntityWorld(client.Entity) ||
                target.Position.DistanceTo(client.Entity.Position) > client.Reach)
                return;

            if (target is LivingEntity)
            {
                // Do damage
                if (LeftClick)
                {
                    var livingEntity = target as LivingEntity;
                    if (livingEntity.Invulnerable)
                        return;

                    var item = client.Entity.SelectedItem.Item;
                    if (item == null)
                        item = new AirBlock();
                    client.Entity.FoodExhaustion += 0.3f;
                    livingEntity.Damage(item.AttackDamage);
                    livingEntity.Velocity /*+*/= DataUtility.RotateY(new Vector3(0, 0, client.Entity.IsSprinting ? 10 : 3),
                                                                     // TODO: Knockback enchantment
                                                                     DataUtility.DegreesToRadians(client.Entity.Yaw));
                    if (livingEntity is PlayerEntity)
                    {
                        (livingEntity as PlayerEntity).LastDamageType = DamageType.Combat;
                        (livingEntity as PlayerEntity).LastAttackingEntity = client.Entity;
                    }
                    // TODO: Physics
                }
            }
        }
예제 #2
0
        public static void UseEntity(MinecraftClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (UseEntityPacket)_packet;
            var target = server.EntityManager.GetEntity(packet.Target);
            if (target == null ||
                server.EntityManager.GetEntityWorld(target) != server.EntityManager.GetEntityWorld(client.Entity) ||
                target.Position.DistanceTo(client.Entity.Position) > client.Reach)
                return;
            target.UsedByEntity(client.World, packet.LeftClick, client.Entity);
            if (target is LivingEntity)
            {
                // Do damage
                // TODO: Move to Craft.Net.Data?
                if (packet.LeftClick)
                {
                    var livingEntity = target as LivingEntity;
                    if (livingEntity.Invulnerable)
                        return;

                    var item = client.Entity.SelectedItem.AsItem();
                    if (item == null)
                        item = new AirBlock();
                    client.Entity.FoodExhaustion += 0.3f;
                    livingEntity.Damage(item.AttackDamage);
                    // TODO: Knockback enchantment
                    livingEntity.Velocity /*+*/= MathHelper.RotateY(new Vector3(0, 0, client.Entity.IsSprinting ? 10 : 3),
                        MathHelper.DegreesToRadians(client.Entity.Yaw));
                    if (livingEntity is PlayerEntity)
                    {
                        (livingEntity as PlayerEntity).LastDamageType = DamageType.Combat;
                        (livingEntity as PlayerEntity).LastAttackingEntity = client.Entity;
                    }
                    // TODO: Physics
                }
            }
        }