Space Engineers

Space Engineers

Fluid Battery
 This topic has been pinned, so it's probably important
Dummy08  [developer] 10 Mar, 2019 @ 11:48am
Script support
As the game battery class does not allow conveyor connection the fluid battery mod is derived from reactor.

Therefor if you would like to use the battery in scripts you can't directly use the IMyBattery Interface.


/// <summary> /// Extension methode does not work here as the script is embedded as a nested class /// </summary> public static class BatteryExtensions { public static ChargeMode GetChargeMode(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.ChargeMode; var property = entity.GetProperty("ChargeMode"); return property != null ? (ChargeMode)property.Cast<long>().GetValue(entity) : ChargeMode.Auto; } public static void SetChargeMode(IMyFunctionalBlock entity, ChargeMode value) { var battery = entity as IMyBatteryBlock; if (battery != null) { battery.ChargeMode = value; return; } var property = entity.GetProperty("ChargeMode"); if (property != null) property.Cast<long>().SetValue(entity, (long)value); } public static float GetMaxStoredPower(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.MaxStoredPower; var property = entity.GetProperty("MaxStoredPower"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetCurrentStoredPower(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.CurrentStoredPower; var property = entity.GetProperty("CurrentStoredPower"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetMaxInput(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.MaxInput; var property = entity.GetProperty("MaxInput"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetMaxOutput(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.MaxOutput; var property = entity.GetProperty("MaxOutput"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetCurrentOutput(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.CurrentOutput; var property = entity.GetProperty("CurrentOutput"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetCurrentInput(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.CurrentInput; var property = entity.GetProperty("CurrentInput"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } }

Last edited by Dummy08; 10 Mar, 2019 @ 12:02pm
< >
Showing 1-1 of 1 comments
Forge 20 Apr, 2019 @ 3:22pm 
This Helped me a lot, thank you (I just had to make the whole class it not static)
< >
Showing 1-1 of 1 comments
Per page: 1530 50