2016-08-02 23:53:14 +02:00

79 lines
2.9 KiB
Lua

local doc_identifier = {}
doc_identifier.huds = {}
doc_identifier.countdown_ids = {}
doc_identifier.identify = function(itemstack, user, pointed_thing)
local username = user:get_player_name()
if pointed_thing.type == "node" then
local pos = pointed_thing.under
local node = minetest.get_node(pos)
if minetest.registered_nodes[node.name] ~= nil then
local nodedef = minetest.registered_nodes[node.name]
local show_error = function(username)
minetest.show_formspec(
username,
"doc_identifier:error_missing_node_info",
"size[12,2;]label[0,0.2;The identification tool was unable to extract information from this block.]button_exit[4.5,1.5;3,1;okay;OK]"
)
end
if(node.name == "ignore") then
show_error(username)
end
if doc.entry_exists("nodes", node.name) then
doc.show_entry(username, "nodes", node.name)
else
show_error(username)
end
end
end
return itemstack
end
function doc_identifier.solid_mode(itemstack, user, pointed_thing)
return ItemStack("doc_identifier:identifier_solid")
end
function doc_identifier.liquid_mode(itemstack, user, pointed_thing)
return ItemStack("doc_identifier:identifier_liquid")
end
minetest.register_tool("doc_identifier:identifier_solid", {
description = "Identification tool",
tool_capabilities = {},
range = 10,
wield_image = "doc_identifier_identifier.png",
inventory_image = "doc_identifier_identifier.png",
liquids_pointable = false,
on_use = doc_identifier.identify,
on_place = doc_identifier.liquid_mode,
on_secondary_use = doc_identifier.liquid_mode,
})
minetest.register_tool("doc_identifier:identifier_liquid", {
description = "Identification tool",
tool_capabilities = {},
range = 10,
groups = { not_in_creative_inventory = 1 },
wield_image = "doc_identifier_identifier_liquid.png",
inventory_image = "doc_identifier_identifier_liquid.png",
liquids_pointable = true,
on_use = doc_identifier.identify,
on_place = doc_identifier.solid_mode,
on_secondary_use = doc_identifier.solid_mode,
})
minetest.register_craft({
output = "doc_identifier:identifier_solid",
recipe = { {"group:stick", "group:stick" },
{"", "group:stick"},
{"group:stick", ""} }
})
minetest.register_alias("doc_identifier:identifier", "doc_identifier:identifier_solid")
-- Add documentation
doc.sub.items.add_helptexts(
{ ["doc_identifier:identifier_solid"] = "This useful little helper can be used to quickly learn more about about one's closer environment. It identifies and analyzes blocks and it shows extensive information of a block on which it is used." },
{ ["doc_identifier:identifier_solid"] = "Punch any block about you wish to learn more about. This will show you a help screen. The identification tool comes in two modes: Solid mode (red) and liquid mode (blue). In liquid mode this tool points to liquids as well while in solid mode this is not the case. Liquid mode is required if you want to identify a liquid. You change the mode with a rightclick." })