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
This commit is contained in:
parent
0af5f94e21
commit
5ba7c54408
@ -89,21 +89,51 @@ local function inventory_set(player, size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function on_craft(itemstack,player,old_craftgrid,craft_inv)
|
local function on_craft(itemstack,player,old_craftgrid,craft_inv)
|
||||||
if itemstack:get_definition().skill ~= nil then
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local probability = skills.get_probability(name,SKILL_CRAFTING,itemstack:get_definition().skill)
|
if not name then return nil end
|
||||||
local rangeLow = ( probability - 10 ) / 100
|
|
||||||
probability = probability / 100
|
local craftItemDef = itemstack:get_definition()
|
||||||
local wear = math.floor(50000 - ( 50000 * math.random(rangeLow,probability) ))
|
if not craftItemDef then return nil end
|
||||||
itemstack:add_wear(wear)
|
|
||||||
local i = skills.add_skill_exp(name,SKILL_CRAFTING,1)
|
local craftItemSkill = craftItemDef.skill
|
||||||
local ii = skills.add_skill_exp(name,itemstack:get_definition().skill,1)
|
if not craftItemSkill then return nil end
|
||||||
if i or ii then
|
|
||||||
|
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!")
|
minetest.chat_send_player(name,"Your skills are increasing!")
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_craft(on_craft)
|
minetest.register_on_craft(on_craft)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user