From 4eb2873dabfd8b0cc8542b5221a229ef37a1f669 Mon Sep 17 00:00:00 2001 From: srifqi Date: Wed, 27 Aug 2014 15:52:31 +0700 Subject: [PATCH] Applying ShadowNinja recommendation See https://github.com/minetest/minetest_game/pull/307#issuecomment-53363617 --- mods/carpet/init.lua | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/mods/carpet/init.lua b/mods/carpet/init.lua index b7c8e3a0..2c80fb37 100644 --- a/mods/carpet/init.lua +++ b/mods/carpet/init.lua @@ -1,27 +1,33 @@ +-- Carpet API carpet = {} --- Carpet API +-- Registering carpet ( carpet.register() ) --[[ + def is a table that contains: name : itemstring "carpet:name" - desc : node description + description : node description (optional) images : node tiles recipeitem : node crafting recipeitem {recipeitem,recipeitem} groups : node groups - sounds : node sounds + sounds : node sounds (optional) --]] -- Carpet will be named carpet:name -function carpet.add(name, desc, images, recipeitem, groups, sounds) +function carpet.register(def) + local name = def.name + local desc = def.description or "" + local recipeitem = def.recipeitem + local sounds = def.sounds or default.node_sound_defaults() -- Node Definition minetest.register_node("carpet:"..name, { description = desc, - tiles = images, + tiles = def.images, paramtype = "light", node_box = { type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -7/16, 0.5}, }, drawtype = "nodebox", - groups = groups, + groups = def.groups, sounds = sounds, }) -- Crafting Definition @@ -55,10 +61,12 @@ carpet.wool = { for _, row in ipairs(carpet.wool) do local name = row[1] local desc = row[2] - carpet.add( - name, desc..' Carpet', - {'wool_'..name..'.png'}, 'wool:'..name, - {snappy=2,choppy=2,oddly_breakable_by_hand=3,flammable=3,falling_node=1,carpet=1}, - default.node_sound_defaults() - ) + carpet.register({ + name = name, + description = desc..' Carpet', + images = {'wool_'..name..'.png'}, + recipeitem = 'wool:'..name, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,flammable=3,falling_node=1,carpet=1}, + sounds = default.node_sound_defaults() + }) end