From 778ddd555fb5be96c2d7dc77d3542120e4848543 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 12 Feb 2021 09:20:32 +0100 Subject: [PATCH 1/3] Move mending code to add_experience function --- mods/HUD/mcl_experience/init.lua | 140 +++++++++++++++---------------- 1 file changed, 68 insertions(+), 72 deletions(-) diff --git a/mods/HUD/mcl_experience/init.lua b/mods/HUD/mcl_experience/init.lua index ff5647616..32c2d9424 100644 --- a/mods/HUD/mcl_experience/init.lua +++ b/mods/HUD/mcl_experience/init.lua @@ -238,6 +238,73 @@ function mcl_experience.add_experience(player, experience) local name = player:get_player_name() local temp_pool = pool[name] + local inv = player:get_inventory() + local candidates = { + {list = "main", index = player:get_wield_index()}, + {list = "armor", index = 2}, + {list = "armor", index = 3}, + {list = "armor", index = 4}, + {list = "armor", index = 5}, + } + local final_candidates = {} + for _, can in ipairs(candidates) do + local stack = inv:get_stack(can.list, can.index) + local wear = stack:get_wear() + if mcl_enchanting.has_enchantment(stack, "mending") and wear > 0 then + can.stack = stack + can.wear = wear + table.insert(final_candidates, can) + end + end + if #final_candidates > 0 then + local can = final_candidates[math.random(#final_candidates)] + local stack, list, index, wear = can.stack, can.list, can.index, can.wear + local unbreaking_level = mcl_enchanting.get_enchantment(stack, "unbreaking") + local uses + local armor_uses = minetest.get_item_group(stack:get_name(), "mcl_armor_uses") + if armor_uses > 0 then + uses = armor_uses + if unbreaking_level > 0 then + uses = uses / (0.6 + 0.4 / (unbreaking_level + 1)) + end + else + local def = stack:get_definition() + if def then + local fixed_uses = def._mcl_uses + if fixed_uses then + uses = fixed_uses + if unbreaking_level > 0 then + uses = uses * (unbreaking_level + 1) + end + end + end + if not uses then + local toolcaps = stack:get_tool_capabilities() + local groupcaps = toolcaps.groupcaps + for _, v in pairs(groupcaps) do + uses = v.uses + break + end + end + end + uses = uses or 0 + local multiplier = 2 * 65535 / uses + local repair = experience * multiplier + local new_wear = wear - repair + if new_wear < 0 then + experience = math.floor(-new_wear / multiplier + 0.5) + new_wear = 0 + else + experience = 0 + end + stack:set_wear(math.floor(new_wear)) + inv:set_stack(list, index, stack) + if can.list == "armor" then + local armor_inv = minetest.get_inventory({type = "detached", name = player:get_player_name() .. "_armor"}) + armor_inv:set_stack(list, index, stack) + end + end + local old_bar, old_xp, old_level = temp_pool.bar, temp_pool.xp, temp_pool.level temp_pool.xp = math.min(math.max(temp_pool.xp + experience, 0), max_xp) @@ -333,78 +400,7 @@ local function xp_step(self, dtime) acceleration = vector.new(goal.x-currentvel.x,goal.y-currentvel.y,goal.z-currentvel.z) self.object:add_velocity(vector.add(acceleration,player_velocity)) elseif distance < 0.8 then - local xp = self._xp - local inv = collector:get_inventory() - local candidates = { - {list = "main", index = collector:get_wield_index()}, - {list = "armor", index = 2}, - {list = "armor", index = 3}, - {list = "armor", index = 4}, - {list = "armor", index = 5}, - } - local final_candidates = {} - for _, can in ipairs(candidates) do - local stack = inv:get_stack(can.list, can.index) - local wear = stack:get_wear() - if mcl_enchanting.has_enchantment(stack, "mending") and wear > 0 then - can.stack = stack - can.wear = wear - table.insert(final_candidates, can) - end - end - if #final_candidates > 0 then - local can = final_candidates[math.random(#final_candidates)] - local stack, list, index, wear = can.stack, can.list, can.index, can.wear - local unbreaking_level = mcl_enchanting.get_enchantment(stack, "unbreaking") - local uses - local armor_uses = minetest.get_item_group(stack:get_name(), "mcl_armor_uses") - if armor_uses > 0 then - uses = armor_uses - if unbreaking_level > 0 then - uses = uses / (0.6 + 0.4 / (unbreaking_level + 1)) - end - else - local def = stack:get_definition() - if def then - local fixed_uses = def._mcl_uses - if fixed_uses then - uses = fixed_uses - if unbreaking_level > 0 then - uses = uses * (unbreaking_level + 1) - end - end - end - if not uses then - local toolcaps = stack:get_tool_capabilities() - local groupcaps = toolcaps.groupcaps - for _, v in pairs(groupcaps) do - uses = v.uses - break - end - end - end - uses = uses or 0 - local multiplier = 2 * 65535 / uses - local repair = xp * multiplier - local new_wear = wear - repair - if new_wear < 0 then - xp = math.floor(-new_wear / multiplier + 0.5) - new_wear = 0 - else - xp = 0 - end - stack:set_wear(math.floor(new_wear)) - inv:set_stack(list, index, stack) - if can.list == "armor" then - local armor_inv = minetest.get_inventory({type = "detached", name = collector:get_player_name() .. "_armor"}) - armor_inv:set_stack(list, index, stack) - end - end - if xp > 0 then - mcl_experience.add_experience(collector, xp) - else - minetest.sound_play("experience",{gain=0.1,to_player = name,pitch=math.random(75,99)/100}) - end + mcl_experience.add_experience(collector, self._xp) self.object:remove() end return From 0dd0c3623e7c4752420743b135ea1f8a71ed2aaa Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 12 Feb 2021 09:25:23 +0100 Subject: [PATCH 2/3] Proper default for 3d_player_preview in settingtypes.txt --- settingtypes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settingtypes.txt b/settingtypes.txt index 7acccf91c..264757db8 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -95,7 +95,7 @@ fire_animation_frames (Fire Animation Frames) int 8 animated_chests (Animated chests) bool true # Whether to preview the player in inventory in 3D (requires Minetest 5.4) -3d_player_preview (3D Player preview) bool true +3d_player_preview (3D Player preview) bool false [Experimental] # Whether ice is translucent. If disabled, ice is fully opaque. From b2e2120b9ea6b7e46dda52cc5ec62804a0b9ab6c Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 12 Feb 2021 10:12:57 +0100 Subject: [PATCH 3/3] Fix shulkerbox model --- .../mcl_chests/models/mcl_chests_shulker.b3d | Bin 84495 -> 25624 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/mods/ITEMS/mcl_chests/models/mcl_chests_shulker.b3d b/mods/ITEMS/mcl_chests/models/mcl_chests_shulker.b3d index 86dde145ba44c0859b4d2f75e85d4f235ef76dcc..2592f86a0c299a010b242645a50ae98584eeab64 100644 GIT binary patch delta 4551 zcmds&yKh`Y6o;=Jp$K7Fk%FQaC*bgg0NKPm0*?1Aj(LQKF}Cx71YD3%g7^ox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