From 3fd1963da9c87aa91b5f1fcaa15c44cd508caac3 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sun, 1 Nov 2020 14:23:43 +0100 Subject: [PATCH] Compass support --- mods/CORE/mcl_enchanting/enchantments.lua | 2 +- mods/CORE/mcl_enchanting/tt.lua | 5 ++++- mods/HELP/tt/init.lua | 27 ++++++++++++++++++++--- mods/ITEMS/mcl_compass/depends.txt | 1 + mods/ITEMS/mcl_compass/init.lua | 8 +++++-- mods/PLAYER/mcl_death_drop/init.lua | 2 +- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/mods/CORE/mcl_enchanting/enchantments.lua b/mods/CORE/mcl_enchanting/enchantments.lua index dfe5559cb9..ee007b91d7 100644 --- a/mods/CORE/mcl_enchanting/enchantments.lua +++ b/mods/CORE/mcl_enchanting/enchantments.lua @@ -275,7 +275,7 @@ mcl_enchanting.enchantments.mending = { max_level = 1, primary = {}, secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true}, - disallow = {non_combat_armor = true, compass = true, clock = true}, + disallow = {}, incompatible = {infinity = true}, weight = 2, description = "Repair the item while gaining XP orbs.", diff --git a/mods/CORE/mcl_enchanting/tt.lua b/mods/CORE/mcl_enchanting/tt.lua index f9b8e34c1d..e6529b0586 100644 --- a/mods/CORE/mcl_enchanting/tt.lua +++ b/mods/CORE/mcl_enchanting/tt.lua @@ -8,7 +8,10 @@ function mcl_enchanting.enchantments_snippet(_, _, itemstack) text = text .. mcl_enchanting.get_colorized_enchantment_description(enchantment, level) .. "\n" end if text ~= "" then - return text, false + if not itemstack:get_definition()._tt_original_description then + text = text:sub(1, text:len() - 1) + end + return text, false end end diff --git a/mods/HELP/tt/init.lua b/mods/HELP/tt/init.lua index a2b747ce83..aa42290bb3 100644 --- a/mods/HELP/tt/init.lua +++ b/mods/HELP/tt/init.lua @@ -14,6 +14,22 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua") -- Apply item description updates +local function equals(t1, t2) + for k, v in pairs(t1) do + local equal + local v2 = rawget(t2, k) + if type(v) == "table" then + equal = equals(v, v2) + else + equal = (v == v2) + end + if not equal then + return false + end + end + return true +end + local function apply_snippets(desc, itemstring, toolcaps, itemstack) local first = true -- Apply snippets @@ -61,11 +77,16 @@ tt.reload_itemstack_description = function(itemstack) local itemstring = itemstack:get_name() local def = itemstack:get_definition() local meta = itemstack:get_meta() - if def._mcl_generate_description then + if def and def._mcl_generate_description then def._mcl_generate_description(itemstack) elseif should_change(itemstring, def) and meta:get_string("name") == "" then - local orig_desc = def._tt_original_description - local desc = apply_snippets(orig_desc, itemstring, itemstack:get_tool_capabilities(), itemstack) + local toolcaps = itemstack:get_tool_capabilities() + local hand_toolcaps = ItemStack(""):get_tool_capabilities() + if equals(toolcaps, hand_toolcaps) then + toolcaps = nil + end + local orig_desc = def._tt_original_description or def.description + local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack) if desc ~= orig_desc then meta:set_string("description", desc) end diff --git a/mods/ITEMS/mcl_compass/depends.txt b/mods/ITEMS/mcl_compass/depends.txt index 53261d53c9..0389d3050a 100644 --- a/mods/ITEMS/mcl_compass/depends.txt +++ b/mods/ITEMS/mcl_compass/depends.txt @@ -2,3 +2,4 @@ mcl_core mcl_worlds mesecons doc? +mcl_enchanting diff --git a/mods/ITEMS/mcl_compass/init.lua b/mods/ITEMS/mcl_compass/init.lua index 7a23cc50d3..1b2810de69 100644 --- a/mods/ITEMS/mcl_compass/init.lua +++ b/mods/ITEMS/mcl_compass/init.lua @@ -56,8 +56,12 @@ minetest.register_globalstep(function(dtime) for j,stack in ipairs(player:get_inventory():get_list("main")) do if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then - local count = stack:get_count() - player:get_inventory():set_stack("main", j, ItemStack("mcl_compass:"..compass_image.." "..count)) + local itemname = "mcl_compass:"..compass_image + if mcl_enchanting.is_enchanted(stack) then + itemname = itemname .. "_enchanted" + end + stack:set_name(itemname) + player:get_inventory():set_stack("main", j, stack) end end end diff --git a/mods/PLAYER/mcl_death_drop/init.lua b/mods/PLAYER/mcl_death_drop/init.lua index adad4b1e71..4e0fa6e629 100644 --- a/mods/PLAYER/mcl_death_drop/init.lua +++ b/mods/PLAYER/mcl_death_drop/init.lua @@ -23,7 +23,7 @@ minetest.register_on_dieplayer(function(player) local z = math.random(0, 9)/3 pos.x = pos.x + x pos.z = pos.z + z - if not void_deadly and drop and mcl_enchanting.get_enchantment(stack, "curse_of_vanishing") > 0 then + if not void_deadly and drop and mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then local def = minetest.registered_items[stack:get_name()] if def and def.on_drop then stack = def.on_drop(stack, player, pos)