From b89ffb12f2859801d227be98ebeeab0c1363ab6e Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 2 Nov 2020 17:38:51 +0100 Subject: [PATCH] Unbreaking for fishing rods --- mods/CORE/mcl_enchanting/enchantments.lua | 2 +- mods/ITEMS/mcl_fishing/init.lua | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/mods/CORE/mcl_enchanting/enchantments.lua b/mods/CORE/mcl_enchanting/enchantments.lua index e48e845727..dd505e9606 100644 --- a/mods/CORE/mcl_enchanting/enchantments.lua +++ b/mods/CORE/mcl_enchanting/enchantments.lua @@ -460,7 +460,7 @@ mcl_enchanting.enchantments.thorns = { requires_tool = false, } --- for tools & weapons implemented via on_enchant; for bows implemented in mcl_bows; for armor implemented in mcl_armor and mcl_tt; unimplemented for Fishing Rods +-- for tools & weapons implemented via on_enchant; for bows implemented in mcl_bows; for armor implemented in mcl_armor and mcl_tt; for fishing rods implemented in mcl_fishing mcl_enchanting.enchantments.unbreaking = { name = "Unbreaking", max_level = 3, diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index 833dded521..b7e1ba73ae 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -32,16 +32,20 @@ local fish = function(itemstack, player) local num = 0 local ent = nil local noent = true - + + + local durability = 65 + local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking") + if unbreaking > 0 then + durability = durability * (unbreaking + 1) + end + --Check for bobber if so handle. for n = 1, #objs do ent = objs[n]:get_luaentity() if ent then if ent.player and ent.objtype=="fishing" then if (player:get_player_name() == ent.player) then - if mcl_experience.throw_experience then - mcl_experience.throw_experience(pos, math.random(1,6)) - end noent = false if ent._dive == true then local itemname @@ -104,10 +108,13 @@ local fish = function(itemstack, player) if inv:room_for_item("main", item) then inv:add_item("main", item) end + if mcl_experience.throw_experience then + mcl_experience.throw_experience(pos, math.random(1,6)) + end if not minetest.is_creative_enabled(player:get_player_name()) then local idef = itemstack:get_definition() - itemstack:add_wear(65535/65) -- 65 uses + itemstack:add_wear(65535/durability) -- 65 uses if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true) end @@ -121,7 +128,7 @@ local fish = function(itemstack, player) if def.walkable then if not minetest.is_creative_enabled(player:get_player_name()) then local idef = itemstack:get_definition() - itemstack:add_wear((65535/65)*2) -- if so and not creative then wear double like in MC. + itemstack:add_wear((65535/durability)*2) -- if so and not creative then wear double like in MC. if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true) end @@ -177,7 +184,7 @@ local bobber_on_step = function(self, dtime) if self._tick % 5 == 0 and self.player ~= nil and player ~= nil then --Destroy bobber if item not wielded. local wield = player:get_wielded_item() - if ((not wield) or (minetest.get_item_groups(wield:get_name(), "fishing_rod") <= 0)) then + if ((not wield) or (minetest.get_item_group(wield:get_name(), "fishing_rod") <= 0)) then self.object:remove() return end