public static void UpdateEntityProp(Entity entity, EntityProp prop, int value) { Player[] players = PlayerInfo.Online.Items; Level lvl = entity.Level; Orientation rot = entity.Rot; byte angle = Orientation.DegreesToPacked(value); if (prop == EntityProp.RotX) { rot.RotX = angle; } if (prop == EntityProp.RotY) { rot.RotY = angle; } if (prop == EntityProp.RotZ) { rot.RotZ = angle; } entity.Rot = rot; if (prop == EntityProp.RotY) { entity.SetYawPitch(rot.RotY, rot.HeadX); } foreach (Player pl in players) { if (pl.level != lvl || !pl.Supports(CpeExt.EntityProperty)) { continue; } if (!pl.CanSeeEntity(entity)) { continue; } byte id = (pl == entity) ? Entities.SelfID : entity.EntityID; pl.Send(Packet.EntityProperty(id, prop, Orientation.PackedToDegrees(angle))); } }
void Goto(Player p, string playerName = null, ushort page = 0) { bool all = false; if (playerName != null) { playerName = playerName.ToLower(); if (playerName == "all") { all = true; } else if (playerName == "public") { playerName = null; } else { playerName = StoredCustomModel.GetPlayerName(playerName) ?? StoredCustomModel.GetPlayerName(playerName + "+"); } } List <string> modelNames; if (all) { var dict = GetAllModels(p); modelNames = dict // public ones first .OrderByDescending(pair => pair.Key == "Public") // then by player name A-Z .ThenBy(pair => pair.Key) .Select(pair => pair.Value) .SelectMany(x => x) .ToList(); } else { modelNames = GetModels(playerName, p); } if (modelNames == null) { return; } // - 1 for our self player var partitionSize = Packet.MaxCustomModels - 1; var partitions = modelNames.Partition(partitionSize).ToList(); if (page >= partitions.Count) { p.Message( "%WPage doesn't exist" ); return; } var total = modelNames.Count; modelNames = partitions[page]; p.Message( "%HViewing %T{0} %Hmodels{1}", total, partitions.Count > 1 ? string.Format( " %S(page %T{0}%S/%T{1}%S)", page + 1, partitions.Count ) : "" ); if (partitions.Count > 1 && page < (partitions.Count - 1)) { p.Message( "%SUse \"%H/cm goto {0} {1}%S\" to go to the next page", playerName, page + 2 ); } var mapName = string.Format( "&f{0} Custom Models{1}", all ? "All" : ( playerName == null ? "Public" : GetNameWithoutPlus(playerName) + "'s" ), page != 0 ? string.Format(" ({0})", page + 1) : "" ); ushort spacing = 4; ushort width = (ushort)( // edges (spacing * 2) + // grass blocks modelNames.Count + // inbetween blocks ((modelNames.Count - 1) * (spacing - 1)) ); ushort height = 1; ushort length = 16; byte[] blocks = new byte[width * height * length]; Level lvl = new Level(mapName, width, height, length, blocks); for (int i = 0; i < blocks.Length; i++) { blocks[i] = 1; } lvl.SaveChanges = false; lvl.ChangedSinceBackup = false; lvl.IsMuseum = true; lvl.BuildAccess.Min = LevelPermission.Nobody; lvl.Config.Physics = 0; lvl.spawnx = spacing; lvl.spawny = 2; lvl.Config.HorizonBlock = 1; lvl.Config.EdgeLevel = 1; lvl.Config.CloudsHeight = -0xFFFFFF; lvl.Config.SidesOffset = 0; lvl.Config.Buildable = false; lvl.Config.Deletable = false; for (ushort i = 0; i < modelNames.Count; i++) { ushort x = (ushort)(spacing + (i * spacing)); ushort y = 0; ushort z = spacing; blocks[lvl.PosToInt(x, y, z)] = 2; var modelName = modelNames[i]; var storedModel = new StoredCustomModel(modelName); if (storedModel.Exists()) { storedModel.LoadFromFile(); } var skinName = p.SkinName; if ( !storedModel.usesHumanSkin && storedModel.defaultSkin != null ) { skinName = storedModel.defaultSkin; } // hack because clients strip + at the end var botName = "&f" + (modelName.EndsWith("+") ? modelName + "&0+" : modelName); var bot = new PlayerBot(botName, lvl) { id = (byte)i, Model = modelName, SkinName = skinName, }; bot.SetInitialPos(Position.FromFeetBlockCoords(x, y + 1, z)); bot.SetYawPitch(Orientation.DegreesToPacked(180), Orientation.DegreesToPacked(0)); bot.ClickedOnText = "/CustomModel wear " + modelName; _ = lvl.Bots.Add(bot); } if (!PlayerActions.ChangeMap(p, lvl)) { return; } }