From 60ccb522d44c1a62b83fef886e1959d3898491fa Mon Sep 17 00:00:00 2001 From: webdesigner97 Date: Wed, 16 Apr 2014 23:44:58 +0200 Subject: [PATCH] Make farming more flexible - API {farming.register_hoe(), farming.register_plant()} - Fertilities -> Plant only grow on soil with a fitting fertility, e.g. Wheat only grows on grassland, while cotton grows in deserts and grassland) - New soil: Desert Sand - Place seeds instead of plants --- mods/farming/API.txt | 27 ++ mods/farming/README.txt | 2 +- mods/farming/api.lua | 284 +++++++++++ mods/farming/hoes.lua | 65 +++ mods/farming/init.lua | 450 +----------------- mods/farming/nodes.lua | 139 ++++++ ...{farming_string.png => farming_cotton.png} | Bin .../textures/farming_desert_sand_soil.png | Bin 0 -> 716 bytes .../textures/farming_desert_sand_soil_wet.png | Bin 0 -> 656 bytes .../farming_desert_sand_soil_wet_side.png | Bin 0 -> 671 bytes 10 files changed, 538 insertions(+), 429 deletions(-) create mode 100644 mods/farming/API.txt create mode 100644 mods/farming/api.lua create mode 100644 mods/farming/hoes.lua create mode 100644 mods/farming/nodes.lua rename mods/farming/textures/{farming_string.png => farming_cotton.png} (100%) create mode 100644 mods/farming/textures/farming_desert_sand_soil.png create mode 100644 mods/farming/textures/farming_desert_sand_soil_wet.png create mode 100644 mods/farming/textures/farming_desert_sand_soil_wet_side.png diff --git a/mods/farming/API.txt b/mods/farming/API.txt new file mode 100644 index 00000000..a2f3d9d6 --- /dev/null +++ b/mods/farming/API.txt @@ -0,0 +1,27 @@ +farming.register_hoe(name, hoe definition) + -> Register a new hoe, see [hoe definition] + +farming.register_plant(name, Plant definition) + -> Register a new growing plant, see [Plant definition] + +Hoe Definition +{ + description = "", -- Description for tooltip + inventory_image = "unknown_item.png", -- Image to be used as wield- and inventory image + max_uses = 30, -- Uses until destroyed + recipe = { -- Craft recipe + {"air", "air", "air"}, + {"", "group:stick"}, + {"", "group:stick"}, + } +} + +Plant definition +{ + description = "", -- Description of seed item + inventory_image = "unknown_item.png", -- Image to be used as seed's wield- and inventory image + steps = 8, -- How many steps the plant has to grow, until it can be harvested + ^ Always provide a plant texture for ech step, format: modname_plantname_i.png (i = stepnumber) + minlight = 13, -- Minimum light to grow + maxlight = LIGHT_MAX -- Maximum light to grow +} \ No newline at end of file diff --git a/mods/farming/README.txt b/mods/farming/README.txt index 75521b2c..4663181a 100644 --- a/mods/farming/README.txt +++ b/mods/farming/README.txt @@ -3,7 +3,7 @@ Minetest 0.4 mod: farming License of source code: ----------------------- -Copyright (C) 2012-2013 PilzAdam +Copyright (C) 2014 webdesigner97 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 diff --git a/mods/farming/api.lua b/mods/farming/api.lua new file mode 100644 index 00000000..f1767d17 --- /dev/null +++ b/mods/farming/api.lua @@ -0,0 +1,284 @@ +-- Wear out hoes, place soil +-- TODO Ignore group:flower +farming.hoe_on_use = function(itemstack, user, pointed_thing, uses) + local pt = pointed_thing + -- check if pointing at a node + if not pt then + return + end + if pt.type ~= "node" then + return + end + + local under = minetest.get_node(pt.under) + local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z} + local above = minetest.get_node(p) + + -- return if any of the nodes is not registered + if not minetest.registered_nodes[under.name] then + return + end + if not minetest.registered_nodes[above.name] then + return + end + + -- check if the node above the pointed thing is air + if above.name ~= "air" then + return + end + + -- check if pointing at soil + if minetest.get_item_group(under.name, "soil") ~= 1 then + return + end + + -- check if (wet) soil defined + local regN = minetest.registered_nodes + if regN[under.name].soil == nil or regN[under.name].soil.wet == nil or regN[under.name].soil.dry == nil then + return + end + + -- turn the node into soil, wear out item and play sound + minetest.set_node(pt.under, {name = regN[under.name].soil.dry}) + minetest.sound_play("default_dig_crumbly", { + pos = pt.under, + gain = 0.5, + }) + itemstack:add_wear(65535/(uses-1)) + return itemstack +end + +-- Register new hoes +farming.register_hoe = function(name, def) + -- Check for : prefix (register new hoes in your mod's namespace) + if name:sub(1,1) ~= ":" then + name = ":" .. name + end + -- Check def table + if def.description == nil then + def.description = "Hoe" + end + if def.inventory_image == nil then + def.inventory_image = "unknown_item.png" + end + if def.recipe == nil then + def.recipe = { + {"air","air",""}, + {"","group:stick",""}, + {"","group:stick",""} + } + end + if def.max_uses == nil then + def.max_uses = 30 + end + -- 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 + }) + -- Register its recipe + minetest.register_craft({ + output = name:gsub(":", "", 1), + recipe = def.recipe + }) +end + +-- Seed placement +farming.place_seed = function(itemstack, placer, pointed_thing, plantname) + local pt = pointed_thing + -- check if pointing at a node + if not pt then + return + end + if pt.type ~= "node" then + return + end + + local under = minetest.get_node(pt.under) + local above = minetest.get_node(pt.above) + + -- return if any of the nodes is not registered + if not minetest.registered_nodes[under.name] then + return + end + if not minetest.registered_nodes[above.name] then + return + end + + -- check if pointing at the top of the node + if pt.above.y ~= pt.under.y+1 then + return + end + + -- check if you can replace the node above the pointed node + if not minetest.registered_nodes[above.name].buildable_to then + return + end + + -- check if pointing at soil + if minetest.get_item_group(under.name, "soil") < 2 then + return + end + + -- add the node and remove 1 item from the itemstack + minetest.add_node(pt.above, {name = plantname, param2 = 1}) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + return itemstack +end + +-- Register plants +farming.register_plant = function(name, def) + local mname = name:split(":")[1] + local pname = name:split(":")[2] + -- Check def table + if def.description == nil then + def.description = "Seed" + end + if def.inventory_image == nil then + def.inventory_image = "unknown_item.png" + end + if def.steps == nil then + return nil + end + if def.minlight == nil then + def.minlight = 1 + end + if def.maxlight == nil then + def.maxlight = 14 + end + if not def.fertility then + def.fertility = {} + end + -- Register seed + local g = {seed = 1, snappy = 3, attached_node = 1} + for k, v in pairs(def.fertility) do + g[v] = 1 + end + minetest.register_node(":" .. mname .. ":seed_" .. pname, { + description = def.description, + tiles = {def.inventory_image}, + inventory_image = def.inventory_image, + wield_image = def.inventory_image, + drawtype = "signlike", + groups = g, + paramtype = "light", + paramtype2 = "wallmounted", + walkable = false, + sunlight_propagates = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}, + }, + fertility = def.fertility, + on_place = function(itemstack, placer, pointed_thing) + return farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname) + end + }) + -- Seed -> plant + minetest.register_abm({ + nodenames = {"group:seed"}, + neighbors = {"group:soil"}, + interval = 90, + chance = 2, + action = function(pos, node) + local seedferts = minetest.registered_nodes[node.name].fertility + local soilferts = {} + -- Collect fertilities of soil + for k, v in pairs(minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name].groups) do + if k == "grassland" or k == "desert" then + soilferts[k] = k + end + end + -- Cannot grow if no fertility match found + local fertmatch = false + for k, v in pairs(seedferts) do + if soilferts[v] ~= nil then + fertmatch = true + break + end + end + + if fertmatch == true and minetest.get_item_group(minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name, "wet") ~= 0 then + minetest.set_node(pos, {name = node.name:gsub("seed_", "") .. "_1"}) + end + end + }) + -- Register harvest + minetest.register_craftitem(":" .. mname .. ":" .. pname, { + description = pname:gsub("^%l", string.upper), + inventory_image = mname .. "_" .. pname .. ".png", + }) + -- Register growing steps + for i=1,def.steps do + local drop = { + items = { + {items = {mname .. ":" .. pname}, rarity = 9 - i}, + {items = {mname .. ":" .. pname}, rarity= 18 - i * 2}, + {items = {mname .. ":seed_" .. pname}, rarity = 9 - i}, + {items = {mname .. ":seed_" .. pname}, rarity = 18 - i * 2}, + } + } + local nodegroups = {snappy = 3, flammable = 2, plant = 1, not_in_creative_inventory = 1, attached_node = 1} + nodegroups[pname] = i + minetest.register_node(mname .. ":" .. pname .. "_" .. i, { + drawtype = "plantlike", + waving = 1, + tiles = {mname .. "_" .. pname .. "_" .. i .. ".png"}, + paramtype = "light", + walkable = false, + buildable_to = true, + is_ground_content = true, + drop = drop, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}, + }, + groups = nodegroups, + sounds = default.node_sound_leaves_defaults(), + }) + end + -- Growing ABM + minetest.register_abm({ + nodenames = {"group:" .. pname}, + neighbors = {"group:soil"}, + interval = 90, + chance = 2, + action = function(pos, node) + -- return if already full grown + if minetest.get_item_group(node.name, pname) == def.steps then + return + end + + -- check if on wet soil + pos.y = pos.y - 1 + local n = minetest.get_node(pos) + if minetest.get_item_group(n.name, "soil") < 3 then + return + end + pos.y = pos.y + 1 + + -- check light + if not minetest.get_node_light(pos) then + return + end + if minetest.get_node_light(pos) < def.minlight or minetest.get_node_light(pos) > def.maxlight then + return + end + + -- grow + local height = minetest.get_item_group(node.name, pname) + 1 + minetest.set_node(pos, {name = mname .. ":" .. pname .. "_" .. height}) + end + }) + -- Return + local r = { + seed = mname .. ":seed_" .. pname, + harvest = mname .. ":" .. pname + } + return r +end diff --git a/mods/farming/hoes.lua b/mods/farming/hoes.lua new file mode 100644 index 00000000..084d586f --- /dev/null +++ b/mods/farming/hoes.lua @@ -0,0 +1,65 @@ +farming.register_hoe(":farming:hoe_wood", { + description = "Wooden Hoe", + inventory_image = "farming_tool_woodhoe.png", + max_uses = 30, + recipe = { + {"group:wood", "group:wood"}, + {"", "group:stick"}, + {"", "group:stick"}, + } +}) + +farming.register_hoe(":farming:hoe_stone", { + description = "Stone Hoe", + inventory_image = "farming_tool_stonehoe.png", + max_uses = 90, + recipe = { + {"group:stone", "group:stone"}, + {"", "group:stick"}, + {"", "group:stick"}, + } +}) + +farming.register_hoe(":farming:hoe_steel", { + description = "Steel Hoe", + inventory_image = "farming_tool_steelhoe.png", + max_uses = 200, + recipe = { + {"default:steel_ingot", "default:steel_ingot"}, + {"", "group:stick"}, + {"", "group:stick"}, + } +}) + +farming.register_hoe(":farming:hoe_bronze", { + description = "Bronze Hoe", + inventory_image = "farming_tool_bronzehoe.png", + max_uses = 220, + recipe = { + {"default:bronze_ingot", "default:bronze_ingot"}, + {"", "group:stick"}, + {"", "group:stick"}, + } +}) + +farming.register_hoe(":farming:hoe_mese", { + description = "Mese Hoe", + inventory_image = "farming_tool_mesehoe.png", + max_uses = 350, + recipe = { + {"default:mese_crystal", "default:mese_crystal"}, + {"", "group:stick"}, + {"", "group:stick"}, + } +}) + +farming.register_hoe(":farming:hoe_diamond", { + description = "Diamond Hoe", + inventory_image = "farming_tool_diamondhoe.png", + max_uses = 500, + recipe = { + {"default:diamond", "default:diamond"}, + {"", "group:stick"}, + {"", "group:stick"}, + } +}) diff --git a/mods/farming/init.lua b/mods/farming/init.lua index 31cacc4d..4f65d5dd 100644 --- a/mods/farming/init.lua +++ b/mods/farming/init.lua @@ -1,304 +1,21 @@ --- Minetest 0.4 mod: farming --- See README.txt for licensing and other information. - +-- Global farming namespace farming = {} +farming.path = minetest.get_modpath("farming") --- --- Soil --- -minetest.register_node("farming:soil", { - description = "Soil", - tiles = {"farming_soil.png", "default_dirt.png"}, - drop = "default:dirt", - is_ground_content = true, - groups = {crumbly=3, not_in_creative_inventory=1, soil=2}, - sounds = default.node_sound_dirt_defaults(), -}) - -minetest.register_node("farming:soil_wet", { - description = "Wet Soil", - tiles = {"farming_soil_wet.png", "farming_soil_wet_side.png"}, - drop = "default:dirt", - is_ground_content = true, - groups = {crumbly=3, not_in_creative_inventory=1, soil=3}, - sounds = default.node_sound_dirt_defaults(), -}) - -minetest.register_abm({ - nodenames = {"farming:soil", "farming:soil_wet"}, - interval = 15, - chance = 4, - action = function(pos, node) - pos.y = pos.y+1 - local nn = minetest.get_node(pos).name - pos.y = pos.y-1 - if minetest.registered_nodes[nn] and - minetest.registered_nodes[nn].walkable and - minetest.get_item_group(nn, "plant") == 0 - then - minetest.set_node(pos, {name="default:dirt"}) - end - -- check if there is water nearby - if minetest.find_node_near(pos, 3, {"group:water"}) then - -- if it is dry soil turn it into wet soil - if node.name == "farming:soil" then - minetest.set_node(pos, {name="farming:soil_wet"}) - end - else - -- turn it back into dirt if it is already dry - if node.name == "farming:soil" then - -- only turn it back if there is no plant on top of it - if minetest.get_item_group(nn, "plant") == 0 then - minetest.set_node(pos, {name="default:dirt"}) - end - - -- if its wet turn it back into dry soil - elseif node.name == "farming:soil_wet" then - minetest.set_node(pos, {name="farming:soil"}) - end - end - end, -}) - --- --- Hoes --- --- turns nodes with group soil=1 into soil -function farming.hoe_on_use(itemstack, user, pointed_thing, uses) - local pt = pointed_thing - -- check if pointing at a node - if not pt then - return - end - if pt.type ~= "node" then - return - end - - local under = minetest.get_node(pt.under) - local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z} - local above = minetest.get_node(p) - - -- return if any of the nodes is not registered - if not minetest.registered_nodes[under.name] then - return - end - if not minetest.registered_nodes[above.name] then - return - end - - -- check if the node above the pointed thing is air - if above.name ~= "air" then - return - end - - -- check if pointing at dirt - if minetest.get_item_group(under.name, "soil") ~= 1 then - return - end - - -- turn the node into soil, wear out item and play sound - minetest.set_node(pt.under, {name="farming:soil"}) - minetest.sound_play("default_dig_crumbly", { - pos = pt.under, - gain = 0.5, - }) - itemstack:add_wear(65535/(uses-1)) - return itemstack -end - -minetest.register_tool("farming:hoe_wood", { - description = "Wooden Hoe", - inventory_image = "farming_tool_woodhoe.png", - - on_use = function(itemstack, user, pointed_thing) - return farming.hoe_on_use(itemstack, user, pointed_thing, 30) - end, -}) - -minetest.register_tool("farming:hoe_stone", { - description = "Stone Hoe", - inventory_image = "farming_tool_stonehoe.png", - - on_use = function(itemstack, user, pointed_thing) - return farming.hoe_on_use(itemstack, user, pointed_thing, 90) - end, -}) - -minetest.register_tool("farming:hoe_steel", { - description = "Steel Hoe", - inventory_image = "farming_tool_steelhoe.png", - - on_use = function(itemstack, user, pointed_thing) - return farming.hoe_on_use(itemstack, user, pointed_thing, 200) - end, -}) - -minetest.register_tool("farming:hoe_bronze", { - description = "Bronze Hoe", - inventory_image = "farming_tool_bronzehoe.png", - - on_use = function(itemstack, user, pointed_thing) - return farming.hoe_on_use(itemstack, user, pointed_thing, 220) - end, -}) - -minetest.register_tool("farming:hoe_mese", { - description = "Mese Hoe", - inventory_image = "farming_tool_mesehoe.png", - - on_use = function(itemstack, user, pointed_thing) - return farming.hoe_on_use(itemstack, user, pointed_thing, 350) - end, -}) - -minetest.register_tool("farming:hoe_diamond", { - description = "Diamond Hoe", - inventory_image = "farming_tool_diamondhoe.png", - - on_use = function(itemstack, user, pointed_thing) - return farming.hoe_on_use(itemstack, user, pointed_thing, 500) - end, -}) - -minetest.register_craft({ - output = "farming:hoe_wood", - recipe = { - {"group:wood", "group:wood"}, - {"", "group:stick"}, - {"", "group:stick"}, - } -}) - -minetest.register_craft({ - output = "farming:hoe_stone", - recipe = { - {"group:stone", "group:stone"}, - {"", "group:stick"}, - {"", "group:stick"}, - } -}) - -minetest.register_craft({ - output = "farming:hoe_steel", - recipe = { - {"default:steel_ingot", "default:steel_ingot"}, - {"", "group:stick"}, - {"", "group:stick"}, - } -}) - -minetest.register_craft({ - output = "farming:hoe_bronze", - recipe = { - {"default:bronze_ingot", "default:bronze_ingot"}, - {"", "group:stick"}, - {"", "group:stick"}, - } -}) - -minetest.register_craft({ - output = "farming:hoe_mese", - recipe = { - {"default:mese_crystal", "default:mese_crystal"}, - {"", "group:stick"}, - {"", "group:stick"}, - } -}) +-- Load files +dofile(farming.path .. "/api.lua") +dofile(farming.path .. "/nodes.lua") +dofile(farming.path .. "/hoes.lua") -minetest.register_craft({ - output = "farming:hoe_diamond", - recipe = { - {"default:diamond", "default:diamond"}, - {"", "group:stick"}, - {"", "group:stick"}, - } -}) - --- --- Override grass for drops --- -for i = 1, 5 do - - minetest.override_item("default:grass_"..i, {drop = { - max_items = 1, - items = { - {items = {'farming:seed_wheat'},rarity = 5}, - {items = {'default:grass_1'}}, - } - }}) -end - -minetest.override_item("default:junglegrass", {drop = { - max_items = 1, - items = { - {items = {'farming:seed_cotton'},rarity = 8}, - {items = {'default:junglegrass'}}, - } - }}) - --- --- Place seeds --- -local function place_seed(itemstack, placer, pointed_thing, plantname) - local pt = pointed_thing - -- check if pointing at a node - if not pt then - return - end - if pt.type ~= "node" then - return - end - - local under = minetest.get_node(pt.under) - local above = minetest.get_node(pt.above) - - -- return if any of the nodes is not registered - if not minetest.registered_nodes[under.name] then - return - end - if not minetest.registered_nodes[above.name] then - return - end - - -- check if pointing at the top of the node - if pt.above.y ~= pt.under.y+1 then - return - end - - -- check if you can replace the node above the pointed node - if not minetest.registered_nodes[above.name].buildable_to then - return - end - - -- check if pointing at soil - if minetest.get_item_group(under.name, "soil") <= 1 then - return - end - - -- add the node and remove 1 item from the itemstack - minetest.add_node(pt.above, {name=plantname}) - if not minetest.setting_getbool("creative_mode") then - itemstack:take_item() - end - return itemstack -end - --- --- Wheat --- -minetest.register_craftitem("farming:seed_wheat", { - description = "Wheat Seed", +-- WHEAT +farming.register_plant("farming:wheat", { + description = "Wheat seed", inventory_image = "farming_wheat_seed.png", - on_place = function(itemstack, placer, pointed_thing) - return place_seed(itemstack, placer, pointed_thing, "farming:wheat_1") - end, + steps = 8, + minlight = 13, + maxlight = LIGHT_MAX, + fertility = {"grassland"} }) - -minetest.register_craftitem("farming:wheat", { - description = "Wheat", - inventory_image = "farming_wheat.png", -}) - minetest.register_craftitem("farming:flour", { description = "Flour", inventory_image = "farming_flour.png", @@ -323,148 +40,25 @@ minetest.register_craft({ recipe = "farming:flour" }) -for i=1,8 do - local drop = { - items = { - {items = {'farming:wheat'},rarity=9-i}, - {items = {'farming:wheat'},rarity=18-i*2}, - {items = {'farming:seed_wheat'},rarity=9-i}, - {items = {'farming:seed_wheat'},rarity=18-i*2}, - } - } - minetest.register_node("farming:wheat_"..i, { - drawtype = "plantlike", - waving = 1, - tiles = {"farming_wheat_"..i..".png"}, - paramtype = "light", - walkable = false, - buildable_to = true, - is_ground_content = true, - drop = drop, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}, - }, - groups = {snappy=3,flammable=2,plant=1,wheat=i,not_in_creative_inventory=1,attached_node=1}, - sounds = default.node_sound_leaves_defaults(), - }) -end - -minetest.register_abm({ - nodenames = {"group:wheat"}, - neighbors = {"group:soil"}, - interval = 90, - chance = 2, - action = function(pos, node) - -- return if already full grown - if minetest.get_item_group(node.name, "wheat") == 8 then - return - end - - -- check if on wet soil - pos.y = pos.y-1 - local n = minetest.get_node(pos) - if minetest.get_item_group(n.name, "soil") < 3 then - return - end - pos.y = pos.y+1 - - -- check light - if not minetest.get_node_light(pos) then - return - end - if minetest.get_node_light(pos) < 13 then - return - end - - -- grow - local height = minetest.get_item_group(node.name, "wheat") + 1 - minetest.set_node(pos, {name="farming:wheat_"..height}) - end -}) - --- -- Cotton --- -minetest.register_craftitem("farming:seed_cotton", { - description = "Cotton Seed", +farming.register_plant("farming:cotton", { + description = "Cotton seed", inventory_image = "farming_cotton_seed.png", - on_place = function(itemstack, placer, pointed_thing) - return place_seed(itemstack, placer, pointed_thing, "farming:cotton_1") - end, + steps = 8, + minlight = 13, + maxlight = LIGHT_MAX, + fertility = {"grassland", "desert"} }) minetest.register_craftitem("farming:string", { description = "String", - inventory_image = "farming_string.png", + inventory_image = "farming_cotton.png", }) minetest.register_craft({ output = "wool:white", recipe = { - {"farming:string", "farming:string"}, - {"farming:string", "farming:string"}, + {"farming:cotton", "farming:cotton"}, + {"farming:cotton", "farming:cotton"}, } }) - -for i=1,8 do - local drop = { - items = { - {items = {'farming:string'},rarity=9-i}, - {items = {'farming:string'},rarity=18-i*2}, - {items = {'farming:string'},rarity=27-i*3}, - {items = {'farming:seed_cotton'},rarity=9-i}, - {items = {'farming:seed_cotton'},rarity=18-i*2}, - {items = {'farming:seed_cotton'},rarity=27-i*3}, - } - } - minetest.register_node("farming:cotton_"..i, { - drawtype = "plantlike", - waving = 1, - tiles = {"farming_cotton_"..i..".png"}, - paramtype = "light", - walkable = false, - buildable_to = true, - is_ground_content = true, - drop = drop, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}, - }, - groups = {snappy=3,flammable=2,plant=1,cotton=i,not_in_creative_inventory=1,attached_node=1}, - sounds = default.node_sound_leaves_defaults(), - }) -end - -minetest.register_abm({ - nodenames = {"group:cotton"}, - neighbors = {"group:soil"}, - interval = 80, - chance = 2, - action = function(pos, node) - -- return if already full grown - if minetest.get_item_group(node.name, "cotton") == 8 then - return - end - - -- check if on wet soil - pos.y = pos.y-1 - local n = minetest.get_node(pos) - if minetest.get_item_group(n.name, "soil") < 3 then - return - end - pos.y = pos.y+1 - - -- check light - if not minetest.get_node_light(pos) then - return - end - if minetest.get_node_light(pos) < 13 then - return - end - - -- grow - local height = minetest.get_item_group(node.name, "cotton") + 1 - minetest.set_node(pos, {name="farming:cotton_"..height}) - end -}) diff --git a/mods/farming/nodes.lua b/mods/farming/nodes.lua new file mode 100644 index 00000000..d5603e7b --- /dev/null +++ b/mods/farming/nodes.lua @@ -0,0 +1,139 @@ +minetest.override_item("default:dirt", { + groups = {crumbly=3,soil=1}, + soil = { + base = "default:dirt", + dry = "farming:soil", + wet = "farming:soil_wet" + } +}) + +minetest.override_item("default:dirt_with_grass", { + groups = {crumbly=3,soil=1}, + soil = { + base = "default:dirt_with_grass", + dry = "farming:soil", + wet = "farming:soil_wet" + } +}) + +minetest.register_node("farming:soil", { + description = "Soil", + tiles = {"farming_soil.png", "default_dirt.png"}, + drop = "default:dirt", + is_ground_content = true, + groups = {crumbly=3, not_in_creative_inventory=1, soil=2, grassland = 1}, + sounds = default.node_sound_dirt_defaults(), + soil = { + base = "default:dirt", + dry = "farming:soil", + wet = "farming:soil_wet" + } +}) + +minetest.register_node("farming:soil_wet", { + description = "Wet Soil", + tiles = {"farming_soil_wet.png", "farming_soil_wet_side.png"}, + drop = "default:dirt", + is_ground_content = true, + groups = {crumbly=3, not_in_creative_inventory=1, soil=3, wet = 1, grassland = 1}, + sounds = default.node_sound_dirt_defaults(), + soil = { + base = "default:dirt", + dry = "farming:soil", + wet = "farming:soil_wet" + } +}) + +minetest.override_item("default:desert_sand", { + groups = {crumbly=3, falling_node=1, sand=1, soil = 1}, + soil = { + base = "default:desert_sand", + dry = "farming:desert_sand_soil", + wet = "farming:desert_sand_soil_wet" + } +}) +minetest.register_node("farming:desert_sand_soil", { + description = "Desert Sand", + tiles = {"farming_desert_sand_soil.png", "default_desert_sand.png"}, + is_ground_content = true, + groups = {crumbly=3, not_in_creative_inventory = 1, falling_node=1, sand=1, soil = 2, desert = 1}, + sounds = default.node_sound_sand_defaults(), + soil = { + base = "default:desert_sand", + dry = "farming:desert_sand_soil", + wet = "farming:desert_sand_soil_wet" + } +}) + +minetest.register_node("farming:desert_sand_soil_wet", { + description = "Desert Sand", + drop = "default:desert_sand", + tiles = {"farming_desert_sand_soil_wet.png", "farming_desert_sand_soil_wet_side.png"}, + is_ground_content = true, + groups = {crumbly=3, falling_node=1, sand=1, not_in_creative_inventory=1, soil=3, wet = 1, desert = 1}, + sounds = default.node_sound_sand_defaults(), + soil = { + base = "default:desert_sand", + dry = "farming:desert_sand_soil", + wet = "farming:desert_sand_soil_wet" + } +}) + +minetest.register_abm({ + nodenames = {"group:soil", "group:wet"}, + interval = 5, + chance = 10, + action = function(pos, node) + pos.y = pos.y+1 + local nn = minetest.get_node(pos).name + node = minetest.registered_nodes[node.name] + pos.y = pos.y-1 + + if node.soil == nil or node.soil.wet == nil or node.soil.base == nil or node.soil.dry == nil then + minetest.log("error", "Could not process soil information of node " .. nn) + return + end + + if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].walkable and minetest.get_item_group(nn, "plant") == 0 and node.name ~= node.soil.base then + minetest.set_node(pos, {name = node.soil.base}) + end + -- check if there is water nearby + if minetest.find_node_near(pos, 3, {"group:water"}) then + -- if it is dry soil and not base node, turn it into wet soil + if node.name ~= node.soil.base and minetest.get_item_group(node.name, "wet") == 0 then + minetest.set_node(pos, {name = node.soil.wet}) + end + else + -- turn it back into base if it is already dry + if minetest.get_item_group(node.name, "wet") == 0 then + -- only turn it back if there is no plant/seed on top of it + if minetest.get_item_group(nn, "plant") == 0 and minetest.get_item_group(nn, "seed") == 0 then + minetest.set_node(pos, {name = node.soil.base}) + end + + -- if its wet turn it back into dry soil + elseif minetest.get_item_group(node.name, "wet") == 1 then + minetest.set_node(pos, {name = node.soil.dry}) + end + end + end, +}) + + +for i = 1, 5 do + minetest.override_item("default:grass_"..i, {drop = { + max_items = 1, + items = { + {items = {'farming:seed_wheat'},rarity = 5}, + {items = {'default:grass_1'}}, + } + }}) +end + +minetest.override_item("default:junglegrass", {drop = { + max_items = 1, + items = { + {items = {'farming:seed_cotton'},rarity = 8}, + {items = {'default:junglegrass'}}, + } +}}) diff --git a/mods/farming/textures/farming_string.png b/mods/farming/textures/farming_cotton.png similarity index 100% rename from mods/farming/textures/farming_string.png rename to mods/farming/textures/farming_cotton.png diff --git a/mods/farming/textures/farming_desert_sand_soil.png b/mods/farming/textures/farming_desert_sand_soil.png new file mode 100644 index 0000000000000000000000000000000000000000..604b7a503c90a3c79928af4e8e05c3626cef306a GIT binary patch literal 716 zcmV;-0yF)IP)wBx9uEVT4#0TVpw_10FyKCW+(3zV3UwtBZ$>Mqv%# zIr7`DzxeO}Jo4A^L`o5_g~NW&m%{@=;Q2N4@9P_n^M!zeLo?<6cI4-W1N!Ijg=5aB zD9hETO}MTF!`R&n484-qLU5;AAa;o^8MjknniPF{TQF-ZWhEvhhyX%ycsXWrsdRn7 zt1%=f*=XMLu-mcLil!*wO4JAl5|yCB)8m=pMv)}ARYHoa&5-~@AIMiDNI-A8jy?)0 zLNlYb#${=s0veF2tkuw{bU4<4YIGsc3h0*~?%0nLK_V`WuY!9eh;#aSWf}vk2U>L& zH^jkc%(3{K!ZOXUwEFc$hS^32)PzgGP-_5n^l4;?V~dt zlXhJ5!qX|!%>LJjqSTP)Tx literal 0 HcmV?d00001 diff --git a/mods/farming/textures/farming_desert_sand_soil_wet.png b/mods/farming/textures/farming_desert_sand_soil_wet.png new file mode 100644 index 0000000000000000000000000000000000000000..cf6b8e46e2f89a4f39ef8fa95976f348fd791217 GIT binary patch literal 656 zcmV;B0&o3^P)2ToN`56_szBm54-?^+SN&=9s91oSBpU>!@*BjT?5R~2mPiSKh z1pB8-txD?yCGk+K6iRUpb77ekz1$lSLHCZCq9TAW5^mQ<8-uADcu)&?3o%*~c}69L!)`_d=BW~VtQa1g z&I@yyIPWT|;4PUKVI7GUVci^^s^Q_Z<~-U)CXmT+r-ifI7miOe!-Zv<7$d1>7>f6x zT<>=-kBuAOp;haQ4d#p{PNLgst~a=UNq{b2?N=_~Z4)+q!*r zq6*Cir3BMtXoRDp~+xp?`Nl(Fm-L7yv&fNNn`+x-Zzy;P8NH}G5bhi}z2WKZ3>8L6{ zy_|Sn7UWAOk%1|^yzJ1WPMmfXl`qacXS{d=5^E?^z qG_l?Wk4JEObjFDPb@FJ9B>5K-Utfb^mPpJ10000j_RhW|Efct=4RE$~5Hu(yH-agqkc*>gr1{um8074DgDrO) zM@8rk^P+@(?SvqNQ^ehwfiwrY4<7$)Aj)z!%mU!F+>xM6rj%R>A_JQO02TvY8?D3o zoq79+SV*9d_ey;>&X<|q;eOkgk`ZE3V1U4IM@;FZu$&Lz_AIzN0MmP7ePp~r)Wf=p zD!mOxcSIF%#u((a@bBL%qJ9uKw7n9Ol9JFFyj>h3>vh2g zV7v&bgTVK#l1|3k=}@xWDjjG0F3jhN