2020-06-13 15:23:14 +02:00
|
|
|
local function set_pos1(name, pos)
|
|
|
|
if pos ~= nil then
|
2020-06-15 14:04:42 +02:00
|
|
|
-- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")")
|
2020-06-13 15:23:14 +02:00
|
|
|
worldedit.pos1[name] = pos
|
|
|
|
worldedit.mark_pos1(name)
|
2022-09-19 18:33:02 +02:00
|
|
|
worldedit.player_notify(name, "pos1 set to "..pos) -- pos is a Vector3
|
2020-06-13 15:23:14 +02:00
|
|
|
else
|
2021-02-24 00:10:45 +01:00
|
|
|
worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist <number>)")
|
2020-06-15 14:04:42 +02:00
|
|
|
-- print("[set_pos1]", name, "nil")
|
2020-06-13 15:23:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local function set_pos2(name, pos)
|
|
|
|
if pos ~= nil then
|
2020-06-15 14:04:42 +02:00
|
|
|
-- print("[set_pos2]", name, "("..pos.x..", "..pos.y..", "..pos.z..")")
|
2020-06-13 15:23:14 +02:00
|
|
|
worldedit.pos2[name] = pos
|
|
|
|
worldedit.mark_pos2(name)
|
2022-09-19 18:33:02 +02:00
|
|
|
worldedit.player_notify(name, "pos2 set to "..pos)
|
2020-06-13 15:23:14 +02:00
|
|
|
else
|
2021-02-24 00:10:45 +01:00
|
|
|
worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist <number>)")
|
2020-06-15 14:04:42 +02:00
|
|
|
-- print("[set_pos2]", name, "nil")
|
2020-06-13 15:23:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-13 03:08:03 +02:00
|
|
|
minetest.register_tool(":worldeditadditions:farwand", {
|
|
|
|
description = "WorldEditAdditions far-reaching wand",
|
|
|
|
inventory_image = "worldeditadditions_farwand.png",
|
|
|
|
|
|
|
|
on_place = function(itemstack, player, pointed_thing)
|
2020-06-13 15:23:14 +02:00
|
|
|
local name = player:get_player_name()
|
2020-06-15 14:04:42 +02:00
|
|
|
-- print("[farwand] on_place", name)
|
2020-06-13 03:08:03 +02:00
|
|
|
-- Right click when pointing at something
|
2020-06-13 15:23:14 +02:00
|
|
|
-- Pointed thing: https://rubenwardy.com/minetest_modding_book/lua_api.html#pointed_thing
|
2022-09-19 18:27:59 +02:00
|
|
|
local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
|
2020-06-13 15:23:14 +02:00
|
|
|
set_pos2(name, looking_pos)
|
2020-06-13 03:08:03 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_use = function(itemstack, player, pointed_thing)
|
2020-06-13 15:23:14 +02:00
|
|
|
local name = player:get_player_name()
|
2020-06-15 14:04:42 +02:00
|
|
|
-- print("[farwand] on_use", name)
|
2022-09-19 18:27:59 +02:00
|
|
|
local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
|
2020-06-13 15:23:14 +02:00
|
|
|
set_pos1(name, looking_pos)
|
2020-06-13 03:08:03 +02:00
|
|
|
-- Left click when pointing at something or nothing
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_secondary_use = function(itemstack, player, pointed_thing)
|
2020-06-13 15:23:14 +02:00
|
|
|
local name = player:get_player_name()
|
2020-06-13 03:08:03 +02:00
|
|
|
-- Right click when pointing at nothing
|
2020-06-15 14:04:42 +02:00
|
|
|
-- print("[farwand] on_secondary_use", name)
|
2020-06-13 03:08:03 +02:00
|
|
|
|
2022-09-19 18:27:59 +02:00
|
|
|
local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
|
2020-06-13 15:23:14 +02:00
|
|
|
set_pos2(name, looking_pos)
|
2020-06-13 03:08:03 +02:00
|
|
|
end
|
|
|
|
})
|