Browse Source

"/give" and "/giveme" no longer need "mod" specifier

In Old Minetest,  the "/give" and "/giveme" commands need a  "mod"
specifier. For example:

      /giveme default:axe_steel

In this example, the "mod" specifier is "default:".

This Final Minetest commit makes the "mod" specifier optional.  If
the specifier is omitted, the two commands will figure out the mod
to use.

The sample "/giveme" command shown above may therefore be shorten-
ed to:

      /giveme axe_steel

The "mod" specifier is still supported.  It should be used to dis-
ambiguate in cases where an object exists in multiple mods.

If an  object exists in  multiple mods and the  "mod" specifier is
omitted,  the two commands will choose one of the two mods to use.
"default" takes precedence over other mods.
master
OldCoder 1 month ago
parent
commit
7827016e24
1 changed files with 16 additions and 0 deletions
  1. 16
    0
      builtin/game/chatcommands.lua

+ 16
- 0
builtin/game/chatcommands.lua View File

@@ -576,6 +576,22 @@ core.register_chatcommand("mods", {
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 tsmods = minetest.get_modnames()
table.insert (tsmods, 1, "default")
for _,tsmod in ipairs (tsmods) do
local tsnode = tsmod .. ":" .. stackstring
if core.registered_items [tsnode] ~= nil or
core.registered_nodes [tsnode] ~= nil then
stackstring = tsnode
break
end
end
end

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

Loading…
Cancel
Save