Update alternode mod to Git commit 19b258a...

https://github.com/AntumMT/mod-alternode/tree/19b258a
master
Jordan Irwin 2021-05-16 19:06:05 -07:00
parent 40259b7066
commit 675f8dd949
15 changed files with 548 additions and 236 deletions

View File

@ -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: [1.1][ver.alternode] *2021-05-14*
* [alternode][] ([MIT][lic.alternode]) -- version: [19b258a Git][ver.alternode] *2021-05-16*
* [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/releases/tag/v1.1
[ver.alternode]: https://github.com/AntumMT/mod-alternode/tree/19b258a
[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

View File

@ -1,4 +1,8 @@
1.2
- formspec shown when infostick "on_place" (right-click) method is called
1.1
- added alternode.unset method to unset node meta data
- added /unsetmeta chat command

View File

@ -2,18 +2,11 @@
### 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
A [Minetest](http://minetest.net/) mod that allows administrators with *server* privilege to examine & alter node meta data. Additionally, a pencil & wand tools are provided with limited use for players to alter *infotext* & *owner* meta value.
### Usage:
Invoke `/giveme alternode:infostick`. Use the infostick on a node to receive coordinate & other information.
**Chat commands:**
#### Chat commands:
- */getmeta <x> <y> <z> <key>*
- prints the value of `key` in meta data of node at `x,y,z`.
@ -22,6 +15,30 @@ Invoke `/giveme alternode:infostick`. Use the infostick on a node to receive coo
- */unsetmeta <x> <y> <z> <key>*
- Unsets the value of `key` in meta data of node at `x,y,z`.
#### Tools:
**Info stick:**
Invoke `/giveme alternode:infostick`. Use the infostick on a node to receive 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.
- *left-click (use):* Opens formspec to set/unset infotext meta attribute.
**Wand:**
- *left-click (use):* Sets/Unsets user as owner.
- *right-click (place):* Checks owner status & outputs to chat log.
### Licensing:
- Code: [MIT](LICENSE.txt)
- Textures: CC0
- `alternode_infostick.png & alternode_pencil.png:` by AntumDeluge
- `alternode_wand.png:` by [rcorre](https://opengameart.org/node/40598)
### Links:
- [Forum](https://forum.minetest.net/viewtopic.php?t=26667)

View File

@ -1,3 +1,7 @@
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

View File

@ -0,0 +1,19 @@
local S = core.get_translator(alternode.modname)
function alternode.get(pos, key)
return core.get_meta(pos):get_string(key)
end
function alternode.set(pos, key, value)
local meta = core.get_meta(pos)
meta:set_string(key, value)
return meta:get_string(key) == value
end
function alternode.unset(pos, key)
local meta = core.get_meta(pos)
meta:set_string(key, nil)
return meta:get_string(key) == ""
end

View File

@ -0,0 +1,159 @@
local S = core.get_translator(alternode.modname)
core.register_chatcommand("getmeta", {
params = S("<x> <y> <z> <key>"),
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]),
z = tonumber(plist[3]),
}
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,
S('"@1" key value not present in node meta data', key))
else
core.chat_send_player(player,
S("Meta value: @1@=@2", key, value))
end
return true
end,
})
core.register_chatcommand("setmeta", {
params = S("<x> <y> <z> <key> <value>"),
description = S("Set 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]),
z = tonumber(plist[3]),
}
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 = {}
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,
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,
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
end,
})
core.register_chatcommand("unsetmeta", {
params = S("<x> <y> <z> <key>"),
description = S("Unset 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]),
z = tonumber(plist[3]),
}
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 retval = alternode.unset(pos, key)
if not retval then
core.chat_send_player(player,
S("Failed to unset node meta at @1,@2,@3",
tostring(pos.x), tostring(pos.y), tostring(pos.z)))
else
core.chat_send_player(player,
S('Unset meta "@1" for node at @2,@3,@4',
key, tostring(pos.x), tostring(pos.y), tostring(pos.z)))
end
return retval
end,
})

View File

@ -0,0 +1,51 @@
-- pencil
local pencil = {
lead = "technic:lead_lump",
stick = "group:stick",
rubber = "technic:rubber",
}
-- FIXME: how to check if items are registered under "group:stick"
if core.global_exists("default") and
core.registered_items[pencil.lead] and core.registered_items[pencil.rubber] then
core.register_craft({
output = alternode.modname .. ":pencil",
recipe = {
{"", "", pencil.lead},
{"", pencil.stick, ""},
{pencil.rubber, "", ""},
},
})
end
-- wand
local wand = {
head = nil,
handle = nil,
}
if core.registered_items["gems_encrustable:aquamarine"] then
wand.head = "gems_encrustable:aquamarine"
elseif core.registered_items["gems:aquamarine"] then
wand.head = "gems:aquamarine"
end
if core.registered_items["gems_encrustable:opal"] then
wand.handle = "gems_encrustable:opal"
elseif core.registered_items["gems:opal"] then
wand.handle = "gems:opal"
end
if wand.head and wand.handle then
core.register_craft({
output = alternode.modname .. ":wand",
recipe = {
{"", "", wand.head},
{"", wand.handle, ""},
{wand.handle, "", ""},
},
})
end

View File

@ -0,0 +1,29 @@
local S = core.get_translator(alternode.modname)
function alternode.show_formspec(pos, node, player)
local nmeta = 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)
-- 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")
local formspec = "formspec_version[4]"
.. "size[16,10]"
.. "label[0.15,0.25;" .. core.formspec_escape(infostring) .. "]"
-- TODO: add fields for get, set, & unset meta data
core.show_formspec(player:get_player_name(), alternode.modname .. ":meta", formspec)
end

