pos1-2 better implementation (used round)

This commit is contained in:
VorTechnix 2023-07-12 09:18:15 -07:00
parent d2fb6db3d0
commit 7766af8a8a
1 changed files with 62 additions and 63 deletions

View File

@ -1,64 +1,63 @@
local weac = worldeditadditions_core local weac = worldeditadditions_core
local Vector3 = weac.Vector3 local Vector3 = weac.Vector3
local function do_set(name, i) local function do_set(name, i)
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
local addend = Vector3.new(0,1,0) -- Add one on the y axis weac.pos.set(name, i, Vector3.round(player:get_pos()))
weac.pos.set(name, i, Vector3.floor(player:get_pos()) + addend) end
end
local function do_set1(name, params_text)
local function do_set1(name, params_text) do_set(name, 1)
do_set(name, 1) end
end local function do_set2(name, params_text)
local function do_set2(name, params_text) do_set(name, 2)
do_set(name, 2) end
end
if minetest.registered_chatcommands["/pos1"] then
if minetest.registered_chatcommands["/pos1"] then minetest.override_chatcommand("/pos1", {
minetest.override_chatcommand("/pos1", { params = "",
params = "", description =
description = "Sets pos1 to the current position of the calling player.",
"Sets pos1 to the current position of the calling player.", func = do_set1
func = do_set1 })
}) else
else minetest.register_chatcommand("/pos1", {
minetest.register_chatcommand("/pos1", { params = "",
params = "", description =
description = "Sets pos1 to the current position of the calling player.",
"Sets pos1 to the current position of the calling player.", privs = { worldedit = true },
privs = { worldedit = true }, func = do_set1
func = do_set1 })
}) end
end if minetest.registered_chatcommands["/pos2"] then
if minetest.registered_chatcommands["/pos2"] then minetest.override_chatcommand("/pos2", {
minetest.override_chatcommand("/pos2", { params = "",
params = "", description = "Sets pos2 to the current position of the calling player.",
description = "Sets pos2 to the current position of the calling player.", func = do_set2
func = do_set2 })
}) else
else minetest.register_chatcommand("/pos2", {
minetest.register_chatcommand("/pos2", { params = "",
params = "", description = "Sets pos2 to the current position of the calling player.",
description = "Sets pos2 to the current position of the calling player.", privs = { worldedit = true },
privs = { worldedit = true }, func = do_set2
func = do_set2 })
}) end
end
minetest.register_chatcommand("//pos", {
minetest.register_chatcommand("//pos", { params = "<index>",
params = "<index>", description = "Sets position <index> to the current position of the calling player.",
description = "Sets position <index> to the current position of the calling player.", privs = { worldedit = true },
privs = { worldedit = true }, func = function(name, params_text)
func = function(name, params_text) local i = tonumber(params_text)
local i = tonumber(params_text) if type(i) ~= "number" then
if type(i) ~= "number" then worldedit.player_notify(name, "Error: Invalid index number given.")
worldedit.player_notify(name, "Error: Invalid index number given.") return
return end
end i = math.floor(i)
i = math.floor(i)
do_set(name, i)
do_set(name, i) end
end
}) })