2022-09-18 16:30:53 +02:00
|
|
|
local wea_c = worldeditadditions_core
|
2024-10-10 05:35:45 +02:00
|
|
|
local wea_t = worldeditadditions_tools
|
2022-09-18 16:30:53 +02:00
|
|
|
local wea = worldeditadditions
|
2022-09-19 18:33:02 +02:00
|
|
|
local Vector3 = wea_c.Vector3
|
2022-09-18 16:30:53 +02:00
|
|
|
|
|
|
|
local function push_pos(player_name, pos)
|
|
|
|
if player_name == nil then return end
|
|
|
|
if pos == nil then
|
|
|
|
worldedit.player_notify(player_name, "[multi wand] Error: Too far away (try raising your maxdist with //farwand maxdist <number>)")
|
|
|
|
else
|
2022-09-18 17:21:36 +02:00
|
|
|
pos = Vector3.clone(pos)
|
2022-09-18 16:30:53 +02:00
|
|
|
wea_c.pos.push(player_name, pos)
|
|
|
|
worldedit.player_notify(player_name, "[multi wand] Added "..pos..". "..wea_c.pos.count(player_name).." points now registered.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function pop_pos(player_name)
|
|
|
|
if player_name == nil then return end
|
|
|
|
local count_before = wea_c.pos.count(player_name)
|
|
|
|
wea_c.pos.pop(player_name)
|
|
|
|
local count_after = wea_c.pos.count(player_name)
|
|
|
|
if count_before > 0 then
|
|
|
|
worldedit.player_notify(player_name, "[multi wand] "..count_before.." -> "..count_after.." points registered")
|
|
|
|
else
|
|
|
|
worldedit.player_notify(player_name, "[multi wand] No points registered")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-10-10 05:35:45 +02:00
|
|
|
wea_t.register_tool("multiwand", {
|
2022-09-18 16:30:53 +02:00
|
|
|
description = "WorldEditAdditions multi-point wand",
|
|
|
|
inventory_image = "worldeditadditions_multiwand.png",
|
|
|
|
|
|
|
|
on_place = function(itemstack, player, pointed_thing)
|
|
|
|
-- Right click when pointing at something
|
|
|
|
-- Pointed thing: https://rubenwardy.com/minetest_modding_book/lua_api.html#pointed_thing
|
2022-09-25 02:43:30 +02:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
-- print("[farwand] on_place", player_name)
|
|
|
|
pop_pos(player_name)
|
2022-09-18 16:30:53 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_use = function(itemstack, player, pointed_thing)
|
|
|
|
-- Left click when pointing at something or nothing
|
2022-09-25 02:43:30 +02:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
-- print("[farwand] on_use", player_name)
|
2024-10-11 01:12:11 +02:00
|
|
|
local looking_pos, node_id = wea_t.do_raycast(player)
|
2022-09-25 02:43:30 +02:00
|
|
|
push_pos(player_name, looking_pos)
|
2022-09-18 16:30:53 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_secondary_use = function(itemstack, player, pointed_thing)
|
|
|
|
-- Right click when pointing at nothing
|
2022-09-25 02:43:30 +02:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
-- print("[farwand] on_secondary_use", player_name)
|
|
|
|
pop_pos(player_name)
|
2022-09-18 16:30:53 +02:00
|
|
|
end
|
|
|
|
})
|