Allow tool repairs on workbench mod coexits with game mechanish

* adapt the fix from the upstream by mt-sane
* becouse there is is also the anvil,
* This also fixes the problem with the vanishing of the tools
  when using the repair craft.
* closed https://github.com/Bremaweb/adventuretest/pull/26
* close #26
* close https://codeber.org/minenux/minetest-game-adventuretest/pulls/26
master
mckaygerhard 2023-01-12 13:49:29 -04:00
parent 0af5f94e21
commit 5ba7c54408
1 changed files with 42 additions and 12 deletions

View File

@ -89,21 +89,51 @@ local function inventory_set(player, size)
end
local function on_craft(itemstack,player,old_craftgrid,craft_inv)
if itemstack:get_definition().skill ~= nil then
local name = player:get_player_name()
local probability = skills.get_probability(name,SKILL_CRAFTING,itemstack:get_definition().skill)
local rangeLow = ( probability - 10 ) / 100
probability = probability / 100
local wear = math.floor(50000 - ( 50000 * math.random(rangeLow,probability) ))
itemstack:add_wear(wear)
local i = skills.add_skill_exp(name,SKILL_CRAFTING,1)
local ii = skills.add_skill_exp(name,itemstack:get_definition().skill,1)
if i or ii then
local name = player:get_player_name()
if not name then return nil end
local craftItemDef = itemstack:get_definition()
if not craftItemDef then return nil end
local craftItemSkill = craftItemDef.skill
if not craftItemSkill then return nil end
if craftItemDef.type == "tool" then
local isSameItem = true
local itemCount = 0
local craftedItemName = craftItemDef.name
for _,recipeStack in ipairs(old_craftgrid) do
local recipeItemName = recipeStack:get_name()
if recipeItemName ~= "" then
itemCount = itemCount + 1
if itemCount > 2 then break end
if recipeItemName ~= craftedItemName then
isSameItem = false
break
end
end
end
if isSameItem and itemCount == 2 then
-- Yes we can ... repair
return nil
end
end
local probability = skills.get_probability(name, SKILL_CRAFTING, craftItemSkill)
local rangeLow = math.max(( probability - 10 ) / 100, 0.0)
probability = probability / 100
local wear = math.floor(50000 - ( 50000 * math.random(rangeLow,probability) ))
itemstack:add_wear(wear)
local craftItemDefw = itemstack:get_definition()
local craftItemSkillw = craftItemDefw.skill
-- local i = skills.add_skill_exp(name,SKILL_CRAFTING,1)
local ii = skills.add_skill_exp(name,craftItemSkillw,1)
if ii then
minetest.chat_send_player(name,"Your skills are increasing!")
end
return itemstack
end
return nil
end
minetest.register_on_craft(on_craft)