function p.get_is_solid() return true end
function p.get_tex() return "block_diamond" end

function p.main()
    set_default_block("s")
end

function p.type_init(id)
    ia_block_new_var_i(id, "diamonds", 10)
end

function p.get_can_use(level, bp)
    return true
end

function p.get_use_msg(level, bp)
    local diamonds_in_box = ga_block_get_i(level, bp, "diamonds")
    return "Diamonds: " .. tostring(diamonds_in_box)
end

function p.on_use(level, bp)
    p.test()

    local diamonds_in_box = ga_block_get_i(level, bp, "diamonds")
    if( diamonds_in_box <= 0 ) then return end
    diamonds_in_box = diamonds_in_box - 1
    ga_block_set_i(level, bp, "diamonds", diamonds_in_box)
    -- --
    local diamonds_in_inv = ga_get_i("var.diamonds")
    diamonds_in_inv = diamonds_in_inv + 1
    ga_set_i("var.diamonds", diamonds_in_inv)
    ga_play_sound("gold")
end

function p.test()
    ga_print("Inside block_diamond_box.test()")
    local bt_of_player_chunk = ga_get_viewer_chunk_bt()
    ga_print("Block type of chunk containing player: " .. bt_of_player_chunk)

    local chunk_id = ga_get_viewer_chunk_id()
    -- local data = ga_search_for_bt_in_chunk(chunk_id, "block_diamond_box")
    local seed = 0 --Seed for pseudo random number generation.
    local data = ga_search_for_bt_in_chunk_random(seed, chunk_id, "block_diamond_box")
    if( data.is_valid ) then
        local pos = data.value --The local block pos.
        ga_print("Found a diamond block in the chunk of the player: position = " .. std.bp_to_str(pos))
    else
        ga_print("Did NOT find a diamond block in the chunk of the player")
    end
end