View File

@ -1,224 +1,16 @@
alternode = {}
alternode.name = core.get_current_modname()
alternode.modname = core.get_current_modname()
alternode.modpath = core.get_modpath(alternode.modname)
local S = core.get_translator(alternode.name)
local scripts = {
"api",
"commands",
"formspec",
"tools",
"crafts",
}
core.register_craftitem(alternode.name .. ":infostick", {
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
local pname = user:get_player_name()
local granted, missing = core.check_player_privs(pname, {server=true,})
if not granted then
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, 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 = 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)
end,
})
function alternode.get(pos, key)
return core.get_meta(pos):get_string(key)
for _, script in ipairs(scripts) do
dofile(alternode.modpath .. "/" .. script .. ".lua")
end
function alternode.set(pos, key, value)
local meta = core.get_meta(pos)
meta:set_string(key, value)
return meta:get_string(key) == value
end
function alternode.unset(pos, key)
local meta = core.get_meta(pos)
meta:set_string(key, nil)
return meta:get_string(key) == ""
end
core.register_chatcommand("setmeta", {
params = S("<x> <y> <z> <key> <value>"),
description = S("Set 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]),
z = tonumber(plist[3]),
}
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 = {}
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,
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,
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
end,
})
core.register_chatcommand("unsetmeta", {
params = S("<x> <y> <z> <key>"),
description = S("Unset 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]),
z = tonumber(plist[3]),
}
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 retval = alternode.unset(pos, key)
if not retval then
core.chat_send_player(player,
S("Failed to unset node meta at @1,@2,@3",
tostring(pos.x), tostring(pos.y), tostring(pos.z)))
else
core.chat_send_player(player,
S('Unset meta "@1" for node at @2,@3,@4',
key, tostring(pos.x), tostring(pos.y), tostring(pos.z)))
end
return retval
end,
})
core.register_chatcommand("getmeta", {
params = S("<x> <y> <z> <key>"),
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]),
z = tonumber(plist[3]),
}
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,
S('"@1" key value not present in node meta data', key))
else
core.chat_send_player(player,
S("Meta value: @1@=@2", key, value))
end
return true
end,
})

View File

