]> git.lizzy.rs Git - xdecor.git/commitdiff
Minor style cleaning
authorJP Guerrero <jeanpatrick.guerrero@gmail.com>
Mon, 5 Dec 2016 11:58:35 +0000 (12:58 +0100)
committerJP Guerrero <jeanpatrick.guerrero@gmail.com>
Mon, 5 Dec 2016 13:08:56 +0000 (14:08 +0100)
handlers/animations.lua
handlers/nodeboxes.lua
handlers/registration.lua
src/cooking.lua
src/enchanting.lua
src/mailbox.lua
src/workbench.lua

index 831ec8bf1d5f58c2dffa9689f2218500523a0ef7..6cfb0987c3c5db8f7fcc0dfc41ed9fe0f17773f8 100644 (file)
@@ -42,7 +42,8 @@ end
 
 function xdecor.sit_dig(pos, digger)
        for _, player in pairs(minetest.get_objects_inside_radius(pos, 0.1)) do
-               if player:is_player() and default.player_attached[player:get_player_name()] then
+               if player:is_player() and
+                           default.player_attached[player:get_player_name()] then
                        return false
                end
        end
index ceb2dc74b01393604b6a108cd93d5769ada1cb70..63da57e385433f0d6f4b5f7813f9592be931c36e 100644 (file)
@@ -1,21 +1,22 @@
 xdecor.box = {
        slab_y = function(height, shift)
-               return { -0.5, -0.5+(shift or 0), -0.5, 0.5, -0.5+height+(shift or 0), 0.5 }
+               return {-0.5, -0.5 + (shift or 0), -0.5, 0.5, -0.5 + height +
+                       (shift or 0), 0.5}
        end,
        slab_z = function(depth)
-               return { -0.5, -0.5, -0.5+depth, 0.5, 0.5, 0.5 }
+               return {-0.5, -0.5, -0.5 + depth, 0.5, 0.5, 0.5}
        end,
        bar_y = function(radius)
-               return { -radius, -0.5, -radius, radius, 0.5, radius }
+               return {-radius, -0.5, -radius, radius, 0.5, radius}
        end,
        cuboid = function(radius_x, radius_y, radius_z)
-               return { -radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z }
+               return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z}
        end
 }
 
 xdecor.nodebox = {
-       regular = { type = "regular" },
-       null = { type = "fixed", fixed = { 0, 0, 0, 0, 0, 0 } }
+       regular = {type="regular"},
+       null = {type="fixed", fixed={0,0,0,0,0,0}}
 }
 
 xdecor.pixelbox = function(size, boxes)
@@ -32,7 +33,7 @@ xdecor.pixelbox = function(size, boxes)
                        ((z + l) / size) - 0.5
                }
        end
-       return { type = "fixed", fixed = fixed }
+       return {type="fixed", fixed=fixed}
 end
 
 local mt = {}
@@ -42,10 +43,10 @@ mt.__index = function(table, key)
 
        if ref_type == "function" then
                return function(...)
-                       return { type = "fixed", fixed = ref(...) }
+                       return {type="fixed", fixed=ref(...)}
                end
        elseif ref_type == "table" then
-               return { type = "fixed", fixed = ref }
+               return {type="fixed", fixed=ref}
        elseif ref_type == "nil" then
                error(key.."could not be found among nodebox presets and functions")
        end
index 680c202abed747fd9454ea4669af5f45fae99972..fc6409e5ebcea2c967c9c2a8450525a75f467470 100644 (file)
@@ -43,10 +43,7 @@ local default_can_dig = function(pos)
 end
 
 function xdecor.register(name, def)
