public static void handleItem(Packet _packet)
 {
     ItemData data = _packet.ReadItemData();
     if (data.playerControl != Client.myId)
     {
         if (ignoredItems.Contains(data.itemId)) return;
         if (Client.items.ContainsKey(data.networkId) && Client.items[data.networkId].clientsideItem != null)
         {
             if(Client.items[data.networkId].clientsideItem.data.id!=data.itemId)
             {
                 Client.items[data.networkId].clientsideItem.Despawn();
                 return;
             }
             Client.items[data.networkId].clientsideItem.transform.position = data.objectData.position;
             Client.items[data.networkId].clientsideItem.transform.rotation = data.objectData.rotation;
             Client.items[data.networkId].clientsideItem.rb.velocity = data.objectData.velocity;
             Client.items[data.networkId].clientsideItem.rb.angularVelocity = data.objectData.angularVelocity;
             Client.items[data.networkId].clientsideItem.rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
             Client.items[data.networkId].toDelete = DateTime.Now.AddMilliseconds(100);
         }
         else
         {
             if(Catalog.current.GetData<BS.ItemData>(data.itemId)!=null)
             {
                 data.clientsideItem = Catalog.current.GetData<BS.ItemData>(data.itemId).Spawn();
                 data.clientsideItem.data.forceLayer = LayerName.MovingObject;
                 data.clientsideItem.SetColliderAndMeshLayer(VRManager.GetLayer(LayerName.MovingObject));
                 data.clientsideItem.data.moduleAI = null;
                 data.clientsideItem.transform.position = data.objectData.position;
                 data.clientsideItem.transform.rotation = data.objectData.rotation;
                 data.clientsideItem.rb.velocity = data.objectData.velocity;
                 data.clientsideItem.rb.angularVelocity = data.objectData.angularVelocity;
                 data.toDelete = DateTime.Now.AddMilliseconds(100);
                 Client.items[data.networkId] = data;
                 Client.networkedItems[data.networkId] = data.clientsideItem;
             }
             else
             {
                 Debug.Log($"{data.itemId} failed to spawn, adding to ignored items list");
                 ignoredItems.Add(data.itemId);
             }
         }
     }
 }
        private void AttachObjects(AttachmentPointLogic point1, AttachmentPointLogic point2, Item ungrabbedItem, Interactor interactor)
        {
            //ungrabbed item definition
            ItemDefinition ungrabbedItemDefinition = point1.GetComponentInParent <ItemDefinition>();
            ItemDefinition point2ItemDefinition    = point2.GetComponentInParent <ItemDefinition>();



            // Getting item position
            Transform point1ItemTransform = point1.GetComponentInParent <ItemDefinition>().transform;
            Transform point2ItemTransform = point2.GetComponentInParent <ItemDefinition>().transform;


            Item     point2Item     = point2ItemTransform.GetComponent <Item>();
            ItemData point2ItemData = point2Item.data;



            point1ItemTransform.MoveAlign(point1.transform, point2.transform);


            // -------------------------------------------------------------------- //
            //                                  Renderes and BladeMeshes            //
            // -------------------------------------------------------------------- //

            foreach (Renderer renderer in ungrabbedItemDefinition.renderers)
            {
                renderer.gameObject.transform.parent = point2ItemTransform;
                point2ItemDefinition.renderers.Add(renderer);
                if (point1.partType == "blade")
                {
                    bladeRenderes.Add(renderer);
                    //Debug.Log("ADDED BLADE " + "Total " + bladeRenderes.Count);
                }
            }

            //Debug.Log("Total blades " + bladeRenderes.Count);

            // -------------------------------------------------------------------- //
            //                                  Damagers                            //
            // -------------------------------------------------------------------- //

            foreach (ItemData.Damager damager1 in point2ItemData.damagers.ToList())
            {
                if (ungrabbedItem.data.damagers.Contains(damager1))
                {
                    point2ItemData.damagers.Remove(damager1);
                    //Debug.Log("Removed damager");
                }
            }

            //Debug.Log(point2ItemData.damagers.Count);

            point2ItemData.damagers.AddRange(ungrabbedItem.data.damagers);

            //Debug.Log(point2ItemData.damagers.Count);

            foreach (DamagerDefinition damagerDefinition in ungrabbedItem.GetComponentsInChildren <DamagerDefinition>())
            {
                damagerDefinition.colliderGroup.transform.parent = point2ItemTransform;

                //Debug.Log("ColliderGroup Name " + damagerDefinition.colliderGroup.name);
                damagerDefinition.transform.parent = point2ItemTransform;
                //Debug.Log("damagerDefinition " + damagerDefinition.name);
            }

            point2ItemDefinition.colliderGroups.AddRange(ungrabbedItemDefinition.colliderGroups);

            point2Item.damagers.Clear();

            foreach (ItemData.Damager damager in point2ItemData.damagers)
            {
                foreach (DamagerDefinition damagerDefinition in point2.GetComponentInParent <ItemDefinition>().GetComponentsInChildren <DamagerDefinition>())
                {
                    if (damagerDefinition.name == damager.transformName)
                    {
                        Damager[] components2 = damagerDefinition.GetComponents <Damager>();
                        for (int j = 0; j < components2.Length; j++)
                        {
                            UnityEngine.Object.Destroy(components2[j]);
                        }
                        if (damagerDefinition.colliderGroup == null)
                        {
                            Debug.LogError("colliderGroup on DamagerDefinition is null");
                        }
                        else
                        {
                            Damager damager2 = damagerDefinition.gameObject.AddComponent <Damager>();
                            damager2.Load(Catalog.current.GetData <DamagerData>(damager.damagerID, true));
                            point2Item.damagers.Add(damager2);
                        }
                    }
                }
            }

            // -------------------------------------------------------------------- //
            //                                  CustomReference                     //
            // -------------------------------------------------------------------- //

            //Debug.Log("Custom ref start");

            foreach (CustomReference customReference in ungrabbedItemDefinition.customReferences)
            {
                if (customReference.transform != null)
                {
                    customReference.transform.parent = point2ItemTransform;
                    point2ItemDefinition.customReferences.Add(customReference);
                }
                else
                {
                    Debug.LogError("Customreference transform" + customReference.name + " on item " + ungrabbedItemDefinition.itemId + " is not set?");
                }
            }


            // -------------------------------------------------------------------- //
            //                                  Reset Mass and stuff                //
            // -------------------------------------------------------------------- //



            point2Item.rb.ResetCenterOfMass();

            Vector3 CoM = point2Item.rb.centerOfMass;

            this.itemCoM = CoM;

            point2Item.rb.mass = (point2Item.rb.mass + ungrabbedItem.rb.mass);

            this.itemMass = point2Item.rb.mass;

            point2Item.rb.angularDrag = 0f;

            this.itemAngularDrag = point2Item.rb.angularDrag;

            point2Item.rb.drag = 0f;

            this.itemDrag = point2Item.rb.drag;

            point2Item.OnGrabEvent += this.fixItemInfo;

            // -------------------------------------------------------------------- //
            //                                  Whooshs                             //
            // -------------------------------------------------------------------- //


            foreach (ItemData.Whoosh whoosh in point2ItemData.whooshs.ToList())
            {
                if (ungrabbedItem.data.whooshs.Contains(whoosh))
                {
                    point2ItemData.whooshs.Remove(whoosh);
                }
            }


            foreach (WhooshPoint whooshPoint in ungrabbedItemDefinition.whooshPoints)
            {
                whooshPoint.transform.parent = point2ItemTransform;
            }

            point2ItemDefinition.whooshPoints.AddRange(ungrabbedItemDefinition.whooshPoints);
            point2ItemData.whooshs.AddRange(ungrabbedItem.data.whooshs);


            foreach (ItemData.Whoosh whoosh in point2ItemData.whooshs.ToList())
            {
                foreach (WhooshPoint whooshPoint in point2ItemDefinition.whooshPoints)
                {
                    if (whooshPoint.name == whoosh.transformName)
                    {
                        FXData data = Catalog.current.GetData <FXData>(whoosh.fxId, true);
                        if (data != null)
                        {
                            Whoosh whoosh2 = whooshPoint.gameObject.GetComponent <Whoosh>();
                            if (!whoosh2)
                            {
                                whoosh2 = whooshPoint.gameObject.AddComponent <Whoosh>();
                            }
                            whoosh2.Load(data, whoosh.trigger, whoosh.minVelocity, whoosh.maxVelocity);
                        }
                    }
                }
            }

            // -------------------------------------------------------------------- //
            //                                  Modules WIP                         //
            // -------------------------------------------------------------------- //

            foreach (ItemModule itemModule in ungrabbedItem.data.modules)
            {
                //Debug.Log(itemModule.type.Name);
                if (itemModule.type.Name != "ItemModuleAI" && itemModule.type.Name != "ItemModulePart")
                {
                    addedModules.Add(itemModule);
                }
            }

            //Debug.Log("Total modules added " + addedModules.Count);

            // Get all modules on the new item and find all added modules
            List <ItemModule> totalAddedModules = new List <ItemModule>();

            foreach (CustomReference customReference1 in point2ItemDefinition.customReferences)
            {
                if (customReference1.transform.GetComponent <AttachmentPointLogic>())
                {
                    AttachmentPointLogic apl = customReference1.transform.GetComponent <AttachmentPointLogic>();

                    if (apl.addedModules.Count > 0)
                    {
                        totalAddedModules.AddRange(apl.addedModules);
                    }
                }
            }

            //Debug.Log("Total added modules to item " + totalAddedModules.Count);


            foreach (ItemModule itemModule1 in totalAddedModules)
            {
                point2ItemData.modules.Add(itemModule1);

                itemModule1.OnItemLoaded(point2Item);

                point2ItemData.modules.Remove(itemModule1);
            }



            // -------------------------------------------------------------------- //
            //                                  Despawn                             //
            // -------------------------------------------------------------------- //

            ungrabbedItem.ResetObjectCollision();
            ungrabbedItem.SetColliderAndMeshLayer(VRManager.GetLayer(LayerName.MovingObject));

            ungrabbedItem.Despawn();

            point2Item.RefreshCollision();

            item = point2Item;
        }