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.

Modding API - changes in modding interface

Discussion in 'Modding API' started by joeblack616, Oct 22, 2014.

Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.
  1. Digi Senior Engineer

    Messages:
    2,385
    If you added it yourself you can use the same object.
    Otherwise you can create an object with the vector and title of the one you want to remove/modify.
     
    Last edited: Jun 17, 2015
  2. midspace Senior Engineer

    Messages:
    2,224
    It appears that IMyPowerProducer has been removed.
    I'm not sure at this stage if it is intentional or not.

    But it does mean the loss of the following properties, of which I haven't found any substitute for:
    CurrentPowerOutput
    MaxPowerOutput
    DefinedPowerOutput
    ProductionEnabled



    Code:
    using System;
    namespace Sandbox.ModAPI.Ingame
    {
    	public interface IMyPowerProducer
    	{
    		/// <summary>
    		/// Currently used power output of the producer in [MW].
    		/// </summary>
    		float CurrentPowerOutput
    		{
    			get;
    		}
    		/// <summary>
    		/// Maximum power output of the producer in [MW].
    		/// </summary>
    		float MaxPowerOutput
    		{
    			get;
    		}
    		/// <summary>
    		/// Max power output defined in definition [MW].
    		/// </summary>
    		float DefinedPowerOutput
    		{
    			get;
    		}
    		/// <summary>
    		/// Power production is enabled
    		/// </summary>
    		bool ProductionEnabled
    		{
    			get;
    		}
    	}
    }
    
     
  3. Gwindalmir Senior Engineer

    Messages:
    1,004
    The most recent patch added ResouceSink and ResouceSource, but I haven't found documentation yet on how to use them.
    I think they are the replacement for IMyPowerProducer.

    EDIT:
    This seems to work:
    Code:
                        // If the block is an FTL cap, treat it differently
                        if (block.FatBlock is Sandbox.ModAPI.Ingame.IMyBatteryBlock && block.FatBlock.BlockDefinition.SubtypeId.Contains("FTLCap"))
                        {
                            var capacitor = block.FatBlock as Sandbox.ModAPI.Ingame.IMyBatteryBlock;
                            var resource = block.FatBlock.Components.Get<Sandbox.Game.EntityComponents.MyResourceSourceComponent>();
                            Logger.Instance.LogDebug(string.Format("Found power source: {2}, Max: {0}, Current: {1}", resource.DefinedOutput, capacitor.CurrentStoredPower, block.FatBlock.BlockDefinition.SubtypeId));
                            maxpower += capacitor.HasCapacityRemaining ? resource.DefinedOutput : resource.MaxOutput;
                            currentpower += resource.CurrentOutput;
                        }
                        else
                        {
                            var reactor = block.FatBlock;
                            var resource = block.FatBlock.Components.Get<Sandbox.Game.EntityComponents.MyResourceSourceComponent>();
                            Logger.Instance.LogDebug(string.Format("Found power source: {2}, Max: {0}, Current: {1}", resource.MaxOutput, resource.CurrentOutput, block.FatBlock.BlockDefinition.SubtypeId));
                            maxpower += resource.MaxOutput;
                            currentpower += resource.CurrentOutput;
                        }
    
    
    The key is
    entity.Components.Get<Sandbox.Game.EntityComponents.MyResourceSourceComponent>()

    I didn't look into ProductionEnabled though, as I don't use that.

    EDIT2:
    One thing I also noticed is that IsWorking is now false if the power is overloaded for Gyros now. Previously it was true if the block was just turned on.
    entity.Enabled seems to now be the power switch.
     
    Last edited: Sep 26, 2015
  4. Lynnux Junior Engineer

    Messages:
    881
    IsWorking = IsFunctional && Enabled
    Enabled always was the power on/off switch. Maybe they are not functional anymore when overloaded ?
     
  5. Gwindalmir Senior Engineer

    Messages:
    1,004
    As I understand it, IsFunctional relates to damage or construction level (are all required internal components present), IsWorking is if it fully operational in every other way (requires full power AND has power).

    Gyros seem to have changed the latter function, so in overload state it no longer functions. Previously the gyros still functioned in an overload state.
    And yeah, Enabled always was the switch, I forgot about it. In my use case, IsWorking was all I needed so it slipped my mind.

    Anyway, I don't mind this behavior. In fact it works better for me anyway.
     
  6. Digi Senior Engineer

    Messages:
    2,385
    There are new dlls in the /bin folder of the game, SpaceEngineers.Game.dll, SpaceEngineers.ObjectBuilders.dll and SpaceEngineers.ObjectBuilders.XmlSerializers.dll... and their MedievalEngineers counterparts.

    Anyone making mod scripts in an IDE will probably need to add those new SE dlls as reference.
     
    Last edited: Jan 7, 2016
  7. midspace Senior Engineer

    Messages:
    2,224
    The SpaceEngineers.ObjectBuilders.XmlSerializers.dll should not be required by mod script developers.
     
  8. Digi Senior Engineer

    Messages:
    2,385
    MyAPIGateway.Input. is now available to read input !

    I suggest you guys use MyControlsSpace to find the control IDs to read the assigned controls, not keys. Unless you want to offer a configurable key setting for your mod, otherwise don't assume someone has a game control assigned to a specific key.

    Only issue now is to determine the control context, if you're in a menu, typing in chat, etc, situations that you might not want input to be read in...

    Also IMyCubeGrid now has an AddBlock() method, yey :}
     
    Last edited: Mar 11, 2016
  9. Rynchodon Trainee Engineer

    Messages:
    35
    Have you looked at Sandbox.Game.Gui.MyGuiScreenTerminal.GetCurrentScreen()?
     
    • Like Like x 1
  10. Digi Senior Engineer

    Messages:
    2,385
    I didn't know about that, no.
    That works for detecting the terminal menu!
    But there's still the chat, escape menu, yes/no popups, mod text popup... and probably more. I'll look around maybe I can find those too.

    EDIT:
    There's also MyGuiScreenGamePlay.ActiveGameplayScreen which is either null or gives the instance of terminals, help menu, build menu and, picker menu and text panel UI (what I've seen so far) but it's still null for chat, F10, F11, mission screens, UI yes/no messages and escape menu.

    However you can't really use the fields from that since it's in an non-whitelisted namespace, all you can do is check its instance and see its ToString() name (and other generic methods)
     
    Last edited: Mar 22, 2016
Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.