aboutsummaryrefslogtreecommitdiff
path: root/init.lua
blob: b5202b0b9377fd20b969fb7d2d431b73031dab78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local channel = minetest.mod_channel_join("randomblocks")

local last_pos

local function get_pointed_thing()
	local pos = minetest.camera:get_pos()
	local pos2 = vector.add(pos, vector.multiply(minetest.camera:get_look_dir(), 100))
	local ray = minetest.raycast(pos, pos2, true, true)
	return ray:next()
end

minetest.register_globalstep(function()
	local pointed_thing = get_pointed_thing()
	if not pointed_thing or pointed_thing.type ~= "node" then return end
	local pos = pointed_thing.under
	if last_pos and not vector.equals(pos, last_pos) then
		channel:send_all(minetest.pos_to_string(last_pos))
	end
	last_pos = pos
end)