summaryrefslogtreecommitdiff
path: root/farming/hoes.lua
diff options
context:
space:
mode:
Diffstat (limited to 'farming/hoes.lua')
-rw-r--r--farming/hoes.lua140
1 files changed, 140 insertions, 0 deletions
diff --git a/farming/hoes.lua b/farming/hoes.lua
index 633e6f0..6ffa98f 100644
--- a/farming/hoes.lua
+++ b/farming/hoes.lua
@@ -330,3 +330,143 @@ minetest.register_craftitem("farming:hoe_bomb", {
end
end,
})
+
+-- Mithril Scythe (special item)
+
+farming.scythe_not_drops = {"farming:trellis", "farming:beanpole"}
+
+farming.add_to_scythe_not_drops = function(item)
+ table.insert(farming.scythe_not_drops, item)
+end
+
+minetest.register_tool("farming:scythe_mithril", {
+ description = S("Mithril Scythe (Right-click crop to harvest and replant)"),
+ inventory_image = "farming_scythe_mithril.png",
+ tool_capabilities = {
+ full_punch_interval = 0.8,
+ max_drop_level = 2,
+ groupcaps = {
+ fleshy = {times = {[2] = 0.65, [3] = 0.25}, uses = 150, maxlevel = 2},
+ snappy = {times = {[2] = 0.70, [3] = 0.25}, uses = 150, maxlevel = 2},
+ },
+ damage_groups = {fleshy = 8},
+ },
+ sound = {breaks = "default_tool_breaks"},
+
+ on_place = function(itemstack, placer, pointed_thing)
+
+ if pointed_thing.type ~= "node" then
+ return
+ end
+
+ local pos = pointed_thing.under
+ local name = placer:get_player_name()
+
+ if minetest.is_protected(pos, name) then
+ return
+ end
+
+ local node = minetest.get_node_or_nil(pos)
+
+ if not node then
+ return
+ end
+
+ local def = minetest.registered_nodes[node.name]
+
+ if not def then
+ return
+ end
+
+ if not def.drop then
+ return
+ end
+
+ if not def.groups
+ or not def.groups.plant then
+ return
+ end
+
+ local drops = minetest.get_node_drops(node.name, "")
+
+ if not drops
+ or #drops == 0
+ or (#drops == 1 and drops[1] == "") then
+ return
+ end
+
+ -- get crop name
+ local mname = node.name:split(":")[1]
+ local pname = node.name:split(":")[2]
+ local sname = tonumber(pname:split("_")[2])
+ pname = pname:split("_")[1]
+
+ if not sname then
+ return
+ end
+
+ -- add dropped items
+ for _, dropped_item in pairs(drops) do
+
+ -- dont drop items on this list
+ for _, not_item in pairs(farming.scythe_not_drops) do
+
+ if dropped_item == not_item then
+ dropped_item = nil
+ end
+ end
+
+ if dropped_item then
+
+ local obj = minetest.add_item(pos, dropped_item)
+
+ if obj then
+
+ obj:set_velocity({
+ x = math.random(-10, 10) / 9,
+ y = 3,
+ z = math.random(-10, 10) / 9,
+ })
+ end
+ end
+ end
+
+ -- Run script hook
+ for _, callback in pairs(core.registered_on_dignodes) do
+ callback(pos, node)
+ end
+
+ -- play sound
+ minetest.sound_play("default_grass_footstep", {pos = pos, gain = 1.0})
+
+ local replace = mname .. ":" .. pname .. "_1"
+
+ if minetest.registered_nodes[replace] then
+
+ local p2 = minetest.registered_nodes[replace].place_param2 or 1
+
+ minetest.set_node(pos, {name = replace, param2 = p2})
+ else
+ minetest.set_node(pos, {name = "air"})
+ end
+
+ if not farming.is_creative(name) then
+
+ itemstack:add_wear(65535 / 150) -- 150 uses
+
+ return itemstack
+ end
+ end,
+})
+
+if minetest.get_modpath("moreores") then
+
+ minetest.register_craft({
+ output = "farming:scythe_mithril",
+ recipe = {
+ {"", "moreores:mithril_ingot", "moreores:mithril_ingot"},
+ {"moreores:mithril_ingot", "", "group:stick"},
+ {"", "", "group:stick"}
+ }
+ })
+end