1 -- Minetest 0.4 mod: farming
2 -- See README.txt for licensing and other information.
7 minetest.register_node("farming:soil", {
9 tiles = {"farming_soil.png", "default_dirt.png"},
10 drop = "default:dirt",
11 is_ground_content = true,
12 groups = {crumbly=3, not_in_creative_inventory=1, soil=2},
13 sounds = default.node_sound_dirt_defaults(),
16 minetest.register_node("farming:soil_wet", {
17 description = "Wet Soil",
18 tiles = {"farming_soil_wet.png", "farming_soil_wet_side.png"},
19 drop = "default:dirt",
20 is_ground_content = true,
21 groups = {crumbly=3, not_in_creative_inventory=1, soil=3},
22 sounds = default.node_sound_dirt_defaults(),
25 minetest.register_abm({
26 nodenames = {"farming:soil", "farming:soil_wet"},
29 action = function(pos, node)
31 local nn = minetest.get_node(pos).name
33 if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].walkable then
34 minetest.set_node(pos, {name="default:dirt"})
36 -- check if there is water nearby
37 if minetest.find_node_near(pos, 3, {"group:water"}) then
38 -- if it is dry soil turn it into wet soil
39 if node.name == "farming:soil" then
40 minetest.set_node(pos, {name="farming:soil_wet"})
43 -- turn it back into dirt if it is already dry
44 if node.name == "farming:soil" then
45 -- only turn it back if there is no plant on top of it
46 if minetest.get_item_group(nn, "plant") == 0 then
47 minetest.set_node(pos, {name="default:dirt"})
50 -- if its wet turn it back into dry soil
51 elseif node.name == "farming:soil_wet" then
52 minetest.set_node(pos, {name="farming:soil"})
61 -- turns nodes with group soil=1 into soil; drop seeds if plowing grass
62 local function hoe_on_use(itemstack, user, pointed_thing, uses)
63 local pt = pointed_thing
64 -- check if pointing at a node
68 if pt.type ~= "node" then
72 local under = minetest.get_node(pt.under)
73 local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
74 local above = minetest.get_node(p)
76 -- return if any of the nodes is not registered
77 if not minetest.registered_nodes[under.name] then
80 if not minetest.registered_nodes[above.name] then
84 -- check if the node above the pointed thing is air
85 if above.name ~= "air" then
89 -- check if pointing at dirt
90 if minetest.get_item_group(under.name, "soil") ~= 1 then
94 -- turn the node into soil, wear out item and play sound
95 minetest.set_node(pt.under, {name="farming:soil"})
96 minetest.sound_play("default_dig_crumbly", {
100 itemstack:add_wear(65535/(uses-1))
104 minetest.register_tool("farming:hoe_wood", {
105 description = "Wooden Hoe",
106 inventory_image = "farming_tool_woodhoe.png",
108 on_use = function(itemstack, user, pointed_thing)
109 return hoe_on_use(itemstack, user, pointed_thing, 30)
113 minetest.register_tool("farming:hoe_stone", {
114 description = "Stone Hoe",
115 inventory_image = "farming_tool_stonehoe.png",
117 on_use = function(itemstack, user, pointed_thing)
118 return hoe_on_use(itemstack, user, pointed_thing, 90)
122 minetest.register_tool("farming:hoe_steel", {
123 description = "Steel Hoe",
124 inventory_image = "farming_tool_steelhoe.png",
126 on_use = function(itemstack, user, pointed_thing)
127 return hoe_on_use(itemstack, user, pointed_thing, 200)
131 minetest.register_tool("farming:hoe_bronze", {
132 description = "Bronze Hoe",
133 inventory_image = "farming_tool_bronzehoe.png",
135 on_use = function(itemstack, user, pointed_thing)
136 return hoe_on_use(itemstack, user, pointed_thing, 220)
140 minetest.register_craft({
141 output = "farming:hoe_wood",
143 {"group:wood", "group:wood"},
144 {"", "default:stick"},
145 {"", "default:stick"},
149 minetest.register_craft({
150 output = "farming:hoe_stone",
152 {"group:stone", "group:stone"},
153 {"", "default:stick"},
154 {"", "default:stick"},
158 minetest.register_craft({
159 output = "farming:hoe_steel",
161 {"default:steel_ingot", "default:steel_ingot"},
162 {"", "default:stick"},
163 {"", "default:stick"},
167 minetest.register_craft({
168 output = "farming:hoe_bronze",
170 {"default:bronze_ingot", "default:bronze_ingot"},
171 {"", "default:stick"},
172 {"", "default:stick"},
177 -- Override grass for drops
179 minetest.register_node(":default:grass_1", {
180 description = "Grass",
181 drawtype = "plantlike",
182 tiles = {"default_grass_1.png"},
183 -- use a bigger inventory image
184 inventory_image = "default_grass_3.png",
185 wield_image = "default_grass_3.png",
192 {items = {'farming:seed_wheat'},rarity = 20},
193 {items = {'default:grass_1'}},
196 groups = {snappy=3,flammable=3,flora=1,attached_node=1},
197 sounds = default.node_sound_leaves_defaults(),
200 fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
202 on_place = function(itemstack, placer, pointed_thing)
203 -- place a random grass node
204 local stack = ItemStack("default:grass_"..math.random(1,5))
205 local ret = minetest.item_place(stack, placer, pointed_thing)
206 return ItemStack("default:grass_1 "..itemstack:get_count()-(1-ret:get_count()))
211 minetest.register_node(":default:grass_"..i, {
212 description = "Grass",
213 drawtype = "plantlike",
214 tiles = {"default_grass_"..i..".png"},
215 inventory_image = "default_grass_"..i..".png",
216 wield_image = "default_grass_"..i..".png",
220 is_ground_content = true,
224 {items = {'farming:seed_wheat'},rarity = 20},
225 {items = {'default:grass_1'}},
228 groups = {snappy=3,flammable=3,flora=1,attached_node=1,not_in_creative_inventory=1},
229 sounds = default.node_sound_leaves_defaults(),
232 fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
237 minetest.register_node(":default:junglegrass", {
238 description = "Jungle Grass",
239 drawtype = "plantlike",
241 tiles = {"default_junglegrass.png"},
242 inventory_image = "default_junglegrass.png",
243 wield_image = "default_junglegrass.png",
247 is_ground_content = true,
251 {items = {'farming:seed_cotton'},rarity = 20},
252 {items = {'default:junglegrass'}},
255 groups = {snappy=3,flammable=2,flora=1,attached_node=1},
256 sounds = default.node_sound_leaves_defaults(),
259 fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
266 local function place_seed(itemstack, placer, pointed_thing, plantname)
267 local pt = pointed_thing
268 -- check if pointing at a node
272 if pt.type ~= "node" then
276 local under = minetest.get_node(pt.under)
277 local above = minetest.get_node(pt.above)
279 -- return if any of the nodes is not registered
280 if not minetest.registered_nodes[under.name] then
283 if not minetest.registered_nodes[above.name] then
287 -- check if pointing at the top of the node
288 if pt.above.y ~= pt.under.y+1 then
292 -- check if you can replace the node above the pointed node
293 if not minetest.registered_nodes[above.name].buildable_to then
297 -- check if pointing at soil
298 if minetest.get_item_group(under.name, "soil") <= 1 then
302 -- add the node and remove 1 item from the itemstack
303 minetest.add_node(pt.above, {name=plantname})
304 if not minetest.setting_getbool("creative_mode") then
305 itemstack:take_item()
313 minetest.register_craftitem("farming:seed_wheat", {
314 description = "Wheat Seed",
315 inventory_image = "farming_wheat_seed.png",
316 on_place = function(itemstack, placer, pointed_thing)
317 return place_seed(itemstack, placer, pointed_thing, "farming:wheat_1")
321 minetest.register_craftitem("farming:wheat", {
322 description = "Wheat",
323 inventory_image = "farming_wheat.png",
326 minetest.register_craftitem("farming:flour", {
327 description = "Flour",
328 inventory_image = "farming_flour.png",
331 minetest.register_craftitem("farming:bread", {
332 description = "Bread",
333 inventory_image = "farming_bread.png",
334 on_use = minetest.item_eat(4),
337 minetest.register_craft({
339 output = "farming:flour",
340 recipe = {"farming:wheat", "farming:wheat", "farming:wheat", "farming:wheat"}
343 minetest.register_craft({
346 output = "farming:bread",
347 recipe = "farming:flour"
353 {items = {'farming:wheat'},rarity=9-i},
354 {items = {'farming:wheat'},rarity=18-i*2},
355 {items = {'farming:seed_wheat'},rarity=9-i},
356 {items = {'farming:seed_wheat'},rarity=18-i*2},
359 minetest.register_node("farming:wheat_"..i, {
360 drawtype = "plantlike",
361 tiles = {"farming_wheat_"..i..".png"},
365 is_ground_content = true,
369 fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
371 groups = {snappy=3,flammable=2,plant=1,wheat=i,not_in_creative_inventory=1,attached_node=1},
372 sounds = default.node_sound_leaves_defaults(),
376 minetest.register_abm({
377 nodenames = {"group:wheat"},
378 neighbors = {"group:soil"},
381 action = function(pos, node)
382 -- return if already full grown
383 if minetest.get_item_group(node.name, "wheat") == 8 then
387 -- check if on wet soil
389 local n = minetest.get_node(pos)
390 if minetest.get_item_group(n.name, "soil") < 3 then
396 if not minetest.get_node_light(pos) then
399 if minetest.get_node_light(pos) < 13 then
404 local height = minetest.get_item_group(node.name, "wheat") + 1
405 minetest.set_node(pos, {name="farming:wheat_"..height})
412 minetest.register_craftitem("farming:seed_cotton", {
413 description = "Cotton Seed",
414 inventory_image = "farming_cotton_seed.png",
415 on_place = function(itemstack, placer, pointed_thing)
416 return place_seed(itemstack, placer, pointed_thing, "farming:cotton_1")
420 minetest.register_craftitem("farming:string", {
421 description = "String",
422 inventory_image = "farming_string.png",
425 minetest.register_craft({
426 output = "wool:white",
428 {"farming:string", "farming:string"},
429 {"farming:string", "farming:string"},
436 {items = {'farming:string'},rarity=9-i},
437 {items = {'farming:string'},rarity=18-i*2},
438 {items = {'farming:string'},rarity=27-i*3},
439 {items = {'farming:seed_cotton'},rarity=9-i},
440 {items = {'farming:seed_cotton'},rarity=18-i*2},
441 {items = {'farming:seed_cotton'},rarity=27-i*3},
444 minetest.register_node("farming:cotton_"..i, {
445 drawtype = "plantlike",
446 tiles = {"farming_cotton_"..i..".png"},
450 is_ground_content = true,
454 fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
456 groups = {snappy=3,flammable=2,plant=1,cotton=i,not_in_creative_inventory=1,attached_node=1},
457 sounds = default.node_sound_leaves_defaults(),
461 minetest.register_abm({
462 nodenames = {"group:cotton"},
463 neighbors = {"group:soil"},
466 action = function(pos, node)
467 -- return if already full grown
468 if minetest.get_item_group(node.name, "cotton") == 8 then
472 -- check if on wet soil
474 local n = minetest.get_node(pos)
475 if minetest.get_item_group(n.name, "soil") < 3 then
481 if not minetest.get_node_light(pos) then
484 if minetest.get_node_light(pos) < 13 then
489 local height = minetest.get_item_group(node.name, "cotton") + 1
490 minetest.set_node(pos, {name="farming:cotton_"..height})