Example #1
0
        private void onCharacterSelection(IServerPlayer fromPlayer, CharacterSelectionPacket p)
        {
            bool didSelectBefore = SerializerUtil.Deserialize(fromPlayer.GetModdata("createCharacter"), false);

            if (didSelectBefore && fromPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
            {
                fromPlayer.BroadcastPlayerData(true);
                fromPlayer.Entity.WatchedAttributes.MarkPathDirty("skinConfig");
                return;
            }

            if (p.DidSelect)
            {
                fromPlayer.SetModdata("createCharacter", SerializerUtil.Serialize <bool>(p.DidSelect));

                setCharacterClass(fromPlayer.Entity, p.CharacterClass, !didSelectBefore || fromPlayer.WorldData.CurrentGameMode == EnumGameMode.Creative);

                var bh = fromPlayer.Entity.GetBehavior <EntityBehaviorExtraSkinnable>();
                bh.ApplyVoice(p.VoiceType, p.VoicePitch, false);

                foreach (var skinpart in p.SkinParts)
                {
                    bh.selectSkinPart(skinpart.Key, skinpart.Value, false);
                }
            }

            fromPlayer.Entity.WatchedAttributes.MarkPathDirty("skinConfig");
            fromPlayer.BroadcastPlayerData(true);
        }
Example #2
0
        private void onCharacterSelection(IServerPlayer fromPlayer, CharacterSelectionPacket p)
        {
            bool didSelectBefore = SerializerUtil.Deserialize(fromPlayer.GetModdata("createCharacter"), false);

            if (didSelectBefore && fromPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
            {
                fromPlayer.BroadcastPlayerData(true);
                fromPlayer.Entity.WatchedAttributes.MarkPathDirty("skinConfig");
                return;
            }

            if (p.DidSelect)
            {
                fromPlayer.SetModdata("createCharacter", SerializerUtil.Serialize <bool>(p.DidSelect));

                setCharacterClass(fromPlayer.Entity, p.CharacterClass, !didSelectBefore || fromPlayer.WorldData.CurrentGameMode == EnumGameMode.Creative);

                /*IInventory inv = fromPlayer.InventoryManager.GetOwnInventory(GlobalConstants.characterInvClassName);
                 * for (int i = 0; i < p.Clothes.Length; i++)
                 * {
                 *  CollectibleObject collObj;
                 *  if (p.Clothes[i].Class == EnumItemClass.Block)
                 *  {
                 *      collObj = api.World.GetBlock(new AssetLocation(p.Clothes[i].Code));
                 *  }
                 *  else
                 *  {
                 *      collObj = api.World.GetItem(new AssetLocation(p.Clothes[i].Code));
                 *  }
                 *
                 *  ItemStack stack = new ItemStack(collObj);
                 *  ItemSlot slot = ((InventoryBase)inv)?[p.Clothes[i].SlotNum];
                 *
                 *  if (stack != null && slot != null)
                 *  {
                 *      string clothcat = stack.Item?.Attributes["clothescategory"]?.AsString();
                 *
                 *      if (clothcat != null && allow)
                 *      {
                 *          slot.Itemstack = stack;
                 *          slot.MarkDirty();
                 *      }
                 *  }
                 * }*/


                var bh = fromPlayer.Entity.GetBehavior <EntityBehaviorExtraSkinnable>();
                foreach (var skinpart in p.SkinParts)
                {
                    bh.selectSkinPart(skinpart.Key, skinpart.Value, false);
                }
            }

            fromPlayer.Entity.WatchedAttributes.MarkPathDirty("skinConfig");
            fromPlayer.BroadcastPlayerData(true);
        }