static void DefineModel(Player p, CustomModel model, CustomModelPart[] parts)
        {
            bool hasV1 = p.Supports(CpeExt.CustomModels, 1);
            bool hasV2 = p.Supports(CpeExt.CustomModels, 2);

            if (hasV1 || hasV2)
            {
                var modelId = GetModelId(p, model.name, true).Value;
                Debug("DefineModel {0} {1} {2}", modelId, p.name, model.name);

                model.partCount = (byte)parts.Length;
                byte[] modelPacket = Packet.DefineModel(modelId, model);
                p.Send(modelPacket);

                foreach (var part in parts)
                {
                    if (hasV2)
                    {
                        p.Send(Packet.DefineModelPartV2(modelId, part));
                    }
                    else if (hasV1)
                    {
                        p.Send(Packet.DefineModelPart(modelId, part));
                    }
                }
            }
        }
Esempio n. 2
0
        static void SpawnRaw(Player dst, byte id, Entity entity, Position pos, Orientation rot,
                             string skin, string name, string model)
        {
            // NOTE: Fix for standard clients
            if (id == Entities.SelfID)
            {
                pos.Y -= 22;
            }
            name = Colors.Cleanup(name, dst.hasTextColors);

            if (dst.Supports(CpeExt.ExtPlayerList, 2))
            {
                dst.Send(Packet.ExtAddEntity2(id, skin, name, pos, rot, dst.hasCP437, dst.hasExtPositions));
            }
            else if (dst.hasExtList)
            {
                dst.Send(Packet.ExtAddEntity(id, skin, name, dst.hasCP437));
                dst.Send(Packet.Teleport(id, pos, rot, dst.hasExtPositions));
            }
            else
            {
                dst.Send(Packet.AddEntity(id, name, pos, rot, dst.hasCP437, dst.hasExtPositions));
            }

            if (dst.hasChangeModel && !model.CaselessEq("humanoid"))
            {
                SendModel(dst, id, model);
            }
            if (dst.Supports(CpeExt.EntityProperty))
            {
                dst.Send(Packet.EntityProperty(id, EntityProp.RotX, Orientation.PackedToDegrees(rot.RotX)));
                dst.Send(Packet.EntityProperty(id, EntityProp.RotZ, Orientation.PackedToDegrees(rot.RotZ)));
                SendModelScales(dst, id, entity);
            }
        }
Esempio n. 3
0
 public byte[] MakeDefinePacket(Player pl)
 {
     if (pl.Supports(CpeExt.BlockDefinitionsExt, 2) && Shape != 0)
     {
         return(Packet.DefineBlockExt(this, true, pl.hasCP437, pl.hasExtBlocks, pl.hasExtTexs));
     }
     else if (pl.Supports(CpeExt.BlockDefinitionsExt) && Shape != 0)
     {
         return(Packet.DefineBlockExt(this, false, pl.hasCP437, pl.hasExtBlocks, pl.hasExtTexs));
     }
     else
     {
         return(Packet.DefineBlock(this, pl.hasCP437, pl.hasExtBlocks, pl.hasExtTexs));
     }
 }
Esempio n. 4
0
        static void HandleGettingMOTD(Player p, ref string motd)
        {
            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (!p.Supports(CpeExt.TextHotkey))
                {
                    continue;
                }
                pl.Send(Packet.TextHotKey("Crouch", "/Crouch◙", 54, 0, true));
            }

            // Check if player has actually toggled crouch, since defaults to false
            if (!p.Extras.GetBoolean("IS_CROUCHING"))
            {
                return;
            }

            // Remove current horspeed rule because client does MOTD checking lamely
            motd = motd
                   .SplitSpaces()
                   .Where(word => !word.CaselessStarts("horspeed="))
                   .Join(" ");

            motd += " horspeed=0.52";
        }
Esempio n. 5
0
 public void Unshow(Player p)
 {
     if (!p.Supports(CpeExt.SelectionCuboid) || !Shows)
     {
         return;
     }
     p.Send(Packet.DeleteSelection(ID));
 }
        static void UndefineModel(Player p, string name)
        {
            lock (ModelNameToIdForPlayer) {
                bool hasV1 = p.Supports(CpeExt.CustomModels, 1);
                bool hasV2 = p.Supports(CpeExt.CustomModels, 2);
                if (hasV1 || hasV2)
                {
                    var modelId = GetModelId(p, name).Value;
                    Debug("UndefineModel {0} {1} {2}", modelId, p.name, name);

                    byte[] modelPacket = Packet.UndefineModel(modelId);
                    p.Send(modelPacket);

                    var modelNameToId = ModelNameToIdForPlayer[p.name];
                    modelNameToId.TryRemove(name, out _);
                }
            }
        }
Esempio n. 7
0
        static void SendModelScales(Player dst, byte id, Entity e)
        {
            if (!dst.Supports(CpeExt.EntityProperty))
            {
                return;
            }

            float max = ModelInfo.MaxScale(e, e.Model);

            SendModelScale(dst, id, EntityProp.ScaleX, e.ScaleX, max);
            SendModelScale(dst, id, EntityProp.ScaleY, e.ScaleY, max);
            SendModelScale(dst, id, EntityProp.ScaleZ, e.ScaleZ, max);
        }