-       def.drawtype = def.drawtype
-               or (def.mesh and "mesh")
-               or (def.node_box and "nodebox")
-
+       def.drawtype = def.drawtype or (def.mesh and "mesh") or (def.node_box and "nodebox")
        def.sounds = def.sounds or default.node_sound_defaults()
 
        if not (def.drawtype == "normal" or def.drawtype == "signlike" or
@@ -79,7 +76,8 @@ function xdecor.register(name, def)
                        local size = inventory.size or default_inventory_size
                        local inv = meta:get_inventory()
                        inv:set_size("main", size)
-                       meta:set_string("formspec", (inventory.formspec or get_formspec_by_size(size))..xbg)
+                       meta:set_string("formspec", (inventory.formspec or
+                                       get_formspec_by_size(size))..xbg)
                end
                def.can_dig = def.can_dig or default_can_dig
        elseif infotext and not def.on_construct then
index 46629ec756278760479c20308dbbeac85187941d..a14e30ec315f1b29b0886eb302ff8ef37aee489e 100644 (file)
@@ -77,7 +77,7 @@ function cauldron.idle_timer(pos)
        return true
 end
 
--- Ugly hack to determine if an item has `minetest.item_eat` in its definition.
+-- Ugly hack to determine if an item has the function `minetest.item_eat` in its definition.
 local function eatable(itemstring)
        local item = itemstring:match("[%w_:]+")
        local on_use_def = minetest.registered_items[item].on_use
index c4f1da85613ba6baf69b97eb3e42edae298ad5c2..117861f0a0ebc25bb89344dfaa083a2289fc0000 100644 (file)
@@ -28,7 +28,8 @@ function enchanting:get_tooltip(enchant, orig_caps, fleshy)
                        sum_caps_times = sum_caps_times + orig_caps.times[i]
                end
                local average_caps_time = sum_caps_times / #orig_caps.times
-               bonus.efficiency = to_percent(average_caps_time, average_caps_time - enchanting.times)
+               bonus.efficiency = to_percent(average_caps_time, average_caps_time -
+                                             enchanting.times)
        end
        if fleshy then
                bonus.damages = to_percent(fleshy, fleshy + enchanting.damages)
@@ -44,6 +45,14 @@ function enchanting:get_tooltip(enchant, orig_caps, fleshy)
        return minetest.colorize(specs[enchant][1], "\n"..cap(enchant)..specs[enchant][2])
 end
 
+local enchant_buttons = {
+       [[ image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency]
+       image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability] ]],
+       "image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]",
+       "image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]",
+       [[ image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]
+       image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed] ]]
+}
 
 function enchanting.formspec(pos, num)
        local meta = minetest.get_meta(pos)
@@ -61,15 +70,6 @@ function enchanting.formspec(pos, num)
                        tooltip[speed;Your speed is increased] ]]
                        ..default.gui_slots..default.get_hotbar_bg(0.5,4.5)
 
-       local enchant_buttons = {
-               [[ image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency]
-               image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability] ]],
-               "image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]",
-               "image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]",
-               [[ image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]
-               image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed] ]]
-       }
-
        formspec = formspec..(enchant_buttons[num] or "")
        meta:set_string("formspec", formspec)
 end
@@ -92,9 +92,7 @@ function enchanting.on_put(pos, listname, _, stack)
 end
 
 function enchanting.fields(pos, _, fields, sender)
-       if not next(fields) or fields.quit then
-               return
-       end
+       if not next(fields) or fields.quit then return end
        local inv = minetest.get_meta(pos):get_inventory()
        local tool = inv:get_stack("tool", 1)
        local mese = inv:get_stack("mese", 1)
@@ -103,7 +101,8 @@ function enchanting.fields(pos, _, fields, sender)
        local enchanted_tool = (mod or "")..":enchanted_"..(name or "").."_"..next(fields)
 
        if mese:get_count() >= mese_cost and minetest.registered_tools[enchanted_tool] then
-               minetest.sound_play("xdecor_enchanting", {to_player=sender:get_player_name(), gain=0.8})
+               minetest.sound_play("xdecor_enchanting", {
+                       to_player=sender:get_player_name(), gain=0.8})
                tool:replace(enchanted_tool)
                tool:add_wear(orig_wear)
                mese:take_item(mese_cost)
