Ejemplo n.º 1
0
    public void BuildFluid(Block block, int x, int y, int z, MeshData meshData)
    {
        Vector3i local    = Map.ToLocalPos(x, y, z);
        Vector3i worldPos = new Vector3i(x, y, z);

        AdjacentBlocks neighbors = Map.GetAdjacentBlocks(x, y, z);

        int   curLevel = block.FluidLevel;
        float offset   = FluidSimulator.GetOffset(curLevel);

        if (IsFluidFaceVisible(curLevel, x, y, z + 1, neighbors.front, Direction.Back))
        {
            BuildFrontFluid(block, local.x, local.y, local.z, meshData, Direction.Front, offset, neighbors.front);
            BuildSquareLight(Axis.Z, worldPos, meshData, squareOffsetFront);
        }

        if (IsFluidFaceVisible(curLevel, x, y, z - 1, neighbors.back, Direction.Front))
        {
            BuildBackFluid(block, local.x, local.y, local.z, meshData, Direction.Back, offset, neighbors.back);
            BuildSquareLight(Axis.Z, worldPos, meshData, squareOffsetBack);
        }

        if (IsFluidFaceVisible(curLevel, x + 1, y, z, neighbors.right, Direction.Left))
        {
            BuildRightFluid(block, local.x, local.y, local.z, meshData, Direction.Right, offset, neighbors.right);
            BuildSquareLight(Axis.X, worldPos, meshData, squareOffsetRight);
        }

        if (IsFluidFaceVisible(curLevel, x - 1, y, z, neighbors.left, Direction.Right))
        {
            BuildLeftFluid(block, local.x, local.y, local.z, meshData, Direction.Left, offset, neighbors.left);
            BuildSquareLight(Axis.X, worldPos, meshData, squareOffsetLeft);
        }

        if (IsFluidFaceVisible(curLevel, x, y + 1, z, neighbors.top, Direction.Down))
        {
            BuildTopFluid(block, local.x, local.y, local.z, meshData, Direction.Up, offset);
            BuildSquareLight(Axis.Y, worldPos, meshData, squareOffsetTop);
        }

        if (IsFluidFaceVisible(curLevel, x, y - 1, z, neighbors.bottom, Direction.Up))
        {
            BuildBottomFluid(block, local.x, local.y, local.z, meshData, Direction.Down);
            BuildSquareLight(Axis.Y, worldPos, meshData, squareOffsetBottom);
        }
    }
Ejemplo n.º 2
0
    private void BuildLeftFluid(Block block, int x, int y, int z, MeshData meshData, int dir, float offset, Block adj)
    {
        AddIndices(meshData);

        float adjOffset = -0.5f;

        if (adj.IsFluid())
        {
            int adjLevel = adj.FluidLevel;
            adjOffset = FluidSimulator.GetOffset(adjLevel);
        }

        meshData.AddVertex(new Vector3(-0.5f, adjOffset, -0.5f), x, y, z);
        meshData.AddVertex(new Vector3(-0.5f, offset, -0.5f), x, y, z);
        meshData.AddVertex(new Vector3(-0.5f, offset, 0.5f), x, y, z);
        meshData.AddVertex(new Vector3(-0.5f, adjOffset, 0.5f), x, y, z);

        AddFluidUVs(block, dir, meshData, offset - adjOffset);
    }