void BuildChunk()
    {
        bool dataFromFile = Load();

        chunkData = new Block[World.chunkSize, World.chunkSize, World.chunkSize];
        for (int z = 0; z < World.chunkSize; z++)
        {
            for (int y = 0; y < World.chunkSize; y++)
            {
                for (int x = 0; x < World.chunkSize; x++)
                {
                    Vector3 pos    = new Vector3(x, y, z);
                    int     worldX = (int)(x + chunk.transform.position.x);
                    int     worldY = (int)(y + chunk.transform.position.y);
                    int     worldZ = (int)(z + chunk.transform.position.z);

                    if (dataFromFile)
                    {
                        chunkData[x, y, z] = new Block(bd.matrix[x, y, z], pos, chunk.gameObject, this);
                        continue;
                    }

                    int surfaceHeight = Utils.GenHeight(worldX, worldZ);
                    if (worldY < 5)
                    {
                        chunkData[x, y, z] = new BedRockBlock(pos, chunk.gameObject, this);
                    }
                    else if (worldY <= Utils.GenStoneHeight(worldX, worldZ))
                    {
                        if (Utils.fBM3D(worldX, worldY, worldZ, 0.01f, 2) < 0.4f && worldY < 40)
                        {
                            chunkData[x, y, z] = new DiamondBlock(pos, chunk.gameObject, this);
                        }
                        if (Utils.fBM3D(worldX, worldY, worldZ, 0.03f, 3) < 0.41f && worldY < 20)
                        {
                            chunkData[x, y, z] = new RedStoneBlock(pos, chunk.gameObject, this);
                        }
                        else
                        {
                            chunkData[x, y, z] = new StoneBlock(pos, chunk.gameObject, this);
                        }
                    }
                    else if (worldY == surfaceHeight)
                    {
                        if (Utils.fBM3D(worldX, worldY, worldZ, 0.175f, 2) < 0.35f && worldY >= 65)
                        {
                            chunkData[x, y, z] = new TreeBlock(TreeBlock.TreeType.PINE, false, true, pos, chunk.gameObject, this);
                        }
                        else
                        {
                            chunkData[x, y, z] = new GrassBlock(pos, chunk.gameObject, this);
                        }
                        // chunkData[x, y, z] = new GrassBlock(pos, chunk.gameObject, this);
                    }
                    else if (worldY < surfaceHeight)
                    {
                        chunkData[x, y, z] = new DirtBlock(pos, chunk.gameObject, this);
                    }
                    else
                    {
                        chunkData[x, y, z] = new AirBlock(pos, chunk.gameObject, this);
                    }

                    if (chunkData[x, y, z].bType != Block.BlockType.WATER && Utils.fBM3D(worldX, worldY, worldZ, 0.08f, 3) < 0.42f)
                    {
                        chunkData[x, y, z] = new AirBlock(pos, chunk.gameObject, this);
                    }
                    if (worldY < 65 && chunkData[x, y, z].bType == Block.BlockType.AIR)
                    {
                        chunkData[x, y, z] = new WaterBlock(pos, fluid.gameObject, this);
                    }
                    if (worldY == 0)
                    {
                        chunkData[x, y, z] = new BedRockBlock(pos, chunk.gameObject, this);
                    }

                    status = ChunkStatus.DRAW;
                }
            }
        }
    }
    private void SetTypeData(BlockType type, bool isConstructor)
    {
        switch (type)
        {
        case BlockType.GRASS:
            if (!isConstructor)
            {
                blockUVs = GrassBlock.UVs;
            }
            MaxHealth = GrassBlock.maxHealth;
            break;

        case BlockType.DIRT:
            if (!isConstructor)
            {
                blockUVs = DirtBlock.UVs;
            }
            MaxHealth = DirtBlock.maxHealth;
            break;

        case BlockType.WATER:
            if (!isConstructor)
            {
                blockUVs = WaterBlock.UVs;
            }
            MaxHealth = WaterBlock.maxHealth;
            break;

        case BlockType.STONE:
            if (!isConstructor)
            {
                blockUVs = StoneBlock.UVs;
            }
            MaxHealth = StoneBlock.maxHealth;
            break;

        case BlockType.SAND:
            if (!isConstructor)
            {
                blockUVs = SandBlock.UVs;
            }
            MaxHealth = SandBlock.maxHealth;
            break;

        case BlockType.LEAVES:
            if (!isConstructor)
            {
                blockUVs = TreeBlock.SetTreeData(TreeBlock.tType, true);
            }
            MaxHealth = TreeBlock.maxHealth;
            break;

        case BlockType.WOOD:
            if (!isConstructor)
            {
                blockUVs = TreeBlock.SetTreeData(TreeBlock.tType, false);
            }
            MaxHealth = TreeBlock.maxHealth;
            break;

        case BlockType.WOODBASE:
            if (!isConstructor)
            {
                blockUVs = TreeBlock.SetTreeData(TreeBlock.tType, false);
            }
            MaxHealth = TreeBlock.maxHealth;
            break;

        case BlockType.BEDROCK:
            if (!isConstructor)
            {
                blockUVs = BedRockBlock.UVs;
            }
            MaxHealth = BedRockBlock.maxHealth;
            break;

        case BlockType.REDSTONE:
            if (!isConstructor)
            {
                blockUVs = RedStoneBlock.UVs;
            }
            MaxHealth = RedStoneBlock.maxHealth;
            break;

        case BlockType.DIAMOND:
            if (!isConstructor)
            {
                blockUVs = DiamondBlock.UVs;
            }
            MaxHealth = DiamondBlock.maxHealth;
            break;

        default:
            if (!isConstructor)
            {
                blockUVs = AirBlock.UVs;
            }
            MaxHealth = AirBlock.maxHealth;
            break;
        }
    }