Cell Class Functions
Defined In: SandInfo
SandInfo.Cell is a class that is used to represent every active cell in the simulation. It contains helper functions that are very useful when making custom behaviors (see Making Custom ElementBehaviors) or just interacting with cell objects.
Getting/Setting Properties
| Return Type | Function |
|---|---|
| void | SetElement() |
| void | SetField() |
| byte | GetField() |
| void | ReplaceTypeAttributesWithDefault() |
Finding Neighbors
| Return Type | Function |
|---|---|
| Cell? | SearchNeighborElements() |
| Cell? | GetNeighbor() |
Movement
| Return Type | Function |
|---|---|
| bool | CanMove() |
| bool | TryMove() |
Method Descriptions
void SetElement(AllElements to)
AllElementsto - The element to assign to the cell.
Sets this cell's Element while marking it updated on this cell's chunk. Marking a cell updated makes sure it sends the updated information to the renderer at the end of the current tick.
void SetField(string FieldName, byte SetTo)
stringFieldName - The name of the field to access. Include prefixes likeR#.byteSetTo - The number to set the field to.
Sets a specified field to a specified value. Also clamps the value to a range of (0, 255).
byte GetField(string FieldName)
stringFieldName - The field whose value to return. Include prefixes likeR#.
Returns the specified field's value.
void ReplaceTypeAttributesWithDefault()
Reverts all changes to this cell's fields and generates new starting fields.
Cell? SearchNeighborElements(PowderSimulation simRef, AllElements targetElement, bool opposite = false, int targetAmount = 1, AllElements? SecondaryTarget = null)
PowderSimulationsimRef - A reference to the PowderSimulation node this cell is a part of.AllElementstargetElement - The element to look for.boolopposite= false- whether to look for any element other thantargetElementwhen true, or to look fortargetElementwhen false.inttargetAmount= 1- The amount of neighbors needed to fulfill the condition. Ex. if targetAmount is 2, it will look for 2 neighbors with the targetElement.AllElements?SecondaryTarget= null- A secondary target that will also fulfill the condition.
Iterates over this cell's neighbors and returns the cell it stops on when the condition defined by the parameters is true.
Cell? GetNeighbor(Vector2I neighbor, PowderSimulation simRef)
Vector2Ineighbor - The transformation applied to this cell's Position to get the neighbor cell from. Use SandInfo's constants like TOPLEFT or TOPRIGHT for better readability.PowderSimulationsimRef - A reference to the PowderSimulation node this cell is a part of.
Returns the neighbor cell specified in neighbor, and null if the neighbor doesn't exist (is past the edge of the simulation).
bool CanMove(Cell NeighborCell)
CellNeighborCell - The cell to check whether it can move to it or not.
This is called in TryMove() so if you are just moving the cell, you do not need to call this.
Returns whether the cell can move or not, only comparing the Cell.Attributes.Type of both cells.
bool TryMove(Vector2I toNeighbor, PowderSimulation simRef)
Vector2ItoNeighbor - The transform applied to this cell's Position to get the neighbor cell from. Use SandInfo's constants like TOPLEFT or TOPRIGHT for better readability.PowderSimulationsimRef - A reference to the PowderSimulation node this cell is a part of.
Attempts to move this cell to one of its neighbors.
Returns whether the move was successful or not.