From 54ce1777f0f6b7b1a9a12a4c3813c6915bdd1653 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sat, 11 Apr 2015 17:36:59 -0700 Subject: Tomatoes. Tomatoes appear to work simple enough, until you harvest them the first time: The plant stays! However, after the 3rd to 5th harvest, the plant wilts and needs to be removed, since no more tomatoes will grow on the plant. Per harvest you can get 1-2 tomatoes only. You can craft the tomatoes to tomato seeds, as expected. --- init.lua | 1 + textures/crops_tomato.png | Bin 0 -> 626 bytes textures/crops_tomato_plant_1.png | Bin 0 -> 729 bytes textures/crops_tomato_plant_2.png | Bin 0 -> 749 bytes textures/crops_tomato_plant_3.png | Bin 0 -> 765 bytes textures/crops_tomato_plant_4.png | Bin 0 -> 766 bytes textures/crops_tomato_plant_5.png | Bin 0 -> 782 bytes textures/crops_tomato_plant_6.png | Bin 0 -> 752 bytes textures/crops_tomato_seed.png | Bin 0 -> 700 bytes tomato.lua | 154 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 155 insertions(+) create mode 100644 textures/crops_tomato.png create mode 100644 textures/crops_tomato_plant_1.png create mode 100644 textures/crops_tomato_plant_2.png create mode 100644 textures/crops_tomato_plant_3.png create mode 100644 textures/crops_tomato_plant_4.png create mode 100644 textures/crops_tomato_plant_5.png create mode 100644 textures/crops_tomato_plant_6.png create mode 100644 textures/crops_tomato_seed.png create mode 100644 tomato.lua diff --git a/init.lua b/init.lua index faf4ad3..bd749bc 100644 --- a/init.lua +++ b/init.lua @@ -12,5 +12,6 @@ of the license, or (at your option) any later version. dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/melon.lua") dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/corn.lua") +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/tomato.lua") minetest.log("action", "[crops] loaded.") diff --git a/textures/crops_tomato.png b/textures/crops_tomato.png new file mode 100644 index 0000000..f100df5 Binary files /dev/null and b/textures/crops_tomato.png differ diff --git a/textures/crops_tomato_plant_1.png b/textures/crops_tomato_plant_1.png new file mode 100644 index 0000000..d9fa087 Binary files /dev/null and b/textures/crops_tomato_plant_1.png differ diff --git a/textures/crops_tomato_plant_2.png b/textures/crops_tomato_plant_2.png new file mode 100644 index 0000000..eaaf6b9 Binary files /dev/null and b/textures/crops_tomato_plant_2.png differ diff --git a/textures/crops_tomato_plant_3.png b/textures/crops_tomato_plant_3.png new file mode 100644 index 0000000..500e02b Binary files /dev/null and b/textures/crops_tomato_plant_3.png differ diff --git a/textures/crops_tomato_plant_4.png b/textures/crops_tomato_plant_4.png new file mode 100644 index 0000000..2936188 Binary files /dev/null and b/textures/crops_tomato_plant_4.png differ diff --git a/textures/crops_tomato_plant_5.png b/textures/crops_tomato_plant_5.png new file mode 100644 index 0000000..6151137 Binary files /dev/null and b/textures/crops_tomato_plant_5.png differ diff --git a/textures/crops_tomato_plant_6.png b/textures/crops_tomato_plant_6.png new file mode 100644 index 0000000..c25cec4 Binary files /dev/null and b/textures/crops_tomato_plant_6.png differ diff --git a/textures/crops_tomato_seed.png b/textures/crops_tomato_seed.png new file mode 100644 index 0000000..ac121eb Binary files /dev/null and b/textures/crops_tomato_seed.png differ diff --git a/tomato.lua b/tomato.lua new file mode 100644 index 0000000..81519a9 --- /dev/null +++ b/tomato.lua @@ -0,0 +1,154 @@ + +--[[ + +Copyright (C) 2015 - Auke Kok + +"crops" is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 +of the license, or (at your option) any later version. + +--]] + +local interval = 90 +local chance = 2 + +minetest.register_node("crops:tomato_seed", { + description = "tomato seed", + inventory_image = "crops_tomato_seed.png", + wield_image = "crops_tomato_seed.png", + tiles = { "crops_tomato_plant_1.png" }, + drawtype = "plantlike", + sunlight_propagates = true, + use_texture_alpha = true, + walkable = false, + paramtype = "light", + groups = { snappy=3,flammable=3,flora=1,attached_node=1 }, + drop = {}, + + on_place = function(itemstack, placer, pointed_thing) + local under = minetest.get_node(pointed_thing.under) + if minetest.get_item_group(under.name, "soil") <= 1 then + return + end + minetest.set_node(pointed_thing.above, {name="crops:tomato_plant_1"}) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + return itemstack + end +}) + +for stage = 1, 4 do +minetest.register_node("crops:tomato_plant_" .. stage , { + description = "tomato plant", + tiles = { "crops_tomato_plant_" .. stage .. ".png" }, + drawtype = "plantlike", + sunlight_propagates = true, + use_texture_alpha = true, + walkable = false, + paramtype = "light", + groups = { snappy=3, flammable=3, flora=1, attached_node=1, not_in_creative_inventory=1 }, + drop = {}, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -0.5 + (((math.min(stage, 4)) + 1) / 5), 0.5} + } +}) +end + +minetest.register_node("crops:tomato_plant_5" , { + description = "tomato plant", + tiles = { "crops_tomato_plant_5.png" }, + drawtype = "plantlike", + sunlight_propagates = true, + use_texture_alpha = true, + walkable = false, + paramtype = "light", + groups = { snappy=3, flammable=3, flora=1, attached_node=1, not_in_creative_inventory=1 }, + drop = {}, + on_dig = function(pos, node, digger) + local drops = {} + for i = 1, math.random(1, 2) do + table.insert(drops, "crops:tomato") + end + core.handle_node_drops(pos, drops, digger) + + local meta = minetest.get_meta(pos) + local ttl = meta:get_int("crops_tomato_ttl") + if ttl > 1 then + minetest.set_node(pos, { name = "crops:tomato_plant_4"}) + meta:set_int("crops_tomato_ttl", ttl - 1) + else + minetest.set_node(pos, { name = "crops:tomato_plant_6"}) + meta:set_int("crops_tomato_ttl", 0) + end + end +}) + +minetest.register_node("crops:tomato_plant_6", { + description = "tomato plant", + tiles = { "crops_tomato_plant_6.png" }, + drawtype = "plantlike", + sunlight_propagates = true, + use_texture_alpha = true, + walkable = false, + paramtype = "light", + groups = { snappy=3, flammable=3, flora=1, attached_node=1, not_in_creative_inventory=1 }, + drop = {}, +}) + +minetest.register_craftitem("crops:tomato", { + description = "Tomato", + inventory_image = "crops_tomato.png", + on_use = minetest.item_eat(1) +}) + +minetest.register_craft({ + type = "shapeless", + output = "crops:tomato_seed", + recipe = { "crops:tomato" } +}) + +-- +-- grows a plant to mature size +-- +minetest.register_abm({ + nodenames = { "crops:tomato_plant_1", "crops:tomato_plant_2", "crops:tomato_plant_3" }, + neighbors = { "group:soil" }, + interval = interval, + chance = chance, + action = function(pos, node, active_object_count, active_object_count_wider) + if minetest.get_node_light(pos, nil) < 13 then + return + end + local n = string.gsub(node.name, "4", "5") + n = string.gsub(n, "3", "4") + n = string.gsub(n, "2", "3") + n = string.gsub(n, "1", "2") + minetest.set_node(pos, { name = n }) + end +}) + +-- +-- grows a tomato +-- +minetest.register_abm({ + nodenames = { "crops:tomato_plant_4" }, + neighbors = { "group:soil" }, + interval = interval, + chance = chance, + action = function(pos, node, active_object_count, active_object_count_wider) + if minetest.get_node_light(pos, nil) < 13 then + return + end + local meta = minetest.get_meta(pos) + local ttl = meta:get_int("crops_tomato_ttl") + if ttl == 0 then + ttl = math.random(4, 6) + end + minetest.set_node(pos, { name = "crops:tomato_plant_5" }) + meta:set_int("crops_tomato_ttl", ttl) + end +}) + -- cgit v1.2.3