public void SetBlockType(string type) { var newtype = BlockTypeDatabase.GetBlockType(type); if (newtype != null) { selectedBlocktype = newtype; } }
public void Start() { if (world == null) { world = FindObjectOfType <World>(); } if (builder == null) { builder = FindObjectOfType <Builder>(); } if (console == null) { console = FindObjectOfType <DebugConsole>(); } selectedBlocktype = BlockTypeDatabase.GetBlockType("Stone"); selectedPosition = new Vector3Int(0, 0, 0); selectedDirection = new Vector3Int(0, 0, 0); }
public static void AddBlockFaceData(Chunk c, Vector3Int block_pos, ref MeshData data) { //if (c.GetBlock(block_pos).Id == 0) return; BlockType blocktype = BlockTypeDatabase.GetBlockType(c.GetBlock(block_pos).Id); if (!blocktype.Solid) { return; } foreach (Direction dir in DirectionUtils.Directions) { Vector3Int neighbour_pos = block_pos + DirectionUtils.CastToVector3Int(dir); if (!BlockTypeDatabase.GetBlockType(c.GetBlock(neighbour_pos).Id).Solid) //if the neigboring block is NOT solid, then we need to update the meshdata to show our cube faces { switch (dir) { case Direction.north: data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y - 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y + 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y + 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y - 0.5f, block_pos.z + 0.5f)); AddQuadTriangleIndices(ref data); AddQuadTextureCoordinates(blocktype.TextureSet.GetTexture(), ref data); break; case Direction.east: data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y - 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y + 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y + 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y - 0.5f, block_pos.z + 0.5f)); AddQuadTriangleIndices(ref data); AddQuadTextureCoordinates(blocktype.TextureSet.GetTexture(), ref data); break; case Direction.south: data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y - 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y + 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y + 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y - 0.5f, block_pos.z - 0.5f)); AddQuadTriangleIndices(ref data); AddQuadTextureCoordinates(blocktype.TextureSet.GetTexture(), ref data); break; case Direction.west: data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y - 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y + 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y + 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y - 0.5f, block_pos.z - 0.5f)); AddQuadTriangleIndices(ref data); AddQuadTextureCoordinates(blocktype.TextureSet.GetTexture(), ref data); break; case Direction.up: data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y + 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y + 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y + 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y + 0.5f, block_pos.z - 0.5f)); AddQuadTriangleIndices(ref data); AddQuadTextureCoordinates(blocktype.TextureSet.GetTexture(), ref data); break; case Direction.down: data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y - 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y - 0.5f, block_pos.z - 0.5f)); data.vertices.Add(new Vector3(block_pos.x + 0.5f, block_pos.y - 0.5f, block_pos.z + 0.5f)); data.vertices.Add(new Vector3(block_pos.x - 0.5f, block_pos.y - 0.5f, block_pos.z + 0.5f)); AddQuadTriangleIndices(ref data); AddQuadTextureCoordinates(blocktype.TextureSet.GetTexture(), ref data); break; } } } }
private void Awake() { BlockTypeDatabase.LoadBlockTypes(); }