2014-10-28 18:01:32 +01:00
|
|
|
|
|
|
|
-- Hoe registration function
|
|
|
|
|
|
|
|
farming.register_hoe = function(name, def)
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- Check for : prefix (register new hoes in your mod's namespace)
|
|
|
|
if name:sub(1,1) ~= ":" then
|
|
|
|
name = ":" .. name
|
|
|
|
end
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- Check def table
|
|
|
|
if def.description == nil then
|
|
|
|
def.description = "Hoe"
|
|
|
|
end
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
if def.inventory_image == nil then
|
|
|
|
def.inventory_image = "unknown_item.png"
|
|
|
|
end
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
if def.recipe == nil then
|
|
|
|
def.recipe = {
|
|
|
|
{"air","air",""},
|
|
|
|
{"","group:stick",""},
|
|
|
|
{"","group:stick",""}
|
|
|
|
}
|
|
|
|
end
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
if def.max_uses == nil then
|
|
|
|
def.max_uses = 30
|
|
|
|
end
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- Register the tool
|
|
|
|
minetest.register_tool(name, {
|
|
|
|
description = def.description,
|
|
|
|
inventory_image = def.inventory_image,
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
return farming.hoe_on_use(itemstack, user, pointed_thing, def.max_uses)
|
|
|
|
end
|
|
|
|
})
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- Register its recipe
|
2015-08-24 16:44:20 +02:00
|
|
|
-- Registration using material made for MFF
|
2015-03-03 22:04:16 +01:00
|
|
|
if def.material == nil then
|
|
|
|
minetest.register_craft({
|
|
|
|
output = name:sub(2),
|
|
|
|
recipe = def.recipe
|
|
|
|
})
|
|
|
|
else
|
|
|
|
minetest.register_craft({
|
|
|
|
output = name:sub(2),
|
|
|
|
recipe = {
|
|
|
|
{def.material, def.material, ""},
|
|
|
|
{"", "group:stick", ""},
|
|
|
|
{"", "group:stick", ""}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
-- Reverse Recipe
|
|
|
|
minetest.register_craft({
|
|
|
|
output = name:sub(2),
|
|
|
|
recipe = {
|
|
|
|
{"", def.material, def.material},
|
|
|
|
{"", "group:stick", ""},
|
|
|
|
{"", "group:stick", ""}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
2014-10-28 18:01:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Turns dirt with group soil=1 into soil
|
|
|
|
|
|
|
|
function farming.hoe_on_use(itemstack, user, pointed_thing, uses)
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
local pt = pointed_thing
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- check if pointing at a node
|
2014-11-13 23:31:49 +01:00
|
|
|
if not pt or pt.type ~= "node" then
|
2014-10-28 18:01:32 +01:00
|
|
|
return
|
|
|
|
end
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
local under = minetest.get_node(pt.under)
|
|
|
|
local upos = pointed_thing.under
|
|
|
|
|
|
|
|
if minetest.is_protected(upos, user:get_player_name()) then
|
|
|
|
minetest.record_protection_violation(upos, user:get_player_name())
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-10-26 23:43:06 +01:00
|
|
|
local p = {x = pt.under.x, y = pt.under.y + 1, z = pt.under.z}
|
2014-10-28 18:01:32 +01:00
|
|
|
local above = minetest.get_node(p)
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- return if any of the nodes is not registered
|
2014-11-13 23:31:49 +01:00
|
|
|
if not minetest.registered_nodes[under.name]
|
|
|
|
or not minetest.registered_nodes[above.name] then
|
2014-10-28 18:01:32 +01:00
|
|
|
return
|
|
|
|
end
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- check if the node above the pointed thing is air
|
|
|
|
if above.name ~= "air" then
|
|
|
|
return
|
|
|
|
end
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- check if pointing at dirt
|
|
|
|
if minetest.get_item_group(under.name, "soil") ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- turn the node into soil, wear out item and play sound
|
2015-08-24 16:44:20 +02:00
|
|
|
minetest.set_node(pt.under, {name = "farming:soil"})
|
2016-03-05 19:14:24 +01:00
|
|
|
|
2015-08-24 16:44:20 +02:00
|
|
|
minetest.sound_play("default_dig_crumbly", {pos = pt.under, gain = 0.5})
|
2015-07-26 19:04:41 +02:00
|
|
|
if not minetest.setting_getbool("creative_mode") then --MFF DEBUT crabman(26/07/2015) not wearout if creative mod and invtweak refill break tools
|
|
|
|
local tool_name = itemstack:get_name()
|
|
|
|
itemstack:add_wear(65535/(uses-1))
|
|
|
|
if itemstack:get_wear() == 0 and minetest.get_modpath("invtweak") then
|
|
|
|
local index = user:get_wield_index()
|
|
|
|
minetest.sound_play("invtweak_tool_break", {pos = user:getpos(), gain = 0.9, max_hear_distance = 5})
|
|
|
|
minetest.after(0.20, refill, user, tool_name, index)
|
|
|
|
end
|
|
|
|
end --MFF FIN
|
2014-10-28 18:01:32 +01:00
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Define Hoes
|
2015-08-24 16:44:20 +02:00
|
|
|
-- Material fields added for MFF
|
2014-10-28 18:01:32 +01:00
|
|
|
|
|
|
|
farming.register_hoe(":farming:hoe_wood", {
|
|
|
|
description = "Wooden Hoe",
|
|
|
|
inventory_image = "farming_tool_woodhoe.png",
|
|
|
|
max_uses = 30,
|
2015-03-03 22:04:16 +01:00
|
|
|
material = "group:wood"
|
2014-10-28 18:01:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
farming.register_hoe(":farming:hoe_stone", {
|
|
|
|
description = "Stone Hoe",
|
|
|
|
inventory_image = "farming_tool_stonehoe.png",
|
|
|
|
max_uses = 90,
|
2015-03-03 22:04:16 +01:00
|
|
|
material = "group:stone"
|
2014-10-28 18:01:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
farming.register_hoe(":farming:hoe_steel", {
|
|
|
|
description = "Steel Hoe",
|
|
|
|
inventory_image = "farming_tool_steelhoe.png",
|
|
|
|
max_uses = 200,
|
2015-03-03 22:04:16 +01:00
|
|
|
material = "default:steel_ingot"
|
2014-10-28 18:01:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
farming.register_hoe(":farming:hoe_bronze", {
|
|
|
|
description = "Bronze Hoe",
|
|
|
|
inventory_image = "farming_tool_bronzehoe.png",
|
|
|
|
max_uses = 220,
|
2015-03-03 22:04:16 +01:00
|
|
|
material = "default:bronze_ingot"
|
2014-10-28 18:01:32 +01:00
|
|
|
})
|
|
|
|
|
2016-04-27 16:01:44 +02:00
|
|
|
farming.register_hoe(":farming:hoe_silver", {
|
|
|
|
description = "Silver Hoe",
|
|
|
|
inventory_image = "farming_tool_silverhoe.png",
|
|
|
|
max_uses = 300,
|
2016-06-03 21:52:52 +02:00
|
|
|
material = "default:silver_ingot"
|
2016-04-27 16:01:44 +02:00
|
|
|
})
|
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
farming.register_hoe(":farming:hoe_mese", {
|
|
|
|
description = "Mese Hoe",
|
|
|
|
inventory_image = "farming_tool_mesehoe.png",
|
|
|
|
max_uses = 350,
|
2015-03-03 22:04:16 +01:00
|
|
|
material = "default:mese_crystal"
|
2014-10-28 18:01:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
farming.register_hoe(":farming:hoe_diamond", {
|
|
|
|
description = "Diamond Hoe",
|
|
|
|
inventory_image = "farming_tool_diamondhoe.png",
|
|
|
|
max_uses = 500,
|
2015-03-03 22:04:16 +01:00
|
|
|
material = "default:diamond"
|
2016-04-27 16:01:44 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
farming.register_hoe(":farming:hoe_mithril", {
|
|
|
|
description = "Mithril Hoe",
|
|
|
|
inventory_image = "farming_tool_mithrilhoe.png",
|
|
|
|
max_uses = 1000,
|
2016-06-03 21:52:52 +02:00
|
|
|
material = "default:mithril_ingot"
|
2016-04-27 16:01:44 +02:00
|
|
|
})
|