@@ -126,10 +125,10 @@ local function allowed(tool)
 end
 
 function enchanting.put(_, listname, _, stack)
-       local item = stack:get_name():match("[^:]+$")
-       if listname == "mese" and item == "mese_crystal" then
+       local stackname = stack:get_name()
+       if listname == "mese" and stackname == "default:mese_crystal" then
                return stack:get_count()
-       elseif listname == "tool" and allowed(item) then
+       elseif listname == "tool" and allowed(stackname:match("[^:]+$")) then
                return 1
        end
        return 0
@@ -232,18 +231,20 @@ function enchanting:register_tools(mod, def)
        for enchant in def.tools[tool].enchants:gmatch("[%w_]+") do
                local original_tool = minetest.registered_tools[mod..":"..tool.."_"..material]
                if not original_tool then break end
+               local original_toolcaps = original_tool.tool_capabilities
 
-               if original_tool.tool_capabilities then
-                       local original_damage_groups = original_tool.tool_capabilities.damage_groups
-                       local original_groupcaps = original_tool.tool_capabilities.groupcaps
+               if original_toolcaps then
+                       local original_damage_groups = original_toolcaps.damage_groups
+                       local original_groupcaps = original_toolcaps.groupcaps
                        local groupcaps = table.copy(original_groupcaps)
                        local fleshy = original_damage_groups.fleshy
-                       local full_punch_interval = original_tool.tool_capabilities.full_punch_interval
-                       local max_drop_level = original_tool.tool_capabilities.max_drop_level
+                       local full_punch_interval = original_toolcaps.full_punch_interval
+                       local max_drop_level = original_toolcaps.max_drop_level
                        local group = next(original_groupcaps)
 
                        if enchant == "durable" then
-                               groupcaps[group].uses = ceil(original_groupcaps[group].uses * enchanting.uses)
+                               groupcaps[group].uses = ceil(original_groupcaps[group].uses *
+                                                            enchanting.uses)
                        elseif enchant == "fast" then
                                for i, time in pairs(original_groupcaps[group].times) do
                                        groupcaps[group].times[i] = time - enchanting.times
@@ -260,7 +261,8 @@ function enchanting:register_tools(mod, def)
                                groups = {not_in_creative_inventory=1},
                                tool_capabilities = {
                                        groupcaps = groupcaps, damage_groups = {fleshy = fleshy},
-                                       full_punch_interval = full_punch_interval, max_drop_level = max_drop_level
+                                       full_punch_interval = full_punch_interval,
+                                       max_drop_level = max_drop_level
                                }
                        })
                end
index dba667b24f23414eb5e679ce502ddc085f319b02..edcbbfcc91a9c5f5ccb4cc14fbf8d0e1d0de1e96 100644 (file)
@@ -28,12 +28,12 @@ local function img_col(stack)
        return ""
 end
 
-function mailbox:formspec(pos, owner, num)
+function mailbox:formspec(pos, owner, is_owner)
        local spos = pos.x..","..pos.y..","..pos.z
        local meta = minetest.get_meta(pos)
        local giver, img = "", ""
 
-       if num == 1 then
+       if is_owner then
                for i = 1, 7 do
                        local giving = meta:get_string("giver"..i)
                        if giving ~= "" then
@@ -42,7 +42,8 @@ function mailbox:formspec(pos, owner, num)
                                local stack_name = stack:match("[%w_:]+")
                                local stack_count = stack:match("%s(%d+)") or 1
 
-                               giver = giver.."#FFFF00,"..giver_name..","..i..",#FFFFFF,x "..stack_count..","
+                               giver = giver.."#FFFF00,"..giver_name..","..i..
+                                       ",#FFFFFF,x "..stack_count..","
                                img = img..i.."="..img_col(stack_name).."^\\[resize:16x16,"
                        end
                end
