Skip to main content

Smelter

A class in Root.Township, Alta.Blacksmithing.

The smelter machine: takes ore or ingots from its ore docks and fuel from its fuel docks, and spawns the output of a smelting recipe or a mould. The server runs the smelting; clients get icons and effects by method sync. Saved with SmelterSaveData.

Constructors​

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

Fields​

40 private and internal fields
MemberWhat it is
private PooledObject activeOperationSmokeThe pooled smoke effect shown while operating.
private Bellows bellowsThe smelter's bellows; its SteadyValue speeds up progress and fuel use.
private Mould currentMouldThe mould in the mould dock, or null.
private float debugFuelDurationSeconds of smelting time one fuel item gives (default 10). Used for real fuel despite the name.
private Renderer fuelAndroidRendererRenderer for the fuel icon on Android builds.
private PickupDock[] fuelDocksDocks that take fuel.
private int fuelIconProgressCurrent fuel icon level, synced to clients.
private SpriteRenderer fuelSpriteSprite renderer for the fuel level icon.
private Fire innerFireThe fire inside the smelter, lit when smelting starts and put out when it stops.
private bool isSmeltingBacking field for IsSmelting. Saved.
private AltaEvent mouldBreakEvent invoked when a mould runs out of uses and is destroyed.
private PickupDock mouldDockDock that takes a mould.
private PhysicalMaterial mouldMaterialPhysical material of the ingots being cast in the mould. Saved.
private Item mouldResultThe item the mould will produce for the current batch. Saved.
private Animation operationalAnimatorAnimation played while the smelter is operating.
private PooledObjectDefinition operationalSmokePooled smoke effect definition shown while operating.
private Transform operationalSmokePositionWhere the operational smoke spawns.
private Renderer oreAndroidRendererRenderer for the ore icon on Android builds.
private PickupDock[] oreDocksDocks that take ore or ingots.
private int oreIconProgressCurrent progress icon level, synced to clients.
private SpriteRenderer oreSpriteSprite renderer for the ore progress icon.
private float progressProgress of the current batch from 0 to 1. Saved.
private SmeltingRecipe recipeThe smelting recipe being run, or null when casting in a mould. Saved.
private float remainingFuelTimeSeconds of fuel left from items already burnt. Saved.
private float requiredFuelFuel time the current batch needs. Saved.
private SoundEffectSet smelterActiveAudioSound played while the smelter operates.
private AudioControl smelterActiveAudioControlControl for the playing operational sound, used to stop it.
private Transform smelterSoundPositionerWhere the operational sound plays from.
private HashSet<Player> smeltingPlayersPlayers who last handled the consumed ore, credited with smelting tasks.
private Transform spawnPointWhere smelted items spawn.
private Sprite[] spriteLevelsIcon sprites for each fill level, from empty upwards.
private AnimationCurve spriteStepsCurve that maps progress or fuel use (0 to 1) to an icon level.
private MethodSyncStruct<Smelter.AnimationEvents> syncEffectsMethod sync for smelter effects.
private MethodSync syncIconsMethod sync for the icon state.
private float totalFuelTotal fuel time available when the batch was checked. Saved.
private SmelterUnlockManager unlockManagerGives the unlocked recipes, materials and speed multiplier; adding an unlock rechecks smelting.
private SoundEffectSet whistleAudioWhistle sound played with the ore, fuel and output willie animations.
private Animation willieFuelAnimatorAnimation played when fuel is used.
private Animation willieOreAnimatorAnimation played when a batch starts.
private Animation willieOutputAnimatorAnimation played when a batch finishes.

Properties​

MemberWhat it is
bool IsSmelting { get; }True while the smelter is running a batch. Synced to clients with the icons.
3 private and internal properties
MemberWhat it is
private static int _MainTex { get; }Shader property id for _MainTex.
private static int IsOperational { get; }Animator hash for the IsOperational parameter.
private static int whistle { get; }Animator hash for whistle. Not used in this file.

Methods​

MemberWhat it is
void CheckSmelt()Server: if not already smelting, restarts the TrySmelt coroutine. The public overload lets other code trigger a check.
override void Initialize()Creates the syncIcons and syncEffects method syncs.
override void InitializeAsServer(SpawnData spawnData)Server: puts out the inner fire if the smelter is not burning.
override void OnConnected(Player player)Sends a joining player the icon state, and the operational effect if smelting.
21 private and internal methods
MemberWhat it is
private void Awake()Hooks the ore, fuel and mould docks and the unlock manager so docking an item calls CheckSmelt, and links the bellows to this smelter.
private Item CheckMould(float totalFuel, Dictionary<Item, int> input, out PhysicalMaterial material, out float requiredFuel, out MouldDefinition activeMould)If a mould is docked and the input is one ingot type the mould allows and has unlocked, consumes the ingots, uses up the mould and returns the mould's product.
private void CheckSmelt(Interactor interactor, Pickup pickup, PickupDock dock)Server: if not already smelting, restarts the TrySmelt coroutine. The public overload lets other code trigger a check.
private void CheckSpriteZero(PickupDock[] docks, SpriteRenderer sprite, Renderer renderer)Sets the dock icon sprite to the empty level when none of the given docks hold anything.
private void Consume(Dictionary<Item, int> requirement)Destroys the required amounts from the ore docks and records the players who last handled those items in smeltingPlayers.
private float EvaluateFuel()Returns the fuel time left plus debugFuelDuration for each item in the first non-empty fuel dock.
private SmeltingRecipe FindRecipe(float totalFuel, Dictionary<Item, int> input, out float requiredFuel)Finds the first unlocked smelting recipe whose inputs exactly match the docked ores and whose duration fits the fuel, and consumes its inputs.
private Dictionary<Item, int> GetInput()Totals the docked items in the ore docks by item type.
private void Alta.Chunks.ISavableFull.LoadSetup()After a load, restarts TrySmelt with the saved progress if the smelter was smelting when saved.
private void MarkPlayersAction(NetworkPrefab spawned)Reports a smelted item to GameTaskManager for each player in smeltingPlayers, for smelting tasks.
private void MouldAdded(Interactor interactor, Pickup pickup, PickupDock dock)Stores the docked mould and checks whether smelting can start.
private void MouldRemoved(Interactor interactor, Pickup pickup, PickupDock dock)Clears the current mould when it is undocked.
private void OnDestroy()Does nothing.
private void PlayEffect(Smelter.AnimationEvents eventIndex)On the server, sends the effect to the chunk; on non-headless builds, plays the matching sound, animation and smoke.
private void ReleaseSmoke(NetworkEntity entity, bool isUnload)Releases the pooled operational smoke when the entity is destroyed by the scene.
private void RestockFuel()Uses one fuel item from the first non-empty fuel dock and adds debugFuelDuration seconds of fuel time.
private void SyncEffects(IPlayer player, Stream stream, Smelter.AnimationEvents eventIndex)Method sync handler that sends an effect index and plays it on remote clients.
private void SyncIcons(IPlayer player, Stream stream)Method sync handler for isSmelting and the fuel and ore icon levels; remote clients update the icon sprites.
private IEnumerator TrySmelt(bool isLoading = false) (iterator)Server coroutine that keeps smelting batches while there is input, fuel and a matching recipe or mould, then spawns the output at spawnPoint.
private void UpdateAndroidSprite(Renderer renderer, Sprite sprite)Sets an icon renderer's texture offset to a sprite's place in its atlas. Not called in this build.
private void UpdateIcons(bool isForced = false)Works out the fuel and progress icon levels and syncs them to the chunk when they change or when forced.

Used in​

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