]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/client/util.lua
Remove NextItem
[dragonfireclient.git] / builtin / client / util.lua
index 595922262641cfd1c754f2c413bdc4f38747e09a..42e383c5c66e588123bdfd084c80405f59494a18 100644 (file)
@@ -1,23 +1,56 @@
 function core.parse_pos(param)
        local p = {}
+       local playerpos = core.localplayer:get_pos()
        p.x, p.y, p.z = string.match(param, "^([~|%d.-]+)[, ] *([~|%d.-]+)[, ] *([~|%d.-]+)$")
        for k, v in pairs(p) do
                if p[k] == "~" then
-                       p[k] = 0
+                       p[k] = playerpos[k]
                else
                        p[k] = tonumber(v)
                end
        end
        if p.x and p.y and p.z then
-               return true, p
+               return true, vector.round(p)
        end
        return false, "Invalid position (" .. param .. ")"
 end 
 
 function core.parse_relative_pos(param)
-       local success, pos = core.parse_pos(param)
+       local success, pos = core.parse_pos(param:gsub("~", "0"))
        if success then pos = vector.round(vector.add(core.localplayer:get_pos(), pos)) end
        return success, pos
 end 
 
-core.anticheat_protection = minetest.settings:get_bool("anticheat_protection")
+function core.find_item(item, mini, maxi)
+       for index, stack in ipairs(core.get_inventory("current_player").main) do
+               if (not mini or index >= mini) and (not maxi or index <= maxi) and stack:get_name() == item then
+                       return index
+               end
+       end
+end
+
+function core.switch_to_item(item)
+       local i = core.find_item(item)
+       if i then
+               core.localplayer:set_wield_index(i)
+               return true
+       else
+               return false
+       end
+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 player = core.localplayer
+       if not player then return end
+       local item = player:get_wielded_item()
+       if not item then return end
+       local def = core.get_item_def(item:get_name())
+       local ray = core.raycast(pos, pos2, true, core.settings:get_bool("point_liquids") or def and def.liquids_pointable)
+       return ray and ray:next()
+end
+
+function core.close_formspec(formname)
+       return core.show_formspec(formname, "")
+end