diff options
author | Auke Kok <auke-jan.h.kok@intel.com> | 2015-04-17 00:27:21 -0700 |
---|---|---|
committer | Auke Kok <auke-jan.h.kok@intel.com> | 2015-04-17 00:27:21 -0700 |
commit | 86df3322d2cceff55012652ef786e5d909a21f58 (patch) | |
tree | cd37f8210b8484c112e8ce5c881ac6692f71fd7e /polebean.lua | |
parent | b72267b19de33311c8272b168f4ae7c3848213b9 (diff) |
Green Beans.
These green beans are unnaturally green, but there's so many
of them that grow on a vine! Sadly, these beans don't grow beans
unsupported, so you stick some sticks together to make a beanpole,
something like this way:
empty empty empty
stick empty stick
stick empty stick
There, that should help the viney bean plant to grow to 2 meters
high. It has remarkable purple flowers, that pop all over the plant
just before the beans grow.
Sadly, once the beans are picked, this plant turns into an unusable
mess that makes it hard for the next plant to grow on the beanpole,
so you salvage the beanpole's sticks after harvesting in order to
make more beanpoles again. It's a bit of work, but worth it, these
beans are delicious!
Diffstat (limited to 'polebean.lua')
-rw-r--r-- | polebean.lua | 267 |
1 files changed, 267 insertions, 0 deletions
diff --git a/polebean.lua b/polebean.lua new file mode 100644 index 0000000..7bea392 --- /dev/null +++ b/polebean.lua @@ -0,0 +1,267 @@ + +--[[ + +Copyright (C) 2015 - Auke Kok <sofar@foo-projects.org> + +"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_craft({ + output = "crops:beanpoles", + recipe = { + {'', '', ''}, + {'default:stick', '', 'default:stick'}, + {'default:stick', '', 'default:stick'}, + } +}) + +minetest.register_craftitem("crops:green_bean", { + description = "Green Bean", + inventory_image = "crops_green_bean.png", + on_use = minetest.item_eat(1) +}) + +minetest.register_craft({ + type = "shapeless", + output = "crops:green_bean_seed", + recipe = { "crops:green_bean" } +}) + +local function crops_beanpole_on_dig(pos, node, digger) + local bottom + local bottom_n + local top + local top_n + local drops = {} + + if node.name == "crops:beanpole_base" or + node.name == "crops:beanpole_plant_base_1" or + node.name == "crops:beanpole_plant_base_2" or + node.name == "crops:beanpole_plant_base_3" or --grown tall enough for top section + node.name == "crops:beanpole_plant_base_4" or --flowering + node.name == "crops:beanpole_plant_base_5" or --ripe + node.name == "crops:beanpole_plant_base_6" --harvested + then + bottom = pos + bottom_n = node + top = { x = pos.x, y = pos.y + 1, z = pos.z } + top_n = minetest.get_node(top) + elseif node.name == "crops:beanpole_top" or + node.name == "crops:beanpole_plant_top_1" or + node.name == "crops:beanpole_plant_top_2" or --flowering + node.name == "crops:beanpole_plant_top_3" or --ripe + node.name == "crops:beanpole_plant_top_4" --harvested + then + top = pos + top_n = node + bottom = { x = pos.x, y = pos.y - 1, z = pos.z } + bottom_n = minetest.get_node(bottom) + else + -- ouch, this shouldn't happen + print("beanpole on_dig falsely attached to: " .. pos.x .. "," .. pos.y .. "," .. pos.z) + return + end + + if bottom_n.name == "crops:beanpole_base" and top_n.name == "crops:beanpole_top" then + -- bare beanpole + table.insert(drops, "crops:beanpoles") + minetest.remove_node(bottom) + minetest.remove_node(top) + elseif ( + bottom_n.name == "crops:beanpole_plant_base_1" or + bottom_n.name == "crops:beanpole_plant_base_2" or + bottom_n.name == "crops:beanpole_plant_base_3" or + bottom_n.name == "crops:beanpole_plant_base_4" + ) and ( + top_n.name == "crops:beanpole_top" or + top_n.name == "crops:beanpole_plant_top_1" or + top_n.name == "crops:beanpole_plant_top_2" + ) then + -- non-ripe + for i = 1,4 do + table.insert(drops, "default:stick") + end + minetest.set_node(bottom, { name = "crops:beanpole_base"}) + minetest.set_node(top, { name = "crops:beanpole_top"}) + elseif bottom_n.name == "crops:beanpole_plant_base_5" and top_n.name == "crops:beanpole_plant_top_3" then + -- ripe beanpole + for i = 1,math.random(3,7) do + table.insert(drops, "crops:green_bean") + end + minetest.set_node(bottom, { name = "crops:beanpole_plant_base_6"}) + minetest.set_node(top, { name = "crops:beanpole_plant_top_4"}) + elseif bottom_n.name == "crops:beanpole_plant_base_6" and top_n.name == "crops:beanpole_plant_top_4" then + -- harvested beans + for i = 1,math.random(3,4) do + table.insert(drops, "default:stick") + end + minetest.remove_node(bottom) + minetest.remove_node(top) + else + -- ouch, this shouldn't happen + print("beanpole on_dig can't handle blocks at to: " .. bottom.x .. "," .. bottom.y .. "," .. bottom.z .. " and " .. top.x .. "," .. top.y .. "," .. top.z) + print("removing a " .. node.name .. " at " .. pos.x .. "," .. pos.y .. "," .. pos.z) + minetest.remove_node(pos) + return + end + + core.handle_node_drops(pos, drops, digger) +end + +minetest.register_node("crops:beanpole_base", { + description = "", + drawtype = "plantlike", + tiles = { "crops_beanpole_base.png" }, + use_texture_alpha = true, + walkable = true, + sunlight_propagates = true, + paramtype = "light", + groups = { snappy=3,flammable=3,flora=1,attached_node=1,not_in_creative_inventory=1 }, + drop = {}, + sounds = default.node_sound_leaves_defaults(), + + on_dig = crops_beanpole_on_dig, +}) + +minetest.register_node("crops:beanpole_top", { + description = "", + drawtype = "plantlike", + tiles = { "crops_beanpole_top.png" }, + use_texture_alpha = true, + walkable = true, + sunlight_propagates = true, + paramtype = "light", + groups = { snappy=3,flammable=3,flora=1,not_in_creative_inventory=1 }, + drop = {}, + sounds = default.node_sound_leaves_defaults(), + + on_dig = crops_beanpole_on_dig, +}) + +minetest.register_node("crops:beanpoles", { + description = "beanpoles", + inventory_image = "crops_beanpole_top.png", + wield_image = "crops_beanpole_top.png", + tiles = { "crops_beanpole_base.png" }, + drawtype = "plantlike", + sunlight_propagates = true, + use_texture_alpha = true, + paramtype = "light", + groups = { snappy=3,flammable=3,flora=1,attached_node=1 }, + drop = {}, + sounds = default.node_sound_leaves_defaults(), + + 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 + local top = { x = pointed_thing.above.x, y = pointed_thing.above.y + 1, z = pointed_thing.above.z } + if not minetest.get_node(top).name == "air" then + return + end + minetest.set_node(pointed_thing.above, {name="crops:beanpole_base"}) + minetest.set_node(top, {name="crops:beanpole_top"}) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + return itemstack + end +}) + +minetest.register_craftitem("crops:green_bean_seed", { + description = "green bean seed", + inventory_image = "crops_green_bean_seed.png", + wield_image = "crops_green_bean_seed.png", + + on_place = function(itemstack, placer, pointed_thing) + local under = minetest.get_node(pointed_thing.under) + if under.name == "crops:beanpole_base" then + minetest.set_node(pointed_thing.under, {name="crops:beanpole_plant_base_1"}) + elseif under.name == "crops:beanpole_top" then + local below = { x = pointed_thing.under.x, y = pointed_thing.under.y - 1, z = pointed_thing.under.z } + if minetest.get_node(below).name == "crops:beanpole_base" then + minetest.set_node(below, {name="crops:beanpole_plant_base_1"}) + else + return + end + else + return + end + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + return itemstack + end +}) + +for stage = 1,6 do +minetest.register_node("crops:beanpole_plant_base_" .. stage, { + description = "green bean plant", + tiles = { "crops_beanpole_plant_base_" .. stage .. ".png" }, + drawtype = "plantlike", + sunlight_propagates = true, + use_texture_alpha = true, + paramtype = "light", + walkable = false, + groups = { snappy=3,flammable=3,flora=1,attached_node=1,not_in_creative_inventory=1 }, + drop = {}, + sounds = default.node_sound_leaves_defaults(), + + on_dig = crops_beanpole_on_dig +}) +end + +for stage = 1,4 do +minetest.register_node("crops:beanpole_plant_top_" .. stage, { + description = "green bean plant", + tiles = { "crops_beanpole_plant_top_" .. stage .. ".png" }, + drawtype = "plantlike", + sunlight_propagates = true, + use_texture_alpha = true, + paramtype = "light", + walkable = true, + groups = { snappy=3,flammable=3,flora=1,not_in_creative_inventory=1 }, + drop = {}, + sounds = default.node_sound_leaves_defaults(), + + on_dig = crops_beanpole_on_dig +}) +end + +minetest.register_abm({ + nodenames = { "crops:beanpole_plant_base_1", "crops:beanpole_plant_base_2", "crops:beanpole_plant_base_3", "crops:beanpole_plant_base_4" }, + interval = interval, + chance = chance, + neighbors = { "group:soil" }, + action = function(pos, node, active_object_count, active_object_count_wider) + if minetest.get_node_light(pos, nil) < 13 then + return + end + if node.name == "crops:beanpole_plant_base_1" then + minetest.set_node(pos, { name = "crops:beanpole_plant_base_2"}) + elseif node.name == "crops:beanpole_plant_base_2" then + minetest.set_node(pos, { name = "crops:beanpole_plant_base_3"}) + elseif node.name == "crops:beanpole_plant_base_3" then + local apos = {x = pos.x, y = pos.y + 1, z = pos.z} + local above = minetest.get_node(apos) + if above.name == "crops:beanpole_top" then + minetest.set_node(apos, { name = "crops:beanpole_plant_top_1" }) + elseif above.name == "crops:beanpole_plant_top_1" then + minetest.set_node(pos, { name = "crops:beanpole_plant_base_4" }) + minetest.set_node(apos, { name = "crops:beanpole_plant_top_2" }) + end + elseif node.name == "crops:beanpole_plant_base_4" then + local apos = {x = pos.x, y = pos.y + 1, z = pos.z} + minetest.set_node(pos, { name = "crops:beanpole_plant_base_5" }) + minetest.set_node(apos, { name = "crops:beanpole_plant_top_3" }) + end + end +}) |