Registering content
Register content on the game thread in OnInitializeMelon, after creating your ModContext. This guide extends the first mod.
Use stable IDs
new ContentId(mod.Id, "alloy_plate") identifies an item in your mod's namespace. Your definitions must use your own namespace. To reference another mod's content, use its full ID, such as ContentId.Parse("another.mod:alloy"). Keep IDs stable across releases. The host resolves custom IDs to native numbers when a world opens.
Use Item.Native.Iron or Item.FromID(101) for stock Iron. Content definitions lists stock item and research reference forms.
Items and fluids
Add a solid item through mod.Items. A fluid uses the same definition type with a Phase and registers through mod.Fluids. A stack size is in the game's units and FluidColorRgb is a 24-bit RGB value.
csharp
using StellarWorks.API;
using StellarWorks.Content;
// In OnInitializeMelon, after RegisterMod.
var plate = mod.Items.Register(new ItemDefinition(new ContentId(mod.Id, "alloy_plate"), "Alloy Plate")
{
StackSize = 20,
Mass = 2f
});
var coolant = mod.Fluids.Register(new ItemDefinition(new ContentId(mod.Id, "coolant"), "Coolant")
{
Phase = FluidPhase.Liquid,
FluidColorRgb = 0x45A2DB
});Use plate.Id in construction or research costs. Use coolant.Id to configure a fluid component. Item and fluid registration makes native content available to the game. Your mod supplies gameplay that produces or grants that content.
Build tabs and research
Register a build category and use its ID with WithCategory before registering the part. As a shortcut, part.WithCategory("blocks") resolves the name in the part's namespace.
csharp
var category = mod.BuildCategories.Register(
new CategoryDefinition(new ContentId(mod.Id, "blocks"), "First Mod Blocks"));
part.WithCategory(category.Id.ToString());After part.Register(), add a research category and technology with the part in UnlocksParts. In a test world, buy Structural Blocks to unlock the recipe. Prerequisites can refer to other technologies using verified IDs.
csharp
var researchCategory = mod.ResearchCategories.Register(
new CategoryDefinition(new ContentId(mod.Id, "engineering"), "First Mod Engineering"));
mod.Research.Register(new ResearchDefinition(new ContentId(mod.Id, "structural_blocks"), "Structural Blocks")
{
Category = researchCategory.Id,
Costs = new[] { new ItemCost(Item.Native.Iron, 1) },
UnlocksParts = new[] { new ContentId(mod.Id, "simple_part") }
});Use PartBuilder.RequiresResearch to gate a part on a separate existing technology. Each attached technology must be researched. Use mod.World.Current?.IsResearched(id) to query current progress from gameplay code.