@@ -59,13 +60,12 @@ function mailbox:formspec(pos, owner, num)
                        "list[nodemeta:"..spos..";mailbox;0,0.75;6,4;]"..
                        "listring[nodemeta:"..spos..";mailbox]"..
                        xbg..default.get_hotbar_bg(0.75,5.25)
-       else
-               return [[ size[8,5]
-                       list[current_player;main;0,1.25;8,4;] ]]..
-                       "label[0,0;Send your goods to\n"..minetest.colorize("#FFFF00", owner).."]"..
-                       "list[nodemeta:"..spos..";drop;3.5,0;1,1;]"..
-                       xbg..default.get_hotbar_bg(0,1.25)
        end
+       return [[ size[8,5]
+               list[current_player;main;0,1.25;8,4;] ]]..
+               "label[0,0;Send your goods to\n"..minetest.colorize("#FFFF00", owner).."]"..
+               "list[nodemeta:"..spos..";drop;3.5,0;1,1;]"..
+               xbg..default.get_hotbar_bg(0,1.25)
 end
 
 function mailbox.dig(pos, player)
@@ -94,11 +94,8 @@ function mailbox.rightclick(pos, node, clicker, itemstack, pointed_thing)
        local player = clicker:get_player_name()
        local owner = meta:get_string("owner")
 
-       if player == owner then
-               minetest.show_formspec(player, "xdecor:mailbox", mailbox:formspec(pos, owner, 1))
-       else
-               minetest.show_formspec(player, "xdecor:mailbox", mailbox:formspec(pos, owner, 0))
-       end
+       minetest.show_formspec(player, "xdecor:mailbox", mailbox:formspec(pos,
+                              owner, (player == owner)))
        return itemstack
 end
 
@@ -108,7 +105,8 @@ function mailbox.put(pos, listname, _, stack, player)
                if inv:room_for_item("mailbox", stack) then
                        return -1
                else
-                       minetest.chat_send_player(player:get_player_name(), "The mailbox is full")
+                       minetest.chat_send_player(player:get_player_name(),
+                                                 "The mailbox is full")
                end
        end
        return 0
index 6b762a46a87ad045371dac07b3219e3fd5f38a15..4b634699d9d5e3e5249f879c96d173636049014d 100644 (file)
@@ -26,7 +26,7 @@ for node, def in pairs(minetest.registered_nodes) do
        end
 end
 
--- Optionally, you can register custom cuttable nodes in the workbench
+-- Optionally, you can register custom cuttable nodes in the workbench.
 workbench.custom_nodes_register = {
        -- "default:leaves",
 }
@@ -172,7 +172,8 @@ end
 
 function workbench.put(_, listname, _, stack)
        local stackname = stack:get_name()
-       if (listname == "tool" and stack:get_wear() > 0 and workbench:repairable(stackname)) or
+       if (listname == "tool" and stack:get_wear() > 0 and
+           workbench:repairable(stackname)) or
           (listname == "input" and minetest.registered_nodes[stackname.."_cube"]) or
           (listname == "hammer" and stackname == "xdecor:hammer") or
            listname == "storage" then
@@ -243,7 +244,7 @@ xdecor.register("workbench", {
 })
 
 for _, d in pairs(workbench.defs) do
-for i = 1, #nodes do
+for i=1, #nodes do
        local node = nodes[i]
        local def = minetest.registered_nodes[node]
 
@@ -269,8 +270,9 @@ for i = 1, #nodes do
                end
 
                if not minetest.registered_nodes["stairs:slab_"..node:match(":(.*)")] then
-                       stairs.register_stair_and_slab(node:match(":(.*)"), node, groups, tiles,
-                               def.description.." Stair", def.description.." Slab", def.sounds)
+                       stairs.register_stair_and_slab(node:match(":(.*)"), node,
+                               groups, tiles, def.description.." Stair",
+                               def.description.." Slab", def.sounds)
                end
 
                minetest.register_node(":"..node.."_"..d[1], {