farming/hoes.lua

201 lines
4.5 KiB
Lua
Raw Normal View History

2014-11-09 20:06:28 +01:00
2016-05-30 13:30:00 +02:00
local S = farming.intllib
2017-07-28 16:48:12 +02:00
local tr = minetest.get_modpath("toolranks")
2016-05-30 13:30:00 +02:00
2014-11-09 20:06:28 +01:00
-- Hoe registration function
farming.register_hoe = function(name, def)
2014-11-09 20:06:28 +01:00
-- Check for : prefix (register new hoes in your mod's namespace)
if name:sub(1,1) ~= ":" then
name = ":" .. name
end
2014-11-09 20:06:28 +01:00
-- Check def table
if def.description == nil then
def.description = "Hoe"
end
2014-11-09 20:06:28 +01:00
if def.inventory_image == nil then
def.inventory_image = "unknown_item.png"
end
2014-11-09 20:06:28 +01:00
if def.recipe == nil then
def.recipe = {
{"air","air",""},
{"","group:stick",""},
{"","group:stick",""}
}
end
2014-11-09 20:06:28 +01:00
if def.max_uses == nil then
def.max_uses = 30
end
2014-11-09 20:06:28 +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
})
2014-11-09 20:06:28 +01:00
-- Register its recipe
2015-08-26 16:05:17 +02: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", ""}
}
})
end
2014-11-09 20:06:28 +01:00
end
-- Turns dirt with group soil=1 into soil
function farming.hoe_on_use(itemstack, user, pointed_thing, uses)
2014-11-09 20:06:28 +01:00
local pt = pointed_thing
2014-11-09 20:06:28 +01:00
-- check if pointing at a node
if not pt or pt.type ~= "node" then
return
end
2017-10-09 12:32:00 +02:00
2014-11-09 20:06:28 +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-07-05 11:54:18 +02:00
local p = {x = pt.under.x, y = pt.under.y + 1, z = pt.under.z}
2014-11-09 20:06:28 +01:00
local above = minetest.get_node(p)
2017-10-09 12:32:00 +02:00
2014-11-09 20:06:28 +01:00
-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name]
or not minetest.registered_nodes[above.name] then
return
end
2017-10-09 12:32:00 +02:00
2014-11-09 20:06:28 +01:00
-- check if the node above the pointed thing is air
if above.name ~= "air" then
return
end
2017-10-09 12:32:00 +02:00
2014-11-09 20:06:28 +01:00
-- check if pointing at dirt
if minetest.get_item_group(under.name, "soil") ~= 1 then
return
end
2017-10-09 12:32:00 +02:00
2014-11-09 20:06:28 +01:00
-- turn the node into soil, wear out item and play sound
2015-07-05 11:54:18 +02:00
minetest.set_node(pt.under, {name = "farming:soil"})
2015-07-05 11:54:18 +02:00
minetest.sound_play("default_dig_crumbly", {pos = pt.under, gain = 0.5})
2017-07-28 16:48:12 +02:00
local wear = 65535 / (uses -1)
2017-10-09 12:32:00 +02:00
if farming.is_creative(user:get_player_name()) then
2017-07-28 16:48:12 +02:00
if tr then
wear = 1
else
wear = 0
end
end
if tr then
itemstack = toolranks.new_afteruse(itemstack, user, under, {wear = wear})
else
itemstack:add_wear(wear)
2015-08-26 16:05:17 +02:00
end
2014-11-09 20:06:28 +01:00
return itemstack
end
-- Define Hoes
farming.register_hoe(":farming:hoe_wood", {
2016-05-30 13:30:00 +02:00
description = S("Wooden Hoe"),
2014-11-09 20:06:28 +01:00
inventory_image = "farming_tool_woodhoe.png",
max_uses = 30,
2015-08-26 16:05:17 +02:00
material = "group:wood"
2014-11-09 20:06:28 +01:00
})
minetest.register_craft({
type = "fuel",
recipe = "farming:hoe_wood",
burntime = 5,
})
2014-11-09 20:06:28 +01:00
farming.register_hoe(":farming:hoe_stone", {
2016-05-30 13:30:00 +02:00
description = S("Stone Hoe"),
2014-11-09 20:06:28 +01:00
inventory_image = "farming_tool_stonehoe.png",
max_uses = 90,
2015-08-26 16:05:17 +02:00
material = "group:stone"
2014-11-09 20:06:28 +01:00
})
farming.register_hoe(":farming:hoe_steel", {
2016-05-30 13:30:00 +02:00
description = S("Steel Hoe"),
2014-11-09 20:06:28 +01:00
inventory_image = "farming_tool_steelhoe.png",
max_uses = 200,
2015-08-26 16:05:17 +02:00
material = "default:steel_ingot"
2014-11-09 20:06:28 +01:00
})
farming.register_hoe(":farming:hoe_bronze", {
2016-05-30 13:30:00 +02:00
description = S("Bronze Hoe"),
2014-11-09 20:06:28 +01:00
inventory_image = "farming_tool_bronzehoe.png",
max_uses = 220,
2015-08-26 16:05:17 +02:00
material = "default:bronze_ingot"
2014-11-09 20:06:28 +01:00
})
farming.register_hoe(":farming:hoe_mese", {
2016-05-30 13:30:00 +02:00
description = S("Mese Hoe"),
2014-11-09 20:06:28 +01:00
inventory_image = "farming_tool_mesehoe.png",
max_uses = 350,
2015-08-26 16:05:17 +02:00
material = "default:mese_crystal"
2014-11-09 20:06:28 +01:00
})
farming.register_hoe(":farming:hoe_diamond", {
2016-05-30 13:30:00 +02:00
description = S("Diamond Hoe"),
2014-11-09 20:06:28 +01:00
inventory_image = "farming_tool_diamondhoe.png",
max_uses = 500,
2015-08-26 16:05:17 +02:00
material = "default:diamond"
})
2017-07-28 16:48:12 +02:00
-- Toolranks support
if tr then
minetest.override_item("farming:hoe_wood", {
original_description = "Wood Hoe",
description = toolranks.create_description("Wood Hoe")})
minetest.override_item("farming:hoe_stone", {
original_description = "Stone Hoe",
description = toolranks.create_description("Stone Hoe")})
minetest.override_item("farming:hoe_steel", {
original_description = "Steel Hoe",
description = toolranks.create_description("Steel Hoe")})
minetest.override_item("farming:hoe_bronze", {
original_description = "Bronze Hoe",
description = toolranks.create_description("Bronze Hoe")})
minetest.override_item("farming:hoe_mese", {
original_description = "Mese Hoe",
description = toolranks.create_description("Mese Hoe")})
minetest.override_item("farming:hoe_diamond", {
original_description = "Diamond Hoe",
description = toolranks.create_description("Diamond Hoe")})
end