TimberBlock
A class in Root.Township, Alta.Carpentry.
A timber block on a chiselling deck, carved in three stages (outer, inner, core). Finishing the outer stage picks a result from the chiselled order; finishing the core frees the result pickups and destroys the block. The server runs it and syncs pieces to clients.
- Listed in Crafting and making
- Inherits or implements
NetworkEntityBehaviour - Nested types
CoreStage,InnerStage,OuterStage,Stage,StageLevel - Documented in Farming, woodcutting and carpentry
Constructors
| Member | What it is |
|---|---|
TimberBlock() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
TimberBlockEvent Done | Raised when the core stage finishes, just before the block is destroyed. |
TimberBlockEvent Modified | Raised the first time a piece in a stage changes. |
21 private and internal fields
| Member | What it is |
|---|---|
private ListenedList<int> chiselledPieces | Indexes of outer pieces finished, used to choose the chisel result. Cleared when the outer stage ends. |
private ColliderGroup colliderGroup | Backing field for ColliderGroup. |
private TimberBlock.CoreStage coreStage | The last stage. Finishing it releases the result and destroys the block. |
private TimberBlock.Stage currentStage | The stage being chiselled now. SetCurrent on a stage changes it. |
private SoundEffectSet destroyingSound | Sound played where a piece is fully chiselled away. |
private MeshFilter[] filters | Mesh filters re-atlased for the block's material. |
private SoundEffectSet hittingSound | Sound set in the inspector. Not used by this class. |
private PooledObjectDefinition hittinPiece | Pooled effect set in the inspector. Not used by this class. |
private TimberBlock.InnerStage innerStage | The middle stage, current after the outer stage ends. |
private bool isInitialized | Whether Initialize has run, so Serialize, save and load can run it first. |
private TimberBlock.OuterStage outerStage | The first stage. Its chiselled pieces decide the result. |
private PhysicalMaterial physicalMaterial | Backing field for PhysicalMaterial. Applied to result pickups and saved. |
private Renderer[] renderers | Renderers given the block's material. |
private ChiselBlockSize size | Backing field for Size, used to pick a chisel definition. |
private Transform spawnCraftPosition | Transform the result pickups are spawned under and stage effects play at. |
private ChiselDefinition spawnedDefinition | The chisel definition whose result was spawned. Saved and synced. |
private Pickup[] spawnedPickups | The result pickups held on the block until the core stage ends. |
private Dictionary<TimberBlock.StageLevel, TimberBlock.Stage> stageMap | Stages by level, filled when each stage initializes. |
private MethodSyncStruct<bool> syncPickup | Method sync for SyncPickup. |
private MethodSyncStruct<int> syncPieceEffects | Method sync for SyncPieceEffects. |
private MethodSyncStruct<bool> syncStatus | Method sync for SyncStatus, sent on connect and when the stage changes. |
Properties
| Member | What it is |
|---|---|
IListenedList<int> ChiselledPieces { get; } | Indexes of outer pieces in the order they were chiselled off. Matched against ChiselDefinition orders. |
ColliderGroup ColliderGroup { get; } | The block's colliders. |
TimberBlock.StageLevel CurrentStageLevel { get; } | Outer, inner or core. |
bool HasFollowedRecipe { get; set; } | Whether the player followed a guide; passed on with the crafted item task. |
bool IsModified { get; } | Whether the block has been carved: true past the outer stage, else whether any outer piece changed. |
PhysicalMaterial PhysicalMaterial { get; } | The wood material of the block. |
ChiselBlockSize Size { get; } | The block's ChiselBlockSize. |
Methods
| Member | What it is |
|---|---|
List<MeshFilter> ActiveFilters() | Mesh filters of the current stage's pieces that are still there. |
TimberPieceBase GetPiece(int index) | A piece of the current stage by index. |
override void Initialize() | Sets up synced messages and the three stages, starting at the outer stage. Runs once. |
void LoadFrom(ChisellingDeckSaveData data) | Restores the stage, pieces, chiselled order, result and material from deck save data. |
void LoadSetup() | Respawns the result pickups if a result was chosen before saving. |
override void OnConnected(Player player) | Server: sends the full block state, and the result pickups if any, to a new player. |
float RefusePercentage() | Share of wedges given back if the block is removed now; drops as pieces are finished. |
void RotateTo(bool isInversedUp) | Server: turns the current stage's pieces to match the block's up direction. |
void SaveInto(ChisellingDeckSaveData data) | Writes the stage, pieces, chiselled order, result and material into deck save data. |
void Serialize(Stream stream, bool isWritingFull) | Writes or reads the stage and piece state, and with full writes the chiselled order and result. |
void SetupPhysicalMaterial(PhysicalMaterial physicalMaterial) | Sets the wood material and, on clients, the matching atlased renderer material. |
10 private and internal methods
| Member | What it is |
|---|---|
private void CallPieceEffect(TimberPieceBase piece) | Server sends the piece's state to chunks; non-headless sides play the destroy effect and sound when a piece reaches full progress. |
private void GetResult() | Server: picks the best chisel definition for the chiselled outer pieces and spawns its result. |
private async void HandleSyncedPickup(uint identifier, int index, bool isAdding) | Client: waits for a synced result pickup to spawn, then parents and freezes it on the block or releases it. |
private void OnDestroy() | Server: destroys any result pickups still held on the block. |
private void ReleaseResult(Player player) | Server: frees the held result pickups into the world, makes them saveable and reports the spawn task for the player. |
private void SpawnResult() | Spawns the chosen definition's pickups at spawnCraftPosition, frozen and non-interactable, in the block's material. |
private void SyncPickup(IPlayer player, Stream stream, bool isAdding) | Syncs whether result pickups are held, with the chisel definition and their entity ids. |
private void SyncPieceEffects(IPlayer player, Stream stream, int pieceIndex) | Syncs one piece's state by index and plays its effect on the receiving side. |
private void SyncStatus(IPlayer player, Stream stream, bool isWritingFull) | Syncs the block's physical material and stage state, applying the material on remote clients. |
private void UpdatePickupCollision(Pickup pickup, bool isEnabling) | Turns all colliders on a result pickup on or off. |
Used in
Members of other types that take, return or hold a TimberBlock: