Browse Source

Improve "/give" and "/giveme" further

This commit improves on previous changes to "/give" and "/giveme".
The new version of the code:

* Handles aliases more correctly
* Fixes a bug related to item counts
* Adds support for a few virtual mods

Note:  Virtual mods are mods  that may not be installed  but exist
regardless  due  to registration of  nodes in the associated name-
spaces by other mods.
master
OldCoder 3 weeks ago
parent
commit
8c9a2d0ad3
1 changed files with 34 additions and 5 deletions
  1. 34
    5
      builtin/game/chatcommands.lua

+ 34
- 5
builtin/game/chatcommands.lua View File

@@ -573,25 +573,54 @@ core.register_chatcommand("mods", {
end,
})

local function handle_give_command(cmd, giver, receiver, stackstring)
local function handle_give_command (cmd, giver, receiver, stackstring)
core.log("action", giver .. " invoked " .. cmd
.. ', stackstring="' .. stackstring .. '"')

if not string.match (stackstring, ":") and
core.registered_items [stackstring] == nil and
core.registered_nodes [stackstring] == nil then
-- ===================================================================

local objword, count = stackstring:match ("^(%w+) +(%d+)$")
if count == nil or string.len (count ) == 0 then
count = nil
objword = stackstring:match ("^(%w+)$")
end
if objword ~= nil and string.len (objword) == 0 then
objword = nil
end

if objword ~= nil and
core.registered_items [objword] == nil and
core.registered_nodes [objword] == nil then

local tsmods = minetest.get_modnames()

-- Check "default" mod first
table.insert (tsmods, 1, "default")

-- Support virtual mods
-- Note: These should be appended as opposed to prepended

table.insert (tsmods, "gloopblocks" )
table.insert (tsmods, "greenlava" )
table.insert (tsmods, "lmb" )
table.insert (tsmods, "lmbb" )

for _,tsmod in ipairs (tsmods) do
local tsnode = tsmod .. ":" .. stackstring
local tsnode = tsmod .. ":" .. objword

if core.registered_items [tsnode] ~= nil or
core.registered_nodes [tsnode] ~= nil then
stackstring = tsnode
if count ~= nil then
stackstring = stackstring .. " " .. count
end
break
end
end
end

-- ===================================================================

local itemstack = ItemStack(stackstring)
if itemstack:is_empty() then
return false, "Cannot give an empty item"

Loading…
Cancel
Save