...
- Create class which extends
Block
*If your new block is a simple cube, you can extendCubeBlock
instead - Override required properties and methods
TexturePaths
should return astring[]
of paths to the textures used by the block. For example:
public override string[] TexturePaths { get { return new[] { "res://Images/grass_top.png", "res://Images/grass_side.png" }; } }
GetTextureIndex
should return an integer index into theTexturePaths
array, for the providedBlockFace
. For example:
public override int GetTextureIndex(BlockFace face)
{
switch(face)
{
case BlockFace.Top:
case BlockFace.Bottom:
return 0;
default:
return 1;
}
}
Add<[Pos/Neg][X/Y/Z]>Face
should write the given face to the SurfaceTool supplied. SeeCubeBlock
for an example.
- Register the block in Game construction, with
Game.RegisterBlock(new MyNewBlockType())
- The block can now be used elsewhere in code. If you need it's
byte
id, you can useGame.GetBlockId<BlockType>()
. Please bear in mind this is a comparitively expensive operation, so you should cache the result.
If you need to get a Block, given an id, useGame.GetBlock(byte id)