Improved flowers' registration system - Specific nodeboxes, - Color groups - All...
authorLeMagnesium <mg.minetest@gmail.com>
Thu, 4 Jun 2015 18:08:54 +0000 (20:08 +0200)
committerNovatux <nathanael.courant@laposte.net>
Sat, 6 Jun 2015 12:51:25 +0000 (14:51 +0200)
mods/flowers/init.lua

index 4037b8207abbbb25725365ff8c939b45c0014d59..672f8b56caa3bfa8842c2d2720d90f756f8ca05b 100644 (file)
@@ -1,6 +1,9 @@
 -- Minetest 0.4 mod: default
 -- See README.txt for licensing and other information.
 
+-- Namespace for functions
+flowers = {}
+
 -- Map Generation
 dofile(minetest.get_modpath("flowers").."/mapgen.lua")
 
@@ -13,13 +16,20 @@ minetest.register_alias("flowers:flower_tulip", "flowers:tulip")
 minetest.register_alias("flowers:flower_viola", "flowers:viola")
 
 -- Flower registration function
-local function add_simple_flower(name, desc, image, f_groups)
+local function add_simple_flower(name, desc, box, f_groups)
+       -- Common flowers' groups
+       f_groups.snappy = 3
+       f_groups.flammable = 2
+       f_groups.flower = 1
+       f_groups.flora = 1
+       f_groups.attached_node = 1
+
        minetest.register_node("flowers:"..name.."", {
                description = desc,
                drawtype = "plantlike",
-               tiles = { image..".png" },
-               inventory_image = image..".png",
-               wield_image = image..".png",
+               tiles = { "flowers_" .. name .. ".png" },
+               inventory_image = "flowers_" .. name .. ".png",
+               wield_image = "flowers_" .. name .. ".png",
                sunlight_propagates = true,
                paramtype = "light",
                walkable = false,
@@ -28,19 +38,24 @@ local function add_simple_flower(name, desc, image, f_groups)
                sounds = default.node_sound_leaves_defaults(),
                selection_box = {
                        type = "fixed",
-                       fixed = { -0.15, -0.5, -0.15, 0.15, 0.2, 0.15 },
-               },
+                       fixed = box
+               }
        })
 end
 
 -- Registrations using the function above
-add_simple_flower("dandelion_yellow", "Yellow Dandelion", "flowers_dandelion_yellow", {snappy=3,flammable=2,flower=1,flora=1,attached_node=1,dig_by_water=1,color_yellow=1})
-add_simple_flower("geranium", "Blue Geranium", "flowers_geranium", {snappy=3,flammable=2,flower=1,flora=1,attached_node=1,dig_by_water=1,color_blue=1})
-add_simple_flower("rose", "Rose", "flowers_rose", {snappy=3,flammable=2,flower=1,flora=1,attached_node=1,dig_by_water=1,color_red=1})
-add_simple_flower("tulip", "Orange Tulip", "flowers_tulip", {snappy=3,flammable=2,flower=1,flora=1,attached_node=1,dig_by_water=1,color_orange=1})
-add_simple_flower("dandelion_white", "White dandelion", "flowers_dandelion_white",{snappy=3,flammable=2,flower=1,flora=1,attached_node=1,color_white=1})
-add_simple_flower("viola", "Viola", "flowers_viola", {snappy=3,flammable=2,flower=1,flora=1,attached_node=1,color_violet=1})
+flowers.datas = {
+       {"dandelion_yellow", "Yellow Dandelion", { -0.15, -0.5, -0.15, 0.15, 0.2, 0.15 }, {color_yellow=1}},
+       {"geranium", "Blue Geranium", { -0.15, -0.5, -0.15, 0.15, 0.2, 0.15 }, {color_blue=1}},
+       {"rose", "Rose", { -0.15, -0.5, -0.15, 0.15, 0.3, 0.15 }, {color_red=1}},
+       {"tulip", "Orange Tulip", { -0.15, -0.5, -0.15, 0.15, 0.2, 0.15 }, {color_orange=1}},
+       {"dandelion_white", "White dandelion", { -0.5, -0.5, -0.5, 0.5, -0.2, 0.5 }, {color_white=1}},
+       {"viola", "Viola", { -0.5, -0.5, -0.5, 0.5, -0.2, 0.5 }, {color_violet=1}}
+}
 
+for _,item in pairs(flowers.datas) do
+       add_simple_flower(unpack(item))
+end
 
 minetest.register_abm({
        nodenames = {"group:flora"},