Update alternode mod to Git commit e167e42...
https://github.com/AntumMT/mod-alternode/tree/e167e42
This commit is contained in:
parent
5bd5c65f89
commit
aa6cb2fbbd
@ -12,7 +12,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
|
||||
***"UPDATES" Denotes updates available***
|
||||
|
||||
* admin/
|
||||
* [alternode][] ([MIT][lic.alternode]) -- version: [990b6bb Git][ver.alternode] *2021-05-17*
|
||||
* [alternode][] ([MIT][lic.alternode]) -- version: [e167e42 Git][ver.alternode] *2021-05-17*
|
||||
* [cleaner][] ([CC0][lic.cc0]) -- version: [0.4 (68222b1 Git)][ver.cleaner] *2017-08-30*
|
||||
* [invisible][] ([LGPL][lic.lgpl2.1] / [CC BY-SA][lic.ccbysa4.0]) -- version: [4 (a2a6504 Git)][ver.invisible]
|
||||
* [no_fall_damage][] ([MIT][lic.no_fall_damage]) -- version [1.0.0][ver.no_fall_damage] *2020-12-19*
|
||||
@ -451,7 +451,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
|
||||
|
||||
[ver.3d_armor]: https://github.com/minetest-mods/3d_armor/tree/f07f050
|
||||
[ver.airtanks]: https://github.com/minetest-mods/airtanks/tree/b686694
|
||||
[ver.alternode]: https://github.com/AntumMT/mod-alternode/tree/990b6bb
|
||||
[ver.alternode]: https://github.com/AntumMT/mod-alternode/tree/e167e42
|
||||
[ver.amber]: https://github.com/theraven262/amber/tree/56627fa
|
||||
[ver.ambience]: https://notabug.org/TenPlus1/ambience/src/e317f727d00d5c034226c0e7217ed0559c208038
|
||||
[ver.animals_aggressive]: https://github.com/AntumMT/mp-animals_aggressive/tree/4eede4d
|
||||
|
@ -1,4 +1,4 @@
|
||||
MIT License
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright © 2021 Jordan Irwin (AntumDeluge)
|
||||
|
||||
|
@ -21,6 +21,9 @@ A [Minetest](http://minetest.net/) mod that allows administrators with *server*
|
||||
|
||||
Invoke `/giveme alternode:infostick`. Use the infostick on a node to receive node coordinates, name, & some select meta info.
|
||||
|
||||
- *left-click (use):* Opens formspec to retrieve & set/unset meta attributes.
|
||||
- *right-click (place):* Print node coordinates, name, & some select meta info.
|
||||
|
||||
**Pencil:**
|
||||
|
||||
The `alternode:pencil` is a tool for players to set/unset the `infotext` meta value of nodes within protected/owned areas.
|
||||
|
@ -1,7 +1,4 @@
|
||||
|
||||
TODO:
|
||||
- specify that "pos" & "name" are NOT meta data when using infostick
|
||||
- create formspec for setting meta with GUI
|
||||
- add HTML docs
|
||||
- add fields in formspec for get, set, & unset meta data
|
||||
- clean up code
|
||||
|
@ -1,29 +1,153 @@
|
||||
|
||||
local S = core.get_translator(alternode.modname)
|
||||
|
||||
local misc = dofile(alternode.modpath .. "/misc_functions.lua")
|
||||
|
||||
function alternode.show_formspec(pos, node, player)
|
||||
|
||||
--- Formspec definitions.
|
||||
--
|
||||
-- @section fs_def
|
||||
|
||||
|
||||
--- Retrieves formspec layout for `alternode:infostick` item.
|
||||
--
|
||||
-- TODO: add fields for get, set, & unset meta data
|
||||
--
|
||||
-- @function alternode.get_infostick_formspec
|
||||
-- @param pos
|
||||
-- @param node
|
||||
-- @param player
|
||||
-- @treturn string Formspec formatted string.
|
||||
function alternode.get_infostick_formspec(pos, node, player, key, msg)
|
||||
local nmeta = core.get_meta(pos)
|
||||
local infostring = S("pos: x@=@1, y@=@2, z@=@3; name@=@4",
|
||||
local infostring = S("Pos: x@=@1, y@=@2, z@=@3; Name: @4; Select meta info:",
|
||||
tostring(pos.x), tostring(pos.y), tostring(pos.z), node.name)
|
||||
|
||||
-- some commonly used meta keys
|
||||
for _, key in ipairs({"id", "infotext", "owner"}) do
|
||||
local value = nmeta:get_string(key)
|
||||
if value and value ~= "" then
|
||||
infostring = infostring .. "; "
|
||||
.. key .. "=" .. value
|
||||
end
|
||||
end
|
||||
|
||||
-- linebreaks are added here so we can keep translator string same as on on_use method
|
||||
infostring = infostring:gsub("; ", "\n")
|
||||
|
||||
-- some commonly used meta keys
|
||||
-- FIXME: why is this being trimmed from formspec?
|
||||
infostring = infostring .. misc.format_meta_values(nmeta, {"id", "infotext", "owner"})
|
||||
|
||||
local value = ""
|
||||
if key then
|
||||
value = nmeta:get_string(key)
|
||||
else
|
||||
key = ""
|
||||
end
|
||||
|
||||
local formspec = "formspec_version[4]"
|
||||
.. "size[16,10]"
|
||||
.. "size[10.65,8]"
|
||||
.. "label[0.15,0.25;" .. core.formspec_escape(infostring) .. "]"
|
||||
.. "field[0.15,3.375;3,0.75;input_key;" .. S("Key:") .. ";" .. key .. "]"
|
||||
.. "field_close_on_enter[input_key;false]"
|
||||
.. "textarea[3.3,3;3,1.5;input_value;" .. S("Value:") .. ";" .. value .. "]"
|
||||
.. "button[6.45,3.375;1.25,0.75;btn_get;" .. S("Get") .. "]"
|
||||
.. "button[7.85,3.375;1.25,0.75;btn_set;" .. S("Set") .. "]"
|
||||
.. "button[9.25,3.375;1.25,0.75;btn_unset;" .. S("Unset") .. "]"
|
||||
|
||||
-- TODO: add fields for get, set, & unset meta data
|
||||
if msg then
|
||||
formspec = formspec
|
||||
.. "label[0.15,5.5;" .. msg .. "]"
|
||||
end
|
||||
|
||||
core.show_formspec(player:get_player_name(), alternode.modname .. ":meta", formspec)
|
||||
return formspec
|
||||
end
|
||||
|
||||
--- Retrieves formspec layout for `alternode:pencil` item.
|
||||
--
|
||||
-- @function alternode.get_pencil_formspec
|
||||
-- @param pos
|
||||
-- @treturn string Formspec formatted string.
|
||||
function alternode.get_pencil_formspec(pos)
|
||||
local infotext = core.get_meta(pos):get_string("infotext")
|
||||
local formspec = "formspec_version[4]"
|
||||
.. "size[6,4]"
|
||||
.. "textarea[1,1;4,1.5;input;" .. S("Infotext") .. ";" .. infotext .. "]"
|
||||
.. "button_exit[1.5,2.75;1.25,0.75;btn_write;" .. S("Write") .. "]"
|
||||
.. "button_exit[3.3,2.75;1.25,0.75;btn_erase;" .. S("Erase") .. "]"
|
||||
|
||||
return formspec
|
||||
end
|
||||
|
||||
|
||||
--- Formspec event handling.
|
||||
--
|
||||
-- @section fs_event
|
||||
|
||||
|
||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == alternode.modname .. ":infostick" then
|
||||
local pmeta = player:get_meta()
|
||||
|
||||
if fields.quit then
|
||||
-- clear position info from player meta
|
||||
pmeta:set_string(alternode.modname .. ":pos", nil)
|
||||
return
|
||||
end
|
||||
|
||||
if not fields.input_key then
|
||||
alternode.log("error", "could not retrieve key input field")
|
||||
return
|
||||
elseif not fields.input_value then
|
||||
alternode.log("error", "could not retrieve value input field")
|
||||
return
|
||||
end
|
||||
|
||||
-- FIXME: how to get node & node meta without storing in player meta?
|
||||
local node = core.deserialize(pmeta:get_string(alternode.modname .. ":node"))
|
||||
local pos = core.deserialize(pmeta:get_string(alternode.modname .. ":pos"))
|
||||
local nmeta = core.get_meta(pos)
|
||||
|
||||
if not node then
|
||||
alternode.log("error", "could not retrieve node")
|
||||
return
|
||||
end
|
||||
if not nmeta then
|
||||
alternode.log("error", "could not retrieve node meta")
|
||||
return
|
||||
end
|
||||
|
||||
local msg = nil
|
||||
if fields.input_key:trim() == "" then
|
||||
msg = S("Key cannot be empty")
|
||||
elseif fields.btn_set then
|
||||
local new_value = fields.input_value:trim()
|
||||
if new_value == "" then
|
||||
msg = S("Value cannot be empty")
|
||||
else
|
||||
nmeta:set_string(fields.input_key, new_value)
|
||||
msg = S('Key "@1" has been set to "@2"', fields.input_key, new_value)
|
||||
end
|
||||
elseif fields.btn_unset then
|
||||
nmeta:set_string(fields.input_key, nil)
|
||||
msg = S('Key "@1" has been unset', fields.input_key)
|
||||
elseif nmeta:get_string(fields.input_key) == "" then
|
||||
msg = S('Key "@1" is not set', fields.input_key)
|
||||
end
|
||||
|
||||
core.show_formspec(player:get_player_name(), alternode.modname .. ":infostick",
|
||||
alternode.get_infostick_formspec(pos, node, player, fields.input_key, msg))
|
||||
elseif formname == alternode.modname .. ":pencil" then
|
||||
if not fields.quit then
|
||||
-- FIXME: how to get node meta without storing in player meta?
|
||||
local pmeta = player:get_meta()
|
||||
local pos = core.deserialize(pmeta:get_string(alternode.modname .. ":pos"))
|
||||
local nmeta = core.get_meta(pos)
|
||||
|
||||
if fields.btn_write then
|
||||
if fields.input:trim() == "" then
|
||||
nmeta:set_string("infotext", nil)
|
||||
else
|
||||
nmeta:set_string("infotext", fields.input)
|
||||
end
|
||||
elseif fields.btn_erase then
|
||||
nmeta:set_string("infotext", nil)
|
||||
end
|
||||
end
|
||||
|
||||
-- clear position info from player meta
|
||||
pmeta:set_string(alternode.modname .. ":pos", nil)
|
||||
end
|
||||
end)
|
||||
|
@ -3,6 +3,11 @@ alternode = {}
|
||||
alternode.modname = core.get_current_modname()
|
||||
alternode.modpath = core.get_modpath(alternode.modname)
|
||||
|
||||
function alternode.log(lvl, msg)
|
||||
core.log(lvl, "[" .. alternode.modname .. "] " .. msg)
|
||||
end
|
||||
|
||||
|
||||
local scripts = {
|
||||
"api",
|
||||
"commands",
|
||||
|
@ -22,8 +22,17 @@ Info Stick=
|
||||
You do not have privileges to use this item (missing priviliges: @1)=
|
||||
This item only works on nodes=
|
||||
Tool for retrieving information about a node=
|
||||
That doesn't seem to be a proper node=
|
||||
pos: x@=@1, y@=@2, z@=@3; name@=@4=
|
||||
Pos: x@=@1, y@=@2, z@=@3; Name: @4; Select meta info:=
|
||||
Key:=
|
||||
Value:=
|
||||
Get=
|
||||
Set=
|
||||
Unset=
|
||||
Key "@1" has been unset=
|
||||
Key "@1" has been set to "@2"=
|
||||
Key cannot be empty=
|
||||
Value cannot be empty=
|
||||
Key "@1" is not set=
|
||||
|
||||
Pencil=
|
||||
Tool for editing node infotext=
|
||||
|
23
mods/admin/alternode/misc_functions.lua
Normal file
23
mods/admin/alternode/misc_functions.lua
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
local function format_meta_values(meta, keys)
|
||||
local meta_values = ""
|
||||
for _, key in ipairs(keys) do
|
||||
local value = meta:get_string(key)
|
||||
if value ~= "" then
|
||||
if meta_values == "" then
|
||||
meta_values = meta_values .. " "
|
||||
else
|
||||
meta_values = meta_values .. ", "
|
||||
end
|
||||
|
||||
meta_values = meta_values .. key .. "=" .. value
|
||||
end
|
||||
end
|
||||
|
||||
return meta_values
|
||||
end
|
||||
|
||||
|
||||
return {
|
||||
format_meta_values = format_meta_values,
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
local S = core.get_translator(alternode.modname)
|
||||
|
||||
local use_s_protect = core.global_exists("s_protect")
|
||||
local misc = dofile(alternode.modpath .. "/misc_functions.lua")
|
||||
|
||||
|
||||
local function check_permissions(player)
|
||||
@ -30,12 +31,31 @@ local function is_area_owner(pos, pname)
|
||||
return false
|
||||
end
|
||||
|
||||
local function check_node_pos(target)
|
||||
if target.type ~= "node" then return end
|
||||
local pos = core.get_pointed_thing_position(target, false)
|
||||
if not core.get_node_or_nil(pos) then return end
|
||||
--- Checks if a thing pointed at is a node.
|
||||
--
|
||||
-- @local
|
||||
-- @function check_node
|
||||
-- @param target pointed_thing
|
||||
-- @param pname Name of player pointing.
|
||||
-- @return `pos`, `node` if the pointed_thing is a node, `nil` otherwise.
|
||||
local function check_node(target, pname)
|
||||
if not target then return false end
|
||||
|
||||
return pos
|
||||
local pos = nil
|
||||
local node = nil
|
||||
if target.type == "node" then
|
||||
pos = core.get_pointed_thing_position(target, false)
|
||||
node = core.get_node_or_nil(pos)
|
||||
if not node then
|
||||
pos = nil
|
||||
end
|
||||
end
|
||||
|
||||
if not pos then
|
||||
core.chat_send_player(pname, S("This item only works on nodes"))
|
||||
end
|
||||
|
||||
return pos, node
|
||||
end
|
||||
|
||||
|
||||
@ -54,52 +74,33 @@ core.register_craftitem(alternode.modname .. ":infostick", {
|
||||
if not check_permissions(user) then return end
|
||||
|
||||
local pname = user:get_player_name()
|
||||
local pos, node = check_node(pointed_thing, pname)
|
||||
if not pos then return end
|
||||
|
||||
if pointed_thing.type ~= "node" then
|
||||
core.chat_send_player(pname, S("This item only works on nodes"))
|
||||
return
|
||||
end
|
||||
-- store pos info for retrieval in callbacks
|
||||
local pmeta = user:get_meta()
|
||||
pmeta:set_string(alternode.modname .. ":pos", core.serialize(pos))
|
||||
pmeta:set_string(alternode.modname .. ":node", core.serialize(node))
|
||||
|
||||
local pos = core.get_pointed_thing_position(pointed_thing, false)
|
||||
local node = core.get_node_or_nil(pos)
|
||||
if not node then
|
||||
core.chat_send_player(pname, S("That doesn't seem to be a proper node"))
|
||||
return
|
||||
end
|
||||
local meta = core.get_meta(pos)
|
||||
|
||||
local infostring = S("pos: x@=@1, y@=@2, z@=@3; name@=@4",
|
||||
tostring(pos.x), tostring(pos.y), tostring(pos.z), node.name)
|
||||
|
||||
for _, key in ipairs({"id", "infotext", "owner"}) do
|
||||
local value = meta:get_string(key)
|
||||
if value and value ~= "" then
|
||||
infostring = infostring .. "; "
|
||||
.. key .. "=" .. value
|
||||
end
|
||||
end
|
||||
|
||||
core.chat_send_player(pname, infostring)
|
||||
core.show_formspec(pname, alternode.modname .. ":infostick",
|
||||
alternode.get_infostick_formspec(pos, node, user))
|
||||
end,
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if not placer:is_player() then return end
|
||||
if not check_permissions(placer) then return end
|
||||
|
||||
local pname = user:get_player_name()
|
||||
local pname = placer:get_player_name()
|
||||
local pos, node = check_node(pointed_thing, pname)
|
||||
if not pos then return end
|
||||
|
||||
if pointed_thing.type ~= "node" then
|
||||
core.chat_send_player(pname, S("This item only works on nodes"))
|
||||
return
|
||||
end
|
||||
local nmeta = core.get_meta(pos)
|
||||
|
||||
local pos = core.get_pointed_thing_position(pointed_thing, false)
|
||||
local node = core.get_node_or_nil(pos)
|
||||
if not node then
|
||||
core.chat_send_player(pname, S("That doesn't seem to be a proper node"))
|
||||
return
|
||||
end
|
||||
local infostring = S("Pos: x@=@1, y@=@2, z@=@3; Name: @4; Select meta info:",
|
||||
tostring(pos.x), tostring(pos.y), tostring(pos.z), node.name)
|
||||
-- some commonly used meta keys
|
||||
infostring = infostring .. misc.format_meta_values(nmeta, {"id", "infotext", "owner"})
|
||||
|
||||
alternode.show_formspec(pos, node, placer)
|
||||
core.chat_send_player(pname, infostring)
|
||||
end,
|
||||
})
|
||||
|
||||
@ -116,57 +117,24 @@ core.register_craftitem(alternode.modname .. ":pencil", {
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if not user:is_player() then return end
|
||||
local pos = check_node_pos(pointed_thing)
|
||||
if not pos then return end
|
||||
|
||||
local pname = user:get_player_name()
|
||||
|
||||
if pointed_thing.type ~= "node" then
|
||||
core.chat_send_player(pname, S("This item only works on nodes"))
|
||||
return
|
||||
end
|
||||
local pos = check_node(pointed_thing, pname)
|
||||
if not pos then return end
|
||||
|
||||
if not is_area_owner(pos, pname) then
|
||||
core.chat_send_player(pname, S("You cannot alter nodes in areas you do not own"))
|
||||
return
|
||||
end
|
||||
|
||||
local infotext = core.get_meta(pos):get_string("infotext")
|
||||
local formspec = "formspec_version[4]"
|
||||
.. "size[6,4]"
|
||||
.. "textarea[1,1;4,1.5;input;" .. S("Infotext") .. ";" .. infotext .. "]"
|
||||
.. "button_exit[1.5,2.75;1.25,0.75;btn_write;" .. S("Write") .. "]"
|
||||
.. "button_exit[3.3,2.75;1.25,0.75;btn_erase;" .. S("Erase") .. "]"
|
||||
|
||||
-- store pos info for retrieval in callbacks
|
||||
user:get_meta():set_string(alternode.modname .. ":pencil:pos", core.serialize(pos))
|
||||
core.show_formspec(pname, alternode.modname .. ":pencil", formspec)
|
||||
user:get_meta():set_string(alternode.modname .. ":pos", core.serialize(pos))
|
||||
core.show_formspec(pname, alternode.modname .. ":pencil",
|
||||
alternode.get_pencil_formspec(pos))
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == alternode.modname .. ":pencil" then
|
||||
-- FIXME: how to get node meta without storing in player meta?
|
||||
local pmeta = player:get_meta()
|
||||
local pos = core.deserialize(pmeta:get_string(alternode.modname .. ":pencil:pos"))
|
||||
local nmeta = core.get_meta(pos)
|
||||
|
||||
if fields.btn_write then
|
||||
if fields.input:trim() == "" then
|
||||
nmeta:set_string("infotext", nil)
|
||||
else
|
||||
nmeta:set_string("infotext", fields.input)
|
||||
end
|
||||
elseif fields.btn_erase then
|
||||
nmeta:set_string("infotext", nil)
|
||||
end
|
||||
|
||||
pmeta:set_string(alternode.modname .. ":pencil:pos", nil)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
--- Player tool to set/unset *owner* meta value.
|
||||
--
|
||||
-- @craftitem alternode:key
|
||||
@ -179,10 +147,11 @@ core.register_craftitem(alternode.modname .. ":key", {
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if not user:is_player() then return end
|
||||
local pos = check_node_pos(pointed_thing)
|
||||
if not pos then return end
|
||||
|
||||
local pname = user:get_player_name()
|
||||
local pos = check_node(pointed_thing, pname)
|
||||
if not pos then return end
|
||||
|
||||
local nmeta = core.get_meta(pos)
|
||||
local node_owner = nmeta:get_string("owner")
|
||||
|
||||
@ -209,10 +178,11 @@ core.register_craftitem(alternode.modname .. ":key", {
|
||||
end,
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if not placer:is_player() then return end
|
||||
local pos = check_node_pos(pointed_thing)
|
||||
|
||||
local pname = user:get_player_name()
|
||||
local pos = check_node(pointed_thing, pname)
|
||||
if not pos then return end
|
||||
|
||||
local pname = placer:get_player_name()
|
||||
local node_owner = core.get_meta(pos):get_string("owner")
|
||||
|
||||
if node_owner == "" then
|
||||
|
Loading…
x
Reference in New Issue
Block a user