112 lines
4.1 KiB
Lua
Raw Normal View History

2016-07-24 16:45:43 +02:00
local doc_identifier = {}
doc_identifier.huds = {}
doc_identifier.countdown_ids = {}
2016-07-24 18:27:15 +02:00
doc_identifier.identify = function(itemstack, user, pointed_thing)
2016-07-24 16:45:43 +02:00
local username = user:get_player_name()
2016-08-04 22:53:06 +02:00
local show_error = function(username, itype)
local message
if itype == "item" then
message = "The identification tool was unable to extract information from this item."
elseif itype == "node" then
message = "The identification tool was unable to extract information from this block."
end
minetest.show_formspec(
username,
"doc_identifier:error_missing_item_info",
"size[12,2;]label[0,0.2;"..minetest.formspec_escape(message).."]button_exit[4.5,1.5;3,1;okay;OK]"
)
end
2016-07-24 16:45:43 +02:00
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]
2016-08-01 23:53:48 +02:00
if(node.name == "ignore") then
2016-08-04 22:53:06 +02:00
show_error(username, "node")
2016-08-01 23:53:48 +02:00
end
if doc.entry_exists("nodes", node.name) then
doc.show_entry(username, "nodes", node.name)
else
2016-08-04 22:53:06 +02:00
show_error(username, "node")
end
end
elseif pointed_thing.type == "object" then
local object = pointed_thing.ref
local le = object:get_luaentity()
if object:is_player() then
-- TODO: Players
elseif le ~= nil then
-- Dropped items
if le.name == "__builtin:item" then
local itemstring = ItemStack(minetest.deserialize(le:get_staticdata()).itemstring):get_name()
if doc.entry_exists("nodes", itemstring) then
doc.show_entry(username, "nodes", itemstring)
elseif doc.entry_exists("tools", itemstring) then
doc.show_entry(username, "tools", itemstring)
elseif doc.entry_exists("craftitems", itemstring) then
doc.show_entry(username, "craftitems", itemstring)
else
show_error(username, "item")
end
2016-08-01 23:53:48 +02:00
end
2016-07-24 16:45:43 +02:00
end
end
return itemstack
end
2016-07-24 18:27:15 +02:00
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
2016-07-24 16:45:43 +02:00
minetest.register_tool("doc_identifier:identifier_solid", {
2016-08-01 23:56:08 +02:00
description = "Identification tool",
2016-07-24 16:45:43 +02:00
tool_capabilities = {},
2016-07-24 19:05:11 +02:00
range = 10,
2016-07-24 16:45:43 +02:00
wield_image = "doc_identifier_identifier.png",
inventory_image = "doc_identifier_identifier.png",
liquids_pointable = false,
2016-07-24 18:27:15 +02:00
on_use = doc_identifier.identify,
on_place = doc_identifier.liquid_mode,
on_secondary_use = doc_identifier.liquid_mode,
2016-07-24 16:45:43 +02:00
})
minetest.register_tool("doc_identifier:identifier_liquid", {
2016-08-01 23:56:08 +02:00
description = "Identification tool",
2016-07-24 16:45:43 +02:00
tool_capabilities = {},
2016-07-24 19:05:11 +02:00
range = 10,
2016-07-24 16:45:43 +02:00
groups = { not_in_creative_inventory = 1 },
wield_image = "doc_identifier_identifier_liquid.png",
inventory_image = "doc_identifier_identifier_liquid.png",
liquids_pointable = true,
2016-07-24 18:27:15 +02:00
on_use = doc_identifier.identify,
on_place = doc_identifier.solid_mode,
on_secondary_use = doc_identifier.solid_mode,
2016-07-24 16:45:43 +02:00
})
2016-08-01 23:53:48 +02:00
minetest.register_craft({
output = "doc_identifier:identifier_solid",
recipe = { {"group:stick", "group:stick" },
{"", "group:stick"},
{"group:stick", ""} }
})
2016-08-04 18:24:46 +02:00
if minetest.get_modpath("default") ~= nil then
minetest.register_craft({
output = "doc_identifier:identifier_solid",
recipe = { { "default:glass" },
{ "group:stick" } }
})
end
2016-08-01 23:53:48 +02:00
2016-07-24 16:45:43 +02:00
minetest.register_alias("doc_identifier:identifier", "doc_identifier:identifier_solid")
2016-07-24 17:57:44 +02:00
-- Add documentation
2016-08-03 15:34:43 +02:00
doc.sub.items.set_items_longdesc(
2016-08-04 22:53:06 +02:00
{ ["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 dropped items and it shows extensive information about the item on which it is used." })
2016-08-03 15:34:43 +02:00
doc.sub.items.set_items_usagehelp(
2016-08-04 22:53:06 +02:00
{ ["doc_identifier:identifier_solid"] = "Punch any block or item about you wish to learn more about. This will open up the Documentation System entry of this particular item. The tool comes in two modes which are changed by a rightclick. In liquid mode (blue) this tool points to liquids as well while in solid mode (red) this is not the case. Liquid mode is required if you want to identify a liquid." })