A while ago, I changed this in my own game to be a little nicer about placing plants. I don't know if it has problems, but I haven't seen any so far...
Code: Select all
--- ./farming_plus-old/carrots.lua 2013-11-03 14:19:44.000000000 -0700
+++ ./farming_plus-new/carrots.lua 2014-05-16 22:53:48.000000000 -0600
@@ -2,13 +2,7 @@
description = "Carrot Seeds",
inventory_image = "farming_carrot_seed.png",
on_place = function(itemstack, placer, pointed_thing)
- local above = minetest.env:get_node(pointed_thing.above)
- if above.name == "air" then
- above.name = "farming_plus:carrot_1"
- minetest.env:set_node(pointed_thing.above, above)
- itemstack:take_item(1)
- return itemstack
- end
+ return farming:place_plant(itemstack, pointed_thing, "farming_plus:carrot_1")
end
})
--- ./farming_plus-old/init.lua 2013-11-03 14:19:44.000000000 -0700
+++ ./farming_plus-new/init.lua 2014-05-16 22:54:57.000000000 -0600
@@ -1,6 +1,19 @@
farming.registered_plants = {}
+function farming:place_plant(itemstack, pointed_thing, plant_name)
+ if pointed_thing.type == "node" then
+ local above = minetest.env:get_node(pointed_thing.above)
+ local under = minetest.env:get_node(pointed_thing.under)
+ if above.name == "air" and minetest.env:get_item_group(under.name, "soil") > 1 then
+ above.name = plant_name
+ minetest.env:set_node(pointed_thing.above, above)
+ itemstack:take_item(1)
+ end
+ end
+ return itemstack
+end
+
function farming:add_plant(full_grown, names, interval, chance)
minetest.register_abm({
nodenames = names,
--- ./farming_plus-old/oranges.lua 2013-11-03 14:19:44.000000000 -0700
+++ ./farming_plus-new/oranges.lua 2014-05-16 22:53:56.000000000 -0600
@@ -2,13 +2,7 @@
description = "Orange Seeds",
inventory_image = "farming_orange_seed.png",
on_place = function(itemstack, placer, pointed_thing)
- local above = minetest.env:get_node(pointed_thing.above)
- if above.name == "air" then
- above.name = "farming_plus:orange_1"
- minetest.env:set_node(pointed_thing.above, above)
- itemstack:take_item(1)
- return itemstack
- end
+ return farming:place_plant(itemstack, pointed_thing, "farming_plus:orange_1")
end
})
--- ./farming_plus-old/potatoes.lua 2013-11-03 14:19:44.000000000 -0700
+++ ./farming_plus-new/potatoes.lua 2014-05-16 22:54:03.000000000 -0600
@@ -2,13 +2,7 @@
description = "Potato Seeds",
inventory_image = "farming_potato_seed.png",
on_place = function(itemstack, placer, pointed_thing)
- local above = minetest.env:get_node(pointed_thing.above)
- if above.name == "air" then
- above.name = "farming_plus:potato_1"
- minetest.env:set_node(pointed_thing.above, above)
- itemstack:take_item(1)
- return itemstack
- end
+ return farming:place_plant(itemstack, pointed_thing, "farming_plus:potato_1")
end
})
--- ./farming_plus-old/pumpkin.lua 2013-11-03 14:19:44.000000000 -0700
+++ ./farming_plus-new/pumpkin.lua 2014-05-16 22:53:36.000000000 -0600
@@ -2,13 +2,7 @@
description = "Pumpkin Seed",
inventory_image = "farming_pumpkin_seed.png",
on_place = function(itemstack, placer, pointed_thing)
- local above = minetest.env:get_node(pointed_thing.above)
- if above.name == "air" then
- above.name = "farming:pumpkin_1"
- minetest.env:set_node(pointed_thing.above, above)
- itemstack:take_item(1)
- return itemstack
- end
+ return farming:place_plant(itemstack, pointed_thing, "farming:pumpkin_1")
end
})
@@ -68,8 +62,7 @@
if tool and tool == "default:sword_wood" or tool == "default:sword_stone" or tool == "default:sword_steel" then
node.name = "farming:pumpkin_face"
minetest.env:set_node(pos, node)
- puncher:get_inventory():add_item("main", ItemStack("farming:pumpkin_seed"))
- if math.random(1, 5) == 1 then
+ for i=1, math.random(1, 5) do
puncher:get_inventory():add_item("main", ItemStack("farming:pumpkin_seed"))
end
end
--- ./farming_plus-old/rhubarb.lua 2013-11-03 14:19:44.000000000 -0700
+++ ./farming_plus-new/rhubarb.lua 2014-05-16 22:54:12.000000000 -0600
@@ -2,13 +2,7 @@
description = "Rhubarb Seeds",
inventory_image = "farming_rhubarb_seed.png",
on_place = function(itemstack, placer, pointed_thing)
- local above = minetest.env:get_node(pointed_thing.above)
- if above.name == "air" then
- above.name = "farming_plus:rhubarb_1"
- minetest.env:set_node(pointed_thing.above, above)
- itemstack:take_item(1)
- return itemstack
- end
+ return farming:place_plant(itemstack, pointed_thing, "farming_plus:rhubarb_1")
end
})
--- ./farming_plus-old/strawberries.lua 2013-11-03 14:19:44.000000000 -0700
+++ ./farming_plus-new/strawberries.lua 2014-05-16 22:54:19.000000000 -0600
@@ -2,13 +2,7 @@
description = "Strawberry Seeds",
inventory_image = "farming_strawberry_seed.png",
on_place = function(itemstack, placer, pointed_thing)
- local above = minetest.env:get_node(pointed_thing.above)
- if above.name == "air" then
- above.name = "farming_plus:strawberry_1"
- minetest.env:set_node(pointed_thing.above, above)
- itemstack:take_item(1)
- return itemstack
- end
+ return farming:place_plant(itemstack, pointed_thing, "farming_plus:strawberry_1")
end
})
--- ./farming_plus-old/tomatoes.lua 2013-11-03 14:19:44.000000000 -0700
+++ ./farming_plus-new/tomatoes.lua 2014-05-16 22:54:26.000000000 -0600
@@ -2,13 +2,7 @@
description = "Tomato Seeds",
inventory_image = "farming_tomato_seed.png",
on_place = function(itemstack, placer, pointed_thing)
- local above = minetest.env:get_node(pointed_thing.above)
- if above.name == "air" then
- above.name = "farming_plus:tomato_1"
- minetest.env:set_node(pointed_thing.above, above)
- itemstack:take_item(1)
- return itemstack
- end
+ return farming:place_plant(itemstack, pointed_thing, "farming_plus:tomato_1")
end
})