]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/client/util.lua
Re-Added Chat Effects
[dragonfireclient.git] / builtin / client / util.lua
index 8956092885de844485a37a75968196134d450a65..783d0ceb1334266d9565589e84737440909c9402 100644 (file)
@@ -20,3 +20,33 @@ function core.parse_relative_pos(param)
        if success then pos = vector.round(vector.add(core.localplayer:get_pos(), pos)) end
        return success, pos
 end 
+
+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