mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Mending
This commit is contained in:
parent
fdbfd4c654
commit
a4d9d22bb0
5 changed files with 76 additions and 4 deletions
|
@ -331,7 +331,75 @@ 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.4 then
|
||||
mcl_experience.add_experience(collector, self._xp)
|
||||
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 repair = (65536 / uses) * xp * 2
|
||||
local new_wear = wear - repair
|
||||
if new_wear < 0 then
|
||||
xp = math.floor(-new_wear / 2)
|
||||
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)
|
||||
end
|
||||
self.object:remove()
|
||||
end
|
||||
return
|
||||
|
|
|
@ -132,6 +132,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
|
|||
-- Trick to disable digging as well
|
||||
on_use = function() return end,
|
||||
groups = {weapon=1,weapon_ranged=1,bow=1,enchantability=1},
|
||||
_mcl_uses = 385,
|
||||
})
|
||||
|
||||
-- Iterates through player inventory and resets all the bows in "charging" state back to their original stage
|
||||
|
@ -189,6 +190,7 @@ for level=0, 2 do
|
|||
on_place = function(itemstack)
|
||||
return itemstack
|
||||
end,
|
||||
_mcl_uses = 385,
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -409,8 +409,8 @@ mcl_enchanting.enchantments.lure = {
|
|||
power_range_table = {{15, 61}, {24, 71}, {33, 81}},
|
||||
}
|
||||
|
||||
-- unimplemented
|
||||
--[[mcl_enchanting.enchantments.mending = {
|
||||
-- implemented in mcl_experience
|
||||
mcl_enchanting.enchantments.mending = {
|
||||
name = S("Mending"),
|
||||
max_level = 1,
|
||||
primary = {},
|
||||
|
@ -424,7 +424,7 @@ mcl_enchanting.enchantments.lure = {
|
|||
requires_tool = true,
|
||||
treasure = true,
|
||||
power_range_table = {{25, 75}},
|
||||
}]]--
|
||||
}
|
||||
|
||||
-- requires missing MineClone2 feature
|
||||
--[[mcl_enchanting.enchantments.multishot = {
|
||||
|
|
|
@ -70,6 +70,7 @@ minetest.register_tool("mcl_fire:flint_and_steel", {
|
|||
return stack
|
||||
end,
|
||||
sound = { breaks = "default_tool_breaks" },
|
||||
_mcl_uses = 65,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
|
|
@ -330,6 +330,7 @@ minetest.register_tool("mcl_fishing:fishing_rod", {
|
|||
on_place = fish,
|
||||
on_secondary_use = fish,
|
||||
sound = { breaks = "default_tool_breaks" },
|
||||
_mcl_uses = 65,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
|
Loading…
Reference in a new issue