From: PilzAdam Date: Sun, 11 Nov 2012 10:47:53 +0000 (+0100) Subject: Add farming mod X-Git-Tag: 0.4.7~9 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5d11a34b04da7ea4f677cfca17e8397d3730540f;p=oweals%2Fminetest_game.git Add farming mod --- diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index e2f81aa4..3a0cf49e 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -1125,7 +1125,7 @@ minetest.register_node("default:apple", { fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2} }, groups = {fleshy=3,dig_immediate=3,flammable=2,leafdecay=1,leafdecay_drop=1}, - on_use = minetest.item_eat(4), + on_use = minetest.item_eat(1), sounds = default.node_sound_defaults(), after_place_node = function(pos, placer, itemstack) if placer:is_player() then diff --git a/mods/farming/README.txt b/mods/farming/README.txt new file mode 100644 index 00000000..b92e0bee --- /dev/null +++ b/mods/farming/README.txt @@ -0,0 +1,57 @@ +Minetest 0.4 mod: farming +========================= + +License of source code: +----------------------- +Copyright (C) 2012-2013 PilzAdam + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + +License of media (textures): +---------------------------- +Created by PilzAdam (License: WTFPL): + farming_bread.png + farming_soil.png + farming_soil_wet.png + farming_soil_wet_side.png + farming_string.png + +Created by Calinou (License: CC BY-SA): + farming_tool_bronzehoe.png + farming_tool_steelhoe.png + farming_tool_stonehoe.png + farming_tool_woodhoe.png + +Created by VanessaE (License: WTFPL): + farming_cotton_seed.png + farming_wheat_seed.png + farming_flour.png + farming_wheat.png + farming_wheat_1.png + farming_wheat_2.png + farming_wheat_3.png + farming_wheat_4.png + farming_wheat_5.png + farming_wheat_5.png + farming_wheat_7.png + farming_wheat_8.png + farming_cotton_1.png + farming_cotton_2.png + farming_cotton_3.png + farming_cotton_4.png + farming_cotton_5.png + farming_cotton_6.png + farming_cotton_7.png + farming_cotton_8.png diff --git a/mods/farming/depends.txt b/mods/farming/depends.txt new file mode 100644 index 00000000..470ec30b --- /dev/null +++ b/mods/farming/depends.txt @@ -0,0 +1,2 @@ +default +wool diff --git a/mods/farming/init.lua b/mods/farming/init.lua new file mode 100644 index 00000000..1fc22a8c --- /dev/null +++ b/mods/farming/init.lua @@ -0,0 +1,492 @@ +-- Minetest 0.4 mod: farming +-- See README.txt for licensing and other information. + +-- +-- 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.env:get_node(pos).name + pos.y = pos.y-1 + if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].walkable then + minetest.env:set_node(pos, {name="default:dirt"}) + end + -- check if there is water nearby + if minetest.env: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.env: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.env:set_node(pos, {name="default:dirt"}) + end + + -- if its wet turn it back into dry soil + elseif node.name == "farming:soil_wet" then + minetest.env:set_node(pos, {name="farming:soil"}) + end + end + end, +}) + +-- +-- Hoes +-- +-- turns nodes with group soil=1 into soil; drop seeds if plowing grass +local function 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.env:get_node(pt.under) + local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z} + local above = minetest.env: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.env: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 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 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 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 hoe_on_use(itemstack, user, pointed_thing, 220) + end, +}) + +minetest.register_craft({ + output = "farming:hoe_wood", + recipe = { + {"group:wood", "group:wood"}, + {"", "default:stick"}, + {"", "default:stick"}, + } +}) + +minetest.register_craft({ + output = "farming:hoe_stone", + recipe = { + {"group:stone", "group:stone"}, + {"", "default:stick"}, + {"", "default:stick"}, + } +}) + +minetest.register_craft({ + output = "farming:hoe_steel", + recipe = { + {"default:steel_ingot", "default:steel_ingot"}, + {"", "default:stick"}, + {"", "default:stick"}, + } +}) + +minetest.register_craft({ + output = "farming:hoe_bronze", + recipe = { + {"default:bronze_ingot", "default:bronze_ingot"}, + {"", "default:stick"}, + {"", "default:stick"}, + } +}) + +-- +-- Override grass for drops +-- +minetest.register_node(":default:grass_1", { + description = "Grass", + drawtype = "plantlike", + tiles = {"default_grass_1.png"}, + -- use a bigger inventory image + inventory_image = "default_grass_3.png", + wield_image = "default_grass_3.png", + paramtype = "light", + walkable = false, + buildable_to = true, + drop = { + max_items = 1, + items = { + {items = {'farming:seed'},rarity = 20}, + {items = {'default:grass_1'}}, + } + }, + groups = {snappy=3,flammable=3,flora=1,attached_node=1}, + sounds = default.node_sound_leaves_defaults(), + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}, + }, + on_place = function(itemstack, placer, pointed_thing) + -- place a random grass node + local stack = ItemStack("default:grass_"..math.random(1,5)) + local ret = minetest.item_place(stack, placer, pointed_thing) + return ItemStack("default:grass_1 "..itemstack:get_count()-(1-ret:get_count())) + end, +}) + +for i=2,5 do + minetest.register_node(":default:grass_"..i, { + description = "Grass", + drawtype = "plantlike", + tiles = {"default_grass_"..i..".png"}, + inventory_image = "default_grass_"..i..".png", + wield_image = "default_grass_"..i..".png", + paramtype = "light", + walkable = false, + buildable_to = true, + is_ground_content = true, + drop = { + max_items = 1, + items = { + {items = {'farming:seed_wheat'},rarity = 20}, + {items = {'default:grass_1'}}, + } + }, + groups = {snappy=3,flammable=3,flora=1,attached_node=1,not_in_creative_inventory=1}, + sounds = default.node_sound_leaves_defaults(), + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}, + }, + }) +end + +minetest.register_node(":default:junglegrass", { + description = "Jungle Grass", + drawtype = "plantlike", + visual_scale = 1.3, + tiles = {"default_junglegrass.png"}, + inventory_image = "default_junglegrass.png", + wield_image = "default_junglegrass.png", + paramtype = "light", + walkable = false, + buildable_to = true, + is_ground_content = true, + drop = { + max_items = 1, + items = { + {items = {'farming:seed_cotton'},rarity = 20}, + {items = {'default:junglegrass'}}, + } + }, + groups = {snappy=3,flammable=2,flora=1,attached_node=1}, + sounds = default.node_sound_leaves_defaults(), + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}, + }, +}) + +-- +-- 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.env:get_node(pt.under) + local above = minetest.env: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.env: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", + inventory_image = "farming_wheat_seed.png", + on_place = function(itemstack, placer, pointed_thing) + return place_seed(itemstack, placer, pointed_thing, "farming:wheat_1") + end, +}) + +minetest.register_craftitem("farming:wheat", { + description = "Wheat", + inventory_image = "farming_wheat.png", +}) + +minetest.register_craftitem("farming:flour", { + description = "Flour", + inventory_image = "farming_flour.png", +}) + +minetest.register_craftitem("farming:bread", { + description = "Bread", + inventory_image = "farming_bread.png", + on_use = minetest.item_eat(4), +}) + +minetest.register_craft({ + type = "shapeless", + output = "farming:flour", + recipe = {"farming:wheat", "farming:wheat", "farming:wheat", "farming:wheat"} +}) + +minetest.register_craft({ + type = "cooking", + cooktime = 15, + output = "farming:bread", + 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", + 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.env: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.env:get_node_light(pos) then + return + end + if minetest.env:get_node_light(pos) < 13 then + return + end + + -- grow + local height = minetest.get_item_group(node.name, "wheat") + 1 + minetest.env:set_node(pos, {name="farming:wheat_"..height}) + end +}) + +-- +-- Cotton +-- +minetest.register_craftitem("farming:seed_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, +}) + +minetest.register_craftitem("farming:string", { + description = "String", + inventory_image = "farming_string.png", +}) + +minetest.register_craft({ + output = "wool:white", + recipe = { + {"farming:string", "farming:string"}, + {"farming:string", "farming:string"}, + } +}) + +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", + 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.env: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.env:get_node_light(pos) then + return + end + if minetest.env:get_node_light(pos) < 13 then + return + end + + -- grow + local height = minetest.get_item_group(node.name, "cotton") + 1 + minetest.env:set_node(pos, {name="farming:cotton_"..height}) + end +}) diff --git a/mods/farming/textures/farming_bread.png b/mods/farming/textures/farming_bread.png new file mode 100644 index 00000000..e508cc7f Binary files /dev/null and b/mods/farming/textures/farming_bread.png differ diff --git a/mods/farming/textures/farming_cotton_1.png b/mods/farming/textures/farming_cotton_1.png new file mode 100644 index 00000000..96195ac0 Binary files /dev/null and b/mods/farming/textures/farming_cotton_1.png differ diff --git a/mods/farming/textures/farming_cotton_2.png b/mods/farming/textures/farming_cotton_2.png new file mode 100644 index 00000000..403a2416 Binary files /dev/null and b/mods/farming/textures/farming_cotton_2.png differ diff --git a/mods/farming/textures/farming_cotton_3.png b/mods/farming/textures/farming_cotton_3.png new file mode 100644 index 00000000..eaec6d06 Binary files /dev/null and b/mods/farming/textures/farming_cotton_3.png differ diff --git a/mods/farming/textures/farming_cotton_4.png b/mods/farming/textures/farming_cotton_4.png new file mode 100644 index 00000000..38404b3d Binary files /dev/null and b/mods/farming/textures/farming_cotton_4.png differ diff --git a/mods/farming/textures/farming_cotton_5.png b/mods/farming/textures/farming_cotton_5.png new file mode 100644 index 00000000..0d4b4d21 Binary files /dev/null and b/mods/farming/textures/farming_cotton_5.png differ diff --git a/mods/farming/textures/farming_cotton_6.png b/mods/farming/textures/farming_cotton_6.png new file mode 100644 index 00000000..8b2b3deb Binary files /dev/null and b/mods/farming/textures/farming_cotton_6.png differ diff --git a/mods/farming/textures/farming_cotton_7.png b/mods/farming/textures/farming_cotton_7.png new file mode 100644 index 00000000..43ae43b7 Binary files /dev/null and b/mods/farming/textures/farming_cotton_7.png differ diff --git a/mods/farming/textures/farming_cotton_8.png b/mods/farming/textures/farming_cotton_8.png new file mode 100644 index 00000000..f673b900 Binary files /dev/null and b/mods/farming/textures/farming_cotton_8.png differ diff --git a/mods/farming/textures/farming_cotton_seed.png b/mods/farming/textures/farming_cotton_seed.png new file mode 100644 index 00000000..1507d45d Binary files /dev/null and b/mods/farming/textures/farming_cotton_seed.png differ diff --git a/mods/farming/textures/farming_flour.png b/mods/farming/textures/farming_flour.png new file mode 100644 index 00000000..ae6e4ee2 Binary files /dev/null and b/mods/farming/textures/farming_flour.png differ diff --git a/mods/farming/textures/farming_soil.png b/mods/farming/textures/farming_soil.png new file mode 100644 index 00000000..f5ffecce Binary files /dev/null and b/mods/farming/textures/farming_soil.png differ diff --git a/mods/farming/textures/farming_soil_wet.png b/mods/farming/textures/farming_soil_wet.png new file mode 100644 index 00000000..e5e6eec4 Binary files /dev/null and b/mods/farming/textures/farming_soil_wet.png differ diff --git a/mods/farming/textures/farming_soil_wet_side.png b/mods/farming/textures/farming_soil_wet_side.png new file mode 100644 index 00000000..4f5b252d Binary files /dev/null and b/mods/farming/textures/farming_soil_wet_side.png differ diff --git a/mods/farming/textures/farming_string.png b/mods/farming/textures/farming_string.png new file mode 100644 index 00000000..f417ec44 Binary files /dev/null and b/mods/farming/textures/farming_string.png differ diff --git a/mods/farming/textures/farming_tool_bronzehoe.png b/mods/farming/textures/farming_tool_bronzehoe.png new file mode 100644 index 00000000..8c608a0e Binary files /dev/null and b/mods/farming/textures/farming_tool_bronzehoe.png differ diff --git a/mods/farming/textures/farming_tool_steelhoe.png b/mods/farming/textures/farming_tool_steelhoe.png new file mode 100644 index 00000000..37aa2684 Binary files /dev/null and b/mods/farming/textures/farming_tool_steelhoe.png differ diff --git a/mods/farming/textures/farming_tool_stonehoe.png b/mods/farming/textures/farming_tool_stonehoe.png new file mode 100644 index 00000000..3f5ab612 Binary files /dev/null and b/mods/farming/textures/farming_tool_stonehoe.png differ diff --git a/mods/farming/textures/farming_tool_woodhoe.png b/mods/farming/textures/farming_tool_woodhoe.png new file mode 100644 index 00000000..2a059f61 Binary files /dev/null and b/mods/farming/textures/farming_tool_woodhoe.png differ diff --git a/mods/farming/textures/farming_wheat.png b/mods/farming/textures/farming_wheat.png new file mode 100644 index 00000000..76c74cbf Binary files /dev/null and b/mods/farming/textures/farming_wheat.png differ diff --git a/mods/farming/textures/farming_wheat_1.png b/mods/farming/textures/farming_wheat_1.png new file mode 100644 index 00000000..1cd77fe8 Binary files /dev/null and b/mods/farming/textures/farming_wheat_1.png differ diff --git a/mods/farming/textures/farming_wheat_2.png b/mods/farming/textures/farming_wheat_2.png new file mode 100644 index 00000000..ee0caee7 Binary files /dev/null and b/mods/farming/textures/farming_wheat_2.png differ diff --git a/mods/farming/textures/farming_wheat_3.png b/mods/farming/textures/farming_wheat_3.png new file mode 100644 index 00000000..002df627 Binary files /dev/null and b/mods/farming/textures/farming_wheat_3.png differ diff --git a/mods/farming/textures/farming_wheat_4.png b/mods/farming/textures/farming_wheat_4.png new file mode 100644 index 00000000..3903715e Binary files /dev/null and b/mods/farming/textures/farming_wheat_4.png differ diff --git a/mods/farming/textures/farming_wheat_5.png b/mods/farming/textures/farming_wheat_5.png new file mode 100644 index 00000000..3dc98f7c Binary files /dev/null and b/mods/farming/textures/farming_wheat_5.png differ diff --git a/mods/farming/textures/farming_wheat_6.png b/mods/farming/textures/farming_wheat_6.png new file mode 100644 index 00000000..75cf6486 Binary files /dev/null and b/mods/farming/textures/farming_wheat_6.png differ diff --git a/mods/farming/textures/farming_wheat_7.png b/mods/farming/textures/farming_wheat_7.png new file mode 100644 index 00000000..b12686dd Binary files /dev/null and b/mods/farming/textures/farming_wheat_7.png differ diff --git a/mods/farming/textures/farming_wheat_8.png b/mods/farming/textures/farming_wheat_8.png new file mode 100644 index 00000000..9263226b Binary files /dev/null and b/mods/farming/textures/farming_wheat_8.png differ diff --git a/mods/farming/textures/farming_wheat_seed.png b/mods/farming/textures/farming_wheat_seed.png new file mode 100644 index 00000000..f0bb14b2 Binary files /dev/null and b/mods/farming/textures/farming_wheat_seed.png differ