1
0
Fork 0

Fix some crashes with set_mod_namespace and bugs

This commit is contained in:
NO11 2021-07-24 14:09:47 +00:00
parent e44e9eaf62
commit c05e57efb1
1 changed files with 28 additions and 18 deletions

View File

@ -1,22 +1,38 @@
mcl_item_id = {} mcl_item_id = {
mod_namespaces = {},
}
local game = "mineclone" local game = "mineclone"
function mcl_item_id.set_mod_namespace(modname, namespace) function mcl_item_id.set_mod_namespace(modname, namespace)
local namespace = namespace or modname 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 end
function mcl_item_id.get_mod_namespace(modname) 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 if namespace then
return namespace return namespace
else else
return return game
end end
end end
local same_id = { local same_id = {
enchanting = { "table" },
experience = { "bottle" },
heads = { "skeleton", "zombie", "creeper", "wither_skeleton" }, heads = { "skeleton", "zombie", "creeper", "wither_skeleton" },
mobitems = { "rabbit", "chicken" }, mobitems = { "rabbit", "chicken" },
walls = { walls = {
@ -34,13 +50,11 @@ local same_id = {
tt.register_snippet(function(itemstring) tt.register_snippet(function(itemstring)
local def = minetest.registered_items[itemstring] local def = minetest.registered_items[itemstring]
local desc = def.description
local item_split = itemstring:find(":") local item_split = itemstring:find(":")
local id_part1 = itemstring:sub(1, item_split) local id_string = itemstring:sub(item_split)
local id_part2 = itemstring:sub(item_split) local id_modname = itemstring:sub(1, item_split - 1)
local modname = id_part1:gsub("%:", "") local new_id = game .. id_string
local new_id = game .. id_part2 local mod_namespace = mcl_item_id.get_mod_namespace(id_modname)
local mod_namespace = mcl_item_id.get_mod_namespace(modname)
for mod, ids in pairs(same_id) do for mod, ids in pairs(same_id) do
for _, id in pairs(ids) do for _, id in pairs(ids) do
if itemstring == "mcl_" .. mod .. ":" .. id then if itemstring == "mcl_" .. mod .. ":" .. id then
@ -48,16 +62,12 @@ tt.register_snippet(function(itemstring)
end end
end end
end end
if mod_namespace ~= game then
if mod_namespace then new_id = mod_namespace .. id_string
new_id = mod_namespace .. id_part2 else
end
if new_id ~= game .. ":book_enchanted" then
minetest.register_alias_force(new_id, itemstring) minetest.register_alias_force(new_id, itemstring)
end end
if minetest.settings:get_bool("mcl_item_id_debug", false) then if minetest.settings:get_bool("mcl_item_id_debug", false) then
return new_id, "#555555" return new_id, "#555555"
end end
end) end)
minetest.register_alias_force(game .. ":book_enchanted", "mcl_enchanting:book_enchanted")