1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

ModAPI Changes

Discussion in 'Modding' started by rexxar, Sep 8, 2016.

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

    rexxar Senior Engineer

    Messages:
    1,532
    Hey guys, we've been hard at work on the ModAPI and I wanted to give you a preview of the upcoming changes. These changes aren't being released this week, but you'll have them Soon™ You have these changes right now!

    First off, massive thanks to Phoenix84 and Malware for all of their hard work <3

    In no particular order:

    IMyShipController now has TryGetPlanetPosition and TryGetPlanetElevation. The latter lets you select the distance to 'sea level' or distance to the actual surface. Obviously they only work on planets. These methods are available in the programmable block

    IMyEntities.
    GetTopMostEntitiesInSphere and GetTopMostEntitiesInBox. These methods are much faster than GetEntitiesInSphere, as they only return top-level entities. For instance, if you scan in the middle of a ship, you'd only get back the grid entity, instead of a list of every single block in the sphere.

    Programmable block can now modify settings in the conveyor sorter.

    IMyCubeBlock now has a SlimBlock property so you can quickly switch between the two.

    In the voxel storage (IMyStorage), there are now two methods which accept delegates: PinAndExecute (overloaded)
    PinAndExecute will pin the voxel storage (so it doesn't close out from underneath you) and execute the supplied method.
    The storage will automatically be unpinned for cleanup (if necessary) when the supplied method returns.

    Also there's a Closed property added, so the voxel storage can be checked to see if it's still valid (not needed inside a pinned action).

    The gravity generator is now fully moddable. In the definition you can specify limits for the gravity range and strength.

    System.Diagnostics.Stopwatch has been added to the ModAPI whitelist (not available for progammable block).

    And GUI access. In MyAPIGateway you'll find a new IMyGui interface. Here's the contents of it

    Code:
    public enum MyTerminalPageEnum
    {
      None = -2,
      Properties = -1,
      Inventory = 0,
      ControlPanel = 1,
      Production = 2,
      Info = 3,
      Factions = 4,
      Gps = 6,
    }
    
    public interface IMyGui
    {
      /// <summary>
      /// Event triggered on gui control created.
      /// </summary>
      event Action<object> GuiControlCreated;
    
      /// <summary>
      /// Event triggered on gui control removed.
      /// </summary>
      event Action<object> GuiControlRemoved;
    
      /// <summary>
      /// Gets the name of the currently open GUI screen.
      /// </summary>
      string ActiveGamePlayScreen { get; }
    
      /// <summary>
      /// Gets the entity the player is currently interacting with.
      /// </summary>
      IMyEntity InteractedEntity { get; }
    
      /// <summary>
      /// Gets an enum describing the currently open GUI screen.
      /// </summary>
      MyTerminalPageEnum GetCurrentScreen { get; }
    
      /// <summary>
      /// Checks if the chat entry box is visible.
      /// </summary>
      bool ChatEntryVisible { get; }
    }
    
    In addition to that, MyCubeBuilder.CubeBuilderState.CurrentBlockDefinition and MyHud.BlockInfo have been re-added to the mod whitelist, so Digi's mods can work again :p

    This is just the first batch of changes, we've got a lot more to come!
     
    Last edited: Sep 16, 2016
    • Like Like x 12
    • Informative Informative x 2
    • Friendly Friendly x 2
  2. 3vil_Luigi

    3vil_Luigi Apprentice Engineer

    Messages:
    191
    nice to see additions to the API :)
     
  3. Phoera

    Phoera Senior Engineer

    Messages:
    1,713
    good one.

    but we have InteractedEntity, and no callback when it changes or interaction happens?
     
  4. Elfi Wolfe

    Elfi Wolfe Apprentice Engineer

    Messages:
    498
    Thank you.
    This will make fixing orbital code much easier. No more dynamic adjustment, now I can code in the right thrust off the bat. And get accurate readings.
     
    • Agree Agree x 1
  5. Hunterakagman

    Hunterakagman Trainee Engineer

    Messages:
    73
    Can some one update the list for all the blocks? All the one I've seen are outdated.
     
  6. Lynnux

    Lynnux Junior Engineer

    Messages:
    881
    (Maybe not so) Stupid questions:
    As usual these Entity-functions are returning all entities including e.g. voxels and floating objects, not only grids ?
    If an object consists of more than one grid (rotor, piston) the entities of all grids (inside the sphere/box) will be returned, right ?
    If GetTopMostEntitiesInBox goes through an asteroid, the asteroid entity will be returned ? I remember that all the existing methods searching entities in a "box"/"AABB" didn't work well.
     
  7. Elfi Wolfe

    Elfi Wolfe Apprentice Engineer

    Messages:
    498
    After staying up to 1 am. It lands, it takes off, it does not overshoot target and can even do suicide landings. Thank you keen. Now I need to clean up the code and figure out the math of how it works.
     
    • Like Like x 1
    • Agree Agree x 1
  8. mric

    mric Trainee Engineer

    Messages:
    27
    Hello people
    What is "voxel storage" ?
     
  9. spiritplumber

    spiritplumber Trainee Engineer

    Messages:
    19
    Haha, and I had just get done with my launch/land autopilot.... using gravity gradients since I couldn't get elevation ;)

    Guess this makes the code a lot simpler!
     
  10. Elfi Wolfe

    Elfi Wolfe Apprentice Engineer

    Messages:
    498
    If you need the MaxEffectiveThrust for Atmo/Ion there is a work around till that method makes it in.
     
  11. Elfi Wolfe

    Elfi Wolfe Apprentice Engineer

    Messages:
    498
    oh doh I forgot to put the workaround here.
    Code:
                //for (int i = 0; i < thrusters.Count; ++i) normalThrust += thrusters[i].MaxEffectiveThrust;
                for (int i=0; i<thrusters.Count; ++i) {
                    if (thrusters[i].GetValueFloat("Override") > 1.0001){
                        normalThrust += thrusters[i].CurrentThrust * 100 / thrusters[i].GetValueFloat("Override");
                    }
                }
    Work around is 0.001% accurate to MaxEffectiveThrust as long as override is greater than 1.0001
     
  12. 1wsx10

    1wsx10 Trainee Engineer

    Messages:
    24
    any ETA till PBs have access to CoM?
     
  13. rexxar

    rexxar Senior Engineer

    Messages:
    1,532
Thread Status:
This last post in this thread was made more than 31 days old.