private static void PlaceEdge(EdgePlacerConfig cfg, Vector3D[] segments)
        {
            MyEntity holderEntity;

            MyEntities.TryGetEntityById(cfg.EntityPlacing, out holderEntity);
            var holderPlayer = holderEntity != null?MyAPIGateway.Players.GetPlayerControllingEntity(holderEntity) : null;

            var def = DefinitionFor(cfg.Placed);

            if (def == null)
            {
                MyEventContext.ValidationFailed();
                return;
            }

            #region Validation

            if (!MyEventContext.Current.IsLocallyInvoked)
            {
                if (holderEntity == null || holderPlayer == null ||
                    MyEventContext.Current.Sender.Value != holderPlayer.SteamUserId)
                {
                    MyEventContext.ValidationFailed();
                    return;
                }

                if (MyAreaPermissionSystem.Static != null)
                {
                    foreach (var pos in segments)
                    {
                        if (MyAreaPermissionSystem.Static.HasPermission(holderPlayer.IdentityId, pos,
                                                                        MyPermissionsConstants.Build))
                        {
                            continue;
                        }
                        holderPlayer.ShowNotification("You cannot build here", 2000, null, new Vector4(1, 0, 0, 1));
                        MyEventContext.ValidationFailed();
                        return;
                    }
                }

                var validPlacedType = false;
                foreach (var item in holderEntity.GetInventory(MyCharacterConstants.MainInventory).Items)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    var itemDef =
                        MyDefinitionManager.Get <MyInventoryItemDefinition>(item.DefinitionId) as MyHandItemDefinition;
                    if (itemDef == null)
                    {
                        continue;
                    }
                    foreach (var behaviorDef in itemDef.Behaviors)
                    {
                        var placeDef = behaviorDef as EdgePlacerBehaviorDefinition;
                        if (placeDef == null || placeDef.Placed != cfg.Placed)
                        {
                            continue;
                        }
                        validPlacedType = true;
                        break;
                    }

                    if (validPlacedType)
                    {
                        break;
                    }
                }

                if (!validPlacedType)
                {
                    MyEventContext.ValidationFailed();
                    MySession.Static.Log.Warning(
                        $"{holderPlayer} tried to place {cfg.Placed}, but has no item that can place it");
                    return;
                }

                var layer     = MySession.Static.Components.Get <BendyController>().GetOrCreateLayer(def.Layer);
                var annotated = AnnotateNodes(layer, segments);
                var tmp       = new List <string>();
                if (!ValidatePath(def, layer, annotated, tmp))
                {
                    holderPlayer.ShowNotification(string.Join("\n", tmp));
                    MyEventContext.ValidationFailed();
                    return;
                }
            }

            #endregion


            var graph = MySession.Static.Components.Get <BendyController>().GetOrCreateLayer(def.Layer);

            for (var i = 1; i < segments.Length; i++)
            {
                var nextNode = graph.GetOrCreateNode(segments[i - 1]);
                var prevNode = graph.GetOrCreateNode(segments[i]);

                if (graph.GetEdge(prevNode, nextNode) != null)
                {
                    continue;
                }

                var obContainer = new MyObjectBuilder_ComponentContainer();
                var worldMatrix = MatrixD.CreateWorld((prevNode.Position + nextNode.Position) / 2,
                                                      Vector3D.Normalize(nextNode.Position - prevNode.Position),
                                                      Vector3D.Normalize(nextNode.Up + prevNode.Up));
                var worldMatrixInv = MatrixD.Invert(worldMatrix);
                ((ICollection <MyObjectBuilder_EntityComponent>)obContainer.Components).Add(
                    new MyObjectBuilder_BendyComponent()
                {
                    Overrides = new[]
                    {
                        new MyObjectBuilder_BendyComponent.NodePose
                        {
                            Index    = 0,
                            Position = (Vector3)Vector3D.Transform(prevNode.Position, worldMatrixInv),
                            Up       = (Vector3)Vector3D.Transform(prevNode.Up, worldMatrixInv)
                        },
                        new MyObjectBuilder_BendyComponent.NodePose
                        {
                            Index    = 1,
                            Position = (Vector3)Vector3D.Transform(nextNode.Position, worldMatrixInv),
                            Up       = (Vector3)Vector3D.Transform(nextNode.Up, worldMatrixInv)
                        }
                    }
                });
                var entOb = new MyObjectBuilder_EntityBase()
                {
                    EntityDefinitionId     = (MyDefinitionId)cfg.Placed,
                    PersistentFlags        = MyPersistentEntityFlags2.InScene,
                    PositionAndOrientation = new MyPositionAndOrientation(worldMatrix),
                    SubtypeName            = cfg.Placed.SubtypeId,
                    ComponentContainer     = obContainer
                };
                var entity = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(entOb);
                if (holderPlayer != null && holderPlayer.IsCreative())
                {
                    entity.Components.Get <ConstructableComponent>()?.InstallFromCreative();
                    ConstructableComponentDefinition.CcComponent test;
                    int test2;
                    entity.Components.Get <ConstructableComponent>()
                    ?.IncreaseIntegrity(1e9f, out test, out test2);
                }

                entity.Components.Get <BendyPhysicsComponent>()?.DestroyEnvItems();

                EntityAdded?.Invoke(holderEntity, holderPlayer, entity);
            }
        }
 public static void RaisePlaceEdge(EdgePlacerConfig cfg, Vector3D[] segments)
 {
     MyMultiplayerModApi.Static.RaiseStaticEvent(x => PlaceEdge, cfg, segments);
 }