Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Adding Cubeblocks

Discussion in 'Modding' started by Innoble, Jul 10, 2016.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Innoble Apprentice Engineer

    Messages:
    238
    I have a question about adding cubeblocks to an existing grid. I know everything in the game has an objectbuilder and I can add stuff like inventory items and ore. I also know remove blocks from grids (raze blocks, with or without lowering build level), but how do I add a completely new block to an existing grid?

    An example would be this:

    I want to add a new armor block to the left of an existing remote control block. I am assuming I need to specify the following things somehow:

    -Armor block definition (type/subtype?)
    -Armor block position in grid
    -Armor block orientation in grid.

    Perhaps it is more complicated for blocks that are terminal blocks.

    I have looked at CubeGrid.Addblock, but I don't know how to set up the objectbuilder for the armor block. There doesn't seem to be any way to specify a position. It would be great if someone could post a snippet of setting up a cubeblock and adding it to an existing cubegrid.

    Just to be clear: I am not talking about making stuff out of a projection. I am talking about what a player does when he/she adds a new block to be welded (without the player action).

    If you know of a mod that does this sort of thing, let me know.
    --- Automerge ---
    To answer my own question here for others to use: Phoenix told me to use the following code from the stargate mod to make new blocks and add them.

    Code:
            // Spawn vortex
                    var gridObjectBuilder = new MyObjectBuilder_CubeGrid()
                    {
                        PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene,
                        GridSizeEnum = MyCubeSize.Large,
                        IsStatic = true,
                        CreatePhysics = false,
                        LinearVelocity = new SerializableVector3(0, 0, 0),
                        AngularVelocity = new SerializableVector3(0, 0, 0),
                        PositionAndOrientation = new MyPositionAndOrientation(Container.Entity.GetTopMostParent().GetPosition(), Container.Entity.GetTopMostParent().WorldMatrix.Backward, Container.Entity.GetTopMostParent().WorldMatrix.Up),
                        DisplayName = "Event Horizon Vortex"
                    };
    
                    MyObjectBuilder_Reactor cube = new MyObjectBuilder_Reactor()
                    {
                        Min = new SerializableVector3I(0, 0, 0),
                        SubtypeName = "Phoenix_Stargate_EventHorizon_Vortex",
                        ColorMaskHSV = new SerializableVector3(0, -1, 0),
                        EntityId = 0,
                        Owner = 0,
                        BlockOrientation = new SerializableBlockOrientation(VRageMath.Base6Directions.Direction.Forward, VRageMath.Base6Directions.Direction.Up),
                        ShareMode = MyOwnershipShareModeEnum.All,
                        CustomName = "Event Horizon Vortex",
                    };
    
                    gridObjectBuilder.CubeBlocks.Add(cube);
                    var tempList = new List<MyObjectBuilder_EntityBase>();
                    tempList.Add(gridObjectBuilder);
                    MyAPIGateway.Entities.RemapObjectBuilderCollection(tempList);
                    tempList.ForEach(item => MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(item));
     
  2. Anonymous Blackness Trainee Engineer

    Messages:
    9
    I tried your code and I still can't get a block to spawn.. Do you know if this functionality has been removed since you posted this?
     
  3. Roxette Senior Engineer

    Messages:
    1,407
    There have been *huge* changes to the cubeblocks data since 2016, I am not at all surprised this code is broken. You would be best asking on the Keen Discord modders channel for current information. The OP hasn't been on this forum in almost a year.
     
Thread Status:
This last post in this thread was made more than 31 days old.