diff options
author | Auke Kok <auke-jan.h.kok@intel.com> | 2015-04-08 01:03:54 -0700 |
---|---|---|
committer | Auke Kok <auke-jan.h.kok@intel.com> | 2015-04-08 01:03:54 -0700 |
commit | 1fa945bf6b4a491dd89d7fe53837cc079c4175e6 (patch) | |
tree | 1174836a716f1766971ba1ba1bc538980238aa1a |
Initial commit.
This should be entirely working now - MELONS!
Work as expected. A seed grows to a plant, plant flowers and an
adjacent melon block grows, and is attached with a stem. Once the
melon block is harvested (which drops 3-5 melon slices), the
stem is lost and the plant will grow a new melon from it's mature
stage.
-rw-r--r-- | depends.txt | 1 | ||||
-rw-r--r-- | init.lua | 2 | ||||
-rw-r--r-- | melon.lua | 191 | ||||
-rw-r--r-- | models/crops_plant_extra_face.obj | 49 | ||||
-rw-r--r-- | textures/crops_melon.png | bin | 0 -> 387 bytes | |||
-rw-r--r-- | textures/crops_melon_bottom.png | bin | 0 -> 667 bytes | |||
-rw-r--r-- | textures/crops_melon_inv.png | bin | 0 -> 1765 bytes | |||
-rw-r--r-- | textures/crops_melon_plant_1.png | bin | 0 -> 509 bytes | |||
-rw-r--r-- | textures/crops_melon_plant_2.png | bin | 0 -> 548 bytes | |||
-rw-r--r-- | textures/crops_melon_plant_3.png | bin | 0 -> 641 bytes | |||
-rw-r--r-- | textures/crops_melon_plant_4.png | bin | 0 -> 721 bytes | |||
-rw-r--r-- | textures/crops_melon_plant_5.png | bin | 0 -> 822 bytes | |||
-rw-r--r-- | textures/crops_melon_seed.png | bin | 0 -> 775 bytes | |||
-rw-r--r-- | textures/crops_melon_slice.png | bin | 0 -> 406 bytes | |||
-rw-r--r-- | textures/crops_melon_stem.png | bin | 0 -> 680 bytes | |||
-rw-r--r-- | textures/crops_melon_top.png | bin | 0 -> 628 bytes |
16 files changed, 243 insertions, 0 deletions
diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..d936b63 --- /dev/null +++ b/init.lua @@ -0,0 +1,2 @@ + +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/melon.lua") diff --git a/melon.lua b/melon.lua new file mode 100644 index 0000000..014335a --- /dev/null +++ b/melon.lua @@ -0,0 +1,191 @@ + +-- FIXME - timers!!! + +local faces = { + [1] = { x = -1, z = 0, r = 3, o = 1 } , + [2] = { x = 1, z = 0, r = 1, o = 3 } , + [3] = { x = 0, z = -1, r = 2, o = 0 } , + [4] = { x = 0, z = 1, r = 0, o = 2 } +} + +minetest.register_node("crops:melon_seed", { + description = "melon seed", + inventory_image = "crops_melon_seed.png", + tiles = { "crops_melon_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:melon_plant_1"}) + itemstack:take_item() + return itemstack + end +}) + +for stage = 1, 5 do +minetest.register_node("crops:melon_plant_" .. stage , { + description = "melon plant", + tiles = { "crops_melon_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 = "crops:melon_seed", + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -0.5 + (((3 * stage) + 1) / 16), 0.5} + } +}) +end + +minetest.register_node("crops:melon_plant_5_attached", { + visual = "mesh", + mesh = "crops_plant_extra_face.obj", + description = "melon plant", + tiles = { "crops_melon_stem.png", "crops_melon_plant_5.png" }, + drawtype = "mesh", + paramtype2 = "facedir", + sunlight_propagates = true, + use_texture_alpha = true, + walkable = false, + paramtype = "light", + groups = { snappy=3, flammable=3, flora=1, attached_node=1, }, + drop = "crops:melon_seed", +}) + + +minetest.register_craftitem("crops:melon_slice", { + description = "Melon slice", + inventory_image = "crops_melon_slice.png", + on_use = minetest.item_eat(1) +}) + +minetest.register_craft({ + type = "shapeless", + output = "crops:melon_seed", + recipe = { "crops:melon_slice" } +}) + +-- +-- the melon "block" +-- +minetest.register_node("crops:melon", { + description = "Melon", + inventory_image = "crops_melon_inv.png", + tiles = { "crops_melon_top.png", "crops_melon_bottom.png", "crops_melon.png", "crops_melon.png", "crops_melon.png", "crops_melon.png" }, + sunlight_propagates = false, + use_texture_alpha = false, + walkable = true, + groups = { snappy=3, flammable=3, oddly_breakable_by_hand=2 }, + drop = {max_items = 5, items = { + { items = {'crops:melon_slice'}, rarity = 1 }, + { items = {'crops:melon_slice'}, rarity = 1 }, + { items = {'crops:melon_slice'}, rarity = 1 }, + { items = {'crops:melon_slice'}, rarity = 2 }, + { items = {'crops:melon_slice'}, rarity = 5 }, + }}, + sounds = default.node_sound_wood_defaults({ + dig = { name = "default_dig_oddly_breakable_by_hand" }, + dug = { name = "default_dig_choppy" } + }), + on_dig = function(pos, node, digger) + local code = minetest.node_dig(pos, node, digger) + for face = 1, 4 do + local s = { x = pos.x + faces[face].x, y = pos.y, z = pos.z + faces[face].z } + local n = minetest.get_node(s) + if n.name == "crops:melon_plant_5_attached" then + -- make sure it was actually attached to this stem + if n.param2 == faces[face].o then + minetest.set_node(s, { name = "crops:melon_plant_5" }) + return code + end + end + end + return code + end +}) + +-- +-- grows a plant to mature size +-- +minetest.register_abm({ + nodenames = { "crops:melon_plant_1", "crops:melon_plant_2", "crops:melon_plant_3","crops:melon_plant_4" }, + interval = 30, + chance = 10, + 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 melon +-- +minetest.register_abm({ + nodenames = { "crops:melon_plant_5" }, + interval = 30, + chance = 10, + action = function(pos, node, active_object_count, active_object_count_wider) + if minetest.get_node_light(pos, nil) < 13 then + return + end + for face = 1, 4 do + local t = { x = pos.x + faces[face].x, y = pos.y, z = pos.z + faces[face].z } + if minetest.get_node(t).name == "crops:melon" then + return + end + end + local r = math.random(1, 4) + local t = { x = pos.x + faces[r].x, y = pos.y, z = pos.z + faces[r].z } + local n = minetest.get_node(t) + if n.name == "ignore" then + return + end + + if minetest.registered_nodes[minetest.get_node({ x = t.x, y = t.y - 1, z = t.z }).name].walkable == false then + return + end + + if minetest.registered_nodes[n.name].drawtype == "plantlike" or + minetest.registered_nodes[n.name].groups.flora == 1 or + n.name == "air" then + minetest.set_node(t, {name = "crops:melon"}) + minetest.set_node(pos, {name = "crops:melon_plant_5_attached", param2 = faces[r].r}) + end + end +}) + +-- +-- return a melon to a normal one if there is no melon attached, so it can +-- grow a new melon again +-- +minetest.register_abm({ + nodenames = { "crops:melon_plant_5_attached" }, + interval = 30, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + for face = 1, 4 do + local t = { x = pos.x + faces[face].x, y = pos.y, z = pos.z + faces[face].z } + if minetest.get_node(t).name == "crops:melon" then + return + end + end + minetest.set_node(pos, {name = "crops:melon_plant_5" }) + end +}) diff --git a/models/crops_plant_extra_face.obj b/models/crops_plant_extra_face.obj new file mode 100644 index 0000000..fd22dd7 --- /dev/null +++ b/models/crops_plant_extra_face.obj @@ -0,0 +1,49 @@ +# Blender v2.60 (sub 0) OBJ File: 'p1.blend' +# www.blender.org +mtllib crops_plant_extra_face.mtl +o Mesh_Stem_Stem +v -0.000000 0.500000 0.500000 +v 0.000000 -0.500000 0.500000 +v 0.000000 -0.500000 -0.500000 +v -0.000000 0.500000 -0.500000 +vt 0.000000 0.000000 +vt 1.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vn 1.000000 0.000000 -0.000000 +g Mesh_Stem_Stem_Material.002 +usemtl Material.002 +s off +f 1/1/1 2/2/1 3/3/1 4/4/1 +o Mesh_Plant_Plant +v 0.359670 -0.500000 0.347329 +v 0.359670 0.500000 0.347329 +v -0.359670 0.500000 -0.347329 +v -0.359670 -0.500000 -0.347329 +v -0.347329 -0.500000 0.359670 +v -0.347329 0.500000 0.359670 +v 0.347329 0.500000 -0.359670 +v 0.347329 -0.500000 -0.359670 +v 0.359670 -0.500000 0.347329 +v -0.359670 -0.500000 -0.347329 +v -0.359670 0.500000 -0.347329 +v 0.359670 0.500000 0.347329 +v -0.347329 -0.500000 0.359670 +v 0.347329 -0.500000 -0.359670 +v 0.347329 0.500000 -0.359670 +v -0.347329 0.500000 0.359670 +vt 1.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vn -0.694658 0.000000 0.719340 +vn -0.719340 -0.000000 -0.694658 +vn 0.694658 -0.000000 -0.719340 +vn 0.719340 0.000000 0.694658 +g Mesh_Plant_Plant_Material.001 +usemtl Material.001 +s off +f 5/5/2 6/6/2 7/7/2 8/8/2 +f 9/5/3 10/6/3 11/7/3 12/8/3 +f 13/5/4 14/8/4 15/7/4 16/6/4 +f 17/5/5 18/8/5 19/7/5 20/6/5 diff --git a/textures/crops_melon.png b/textures/crops_melon.png Binary files differnew file mode 100644 index 0000000..46557a0 --- /dev/null +++ b/textures/crops_melon.png diff --git a/textures/crops_melon_bottom.png b/textures/crops_melon_bottom.png Binary files differnew file mode 100644 index 0000000..572c1d0 --- /dev/null +++ b/textures/crops_melon_bottom.png diff --git a/textures/crops_melon_inv.png b/textures/crops_melon_inv.png Binary files differnew file mode 100644 index 0000000..6ab4574 --- /dev/null +++ b/textures/crops_melon_inv.png diff --git a/textures/crops_melon_plant_1.png b/textures/crops_melon_plant_1.png Binary files differnew file mode 100644 index 0000000..961213a --- /dev/null +++ b/textures/crops_melon_plant_1.png diff --git a/textures/crops_melon_plant_2.png b/textures/crops_melon_plant_2.png Binary files differnew file mode 100644 index 0000000..c9b4315 --- /dev/null +++ b/textures/crops_melon_plant_2.png diff --git a/textures/crops_melon_plant_3.png b/textures/crops_melon_plant_3.png Binary files differnew file mode 100644 index 0000000..930a872 --- /dev/null +++ b/textures/crops_melon_plant_3.png diff --git a/textures/crops_melon_plant_4.png b/textures/crops_melon_plant_4.png Binary files differnew file mode 100644 index 0000000..f4f234c --- /dev/null +++ b/textures/crops_melon_plant_4.png diff --git a/textures/crops_melon_plant_5.png b/textures/crops_melon_plant_5.png Binary files differnew file mode 100644 index 0000000..fc021b6 --- /dev/null +++ b/textures/crops_melon_plant_5.png diff --git a/textures/crops_melon_seed.png b/textures/crops_melon_seed.png Binary files differnew file mode 100644 index 0000000..603f19a --- /dev/null +++ b/textures/crops_melon_seed.png diff --git a/textures/crops_melon_slice.png b/textures/crops_melon_slice.png Binary files differnew file mode 100644 index 0000000..4691556 --- /dev/null +++ b/textures/crops_melon_slice.png diff --git a/textures/crops_melon_stem.png b/textures/crops_melon_stem.png Binary files differnew file mode 100644 index 0000000..aff846b --- /dev/null +++ b/textures/crops_melon_stem.png diff --git a/textures/crops_melon_top.png b/textures/crops_melon_top.png Binary files differnew file mode 100644 index 0000000..796cb1b --- /dev/null +++ b/textures/crops_melon_top.png |