Space Engineers

Space Engineers

Not enough ratings
ModAPI/Ingame Interface Expansion and Improvements
By jolk
With SE Update 01.142, the ModAPI interfaces will be expanded. Additionally, a new script compiler is now used, based on Roslyn (https://github.com/dotnet/roslyn).

There are several important changes that will affect mods:
1. Every Cube Block now has its own ModAPI and Ingame interfaces. This may now cause “ambiguous reference” and “cannot convert from” errors.
2. All interface type hierarchy is properly inherited. This will reduce the multiple casting operations required to access available properties/methods.
3. There is now a VRage.ModAPI.Ingame.IMyEntity interface, for use in Ingame scripts that is whitelisted. However this does not contain all the IMyEntity properties. This change may now cause “does not contain a definition for 'GameLogic'“ and similar errors.

Due to the previous missing interfaces, many modders have placed ‘using’ declarations for the Ingame namespaces. These are no longer needed and must be removed.

Except for possible small edge cases, there should be no reason to use any ingame interface!
 
Rate  
Favorite
Favorited
Unfavorite
ModAPI Changes
There are several important changes that will affect mods:

1. Every Cube Block now has its own ModAPI and Ingame interfaces. This may now cause “ambiguous reference” and “cannot convert from” errors.

2. All interface type hierarchy is properly inherited. This will reduce the multiple casting operations required to access available properties/methods.

3. There is now a VRage.ModAPI.Ingame.IMyEntity interface, for use in Ingame scripts that is whitelisted. However this does not contain all the IMyEntity properties. This change may now cause “does not contain a definition for 'GameLogic'“ and similar errors.

Due to the previous missing interfaces, many modders have placed ‘using’ declarations for the Ingame namespaces. These are no longer needed and must be removed.

Except for possible small edge cases, there should be no reason to use any ingame interface!
Possible error examples
It may look scary at first. Depending on the mod, you could have no errors, or hundreds!

Mixing both namespaces will show various error messages, such as:

2016-05-30 16:53:32.874 - Thread: 1 ->
C:\Users\<Username>\AppData\Roaming\SpaceEngineers\Mods\FTL\Data\Scripts\FTL\FTLBase.cs(52,18): 'IMyFunctionalBlock' is an ambiguous reference between 'Sandbox.ModAPI.Ingame.IMyFunctionalBlock' and 'Sandbox.ModAPI.IMyFunctionalBlock'

2016-05-30 16:47:04.549 - Thread: 1 ->
C:\Users\<Username>\AppData\Roaming\SpaceEngineers\Mods\Portal\Data\Scripts\Stargate\Stargate.cs(966,39): 'IMyFunctionalBlock' does not contain a definition for 'GameLogic' and no extension method 'GameLogic' accepting a first argument of type 'IMyFunctionalBlock' could be found (are you missing a using directive or an assembly reference?)

2016-05-30 16:47:04.549 - Thread: 1 ->
C:\Users\<Username>\AppData\Roaming\SpaceEngineers\Mods\Portal\Data\Scripts\Stargate\Stargate.cs(971,53): Argument 1: cannot convert from 'Sandbox.ModAPI.Ingame.IMyFunctionalBlock' to 'VRage.ModAPI.IMyEntity'
Steps to fix
1. Remove all Ingame using declarations, of any style.
2. Go through remaining code and make sure all Ingame types refer to ModAPI interfaces.

Step one
The first thing to do is to remove all the Ingame using declarations. That should clear up at least 90% of the errors.

For example:
If your using statements look like this:
using VRageMath; using Sandbox.Game.Entities; using VRage.Game.ModAPI; using Ingame = VRage.Game.ModAPI.Ingame; using SpaceEngineers.Game.ModAPI; using SpaceEngineers.Game.ModAPI.Ingame; using Sandbox.ModAPI.Interfaces.Terminal; using VRage.Utils; using IMyBeacon = Sandbox.ModAPI.Ingame.IMyBeacon;

Notice the BOLD lines, which are Ingame namespaces and types

The solution is to change them to match similar to below:
using VRageMath; using Sandbox.Game.Entities; using VRage.Game.ModAPI; using SpaceEngineers.Game.ModAPI; using Sandbox.ModAPI.Interfaces.Terminal; using VRage.Utils; using Sandbox.ModAPI;
Notice the BOLD lines were completely removed or replaced.

Step two
Go through the remaining code and remove any fully qualified type names.

For example:
static void TerminalControls_CustomActionGetter(Sandbox.ModAPI.Ingame.IMyTerminalBlock block, List<IMyTerminalAction> actions) { }
Should be changed to:
static void TerminalControls_CustomActionGetter(IMyTerminalBlock block, List<IMyTerminalAction> actions) { }
Notice the BOLD part was removed.
Additional notes
Not all the Ingame interfaces added will actually be usable in the Programmable Block. This includes types such as IMyPistonTop, IMyConveyor, and more.
They have been added for completeness’ sake, and possible future use.

Programmable blocks can only access blocks which inherit from the IMyTerminalBlock type.

If any other types are present in the Ingame namespace, but missing from the ModAPI namespace, please let us know.
Programmable block changes
The Blocks property of IMyBlockGroup has been replaced with a GetBlocks method. This was done for performance and memory saving reasons, but also to make it more consistent with the rest of the grid terminal system.

void IMyBlockGroup.GetBlocks(List<IMyTerminalBlock> blocks, Func<IMyTerminalBlock, bool> collect) { // Allow a pure collect search by allowing a null block list if (blocks != null) { blocks.Clear(); } for (var index = 0; index < Blocks.Count; index++) { var block = Blocks[index]; if (!block.IsAccessibleForProgrammableBlock || (collect != null && !collect(block))) { continue; } if (blocks != null) { blocks.Add(block); } } }
Please update your code accordingly.
Roslyn Compiler
The script compiler has been changed to the open source Roslyn compiler. This will allow scripts to compile and run more reliably and consistently, and allow scripters and modders to take advantage of C# 6.0 features.
Whitelist
Additionally we updated the whitelisting system. The old type whitelist was letting through some types that weren't actually supposed to be whitelisted. The new whitelist will block these types the way they were supposed to, so if your mod is using them it will not work any longer. Please report any missing whitelistings and we will consider whether it's safe to let them through.

The following namespaces are whitelisted in the Programmable block:
• Sandbox.ModAPI.Ingame
• SpaceEngineers.Game.ModAPI.Ingame
• System.Collections
• System.Collections.Generic
• System.Collections.Concurrent
• System.Linq
• System.Text
• System.Text.RegularExpressions
• System.Globalization
• VRage.Game.ModAPI.Ingame
• VRageMath

In addition to the above, the following namespaces are also available in the ModAPI:
• Sandbox.Common.ObjectBuilders
• Sandbox.Common.ObjectBuilders.Definitions
• Sandbox.Definitions
• Sandbox.Game
• Sandbox.Game.Entities
• Sandbox.Game.EntityComponents
• Sandbox.Game.Lights
• Sandbox.ModAPI
• Sandbox.ModAPI.Weapons
• SpaceEngineers.Game.ModAPI
• System.Timers
• VRage
• VRage.Collections
• VRage.Game
• VRage.Game.Components
• VRage.Game.Entity
• VRage.Game.ModAPI
• VRage.Game.ModAPI.Interfaces
• VRage.Game.ObjectBuilders
• VRage.ObjectBuilders
• VRage.Library.Utils
• VRage.ModAPI
• VRage.Utils
• VRage.Voxels

There are additional specific types whitelisted which are not listed above.

The above list, including additions and deletions, are subject to change.
< >
5 Comments
Cookies Jul 11, 2016 @ 5:28pm 
What I wonder is: Will we ever be able to control assembler queues via programmable blocks? :steamsalty:
thorwin99 Jul 1, 2016 @ 8:00am 
I cant get the blocks of a Blockgroup of HangarDoors. It is always Count 0
ichabod the tardigrade Jun 29, 2016 @ 7:46pm 
dose this mean ill have to change my guide on opening the game. I looked deep in the games files to get the information on my guide (not realy XD)
LukeStrike Jun 24, 2016 @ 10:25pm 
"Every Cube Block now has its own ModAPI and Ingame interfaces."

What does it means ? Even the non terminal blocks will have an interface now ? (required) So we can query for example the armor/ladder/etc blocks to get their state, color, missing components, etc ?

LKS
IllidanS4 Jun 23, 2016 @ 5:52pm 
Hmm, I wasn't able to install Roslyn on Windows 7 back then, I guess it won't be a problem now?