@ -1,12 +1,6 @@
# 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=
<x> <y> <z> <key>=
<x> <y> <z> <key> <value>=
Set meta data of a node=
@ -21,3 +15,28 @@ Set meta "@1@=@2" for node at @3,@4,@5=
Unset meta "@1" for node at @2,@3,@4=
"@1" key value not present in node meta data=
Meta value: @1@=@2=
# tools
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=
Pencil=
Tool for editing node infotext=
You cannot alter nodes in areas you do not own=
Infotext=
Write=
Erase=
Ownit Wand=
Tool for setting node owner=
You cannot take ownership of a node owned by @1=
You cannot take ownership of nodes in areas you do not own=
You no longer own this node=
You now own this node=
This node is unowned=
This node is owned by @1=

View File

@ -3,3 +3,4 @@ title = Alter Node
description = Manage node meta data
version = 1.1
author = Jordan Irwin (AntumDeluge)
optional_depends = default, technic, simple_protection, gems, gems_encrustable

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 B

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

View File

@ -0,0 +1,217 @@
local S = core.get_translator(alternode.modname)
local use_s_protect = core.global_exists("s_protect")
local function check_permissions(player)
local pname = player:get_player_name()
local granted, missing = core.check_player_privs(pname, {server=true,})
if not granted then
core.chat_send_player(pname,
S("You do not have privileges to use this item (missing priviliges: @1)", table.concat(missing, ", ")))
return false
end
return true
end
local function target_is_node(target)
if target.type ~= "node" then
core.chat_send_player(pname, S("This item only works on nodes"))
return false
end
return true
end
local function is_area_owner(pos, pname)
if not pname then return false end
if use_s_protect then
local claim = s_protect.get_claim(pos)
if claim then return pname == claim.owner end
else
return core.is_protected(pos, pname)
end
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
return pos
end
--- Admin tool to retrieve node node coordinates, name, & some select meta info.
--
-- @craftitem alternode:infostick
-- @use
-- @place
core.register_craftitem(alternode.modname .. ":infostick", {
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
if not check_permissions(user) then return end
if not target_is_node(pointed_thing) then return end
local pname = user:get_player_name()
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)
end,
on_place = function(itemstack, placer, pointed_thing)
if not placer:is_player() then return end
if not check_permissions(placer) then return end
if not target_is_node(pointed_thing) then 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
alternode.show_formspec(pos, node, placer)
end,
})
--- Player tool to alter *infotext* meta value.
--
-- @craftitem alternode:pencil
-- @use
-- @place
core.register_craftitem(alternode.modname .. ":pencil", {
description = S("Tool for editing node infotext"),
short_description = S("Pencil"),
inventory_image = "alternode_pencil.png",
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 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)
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:wand
-- @use
-- @place
core.register_craftitem(alternode.modname .. ":wand", {
description = S("Tool for setting node owner"),
short_description = S("Ownit Wand"),
inventory_image = "alternode_wand.png",
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 nmeta = core.get_meta(pos)
local node_owner = nmeta:get_string("owner")
if node_owner ~= "" and pname ~= node_owner then
core.chat_send_player(pname, S("You cannot take ownership of a node owned by @1", node_owner))
return
end
local unown = false
if pname == node_owner then unown = true end
if unown then
nmeta:set_string("owner", nil)
core.chat_send_player(pname, S("You no longer own this node"))
else
if not is_area_owner(pos, pname) then
core.chat_send_player(pname, S("You cannot take ownership of nodes in areas you do not own"))
return
end
nmeta:set_string("owner", pname)
core.chat_send_player(pname, S("You now own this node"))
end
end,
on_place = function(itemstack, placer, pointed_thing)
if not placer:is_player() then return end
local pos = check_node_pos(pointed_thing)
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
core.chat_send_player(pname, S("This node is unowned"))
else
core.chat_send_player(pname, S("This node is owned by @1", node_owner))
end
end,
})
core.register_alias("ownit:wand", alternode.modname .. ":wand")