mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Fix some crashes with set_mod_namespace and bugs
This commit is contained in:
parent
e44e9eaf62
commit
c05e57efb1
1 changed files with 28 additions and 18 deletions
|
@ -1,22 +1,38 @@
|
|||
mcl_item_id = {}
|
||||
mcl_item_id = {
|
||||
mod_namespaces = {},
|
||||
}
|
||||
|
||||
local game = "mineclone"
|
||||
|
||||
function mcl_item_id.set_mod_namespace(modname, namespace)
|
||||
local namespace = namespace or modname
|
||||
mcl_item_id[modname .. "_namespace"] = namespace
|
||||
mcl_item_id.mod_namespaces[modname] = namespace
|
||||
minetest.register_on_mods_loaded(function()
|
||||
for item, def in pairs(minetest.registered_items) do
|
||||
local item_split = item:find(":")
|
||||
if item_split then
|
||||
local id_modname = item:sub(1, item_split - 1)
|
||||
local id_string = item:sub(item_split)
|
||||
if id_modname == modname then
|
||||
minetest.register_alias_force(namespace .. id_string, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function mcl_item_id.get_mod_namespace(modname)
|
||||
local namespace = mcl_item_id[modname .. "_namespace"]
|
||||
local namespace = mcl_item_id.mod_namespaces[modname]
|
||||
if namespace then
|
||||
return namespace
|
||||
else
|
||||
return
|
||||
return game
|
||||
end
|
||||
end
|
||||
|
||||
local same_id = {
|
||||
enchanting = { "table" },
|
||||
experience = { "bottle" },
|
||||
heads = { "skeleton", "zombie", "creeper", "wither_skeleton" },
|
||||
mobitems = { "rabbit", "chicken" },
|
||||
walls = {
|
||||
|
@ -34,13 +50,11 @@ local same_id = {
|
|||
|
||||
tt.register_snippet(function(itemstring)
|
||||
local def = minetest.registered_items[itemstring]
|
||||
local desc = def.description
|
||||
local item_split = itemstring:find(":")
|
||||
local id_part1 = itemstring:sub(1, item_split)
|
||||
local id_part2 = itemstring:sub(item_split)
|
||||
local modname = id_part1:gsub("%:", "")
|
||||
local new_id = game .. id_part2
|
||||
local mod_namespace = mcl_item_id.get_mod_namespace(modname)
|
||||
local id_string = itemstring:sub(item_split)
|
||||
local id_modname = itemstring:sub(1, item_split - 1)
|
||||
local new_id = game .. id_string
|
||||
local mod_namespace = mcl_item_id.get_mod_namespace(id_modname)
|
||||
for mod, ids in pairs(same_id) do
|
||||
for _, id in pairs(ids) do
|
||||
if itemstring == "mcl_" .. mod .. ":" .. id then
|
||||
|
@ -48,16 +62,12 @@ tt.register_snippet(function(itemstring)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if mod_namespace then
|
||||
new_id = mod_namespace .. id_part2
|
||||
end
|
||||
if new_id ~= game .. ":book_enchanted" then
|
||||
if mod_namespace ~= game then
|
||||
new_id = mod_namespace .. id_string
|
||||
else
|
||||
minetest.register_alias_force(new_id, itemstring)
|
||||
end
|
||||
if minetest.settings:get_bool("mcl_item_id_debug", false) then
|
||||
return new_id, "#555555"
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_alias_force(game .. ":book_enchanted", "mcl_enchanting:book_enchanted")
|
||||
|
|
Loading…
Reference in a new issue