1
0
Fork 0

Merge (latest mcl_enchanting)

production
kay27 2021-04-26 00:34:15 +00:00
commit 0a6c3a4414
3 changed files with 18 additions and 9 deletions

View File

@ -770,6 +770,11 @@ mcl_enchanting.enchantments.unbreaking = {
description = S("Increases item durability."), description = S("Increases item durability."),
curse = false, curse = false,
on_enchant = function(itemstack, level) on_enchant = function(itemstack, level)
local name = itemstack:get_name()
if not minetest.registered_tools[name].tool_capabilities then
return
end
local tool_capabilities = itemstack:get_tool_capabilities() local tool_capabilities = itemstack:get_tool_capabilities()
tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * (1 + level) tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * (1 + level)
itemstack:get_meta():set_tool_capabilities(tool_capabilities) itemstack:get_meta():set_tool_capabilities(tool_capabilities)

View File

@ -12,7 +12,7 @@ end
function mcl_enchanting.unload_enchantments(itemstack) function mcl_enchanting.unload_enchantments(itemstack)
local itemdef = itemstack:get_definition() local itemdef = itemstack:get_definition()
if itemdef.tool_capabilities then if itemdef.tool_capabilities then
itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities) itemstack:get_meta():set_tool_capabilities(nil)
end end
local meta = itemstack:get_meta() local meta = itemstack:get_meta()
if meta:get_string("name") == "" then if meta:get_string("name") == "" then
@ -469,13 +469,13 @@ function mcl_enchanting.show_enchanting_formspec(player)
local formspec = "" local formspec = ""
.. "size[9.07,8.6;]" .. "size[9.07,8.6;]"
.. "formspec_version[3]" .. "formspec_version[3]"
.. "label[0,0;" .. C(mcl_colors.DARK_GRAY) .. F(table_name) .. "]" .. "label[0,0;" .. C("#313131") .. F(table_name) .. "]"
.. mcl_formspec.get_itemslot_bg(0.2, 2.4, 1, 1) .. mcl_formspec.get_itemslot_bg(0.2, 2.4, 1, 1)
.. "list[current_player;enchanting_item;0.2,2.4;1,1]" .. "list[current_player;enchanting_item;0.2,2.4;1,1]"
.. mcl_formspec.get_itemslot_bg(1.1, 2.4, 1, 1) .. mcl_formspec.get_itemslot_bg(1.1, 2.4, 1, 1)
.. "image[1.1,2.4;1,1;mcl_enchanting_lapis_background.png]" .. "image[1.1,2.4;1,1;mcl_enchanting_lapis_background.png]"
.. "list[current_player;enchanting_lapis;1.1,2.4;1,1]" .. "list[current_player;enchanting_lapis;1.1,2.4;1,1]"
.. "label[0,4;" .. C(mcl_colors.DARK_GRAY) .. F(S("Inventory")).."]" .. "label[0,4;" .. C("#313131") .. F(S("Inventory")).."]"
.. mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3) .. mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3)
.. mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1) .. mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1)
.. "list[current_player;main;0,4.5;9,3;9]" .. "list[current_player;main;0,4.5;9,3;9]"
@ -502,11 +502,11 @@ function mcl_enchanting.show_enchanting_formspec(player)
local hover_ending = (can_enchant and "_hovered" or "_off") local hover_ending = (can_enchant and "_hovered" or "_off")
formspec = formspec formspec = formspec
.. "container[3.2," .. y .. "]" .. "container[3.2," .. y .. "]"
.. (slot and "tooltip[button_" .. i .. ";" .. C(mcl_colors.GRAY) .. ((slot.description and F(slot.description)) or "") .. " " .. C(mcl_colors.WHITE) .. " . . . ?\n\n" .. (enough_levels and C(enough_lapis and mcl_colors.GRAY or mcl_colors.RED) .. F(S("@1 Lapis Lazuli", i)) .. "\n" .. C(mcl_colors.GRAY) .. F(S("@1 Enchantment Levels", i)) or C(mcl_colors.RED) .. F(S("Level requirement: @1", slot.level_requirement))) .. "]" or "") .. (slot and "tooltip[button_" .. i .. ";" .. C("#818181") .. ((slot.description and F(slot.description)) or "") .. " " .. C("#FFFFFF") .. " . . . ?\n\n" .. (enough_levels and C(enough_lapis and "#818181" or "#FC5454") .. F(S("@1 Lapis Lazuli", i)) .. "\n" .. C("#818181") .. F(S("@1 Enchantment Levels", i)) or C("#FC5454") .. F(S("Level requirement: @1", slot.level_requirement))) .. "]" or "")
.. "style[button_" .. i .. ";bgimg=mcl_enchanting_button" .. ending .. ".png;bgimg_hovered=mcl_enchanting_button" .. hover_ending .. ".png;bgimg_pressed=mcl_enchanting_button" .. hover_ending .. ".png]" .. "style[button_" .. i .. ";bgimg=mcl_enchanting_button" .. ending .. ".png;bgimg_hovered=mcl_enchanting_button" .. hover_ending .. ".png;bgimg_pressed=mcl_enchanting_button" .. hover_ending .. ".png]"
.. "button[0,0;7.5,1.3;button_" .. i .. ";]" .. "button[0,0;7.5,1.3;button_" .. i .. ";]"
.. (slot and "image[0,0;1.3,1.3;mcl_enchanting_number_" .. i .. ending .. ".png]" or "") .. (slot and "image[0,0;1.3,1.3;mcl_enchanting_number_" .. i .. ending .. ".png]" or "")
.. (slot and "label[7.2,1.1;" .. C(can_enchant and mcl_colors.GREEN or mcl_colors.DARK_GREEN) .. slot.level_requirement .. "]" or "") .. (slot and "label[7.2,1.1;" .. C(can_enchant and "#80FF20" or "#407F10") .. slot.level_requirement .. "]" or "")
.. (slot and slot.glyphs or "") .. (slot and slot.glyphs or "")
.. "container_end[]" .. "container_end[]"
y = y + 1.35 y = y + 1.35

