implement multi-point wand

This commit is contained in:
Starbeamrainbowlabs 2022-09-18 15:30:53 +01:00
parent 9932852053
commit fa62864e16
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
4 changed files with 76 additions and 4 deletions

@ -4,6 +4,9 @@ local positions_count_limit = 999
local positions = {}
local function ensure_player(player_name)
if player_name == nil then
minetest.log("error", "[wea core:pos:ensure_player] player_name is nil")
end
if not positions[player_name] then
positions[player_name] = {}
end
@ -26,7 +29,7 @@ local function get_pos_all(player_name)
end
local function pos_count(player_name)
ensure_player(player_name)
return #pos_count[player_name]
return #positions[player_name]
end
local function set_pos(player_name, i, pos)
@ -44,14 +47,25 @@ local function clear(player_name)
positions[player_name] = nil
end
end
local function pop_pos(player_name)
ensure_player(player_name)
if #positions[player_name] <= 0 then return nil end
return table.remove(positions[player_name])
end
local function push_pos(player_name, pos)
ensure_player(player_name)
table.insert(positions[player_name], pos)
end
return {
get = get_pos,
get1 = get_pos1,
get2 = get_pos2,
get_all = get_pos_all,
count = pos_count,
clear = clear,
pop = pop_pos,
push = push_pos,
set = set_pos,
set_all = set_pos_all,
count = pos_count,
clear = clear
}
}

@ -28,6 +28,7 @@ wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua")
wea_c.register_alias = dofile(modpath.."/core/register_alias.lua")
wea_c.pos = dofile(modpath.."/core/pos.lua")
print("WEA_C pos", wea_c.pos.push)
-- Initialise WorldEdit stuff if the WorldEdit mod is not present
if minetest.global_exists("worldedit") then

@ -7,5 +7,6 @@ local modpath = minetest.get_modpath("worldeditadditions_farwand")
dofile(modpath.."/lib/do_raycast.lua")
dofile(modpath.."/lib/farwand.lua")
dofile(modpath.."/lib/cloudwand.lua")
dofile(modpath.."/lib/multiwand.lua")
dofile(modpath.."/lib/chatcommand.lua")
dofile(modpath.."/lib/settings.lua")

@ -0,0 +1,56 @@
local wea_c = worldeditadditions_core
local wea = worldeditadditions
local Vector3 = wea.Vector3
local function push_pos(player_name, pos)
pos = Vector3.clone(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
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
minetest.register_tool(":worldeditadditions:multiwand", {
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
-- print("[farwand] on_place", name)
local name = player:get_player_name()
pop_pos(name)
end,
on_use = function(itemstack, player, pointed_thing)
-- Left click when pointing at something or nothing
local name = player:get_player_name()
-- print("[farwand] on_use", name)
local looking_pos, node_id = wea.farwand.do_raycast(player)
push_pos(name, looking_pos)
end,
on_secondary_use = function(itemstack, player, pointed_thing)
-- Right click when pointing at nothing
-- print("[farwand] on_secondary_use", name)
local name = player:get_player_name()
-- local looking_pos, node_id = do_raycast(player)
pop_pos(name)
end
})