make mcl_potions use the new virtual item API

This commit is contained in:
goblin_mode 2024-10-08 16:11:55 +02:00 committed by cora
parent 355c9c14af
commit fa89c0c311
4 changed files with 31 additions and 2 deletions

View File

@ -234,7 +234,8 @@ function mcl_potions.register_lingering(name, descr, color, def)
ent._plus = item:get_meta():get_int("mcl_potions:potion_plus")
ent._effect_list = def._effect_list
end
end
end,
_get_all_virtual_items = def._get_all_virtual_items
})
local w = 0.7

View File

@ -29,6 +29,27 @@ local potion_intro = S("Drinking a potion gives you a particular effect or set o
-- ██║░░░░░╚█████╔╝░░░██║░░░██║╚█████╔╝██║░╚███║██████╔╝
-- ╚═╝░░░░░░╚════╝░░░░╚═╝░░░╚═╝░╚════╝░╚═╝░░╚══╝╚═════╝░
local function generate_get_all_virtual_items_func(itemname, pdef)
return function()
local output = {brew = {}}
if pdef.has_potent then
local stack = ItemStack(itemname)
local potency = pdef._default_potent_level - 1
stack:get_meta():set_int("mcl_potions:potion_potent", potency)
tt.reload_itemstack_description(stack)
table.insert(output.brew, stack:to_string())
end
if pdef.has_plus then
local stack = ItemStack(itemname)
local extend = pdef._default_extend_level - 1
stack:get_meta():set_int("mcl_potions:potion_plus", extend)
tt.reload_itemstack_description(stack)
table.insert(output.brew, stack:to_string())
end
return output
end
end
local function generate_on_use(vanish, effects, _, on_use, custom_effect)
return function(itemstack, user, pointed_thing)
@ -211,6 +232,8 @@ function mcl_potions.register_potion(def)
local internal_def = table.copy(pdef)
local itemname = modname .. ":" .. name
pdef._get_all_virtual_items = generate_get_all_virtual_items_func(itemname, pdef)
minetest.register_craftitem (itemname, pdef)
if def.has_splash or def.has_splash == nil then
@ -230,6 +253,7 @@ function mcl_potions.register_potion(def)
sdef.custom_effect = def.custom_effect
sdef.on_splash = def.custom_splash_effect
sdef.base_potion = itemname
sdef._get_all_virtual_items = generate_get_all_virtual_items_func("mcl_potions:" .. name .. "_splash", sdef)
if not def._effect_list then sdef.instant = true end
mcl_potions.register_splash(name, splash_desc, color, sdef)
internal_def.has_splash = true
@ -253,6 +277,7 @@ function mcl_potions.register_potion(def)
ldef.on_splash = def.custom_splash_effect
ldef.while_lingering = def.custom_linger_effect
ldef.base_potion = itemname
ldef._get_all_virtual_items = generate_get_all_virtual_items_func("mcl_potions:" .. name .. "_lingering", ldef)
if not def._effect_list then ldef.instant = true end
mcl_potions.register_lingering(name, ling_desc, color, ldef)
internal_def.has_lingering = true
@ -281,6 +306,7 @@ function mcl_potions.register_potion(def)
adef._default_potent_level = pdef._default_potent_level
adef._default_extend_level = pdef._default_extend_level
adef.custom_effect = def.custom_effect
adef._get_all_virtual_items = generate_get_all_virtual_items_func("mcl_potions:" .. name .. "_arrow", adef)
if not def._effect_list then adef.instant = true end
mcl_potions.register_arrow(name, arr_desc, color, adef)
internal_def.has_arrow = true

View File

@ -67,7 +67,8 @@ function mcl_potions.register_splash(name, descr, color, def)
ent._plus = item:get_meta():get_int("mcl_potions:potion_plus")
ent._effect_list = def._effect_list
end
end
end,
_get_all_virtual_items = def._get_all_virtual_items
})
local w = 0.7

View File

@ -31,6 +31,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
_default_extend_level = def._default_extend_level,
inventory_image = "mcl_bows_arrow_inv.png^(mcl_potions_arrow_inv.png^[colorize:"..color..":100)",
groups = groups,
_get_all_virtual_items = def._get_all_virtual_items
}))
local ARROW_ENTITY = table.copy(minetest.registered_entities["mcl_bows:arrow_entity"])