Esempio n. 8
0
        static void SendModelScales(Player pl, byte id, Entity entity)
        {
            if (!pl.Supports(CpeExt.EntityProperty))
            {
                return;
            }

            float max = ModelInfo.MaxScale(entity, entity.Model);

            SendModelScale(pl, id, EntityProp.ScaleX, entity.ScaleX, max);
            SendModelScale(pl, id, EntityProp.ScaleY, entity.ScaleY, max);
            SendModelScale(pl, id, EntityProp.ScaleZ, entity.ScaleZ, max);
        }
Esempio n. 9
0
        static void SendModelScales(Player pl, byte id, Entity entity)
        {
            if (!pl.Supports(CpeExt.EntityProperty))
            {
                return;
            }

            string model = entity.Model;
            float  scale = AABB.GetScaleFrom(ref model);

            SendModelScale(pl, id, EntityProp.ScaleX, entity.ScaleX * scale);
            SendModelScale(pl, id, EntityProp.ScaleY, entity.ScaleY * scale);
            SendModelScale(pl, id, EntityProp.ScaleZ, entity.ScaleZ * scale);
        }
Esempio n. 10
0
        public void Show(Player p)
        {
            if (!p.Supports(CpeExt.SelectionCuboid) || !Shows)
            {
                return;
            }

            ColorDesc col; Colors.TryParseHex(Config.ShowColor, out col);
            Vec3U16   min = new Vec3U16(MinX, MinY, MinZ);
            Vec3U16   max = new Vec3U16((ushort)(MaxX + 1), (ushort)(MaxY + 1), (ushort)(MaxZ + 1));

            p.Send(Packet.MakeSelection(ID, Config.Name, min, max,
                                        col.R, col.G, col.B, (byte)Config.ShowAlpha, p.hasCP437));
        }
Esempio n. 11
0
        public static void DefineEffectsFor(Player p)
        {
            if (!p.Supports(CpeExt.CustomParticles))
            {
                p.Message("%WCould not define custom particles because your client is outdated.");
                return;
            }
            p.Socket.LowLatency = true;

            foreach (KeyValuePair <string, EffectConfig> entry in effectAtEffectName)
            {
                DefineEffect(p, entry.Value);
            }
        }
Esempio n. 12
0
        public void Show(Player p)
        {
            if (!p.Supports(CpeExt.SelectionCuboid) || !Shows)
            {
                return;
            }

            ColorDesc col = Colors.ParseHex(Config.ShowColor);

            p.Send(Packet.MakeSelection(
                       ID, "", new Vec3U16(MinX, MinY, MinZ),
                       new Vec3U16((ushort)(MaxX + 1), (ushort)(MaxY + 1), (ushort)(MaxZ + 1)),
                       col.R, col.G, col.B, Config.ShowAlpha, p.hasCP437));
        }
Esempio n. 13
0
        public static void SpawnEffectFor(Player p, string effectName, float x, float y, float z, float originX, float originY, float originZ)
        {
            EffectConfig effect;

            if (!effectAtEffectName.TryGetValue(effectName, out effect))
            {
                p.Message("%WCould not find effect named \"{0}\" !", effectName);
                return;
            }
            if (!p.Supports(CpeExt.CustomParticles))
            {
                return;
            }
            p.Send(Packet.SpawnEffect(effect.ID, x, y - effect.offset, z, originX, originY - effect.offset, originZ));
        }
Esempio n. 14
0
        static void SpawnRaw(Player dst, byte id, Entity e, Position pos, Orientation rot,
                             string skin, string name, string model)
        {
            dst.Session.SendSpawnEntity(id, name, skin, pos, rot);

            if (dst.hasChangeModel)
            {
                OnSendingModelEvent.Call(e, ref model, dst);
                if (!model.CaselessEq("humanoid"))
                {
                    dst.Session.SendChangeModel(id, model);
                }
            }

            if (dst.Supports(CpeExt.EntityProperty))
            {
                dst.Send(Packet.EntityProperty(id, EntityProp.RotX, Orientation.PackedToDegrees(rot.RotX)));
                dst.Send(Packet.EntityProperty(id, EntityProp.RotZ, Orientation.PackedToDegrees(rot.RotZ)));
                SendModelScales(dst, id, e);
            }
        }
Esempio n. 15
0
        public static void HitPlayer(PlayerBot bot, Player p, Orientation rot)
        {
            // Send player backwards if hit
            // Code "borrowed" from PvP plugin

            int srcHeight = ModelInfo.CalcEyeHeight(bot);
            int dstHeight = ModelInfo.CalcEyeHeight(p);
            int dx2 = bot.Pos.X - p.Pos.X, dy2 = (bot.Pos.Y + srcHeight) - (p.Pos.Y + dstHeight), dz2 = bot.Pos.Z - p.Pos.Z;

            Vec3F32 dir2 = new Vec3F32(dx2, dy2, dz2);

            if (dir2.Length > 0)
            {
                dir2 = Vec3F32.Normalise(dir2);
            }

            float mult    = 1 / ModelInfo.GetRawScale(p.Model);
            float plScale = ModelInfo.GetRawScale(p.Model);

            float VelocityY = 1.0117f * mult;

            if (dir2.Length <= 0)
            {
                VelocityY = 0;
            }

            if (p.Supports(CpeExt.VelocityControl))
            {
                // Intensity of force is in part determined by model scale
                p.Send(Packet.VelocityControl((-dir2.X * mult) * 0.57f, VelocityY, (-dir2.Z * mult) * 0.57f, 0, 1, 0));
            }

            // If we are very close to a player, switch from trying to look
            // at them to just facing the opposite direction to them

            rot.RotY = (byte)(p.Rot.RotY + 128);
            bot.Rot  = rot;
        }