mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-13 05:50:31 +01:00
Updated metatools
- Added itemstack handler (write,read,erase)
This commit is contained in:
parent
8dc2c33ae6
commit
b773b7b4f4
|
@ -16,10 +16,50 @@ stratum.
|
|||
"metatools_stick.png" by Ataron (CC-BY-NC-SA)
|
||||
|
||||
# Todo
|
||||
- Add a way to SET the metadatas (will be complicated)
|
||||
- Fix the LICENSE
|
||||
- Add a check if set is done in Node/fields/
|
||||
- Add a table handler for meta::set
|
||||
|
||||
# Special thanks
|
||||
- mgl512 (Le_Docteur) for its locked itemframe which gave me the idea of a tool
|
||||
allowing to see/edit metadatas
|
||||
- Ataron who created the stick's texture
|
||||
|
||||
# Command tutorial
|
||||
|
||||
- help => Get help
|
||||
- open (x,y,z) => Open the node to manipulate at pos (x,y,z)
|
||||
- show => Show fields/path list at actual position
|
||||
- enter <path> => Enter next stratum through <path>
|
||||
- quit => Quit actual field and go back to previous stratum
|
||||
- set <name> <value> => Set metadata <name> to <value> (create it if it doesn't exist)
|
||||
- itemstack => Manipulate itemstacks in Node/inventory/*/
|
||||
- read <name> => Read itemstack at field name (itemstring and count)
|
||||
- erase <name> => Erase itemstack at field name
|
||||
- write <name> <itemstring> [<count>] => Set itemstack in field <name> with item <itemstring> and count <count>. Default count is one, 0 not handled.
|
||||
- close => Close node
|
||||
|
||||
Node metadatas look like this :
|
||||
|
||||
Stratum : 0 1 2 ...
|
||||
Nodes/
|
||||
|
|
||||
+- fields
|
||||
| |
|
||||
| +- foo
|
||||
| +- bar
|
||||
| +- ...
|
||||
+- inventory
|
||||
|
|
||||
+- main
|
||||
| |
|
||||
| +- 1
|
||||
| +- 2
|
||||
| +- 3
|
||||
| +- ...
|
||||
+- craft
|
||||
| |
|
||||
| +- 1
|
||||
| +- 2
|
||||
| +- 3
|
||||
| +- ...
|
||||
+- ...
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
-- Meta-tools mod ßý Mg --
|
||||
-- License : GPLv2+
|
||||
-- License : GPLv3+
|
||||
--
|
||||
|
||||
metatools = {}
|
||||
|
@ -69,8 +69,12 @@ minetest.register_chatcommand("meta", {
|
|||
minetest.chat_send_player(name," open (x,y,z) : open node at pos x,y,z")
|
||||
minetest.chat_send_player(name," show : show fields at node/depth")
|
||||
minetest.chat_send_player(name," enter name : enter in field name at node/depth")
|
||||
minetest.chat_send_player(name," quit name : quit field name at node/depth")
|
||||
minetest.chat_send_player(name," quit : quit actual field at node/depth")
|
||||
minetest.chat_send_player(name," set name value : set field name to value at node/depth")
|
||||
minetest.chat_send_player(name," itemstack <subcommand>")
|
||||
minetest.chat_send_player(name," read <field> : send you the itemstring, and amount of items in <field>")
|
||||
minetest.chat_send_player(name," erase <field> : set to empty stack <field>")
|
||||
minetest.chat_send_player(name," write <field> <itemstring> [amount]: set the itemstack <field>")
|
||||
minetest.chat_send_player(name," close : close the current node")
|
||||
|
||||
elseif paramlist[1] == "open" then
|
||||
|
@ -249,6 +253,120 @@ minetest.register_chatcommand("meta", {
|
|||
minetest.log("action","[metatools] Player " .. name .. " set variable " .. paramlist[2] .. " to value " .. paramlist[3] .. " in stratum " .. meta_info[name]["stratum"] .. " of node " .. minetest.get_node(meta_info[name]["node"]).name .. " at pos " .. minetest.pos_to_string(meta_info[name]["node"]))
|
||||
metatools.actualize_metalist(name)
|
||||
return true
|
||||
|
||||
elseif paramlist[1] == "itemstack" then
|
||||
if not meta_info[name] or not meta_info[name]["node"] then
|
||||
minetest.chat_send_player(name,"- meta::itemstack - You have no node open, use /meta open (x,y,z) to open one")
|
||||
minetest.log("action","[metatools] Player "..name.." failed itemstack : no node opened")
|
||||
return false
|
||||
end
|
||||
|
||||
if not paramlist[2] then
|
||||
minetest.chat_send_player(name,"- meta::itemstack - You must provide a subcommand for the itemstack subcommand")
|
||||
minetest.log("action","[metatools] Player "..name.." failed itemstack : no subcommand")
|
||||
return false
|
||||
end
|
||||
|
||||
if not (meta_info[name]["stratum"] > 1 and meta_info[name]["pathname"][meta_info[name]["stratum"]-1] == "inventory") then
|
||||
minetest.chat_send_player(name,"- meta::itemstack - Itemstack must only exist in inventory fields")
|
||||
minetest.log("action","[metatools] Player " .. name .. " tried to access itemstack out of inventory's fields")
|
||||
return false
|
||||
end
|
||||
|
||||
if paramlist[2] == "read" then
|
||||
|
||||
if not paramlist[3] then
|
||||
minetest.chat_send_player(name,"- meta::itemstack::read - You must provide a field name (eg. a number) to read")
|
||||
minetest.log("action","[metatools] Player " .. name .. " failed itemstack reading : no field name")
|
||||
return false
|
||||
end
|
||||
|
||||
for key,value in pairs(meta_info[name]["pointer"]) do
|
||||
if key ~= nil and key.."" == paramlist[3] then -- Forced conversion to string type
|
||||
local itemstack = value
|
||||
if not itemstack:get_name() or not itemstack:get_count() then
|
||||
minetest.chat_send_player(name,"- meta::itemstack::read - Itemstack recognition failed. Field content isn't an itemstack")
|
||||
minetest.log("action","[metatools] Player " .. name .. " tried to access field " .. key .. " which is not an itemstack")
|
||||
end
|
||||
local itemname = itemstack:get_name()
|
||||
local itemcount = itemstack:get_count()
|
||||
if itemname == "" then
|
||||
minetest.chat_send_player(name,"- meta::itemstack::read - Itemstack of field ".. key .." is empty")
|
||||
minetest.log("action","[metatools] Player ".. name .. " read itemstack of field ".. key .." : empty stack")
|
||||
else
|
||||
minetest.chat_send_player(name,"- meta::itemstack::read - Itemstack of field ".. key .." : "..itemstack:get_name().." "..itemstack:get_count())
|
||||
minetest.log("action","[metatools] Player ".. name .. " read itemstack of field ".. key .." : "..itemname.." "..itemcount)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name,"- meta::itemstack::read - Field " .. paramlist[3] .. " doesn't exist")
|
||||
minetest.log("action","[metatools] Player " .. name .. " tried to access itemstack in unknown field " .. paramlist[3])
|
||||
|
||||
elseif paramlist[2] == "erase" then
|
||||
|
||||
if not paramlist[3] then
|
||||
minetest.chat_send_player(name,"- meta::itemstack::write - You must provide a field name (eg. a number) to erase")
|
||||
minetest.log("action","[metatools] Player " .. name .. " failed itemstack erasing : no field name")
|
||||
return false
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(meta_info[name]["node"])
|
||||
local inv = meta:get_inventory()
|
||||
for key,value in pairs(meta_info[name]["pointer"]) do
|
||||
if key ~= nil and key.."" == paramlist[3] then -- Forced conversion to string type
|
||||
local itemstack = value
|
||||
inv:set_stack(meta_info[name]["pathname"][meta_info[name]["stratum"]],key+0,nil)
|
||||
minetest.chat_send_player(name,"- meta::itemstack::erase - Itemstack of field ".. key .." cleared")
|
||||
minetest.log("action","[metatools] Player ".. name .. " cleared itemstack of field ".. key)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name,"- meta::itemstack::erase - Field " .. paramlist[3] .. " doesn't exist")
|
||||
minetest.log("action","[metatools] Player " .. name .. " tried to erase itemstack in unknown field " .. paramlist[3])
|
||||
|
||||
elseif paramlist[2] == "write" then
|
||||
|
||||
if not paramlist[3] then
|
||||
minetest.chat_send_player(name,"- meta::itemstack::write - You must provide a field name (eg. a number) to write to")
|
||||
minetest.log("action","[metatools] Player " .. name .. " failed itemstack writing : no field name")
|
||||
return false
|
||||
end
|
||||
if not paramlist[4] then
|
||||
minetest.chat_send_player(name,"- meta::itemstack::write - You must provide an itemstring (eg. 'default:chest') for the itemstack to write")
|
||||
minetest.log("action","[metatools] Player " .. name .. " failed itemstack writing : no itemstring")
|
||||
return false
|
||||
end
|
||||
|
||||
if paramlist[5] and paramlist[5] == 0 then
|
||||
minetest.chat_send_player(name,"- meta::itemstack::write - It is useless to write 0 items. Use meta erase "..paramlist[3].." instead")
|
||||
minetest.log("action","[metatools] Player ".. name .. " wanted to write 0 items in " .. paramlist[3] .. " inventory field")
|
||||
return false
|
||||
end
|
||||
|
||||
local itemstring = paramlist[4]
|
||||
local itemcount = paramlist[5] or 1
|
||||
|
||||
local meta = minetest.get_meta(meta_info[name]["node"])
|
||||
local inv = meta:get_inventory()
|
||||
for key,value in pairs(meta_info[name]["pointer"]) do
|
||||
if key ~= nil and key.."" == paramlist[3] then -- Forced conversion to string type
|
||||
inv:set_stack(meta_info[name]["pathname"][meta_info[name]["stratum"]],key+0,ItemStack({name = itemstring,count = itemcount}))
|
||||
minetest.chat_send_player(name,"- meta::itemstack::write - Itemstack written in field ".. key)
|
||||
minetest.log("action","[metatools] Player ".. name .. " wrote itemstack '".. itemstring.. " " ..itemcount.."' in field ".. key)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name,"- meta::itemstack::write - Field " .. paramlist[3] .. " doesn't exist")
|
||||
minetest.log("action","[metatools] Player " .. name .. " tried to write itemstack in unknown field " .. paramlist[3])
|
||||
|
||||
else
|
||||
minetest.chat_send_player("- meta::itemstack - Subcommand " .. paramlist[2] .. " unknown. Typ /meta help for help")
|
||||
return false
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name,"- meta - Subcommand " .. paramlist[1] .. " not known. Type /meta help for help")
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue
Block a user