2020-07-06 15:50:55 +02:00
|
|
|
function core.parse_pos(param)
|
|
|
|
local p = {}
|
2020-07-18 20:01:17 +02:00
|
|
|
local playerpos = core.localplayer:get_pos()
|
2020-07-06 15:50:55 +02:00
|
|
|
p.x, p.y, p.z = string.match(param, "^([~|%d.-]+)[, ] *([~|%d.-]+)[, ] *([~|%d.-]+)$")
|
|
|
|
for k, v in pairs(p) do
|
|
|
|
if p[k] == "~" then
|
2020-07-18 20:01:17 +02:00
|
|
|
p[k] = playerpos[k]
|
2020-07-06 15:50:55 +02:00
|
|
|
else
|
|
|
|
p[k] = tonumber(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if p.x and p.y and p.z then
|
2020-07-18 20:01:17 +02:00
|
|
|
return true, vector.round(p)
|
2020-07-06 15:50:55 +02:00
|
|
|
end
|
|
|
|
return false, "Invalid position (" .. param .. ")"
|
|
|
|
end
|
2020-07-18 13:20:08 +02:00
|
|
|
|
|
|
|
function core.parse_relative_pos(param)
|
2020-07-18 20:01:17 +02:00
|
|
|
local success, pos = core.parse_pos(param:gsub("~", "0"))
|
2020-07-18 13:20:08 +02:00
|
|
|
if success then pos = vector.round(vector.add(core.localplayer:get_pos(), pos)) end
|
|
|
|
return success, pos
|
|
|
|
end
|
2020-10-18 16:18:07 +02:00
|
|
|
|
|
|
|
function core.switch_to_item(item)
|
|
|
|
for index, stack in ipairs(core.get_inventory("current_player").main) do
|
|
|
|
if stack:get_name() == item then
|
|
|
|
core.localplayer:set_wield_index(index - 1)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function core.get_pointed_thing()
|
|
|
|
local pos = core.camera:get_pos()
|
|
|
|
local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 5))
|
|
|
|
local ray = core.raycast(pos, pos2, true, true)
|
|
|
|
|
|
|
|
return ray:next()
|
|
|
|
end
|