123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- local modname = minetest.get_current_modname()
- local S = minetest.get_translator(modname)
- local get_prospect = _G[modname].get_prospect
- reading_message_chart =
- {
- {-3, "Found traces of traces of @1."},
- {-2, "Found traces of @1."},
- {-0.3, "Found large traces of @1."},
- {0, "Found @1."},
- }
- local function get_message_from_reading(strength)
- local ret
- for k, v in ipairs(reading_message_chart)
- do
- print(k, type(k))
- if strength >= v[1]
- then
- ret = v[2]
- end
- end
- return ret
- end
- minetest.register_tool(modname .. ":pick",
- {
- description = S("Prospector pick"),
- inventory_image = modname .. "_pick.png",
- on_use = function(itemstack, user, pointed_thing)
- if pointed_thing.type == "node"
- then
- local prospect = get_prospect(pointed_thing.under)
- local highest_name
- local highest_val = -math.huge
- for k, v in pairs(prospect)
- do
- if v > highest_val
- then
- highest_name = k
- highest_val = v
- end
- end
- if highest_name
- then
- local msg =
- highest_val < -3 and S("Found nothing.") or
- S(get_message_from_reading(highest_val), highest_name)
- minetest.chat_send_player(user:get_player_name(), msg)
- else
- minetest.chat_send_player(user:get_player_name(), S("Found nothing.") )
- end
- end
- end,
- })
|