From aa239c4ae3d89cf146198de5f0046856e570d223 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Tue, 14 Apr 2015 01:09:35 -0700 Subject: Potatoes. The plants themselves don't drop anything. Only if the plant matures can you dig potatoes from the soil. If you can reach the soil from the side you can save yourself one dig by digging the soil as that will remove the plant from the top, but otherwise you need to dig twice: once to remove the plant, once to dig out the potatoes. You get 3-5 potatoes. Each potato gives one (set of) "potato eyes" which are the clones that can grow back to potatoes. The plant itself is purposedly drawn "low" and not as a full block as that's how the plant grows without support, mostly close to the ground. Be careful not to dig the plant when there's flowers! You have to wait until the soil below shows potatoes. It's fairly easy to see the difference, though. --- init.lua | 5 +- potato.lua | 148 ++++++++++++++++++++++++++++++++++++++ textures/crops_potato.png | Bin 0 -> 453 bytes textures/crops_potato_eyes.png | Bin 0 -> 552 bytes textures/crops_potato_plant_1.png | Bin 0 -> 255 bytes textures/crops_potato_plant_2.png | Bin 0 -> 316 bytes textures/crops_potato_plant_3.png | Bin 0 -> 380 bytes textures/crops_potato_plant_4.png | Bin 0 -> 417 bytes textures/crops_potato_soil.png | Bin 0 -> 911 bytes 9 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 potato.lua create mode 100644 textures/crops_potato.png create mode 100644 textures/crops_potato_eyes.png create mode 100644 textures/crops_potato_plant_1.png create mode 100644 textures/crops_potato_plant_2.png create mode 100644 textures/crops_potato_plant_3.png create mode 100644 textures/crops_potato_plant_4.png create mode 100644 textures/crops_potato_soil.png diff --git a/init.lua b/init.lua index 38c098f..90fcc87 100644 --- a/init.lua +++ b/init.lua @@ -10,11 +10,12 @@ of the license, or (at your option) any later version. --]] -local crops_interval = 30 -local crops_chance = 8 +crops_interval = 30 +crops_chance = 8 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") +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/potato.lua") minetest.log("action", "[crops] loaded.") diff --git a/potato.lua b/potato.lua new file mode 100644 index 0000000..a652075 --- /dev/null +++ b/potato.lua @@ -0,0 +1,148 @@ + +--[[ + +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 = crops_interval +local chance = crops_chance + +minetest.register_node("crops:potato_eyes", { + description = "potato eyes", + inventory_image = "crops_potato_eyes.png", + wield_image = "crops_potato_eyes.png", + tiles = { "crops_potato_plant_1.png" }, + drawtype = "plantlike", + sunlight_propagates = false, + use_texture_alpha = true, + walkable = false, + paramtype = "light", + groups = { snappy=3,flammable=3,flora=1,attached_node=1 }, + + 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:potato_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:potato_plant_" .. stage , { + description = "potato plant", + tiles = { "crops_potato_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 = {}, + sounds = default.node_sound_leaves_defaults(), + 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_craftitem("crops:potato", { + description = "potato", + inventory_image = "crops_potato.png", + on_use = minetest.item_eat(1) +}) + +minetest.register_craft({ + type = "shapeless", + output = "crops:potato_eyes", + recipe = { "crops:potato" } +}) + +-- +-- the potatoes "block" +-- +minetest.register_node("crops:soil_with_potatoes", { + description = "Soil with potatoes", + tiles = { "default_dirt.png^crops_potato_soil.png", "default_dirt.png" }, + sunlight_propagates = false, + use_texture_alpha = false, + walkable = true, + groups = { snappy=3, flammable=3, oddly_breakable_by_hand=2, soil=1 }, + paramtype2 = "facedir", + drop = {max_items = 5, items = { + { items = {'crops:potato'}, rarity = 1 }, + { items = {'crops:potato'}, rarity = 1 }, + { items = {'crops:potato'}, rarity = 1 }, + { items = {'crops:potato'}, rarity = 2 }, + { items = {'crops:potato'}, rarity = 5 }, + }}, + sounds = default.node_sound_dirt_defaults(), + on_dig = function(pos, node, digger) + local drops = {} + for i = 1, math.random(3, 5) do + table.insert(drops, "crops:potato") + end + core.handle_node_drops(pos, drops, digger) + minetest.set_node(pos, { name = "farming:soil" }) + local above = { x = pos.x, y = pos.y + 1, z = pos.z } + if minetest.get_node(above).name == "crops:potato_plant_4" then + minetest.set_node(above, { name = "air" }) + end + end +}) + +-- +-- grows a plant to mature size +-- +minetest.register_abm({ + nodenames = { "crops:potato_plant_1", "crops:potato_plant_2", "crops:potato_plant_3" }, + neighbors = { "group:soil" }, + interval = interval, + chance = chance, + action = function(pos, node, active_object_count, active_object_count_wider) + local below = { x = pos.x, y = pos.y - 1, z = pos.z } + if not minetest.registered_nodes[minetest.get_node(below).name].groups.soil then + return + end + if minetest.get_node_light(pos, nil) < 13 then + return + end + local n = string.gsub(node.name, "3", "4") + n = string.gsub(n, "2", "3") + n = string.gsub(n, "1", "2") + minetest.set_node(pos, { name = n }) + end +}) + +-- +-- grows the final potatoes in the soil beneath +-- +minetest.register_abm({ + nodenames = { "crops:potato_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 below = { x = pos.x, y = pos.y - 1, z = pos.z } + if not minetest.registered_nodes[minetest.get_node(below).name].groups.soil then + return + end + local below = { x = pos.x, y = pos.y - 1, z = pos.z} + minetest.set_node(below, { name = "crops:soil_with_potatoes" }) + end +}) + diff --git a/textures/crops_potato.png b/textures/crops_potato.png new file mode 100644 index 0000000..486e972 Binary files /dev/null and b/textures/crops_potato.png differ diff --git a/textures/crops_potato_eyes.png b/textures/crops_potato_eyes.png new file mode 100644 index 0000000..ad8e908 Binary files /dev/null and b/textures/crops_potato_eyes.png differ diff --git a/textures/crops_potato_plant_1.png b/textures/crops_potato_plant_1.png new file mode 100644 index 0000000..8536fec Binary files /dev/null and b/textures/crops_potato_plant_1.png differ diff --git a/textures/crops_potato_plant_2.png b/textures/crops_potato_plant_2.png new file mode 100644 index 0000000..824c8cb Binary files /dev/null and b/textures/crops_potato_plant_2.png differ diff --git a/textures/crops_potato_plant_3.png b/textures/crops_potato_plant_3.png new file mode 100644 index 0000000..a286fa1 Binary files /dev/null and b/textures/crops_potato_plant_3.png differ diff --git a/textures/crops_potato_plant_4.png b/textures/crops_potato_plant_4.png new file mode 100644 index 0000000..41ebb66 Binary files /dev/null and b/textures/crops_potato_plant_4.png differ diff --git a/textures/crops_potato_soil.png b/textures/crops_potato_soil.png new file mode 100644 index 0000000..a3ee797 Binary files /dev/null and b/textures/crops_potato_soil.png differ -- cgit v1.2.3