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.
- Listed in Crafting and making
- Inherits or implements
NetworkEntityBehaviour,ISavableFull<SmelterSaveData>,ISavable<SmelterSaveData>,ISavableSave<SmelterSaveData>,ISavableSaveBase,ISavableFull - Derived types
SmelterSaveData - Nested types
AnimationEvents - Documented in Smelting and forging
Constructors
| Member | What it is |
|---|---|
Smelter() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
40 private and internal fields
| Member | What it is |
|---|---|
private PooledObject activeOperationSmoke | The pooled smoke effect shown while operating. |
private Bellows bellows | The smelter's bellows; its SteadyValue speeds up progress and fuel use. |
private Mould currentMould | The mould in the mould dock, or null. |
private float debugFuelDuration | Seconds of smelting time one fuel item gives (default 10). Used for real fuel despite the name. |
private Renderer fuelAndroidRenderer | Renderer for the fuel icon on Android builds. |
private PickupDock[] fuelDocks | Docks that take fuel. |
private int fuelIconProgress | Current fuel icon level, synced to clients. |
private SpriteRenderer fuelSprite | Sprite renderer for the fuel level icon. |
private Fire innerFire | The fire inside the smelter, lit when smelting starts and put out when it stops. |
private bool isSmelting | Backing field for IsSmelting. Saved. |
private AltaEvent mouldBreak | Event invoked when a mould runs out of uses and is destroyed. |
private PickupDock mouldDock | Dock that takes a mould. |
private PhysicalMaterial mouldMaterial | Physical material of the ingots being cast in the mould. Saved. |
private Item mouldResult | The item the mould will produce for the current batch. Saved. |
private Animation operationalAnimator | Animation played while the smelter is operating. |
private PooledObjectDefinition operationalSmoke | Pooled smoke effect definition shown while operating. |
private Transform operationalSmokePosition | Where the operational smoke spawns. |
private Renderer oreAndroidRenderer | Renderer for the ore icon on Android builds. |
private PickupDock[] oreDocks | Docks that take ore or ingots. |
private int oreIconProgress | Current progress icon level, synced to clients. |
private SpriteRenderer oreSprite | Sprite renderer for the ore progress icon. |
private float progress | Progress of the current batch from 0 to 1. Saved. |
private SmeltingRecipe recipe | The smelting recipe being run, or null when casting in a mould. Saved. |
private float remainingFuelTime | Seconds of fuel left from items already burnt. Saved. |
private float requiredFuel | Fuel time the current batch needs. Saved. |
private SoundEffectSet smelterActiveAudio | Sound played while the smelter operates. |
private AudioControl smelterActiveAudioControl | Control for the playing operational sound, used to stop it. |
private Transform smelterSoundPositioner | Where the operational sound plays from. |
private HashSet<Player> smeltingPlayers | Players who last handled the consumed ore, credited with smelting tasks. |
private Transform spawnPoint | Where smelted items spawn. |
private Sprite[] spriteLevels | Icon sprites for each fill level, from empty upwards. |
private AnimationCurve spriteSteps | Curve that maps progress or fuel use (0 to 1) to an icon level. |
private MethodSyncStruct<Smelter.AnimationEvents> syncEffects | Method sync for smelter effects. |
private MethodSync syncIcons | Method sync for the icon state. |
private float totalFuel | Total fuel time available when the batch was checked. Saved. |
private SmelterUnlockManager unlockManager | Gives the unlocked recipes, materials and speed multiplier; adding an unlock rechecks smelting. |
private SoundEffectSet whistleAudio | Whistle sound played with the ore, fuel and output willie animations. |
private Animation willieFuelAnimator | Animation played when fuel is used. |
private Animation willieOreAnimator | Animation played when a batch starts. |
private Animation willieOutputAnimator | Animation played when a batch finishes. |
Properties
| Member | What it is |
|---|---|
bool IsSmelting { get; } | True while the smelter is running a batch. Synced to clients with the icons. |
3 private and internal properties
Methods
| Member | What 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
| Member | What 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: