Skip to content

Resource networks ​

StellarWorks components use the native StellarDrive power, fluid, and signal networks. Configure a participant with the same name as its cable socket. Use authority for simulation and replication for client displays.

Consume power ​

In the first mod, add this before part.Register() and import StellarWorks.Resources. This example assumes the part has no other cable sockets.

csharp
part.WithSocket(new SocketDefinition("power_in", SocketKind.Power, new Vector3(0.4f, 0, 0), slot: 0))
    .AddComponent(ResourceComponentIds.PowerConsumer, ComponentConfiguration.From(new
    {
        socket = "power_in",
        requestedWatts = 100f,
        minimumOperatingWatts = 80f
    }));

Connect the part to a powered cable network. On the authoritative instance, read Part.GetComponent<PowerConsumer>() and check IsOperational or DeliveredWatts. A partial allocation can run the part if it meets the minimum. PowerProducer supplies a network and PowerStorage charges or discharges using configured watts and capacity in joules.

Store and transfer fluid ​

Give a tank one fluid socket and add ResourceComponentIds.FluidStorage with its socket and capacity. To feed a tank, give a separate part an output socket and add a FluidProducer configured with a fluid and rate.

csharp
part.WithSocket(new SocketDefinition("gas_out", SocketKind.Fluid, new Vector3(-0.4f, 0, 0), slot: 1))
    .AddComponent(ResourceComponentIds.FluidProducer, ComponentConfiguration.From(new
    {
        socket = "gas_out",
        fluid = BuiltInFluidIds.Helium.ToString(),
        ratePerSecond = 1f
    }));

This example uses slot 1 after the power socket in the preceding section. Use a registered fluid's stable ID as a string. A producer sends fluid when its native group can receive it. A consumer removes the configured fluid when available. A FluidPump moves fluid between separate input and output groups and requires a power consumer by default.

Read and drive a signal ​

Attach SignalInput to read a native group. Check Reading.HasSignal separately from the value, since a connected signal can be zero. Attach SignalOutput to set a value before the next signal evaluation. Use SignalGate with an input and a target resource component on the same part to enable that component when the input reaches the configured threshold.

Coordinate transfers in a solver step ​

Subscribe to mod.Events.Resources.BeforePower to set electrical limits for the current step. Subscribe to BeforeFluidBalance to settle a coupled fluid transfer. Both callbacks run on the world authority.

Within the callback, check step.IsSimulated(part) and use step.Seconds to convert rates to step quantities. Inspect live quantities with Available and Room. To allocate multiple recipes against shared capacity, call Allocate, scale each recipe by its returned fraction, then apply each with TryTransfer. Treat the result of TryTransfer as authoritative and update your component's bookkeeping after it succeeds. The step handle expires when dispatch ends. Resource API reference

StellarWorks documentation · Mods for StellarDrive