Abstract inventory handling, add docs
This commit is contained in:
parent
262340c945
commit
690248aa06
20
README.md
20
README.md
@ -38,4 +38,22 @@ You are still responsible for complying with licensing for all media files in th
|
||||
- Complying with sublicensing requirements when selecting the license for your own projet containing these media.
|
||||
- Anything else required by the license that applies to any file you use.
|
||||
|
||||
This tool may also rip media from "private" mods you might have installed, including things you don't actually have the right to redistribute; you are responsible for manually ensuring these are not included in any product you create using this tool.
|
||||
This tool may also rip media from "private" mods you might have installed, including things you don't actually have the right to redistribute; you are responsible for manually ensuring these are not included in any product you create using this tool.
|
||||
|
||||
## Commands
|
||||
|
||||
Minetest "items" includes all nodes, craftitems and tools. The definition ripper mod supports exporting all of them, though it is more focused on nodes.
|
||||
|
||||
### Basic commands:
|
||||
|
||||
- `/defripper` - re-export all item definitions already marked for export (saved in mod storage).
|
||||
- `/defripper_clear` - clear all saved definitions.
|
||||
- `/defripper_add <pattern>` - add all definitions whose technical name (modname:item_name) matches the given lua pattern.
|
||||
- `/defripper_rm <pattern>` - remove all definitions whose technical name (modname:item_name) matches the given lua pattern.
|
||||
- `/defripper_inv` - add all definitions for items currently in the player's inventory.
|
||||
|
||||
### Area-scanning commands:
|
||||
|
||||
- For each of these commands, if the `defripper_node_inv` setting is `true` (default `false`), it will descend into node meta inventories and rip items found there as well.
|
||||
- `/defripper_here [rx [ry [rz]]]` - rip all nodes/items within a cuboid/rectanguloid centered around the player, right now.
|
||||
- `/defripper_step [rx [ry [rz [step]]]]` - rip all nodes/items within a cuboid/rectanguloid centered around the player, continuously, every time the player moves `step` nodes, until the server is restarted or command is re-run to change it. `/defripper_step 0` disables it.
|
36
commands.lua
36
commands.lua
@ -1,6 +1,6 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local minetest, next, pairs, pcall, string, tonumber, vector
|
||||
= minetest, next, pairs, pcall, string, tonumber, vector
|
||||
local ipairs, minetest, next, pairs, pcall, string, tonumber, vector
|
||||
= ipairs, minetest, next, pairs, pcall, string, tonumber, vector
|
||||
local string_format, string_gsub, string_match
|
||||
= string.format, string.gsub, string.match
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
@ -32,19 +32,27 @@ minetest.register_chatcommand(modname .. "_clear", {
|
||||
end
|
||||
})
|
||||
|
||||
local function ripinv(inv)
|
||||
local dirty
|
||||
for _, list in pairs(inv:get_lists()) do
|
||||
for _, stack in pairs(list) do
|
||||
local n = stack:get_name()
|
||||
if n and n ~= "" and not exportdb[n] then
|
||||
exportdb[n] = true
|
||||
dirty = true
|
||||
end
|
||||
end
|
||||
end
|
||||
return dirty
|
||||
end
|
||||
|
||||
minetest.register_chatcommand(modname .. "_inv", {
|
||||
description = "Rip all items in inventory",
|
||||
privs = {server = true},
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return false, "invalid player" end
|
||||
for _, list in pairs(player:get_inventory():get_lists()) do
|
||||
for _, stack in pairs(list) do
|
||||
if not stack:is_empty() then
|
||||
exportdb[stack:get_name()] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
ripinv(player:get_inventory())
|
||||
return save_export_report()
|
||||
end
|
||||
})
|
||||
@ -89,12 +97,20 @@ local function ripradius(pos, radius)
|
||||
local dirty
|
||||
for k in pairs(foundids) do
|
||||
local n = minetest.get_name_from_content_id(k)
|
||||
if n and not exportdb[n] then
|
||||
if n and n ~= "" and not exportdb[n] then
|
||||
exportdb[n] = true
|
||||
dirty = true
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.settings:get_bool(modname .. "_node_inv") then
|
||||
for _, p in ipairs(minetest.find_nodes_with_meta(
|
||||
vector.subtract(pos, radius),
|
||||
vector.add(pos, radius))) do
|
||||
dirty = ripinv(minetest.get_meta(p):get_inventory()) or dirty
|
||||
end
|
||||
end
|
||||
|
||||
return dirty
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user