Making crafting recipes add wear to tools

Post Reply
MHL
Member
Posts: 404
Joined: Mon Aug 20, 2018 00:44
GitHub: NOT APPLICABLE
IRC: MCL
In-game: singleplayer
Location: Somewhere in SSWZ
Contact:

Making crafting recipes add wear to tools

by MHL » Post

How to make a crafting recipe that will output a weared tool?
COME SEE MY MINETEST MAP!!! FRANCAIS TRADDUCCIONS COMING SOON! ČESKY PŘEKLAD JIŽ NEDLOUHO!!!

User avatar
AiTechEye
Member
Posts: 890
Joined: Fri May 29, 2015 21:14
GitHub: AiTechEye
Location: ¯\_(ツ)_/¯

Re: Making crafting recipes add wear to tools

by AiTechEye » Post

"tool count wear"

Code: Select all

minetest.register_craft({
	output = "default:pick_wood 1 60000",
	recipe = {
		{"","default:dirt",""},
		{"","default:stick",""},
		{"","default:stick",""},
	}
})
you can also do /giveme default:pick_wood 1 60000

MHL
Member
Posts: 404
Joined: Mon Aug 20, 2018 00:44
GitHub: NOT APPLICABLE
IRC: MCL
In-game: singleplayer
Location: Somewhere in SSWZ
Contact:

Re: Making crafting recipes add wear to tools

by MHL » Post

Is there a way to get the durability of a tool subtract a value from it and output a tool with that durability.
Example:
Recipe: [] [default:dirt] []
[] [default:pick_stone (full durability)] [] | Output = default:pick_stone (durability of 50,000)
[] [] []
COME SEE MY MINETEST MAP!!! FRANCAIS TRADDUCCIONS COMING SOON! ČESKY PŘEKLAD JIŽ NEDLOUHO!!!

User avatar
AiTechEye
Member
Posts: 890
Joined: Fri May 29, 2015 21:14
GitHub: AiTechEye
Location: ¯\_(ツ)_/¯

Re: Making crafting recipes add wear to tools

by AiTechEye » Post

I do not fully understand what you mean, but try this:

wood pick + dirt = +repair 50%

Code: Select all

minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv)
	if itemstack:get_name()=="default:pick_wood" then

		local wear=0
		local dirt=false

		for i, it in pairs(old_craft_grid) do
			if it:get_name()=="default:pick_wood" then
				wear=it:get_wear()
			elseif it:get_name()=="default:dirt" then
				dirt=true
			end
		end
		if dirt then
			local new_wear=wear - (65534/2)
			if new_wear<0 then new_wear=0 end-- 	-wear makes it start over on 65535
			return "default:pick_wood 1 " .. new_wear
		end
	end
	return itemstack
end)

minetest.register_craft({
	output ="default:pick_wood",
	recipe = {
  		{"","default:dirt",""},
     		{"","default:pick_wood",""},
     		{"","",""},
	}
})
and try this too:

Code: Select all

print(minetest.registered_items["default:pick_wood"].tool_capabilities.groupcaps.cracky.uses)
print(dump(minetest.registered_items["default:pick_wood"]))

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests