Skip to main content

Mould

A class in Root.Township, the global namespace.

A casting mould item that holds a MouldDefinition (what it casts and how many ingots it costs) and optionally a limited number of uses. Both sides; the server picks and syncs the definition.

Constructors​

MemberWhat it is
Mould()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

14 private and internal fields
MemberWhat it is
private MouldDefinition definitionBacking field for Definition. Saved.
private MeshFilter graphicMesh showing the shape the mould makes.
private TextRenderer inputCountText showing the definition's cost.
private bool isGeneratingWhether a blank mould picks a random definition when spawned. Off for crafted moulds.
private bool isUsingRestrictorBacking field for IsUsingRestrictor. Defaults to true.
private LODGroup lodGroupLOD group whose first level gets the shape and text renderers.
private static Logger loggerPrivate: logger. Not used in this build.
private TextRenderer outputCountText showing how many items one use makes, shown when more than one.
private MeshRenderer outputQuantityRendererThe 'x' renderer next to outputCount.
private MethodSync syncPrivate: message for Sync, sent when the definition changes and to joining players.
private MethodSync syncUsePrivate: message for SyncUse, sent by Consume.
private int usageBacking field for Usage. -1 means unlimited uses.
private IntegerVisual usageVisualOptional visual showing the uses left.
private static List<Renderer> workingRenderersListPrivate static: scratch list used to rebuild the LOD renderers.

Properties​

MemberWhat it is
MouldDefinition Definition { get; }What this mould casts, or null for an empty mould. Saved with the mould.
bool IsUsingRestrictor { get; }Whether a MouldRestrictor keeps only one mould per definition, destroying the older copy when a new one registers.
int Usage { get; }Uses left. -1 means unlimited; the smelter breaks the mould when Consume takes it to zero.
protected override bool IsGeneratingFirstTime { get; }True only when the mould has no definition yet and is set to generate one.
1 private and internal property
MemberWhat it is
private bool Alta.Crafting.IBlockGenericDecrafting.CanDecraft { get; }True only while the mould has no definition (it is blank).

Methods​

MemberWhat it is
bool Consume()Server: uses up one charge if the mould has limited uses and syncs it. Returns true when uses reach zero.
override void Initialize()Sets up the network syncs for the definition and the remaining uses.
override void OnConnected(Player player)Sends the current definition and uses to a player who joins.
void SetDefinition(MouldDefinition definition, bool isOnvalidate = false)Changes what the mould casts. The server syncs it; clients rebuild the mesh, cost and output-count visuals.
protected override void Generate(SpawnData spawnData)On first spawn, gives the mould a random definition if generation is turned on for it.
3 private and internal methods
MemberWhat it is
private void OnValidate()Empty in this build.
private void Sync(IPlayer player, Stream stream)Private: syncs the definition hash and, if the mould has limited uses, the uses left. Clients apply them.
private void SyncUse(IPlayer player, Stream stream)Private: syncs the uses left and updates the visual on clients.

Used in​

Members of other types that take, return or hold a Mould: