Skip to main content

GenericCraftingStation

A class in Root.Township, Alta.Crafting.

A crafting station driven by a recipe page in its dock: it shows ghost pieces you fill with the right materials and nail, then lets you pull out the finished item. The server runs the project; clients send nail hits and piece grabs.

Constructors​

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

Fields​

25 private and internal fields
MemberWhat it is
private float androidMaxDistanceToRenderProjectGhostSquaredAndroid ghost render distance, squared. Nothing reads it.
private float androidMaxDistanceToRenderProjectSquaredAndroid project render distance, squared. Nothing reads it.
private IProject currentProjectThe project being built, or null when the station is empty.
private Interactable fakeInteractableInteractable over the finished project that players grab to take the result.
private BoxCollider fakeInteractableColliderBox collider for fakeInteractable, sized to the project when complete.
private bool isSyncingAllowedTurned off while SetupProjectFromResult rebuilds a project, so per-piece syncs aren't sent.
private static Logger loggerNLog logger for this class.
private float maxDistanceToRenderProjectGhostSquaredSquared distance within which the project ghost renders, used by UpdateDistanceLOD.
private float maxDistanceToRenderProjectSquaredSquared distance within which the project renders, used by UpdateDistanceLOD.
private Transform piecesParentBacking field for PiecesParent. The result spawns at its position.
private PickupDock recipeDockDock that holds the recipe page.
private MethodSyncStruct<GenericCraftingStation.ClientSideNailHitSync> syncClientNailHitMethod sync for SyncClientNailHit.
private MethodSyncStruct<int> syncDestroyEffectMethod sync for SyncDestroyEffect.
private MethodSync syncFullMethod sync for SyncFull.
private MethodSyncStruct<NailIdentifier> syncNailHitMethod sync for SyncNailHit.
private MethodSyncStruct<int> syncPieceMethod sync for SyncPiece.
private MethodSyncStruct<int> syncPieceGrabMethod sync for SyncPieceGrab.
private MethodSync syncProjectMethod sync for SyncProject.
private MethodSyncStruct<bool> syncProjectStatusMethod sync for SyncProjectStatus.
private static List<Rigidbody> toRemoveStatic scratch list used by TrackPickups.
private Dictionary<Rigidbody, GenericCraftingStation.PickupColliders> trackedPickupsCrafting component pickups inside the station's trigger, by rigidbody, with the colliders seen.
private IUnityUpdateMethod trackPickupsUpdate registration for TrackPickups, live while any pickup is tracked.
private static IUnityUpdateMethod updateDistanceLODStatic update registration for the distance LOD method.
private static UpdateModule updateModuleStatic update module that runs TrackPickups.
private static Dictionary<GenericCraftingStation, Vector3> updatingStationsStatic map of stations with a project to their positions, for distance LOD.

Properties​

MemberWhat it is
Transform PiecesParent { get; }Parent transform of the project's pieces; the completed effect plays here.
1 private and internal property
MemberWhat it is
private bool IsEmpty { get; }True when there's no current project.

Methods​

MemberWhat it is
void ChangedPieces()Server: resyncs the project status, or clears the project and returns materials if no page is docked and no piece is filled.
override void Initialize()Sets up the station's synced messages and hooks the recipe dock filter and the finished-item grab.
override void InitializeAsServer(SpawnData spawnData)Server: hooks page dock and undock, and loads the recipe of a page already docked.
override void OnConnected(Player player)Server: sends the full project state to a new player.
void RequestClientNailHit(int pieceHash, int nailIndex, ImpactHitWithTool impactWithTool)Client: sends a nail hit on a piece to the server.
void RequestDestroyEffect(int pieceHash)Server: tells clients to play a piece's destroy effect.
void RequestSyncNailHit(NailIdentifier nailArguments)Server: syncs a nail hit to clients.
void RequestSyncPiece(GenericCraftingPiece piece)Server: syncs one piece's state to clients.
void RequestSyncPieceGrab(GenericCraftingPiece piece)Client: tells the server a piece was grabbed.
void SetupProjectFromResult(GenericCraftingResult result)Rebuilds a complete project from a finished item placed back on the station (keeping its materials) and destroys the item.
void TriggerEnter(Collider other)Starts tracking a crafting component pickup that enters the station area. Already crafted pickups are ignored.
void TriggerExit(Collider other)Stops tracking a pickup once all its colliders have left.
void TryAddPiece(int bestPieceKey, Action<GenericCraftingPiece> callback)Calls back with the piece for a key if it isn't filled yet. Logs an error for an unknown key.
int TrySetClosestPiece(GenericCraftingComponent component, Vector3 position, Action<GenericCraftingPiece> callback)Finds the nearest piece that accepts a component within animate range and calls back with it. Returns its key or -1.
void UpdateProjectComplete(bool hasEffects = false)Syncs whether the project is complete and turns the grab area for the finished item on or off.
33 private and internal methods
MemberWhat it is
private IEnumerator AddItemOnReleaseCoroutine(Pickup pickup) (iterator)Waits to the end of the frame after a component is let go, then adds it to the project if it's still valid.
private void CheckFakeInteractable(bool hasEffects)Client: turns on the grab-result collider when the project is complete, with the completion effect if asked.
private bool CheckPageForRecipe(Pickup pagePickup, out GenericCraftingRecipe recipe)Gets the generic crafting recipe from a page pickup, if it has one.
private void CleanDestroy(NetworkEntity entity, bool isUnload)Clears the project without returning materials when the scene destroys the station.
private void ClearLOD()Removes the station from the distance LOD list.
private void ClearProject(bool isReturningMaterials)Clears the current project, optionally returning materials, and the server syncs the empty project.
private void ClearTracked()Unhooks and forgets every tracked pickup. Called on destroy.
private void ComponentReleased(Interactable interactable, Interactor interactor)Server: when a tracked pickup is let go, starts AddItemOnReleaseCoroutine for it.
private void DockingFilter(Interactor interactor, PickupDock dock, ref bool result)Client: refuses docking for pickups inside the station's trigger.
private void GrabResult(Interactable interactable, Interactor interactor)Server: when the finished project is grabbed, spawns the result and swaps it into the hand.
private void GrabResultFilter(Interactor interactor, Interactable interactable, ref bool result)Blocks grabbing the result until the project is complete.
private bool IsPickupValidToAdd(Pickup pickup)False for pickups that are held, docked or already crafted.
private void LoadRecipe(GenericCraftingRecipe recipe)Starts a project from a recipe and syncs it to chunks.
private void OnDestroy()Calls ClearTracked.
private void OnPageDocked(Interactor interactor, Pickup pickup, PickupDock dock)Server: starts a project from the docked page unless pieces are already filled.
private void OnPageUndocked(Interactor interactor, Pickup pickup, PickupDock dock)Server: clears an unfinished project, returning materials, when the page is removed and no pieces are filled.
private void PageFilter(Interactor interactor, Pickup pickup, ref bool result)Only lets pages that hold a generic crafting recipe dock in recipeDock.
private void SetupFakeInteractable()Fits the grab-result collider around the bounds of all project pieces.
private void SetupLOD()Client: adds the station to the distance LOD list.
private void SetupProjectFromPage()Starts a project from the page in recipeDock, if it holds a recipe.
private NetworkEntity SpawnResult()Spawns the recipe's result, clears the project and starts a new one from the docked page.
private void StopAnimating()Stops the placement animation on every project piece.
private void SyncClientNailHit(IPlayer player, Stream stream, GenericCraftingStation.ClientSideNailHitSync arguments)Server: applies a nail hit reported by a client, working out damage from the tool.
private void SyncDestroyEffect(IPlayer player, Stream stream, int pieceIndex)Hands a piece's destroy effect sync to the project.
private void SyncFull(IPlayer player, Stream stream)Syncs the whole station: recipe, every piece and the project status. Sent on connect.
private void SyncNailHit(IPlayer player, Stream stream, NailIdentifier identifier)Syncs a nail's state and the piece's failure, playing the nail effect on clients.
private void SyncPiece(IPlayer player, Stream stream, int pieceIndex)Hands one piece's sync to the project.
private void SyncPieceGrab(IPlayer player, Stream stream, int pieceIndex)Syncs a piece being grabbed, sent by clients.
private void SyncProject(IPlayer player, Stream stream)Syncs which recipe is loaded; clients start or clear their project to match.
private void SyncProjectStatus(IPlayer player, Stream stream, bool hasEffects)Syncs whether the project is complete or its current level, and updates the grab-result collider on clients.
private void TrackPickups()Per-frame while pickups are in the trigger: drops docked or destroyed ones and lets held components track the station.
private static void UpdateDistanceLOD()Sets each project's render level by distance from the local player's head. Never registered; see UpdateDistanceLODSingleGhost.
private static void UpdateDistanceLODSingleGhost()Empty. This, not UpdateDistanceLOD, is what SetupLOD registers, so distance LOD does nothing.

Used in​

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