View File

@ -45,22 +45,26 @@ end
-- To make it more efficient it will first check a hash value to determine if -- To make it more efficient it will first check a hash value to determine if
-- the tool needs to be updated. -- the tool needs to be updated.
function mcl_enchanting.update_groupcaps(itemstack) function mcl_enchanting.update_groupcaps(itemstack)
if not itemstack:get_meta():get("tool_capabilities") then local name = itemstack:get_name()
if not minetest.registered_tools[name].tool_capabilities then
return return
end end
local name = itemstack:get_name()
local efficiency = mcl_enchanting.get_enchantment(itemstack, "efficiency") local efficiency = mcl_enchanting.get_enchantment(itemstack, "efficiency")
local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking")
if unbreaking == 0 and efficiency == 0 then
return
end
local groupcaps = get_efficiency_groupcaps(name, efficiency) local groupcaps = get_efficiency_groupcaps(name, efficiency)
local hash = itemstack:get_meta():get_string("groupcaps_hash") local hash = itemstack:get_meta():get_string("groupcaps_hash")
if not hash or hash ~= groupcaps.hash then if not hash or hash ~= groupcaps.hash then
local tool_capabilities = itemstack:get_tool_capabilities() local tool_capabilities = itemstack:get_tool_capabilities()
tool_capabilities.groupcaps = groupcaps.values tool_capabilities.groupcaps = table.copy(groupcaps.values)
-- Increase the number of uses depending on the unbreaking level -- Increase the number of uses depending on the unbreaking level
-- of the tool. -- of the tool.
local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking")
for group, capability in pairs(tool_capabilities.groupcaps) do for group, capability in pairs(tool_capabilities.groupcaps) do
capability.uses = capability.uses * (1 + unbreaking) capability.uses = capability.uses * (1 + unbreaking)
end end