Merge branch 'master' into mineclone5

This commit is contained in:
Lizzy Fleckenstein 2021-04-29 11:59:04 +02:00
commit df8b4dddec
3 changed files with 37 additions and 8 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

After

Width:  |  Height:  |  Size: 144 B

View File

@ -92,9 +92,11 @@ function mcl_armor.register_set(def)
local groups = def.groups or {} local groups = def.groups or {}
local on_equip_callbacks = def.on_equip_callbacks or {} local on_equip_callbacks = def.on_equip_callbacks or {}
local on_unequip_callbacks = def.on_unequip_callbacks or {} local on_unequip_callbacks = def.on_unequip_callbacks or {}
local on_break_callbacks = def.on_break_callbacks or {}
local textures = def.textures or {} local textures = def.textures or {}
local previews = def.previews or {} local previews = def.previews or {}
local durabilities = def.durabilities or {} local durabilities = def.durabilities or {}
local element_groups = def.element_groups or {}
for name, element in pairs(mcl_armor.elements) do for name, element in pairs(mcl_armor.elements) do
local itemname = element.name .. "_" .. def.name local itemname = element.name .. "_" .. def.name
@ -110,6 +112,10 @@ function mcl_armor.register_set(def)
groups.mcl_armor_uses = (durabilities[name] or math.floor(def.durability * element.durability)) + 1 groups.mcl_armor_uses = (durabilities[name] or math.floor(def.durability * element.durability)) + 1
groups.enchantability = def.enchantability groups.enchantability = def.enchantability
for k, v in pairs(element_groups) do
groups[k] = v
end
minetest.register_tool(itemstring, { minetest.register_tool(itemstring, {
description = S(def.description .. " " .. (descriptions[name] or element.description)), description = S(def.description .. " " .. (descriptions[name] or element.description)),
_doc_items_longdesc = mcl_armor.longdesc, _doc_items_longdesc = mcl_armor.longdesc,
@ -125,6 +131,7 @@ function mcl_armor.register_set(def)
on_secondary_use = mcl_armor.equip_on_use, on_secondary_use = mcl_armor.equip_on_use,
_on_equip = on_equip_callbacks[name] or def.on_equip, _on_equip = on_equip_callbacks[name] or def.on_equip,
_on_unequip = on_unequip_callbacks[name] or def.on_unequip, _on_unequip = on_unequip_callbacks[name] or def.on_unequip,
_on_break = on_break_callbacks[name] or def.on_break,
_mcl_armor_element = name, _mcl_armor_element = name,
_mcl_armor_texture = textures[name] or modname .. "_" .. itemname .. ".png", _mcl_armor_texture = textures[name] or modname .. "_" .. itemname .. ".png",
_mcl_armor_preview = previews[name] or modname .. "_" .. itemname .. "_preview.png", _mcl_armor_preview = previews[name] or modname .. "_" .. itemname .. "_preview.png",
@ -203,12 +210,26 @@ function mcl_armor.update(obj)
if not itemstack:is_empty() then if not itemstack:is_empty() then
local def = itemstack:get_definition() local def = itemstack:get_definition()
if def._mcl_armor_texture then local texture = def._mcl_armor_texture
info.texture = "(" .. def._mcl_armor_texture .. ")" .. (info.texture and "^" .. info.texture or "")
if texture then
if type(texture) == "function" then
texture = texture(obj, itemstack)
end
if texture then
info.texture = "(" .. texture .. ")" .. (info.texture and "^" .. info.texture or "")
end
end end
if obj:is_player() and def._mcl_armor_preview then local preview = def._mcl_armor_preview
info.preview = "(player.png^[opacity:0^" .. def._mcl_armor_preview .. ")" .. (info.preview and "^" .. info.preview or "" )
if obj:is_player() and preview then
if type(preview) == "function" then
preview = preview(obj, itemstack)
end
if preview then
info.preview = "(player.png^[opacity:0^" .. def._mcl_armor_preview .. ")" .. (info.preview and "^" .. info.preview or "" )
end
end end
info.points = info.points + minetest.get_item_group(itemname, "mcl_armor_points") info.points = info.points + minetest.get_item_group(itemname, "mcl_armor_points")

View File

@ -1,3 +1,12 @@
local function use_durability(obj, inv, index, stack, uses)
local def = stack:get_definition()
mcl_util.use_item_durability(stack, uses)
if stack:is_empty() and def and def._on_break then
stack = def._on_break(obj) or stack
end
inv:set_stack("armor", index, stack)
end
mcl_damage.register_modifier(function(obj, damage, reason) mcl_damage.register_modifier(function(obj, damage, reason)
local flags = reason.flags local flags = reason.flags
@ -28,8 +37,7 @@ mcl_damage.register_modifier(function(obj, damage, reason)
points = points + minetest.get_item_group(itemname, "mcl_armor_points") points = points + minetest.get_item_group(itemname, "mcl_armor_points")
toughness = toughness + minetest.get_item_group(itemname, "mcl_armor_toughness") toughness = toughness + minetest.get_item_group(itemname, "mcl_armor_toughness")
mcl_util.use_item_durability(itemstack, uses) use_durability(obj, inv, element.index, itemstack, uses)
inv:set_stack("armor", element.index, itemstack)
end end
if not flags.bypasses_magic then if not flags.bypasses_magic then
@ -84,8 +92,8 @@ mcl_damage.register_modifier(function(obj, damage, reason)
mcl_util.deal_damage(reason.source, thorns_damage, {type = "thorns", direct = obj}) mcl_util.deal_damage(reason.source, thorns_damage, {type = "thorns", direct = obj})
local thorns_item = thorns_pieces[math.random(#thorns_pieces)] local thorns_item = thorns_pieces[math.random(#thorns_pieces)]
mcl_util.use_item_durability(thorns_item.itemstack, 2)
inv:set_stack("armor", thorns_item.index, thorns_item.itemstack) use_durability(obj, inv, thorns_item.index, thorns_item.itemstack, 2)
end end
mcl_armor.update(obj) mcl_armor.update(obj)