Пример #1
0
    // On random Update spread grass to any nearby dirt blocks on the surface
    public override void RandomUpdate(Chunk chunk, Vector3Int localPos, Vector3Int globalPos)
    {
        ChunkBlocks blocks  = chunk.blocks;
        WorldBlocks blocksW = chunk.world.blocks;

        int minX = localPos.x <= 0 ? 0 : 1;
        int maxX = localPos.x >= Env.ChunkMask ? 0 : 1;
        int minY = localPos.y <= 0 ? 0 : 1;
        int maxY = localPos.y >= Env.ChunkMask ? 0 : 1;
        int minZ = localPos.z <= 0 ? 0 : 1;
        int maxZ = localPos.z >= Env.ChunkMask ? 0 : 1;

        for (int x = -minX; x <= maxX; x++)
        {
            for (int y = -minY; y <= maxY; y++)
            {
                for (int z = -minZ; z <= maxZ; z++)
                {
                    Vector3Int newPos = localPos.Add(x, y, z);
                    if (blocks.Get(newPos).Equals(dirt) &&
                        blocksW.Get(globalPos.Add(x, y + 1, z)).Equals(air))
                    {
                        blocks.Modify(newPos, grass, true);
                    }
                }
            }
        }
    }
Пример #2
0
    public override void BuildBlock(Chunk chunk, Vector3Int localPos, Vector3Int globalPos)
    {
        Rect texture;
        RenderGeometryBatcher batcher = chunk.GeometryHandler.Batcher;
        WorldBlocks           blocks  = chunk.world.blocks;

        for (int d = 0; d < 6; d++)
        {
            Direction dir = DirectionUtils.Get(d);
            if (!connectedMeshConfig.directionalTris.ContainsKey(dir))
            {
                continue;
            }

            if (connectedMeshConfig.connectsToSolid && blocks.GetBlock(globalPos + dir).IsSolid(DirectionUtils.Opposite(dir)))
            {
                texture = connectedMeshConfig.texture.GetTexture(chunk, localPos, globalPos, dir);
                batcher.AddMeshData(connectedMeshConfig.directionalTris[dir], connectedMeshConfig.directionalVerts[dir], texture, localPos);
            }
            else if (connectedMeshConfig.connectsToTypes.Length != 0)
            {
                int neighborType = blocks.Get(globalPos.Add(dir)).Type;
                for (int i = 0; i < connectedMeshConfig.connectsToTypes.Length; i++)
                {
                    if (neighborType == connectedMeshConfig.connectsToTypes[i])
                    {
                        texture = connectedMeshConfig.texture.GetTexture(chunk, localPos, globalPos, dir);
                        batcher.AddMeshData(connectedMeshConfig.directionalTris[dir], connectedMeshConfig.directionalVerts[dir], texture, localPos);
                        break;
                    }
                }
            }
        }

        texture = customMeshConfig.texture.GetTexture(chunk, localPos, globalPos, Direction.down);
        batcher.AddMeshData(customMeshConfig.tris, customMeshConfig.verts, texture, localPos);
    }