Skip to main content

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.

Constructors​

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

Fields​

MemberWhat it is
TimberBlockEvent DoneRaised when the core stage finishes, just before the block is destroyed.
TimberBlockEvent ModifiedRaised the first time a piece in a stage changes.
21 private and internal fields
MemberWhat it is
private ListenedList<int> chiselledPiecesIndexes of outer pieces finished, used to choose the chisel result. Cleared when the outer stage ends.
private ColliderGroup colliderGroupBacking field for ColliderGroup.
private TimberBlock.CoreStage coreStageThe last stage. Finishing it releases the result and destroys the block.
private TimberBlock.Stage currentStageThe stage being chiselled now. SetCurrent on a stage changes it.
private SoundEffectSet destroyingSoundSound played where a piece is fully chiselled away.
private MeshFilter[] filtersMesh filters re-atlased for the block's material.
private SoundEffectSet hittingSoundSound set in the inspector. Not used by this class.
private PooledObjectDefinition hittinPiecePooled effect set in the inspector. Not used by this class.
private TimberBlock.InnerStage innerStageThe middle stage, current after the outer stage ends.
private bool isInitializedWhether Initialize has run, so Serialize, save and load can run it first.
private TimberBlock.OuterStage outerStageThe first stage. Its chiselled pieces decide the result.
private PhysicalMaterial physicalMaterialBacking field for PhysicalMaterial. Applied to result pickups and saved.
private Renderer[] renderersRenderers given the block's material.
private ChiselBlockSize sizeBacking field for Size, used to pick a chisel definition.
private Transform spawnCraftPositionTransform the result pickups are spawned under and stage effects play at.
private ChiselDefinition spawnedDefinitionThe chisel definition whose result was spawned. Saved and synced.
private Pickup[] spawnedPickupsThe result pickups held on the block until the core stage ends.
private Dictionary<TimberBlock.StageLevel, TimberBlock.Stage> stageMapStages by level, filled when each stage initializes.
private MethodSyncStruct<bool> syncPickupMethod sync for SyncPickup.
private MethodSyncStruct<int> syncPieceEffectsMethod sync for SyncPieceEffects.
private MethodSyncStruct<bool> syncStatusMethod sync for SyncStatus, sent on connect and when the stage changes.

Properties​

MemberWhat 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​

MemberWhat 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
MemberWhat 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: