1 function core.parse_pos(param)
3 local playerpos = core.localplayer:get_pos()
4 p.x, p.y, p.z = string.match(param, "^([~|%d.-]+)[, ] *([~|%d.-]+)[, ] *([~|%d.-]+)$")
5 for k, v in pairs(p) do
12 if p.x and p.y and p.z then
13 return true, vector.round(p)
15 return false, "Invalid position (" .. param .. ")"
18 function core.parse_relative_pos(param)
19 local success, pos = core.parse_pos(param:gsub("~", "0"))
20 if success then pos = vector.round(vector.add(core.localplayer:get_pos(), pos)) end
24 function core.find_item(item, mini, maxi)
25 for index, stack in ipairs(core.get_inventory("current_player").main) do
26 if (not mini or index >= mini) and (not maxi or index <= maxi) and stack:get_name() == item then
32 function core.switch_to_item(item)
33 local i = core.find_item(item)
35 core.localplayer:set_wield_index(i)
42 function core.get_pointed_thing()
43 local pos = core.camera:get_pos()
44 local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 7))
45 local player = core.localplayer
46 if not player then return end
47 local item = player:get_wielded_item()
48 if not item then return end
49 local def = core.get_item_def(item:get_name())
50 local ray = core.raycast(pos, pos2, true, core.settings:get_bool("point_liquids") or def and def.liquids_pointable)
51 return ray and ray:next()
54 function core.close_formspec(formname)
55 return core.show_formspec(formname, "")