From f7b38b854a8d255afe43567de86887e9409b53dd Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Wed, 5 May 2021 07:08:29 -0700 Subject: [PATCH] Update alternode mod to v1.0... Release: https://github.com/AntumMT/mod-alternode/releases/tag/v1.0 --- README.md | 4 + mods/admin/alternode/README.md | 27 ++++ mods/admin/alternode/TODO.txt | 3 + mods/admin/alternode/init.lua | 127 ++++++++++-------- mods/admin/alternode/locale/template.txt | 20 +++ mods/admin/alternode/mod.conf | 2 + .../textures/alternode_infostick.png | Bin 0 -> 203 bytes 7 files changed, 126 insertions(+), 57 deletions(-) create mode 100644 mods/admin/alternode/README.md create mode 100644 mods/admin/alternode/TODO.txt create mode 100644 mods/admin/alternode/locale/template.txt create mode 100644 mods/admin/alternode/textures/alternode_infostick.png diff --git a/README.md b/README.md index b9260439..e0b908a0 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,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: [1.0][ver.alternode] *2021-05-03* * [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* @@ -230,6 +231,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m [3d_armor]: https://forum.minetest.net/viewtopic.php?t=4654 [airtanks]: https://forum.minetest.net/viewtopic.php?t=17102 +[alternode]: https://forum.minetest.net/viewtopic.php?t=26667 [amber]: https://forum.minetest.net/viewtopic.php?t=18186 [ambience]: https://forum.minetest.net/viewtopic.php?t=2807 [animals_aggressive]: https://github.com/AntumMT/mp-animals_aggressive @@ -372,6 +374,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m [lic.3d_armor]: mods/modpacks/3d_armor/LICENSE.md [lic.airtanks]: mods/equipment/airtanks/LICENSE.txt +[lic.alternode]: mods/admin/alternode/LICENSE.txt [lic.ambience]: mods/sound/ambience/README.md [lic.ambience_sounds]: mods/sound/ambience/sounds/SoundLicenses.txt [lic.antum]: mods/antum/LICENSE.txt @@ -461,6 +464,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m [ver.3d_armor]: https://github.com/stujones11/minetest-3d_armor/tree/47ecef4 [ver.airtanks]: https://github.com/minetest-mods/airtanks/tree/b686694 +[ver.alternode]: https://github.com/AntumMT/mod-alternode/releases/tag/v1.0 [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 diff --git a/mods/admin/alternode/README.md b/mods/admin/alternode/README.md new file mode 100644 index 00000000..5617bfd4 --- /dev/null +++ b/mods/admin/alternode/README.md @@ -0,0 +1,27 @@ +## Alternode: Node Meta Manipulation + +### Description: + +A [Minetest](http://minetest.net/) mod that allows administrators with *server* privilege to examine & alter node meta data. + +### Licensing: + +- Code: [MIT](LICENSE.txt) +- Textures: CC0 + +### Usage: + +Invoke `/giveme alternode:infostick`. Use the infostick on a node to receive coordinate & other information. + +**Chat commands:** + +- */getmeta * + - prints the value of `key` in the node's meta data at `x,y,z`. +- */setmeta string|int|float * + - Sets the value of `key` in the meta data of node at `x,y,z`. + +### Links: + +- [Forum](https://forum.minetest.net/viewtopic.php?t=26667) +- [Git repo](http://github.com/AntumMT/mod-alternode) +- [TODO](TODO.txt) diff --git a/mods/admin/alternode/TODO.txt b/mods/admin/alternode/TODO.txt new file mode 100644 index 00000000..7bb9fe85 --- /dev/null +++ b/mods/admin/alternode/TODO.txt @@ -0,0 +1,3 @@ + +TODO: +- specify that "pos" & "name" are NOT meta data when using infostick diff --git a/mods/admin/alternode/init.lua b/mods/admin/alternode/init.lua index 023cd2f2..eaf156cf 100644 --- a/mods/admin/alternode/init.lua +++ b/mods/admin/alternode/init.lua @@ -2,11 +2,13 @@ alternode = {} alternode.name = core.get_current_modname() +local S = core.get_translator(alternode.name) + core.register_craftitem(alternode.name .. ":infostick", { - description = "Tool for retrieving information about node", - short_description = "Info Stick", - inventory_image = "default_stick.png", + description = S("Tool for retrieving information about a node"), + short_description = S("Info Stick"), + inventory_image = "alternode_infostick.png", stack_max = 1, on_use = function(itemstack, user, pointed_thing) if not user:is_player() then return end @@ -15,21 +17,26 @@ core.register_craftitem(alternode.name .. ":infostick", { local granted, missing = core.check_player_privs(pname, {server=true,}) if not granted then - core.chat_send_player(pname, "You do not have privileges to use this item (missing priviliges: " .. table.concat(missing, ", ") .. ")") + core.chat_send_player(pname, + S("You do not have privileges to use this item (missing priviliges: @1)", table.concat(missing, ", "))) return end if pointed_thing.type ~= "node" then - core.chat_send_player(pname, "This item only works on nodes") + core.chat_send_player(pname, S("This item only works on nodes")) return end 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 = "pos: x=" .. tostring(pos.x) - .. ", y=" .. tostring(pos.y) - .. ", z=" .. tostring(pos.z) + 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({"infotext", "owner"}) do local value = meta:get_string(key) @@ -53,30 +60,22 @@ function alternode.set(pos, key, value) return meta:get_string(key) == value end -function alternode.set_int(pos, key, value) - local meta = core.get_meta(pos) - meta:set_int(key, value) - return meta:get_int(key) == value -end - -function alternode.set_float(pos, key, value) - local meta = core.get_meta(pos) - meta:set_float(key, value) - return meta:get_float(key) == value -end - core.register_chatcommand("setmeta", { - params = " string|int|float ", - description = "Alter meta data of a node", + params = S(" "), + description = S("Alter meta data of a node"), privs = {server=true,}, func = function(player, param) local plist = string.split(param, " ") + if #plist < 3 then + core.chat_send_player(player, S("You must supply proper coordinates")) + return false + end + for _, p in ipairs({plist[1], plist[2], plist[3]}) do if tonumber(p) == nil then - core.chat_send_player(player, - "Coordinate parameters must be numbers") + core.chat_send_player(player, S("You must supply proper coordinates")) return false end end @@ -87,43 +86,37 @@ core.register_chatcommand("setmeta", { z = tonumber(plist[3]), } - local vtype = plist[4] - local key = plist[5] - local value = plist[6] - local retval = false - if vtype == "int" then - retval = alternode.set_int(pos, key, tonumber(value)) - elseif vtype == "float" then - retval = alternode.set_float(pos, key, tonumber(value)) - elseif vtype == "string" then - local rem = {} - for idx, word in ipairs(plist) do - if idx > 5 then - table.insert(rem, word) - end - end + local key = plist[4] + if key then key = key:trim() end - retval = alternode.set(pos, key, table.concat(rem, " ")) - else - core.chat_send_player(player, - "Unknown meta data type: " .. vtype) + if not key or key == "" then + core.chat_send_player(player, S("You must supply a key parameter")) return false end + local value = {} + for idx, word in ipairs(plist) do + if idx > 4 then + table.insert(value, word) + end + end + + if #value == 0 then + core.chat_send_player(player, S("You must supply a value parameter")) + return false + end + + local retval = alternode.set(pos, key, table.concat(value, " "):trim()) + if not retval then core.chat_send_player(player, - "Failed to set node meta at " - .. tostring(pos.x) .. "," - .. tostring(pos.y) .. "," - .. tostring(pos.z)) + S("Failed to set node meta at @1,@2,@3", + tostring(pos.x), tostring(pos.y), tostring(pos.z))) else core.chat_send_player(player, - "Set meta \"" .. key .. "=" - .. core.get_meta(pos):get_string(key) - .. "\" for node at " - .. tostring(pos.x) .. "," - .. tostring(pos.y) .. "," - .. tostring(pos.z)) + S('Set meta "@1@=@2" for node at @3,@4,@5', + key, core.get_meta(pos):get_string(key), + tostring(pos.x), tostring(pos.y), tostring(pos.z))) end return retval @@ -131,11 +124,24 @@ core.register_chatcommand("setmeta", { }) core.register_chatcommand("getmeta", { - params = " ", - description = "Retrieve meta data of a node", + params = S(" "), + description = S("Retrieve meta data of a node"), privs = {server=true,}, func = function(player, param) local plist = string.split(param, " ") + + if #plist < 3 then + core.chat_send_player(player, S("You must supply proper coordinates")) + return false + end + + for _, p in ipairs({plist[1], plist[2], plist[3]}) do + if tonumber(p) == nil then + core.chat_send_player(player, S("You must supply proper coordinates")) + return false + end + end + local pos = { x = tonumber(plist[1]), y = tonumber(plist[2]), @@ -143,13 +149,20 @@ core.register_chatcommand("getmeta", { } local key = plist[4] + if key then key = key:trim() end + + if not key or key == "" then + core.chat_send_player(player, S("You must supply a key parameter")) + return false + end + local value = alternode.get(pos, key) if not value or value == "" then core.chat_send_player(player, - "\"" .. key .. "\" key value not present in node meta data") + S('"@1" key value not present in node meta data', key)) else core.chat_send_player(player, - "Meta value: " .. key .. "=" .. value) + S("Meta value: @1@=@2", key, value)) end return true diff --git a/mods/admin/alternode/locale/template.txt b/mods/admin/alternode/locale/template.txt new file mode 100644 index 00000000..214cec0e --- /dev/null +++ b/mods/admin/alternode/locale/template.txt @@ -0,0 +1,20 @@ +# Translated by: + + +Tool for retrieving information about a node= +Info Stick= +You do not have privileges to use this item (missing priviliges: @1)= +This item only works on nodes= +That doesn't seem to be a proper node= +pos: x@=@1, y@=@2, z@=@3; name@=@4= + = + = +Alter meta data of a node= +Retrieve meta data of a node= +You must supply proper coordinates= +You must supply a key parameter= +You must supply a value parameter= +Failed to set node meta at @1,@2,@3= +Set meta "@1@=@2" for node at @3,@4,@5= +"@1" key value not present in node meta data= +Meta value: @1@=@2= diff --git a/mods/admin/alternode/mod.conf b/mods/admin/alternode/mod.conf index c3a7caa7..a753befb 100644 --- a/mods/admin/alternode/mod.conf +++ b/mods/admin/alternode/mod.conf @@ -1,3 +1,5 @@ name = alternode title = Alter Node description = Manage node meta data +version = 1.0 +author = Jordan Irwin (AntumDeluge) diff --git a/mods/admin/alternode/textures/alternode_infostick.png b/mods/admin/alternode/textures/alternode_infostick.png new file mode 100644 index 0000000000000000000000000000000000000000..86449fe8be49f7a15d947a08982637bc02726885 GIT binary patch literal 203 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F3${@^GvDCf{D9B#o z>Fdh=l$D8tUv9R6cpXqE%hSa%#NzbYODA~`DDb#k%>R|oIcwpBhZAIkT90ls5)yat zHT=A)Zg)Z;kJ(N vyQg)qrloa76nwDjP+j)DRbpp{yix<>y)0=Z*Gi*Epsfs^u6{1-oD!M