Skip to main content

PersonalChunk

A class in Root.Township, Alta.Inventory.

A chunk that loads one player's personal storage, saved under a name with that player's ID. Server only; one player at a time, and a player can only use one at a time.

Constructors​

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

Fields​

4 private and internal fields
MemberWhat it is
private Chunk chunkThe chunk on this object.
private static HashSet<IPlayer> currentlyUsingPlayers who have a personal chunk loaded, across all instances.
private string nameSuffixPart of the chunk name, so different personal chunks don't share a save. Defaults to Storage.
private NetworkPrefab prefabPrefab spawned the first time a player's chunk is empty.

Properties​

MemberWhat it is
IPlayer CurrentPlayer { get; private set; }The player whose storage is loaded, or null.

Methods​

MemberWhat it is
override void Initialize()Gets the chunk and marks it not static.
void Load(IPlayer player)Server: renames the chunk to Personal Chunk plus suffix and the player's ID, force loads it, and spawns contents once loaded.
void Unload(IPlayer player)Server: unloads and saves the chunk if this player is the current one.
2 private and internal methods
MemberWhat it is
private void RemoveCurrentPlayer()Force unloads and saves the chunk and frees the current player.
private void SpawnInitialDocks(Chunk chunk)Once loaded, spawns prefab if the chunk is empty (else re-parents the first entity), then adds the player to the chunk.