From de94a402b91123ce248352bd9c97d4b7753d3573 Mon Sep 17 00:00:00 2001 From: JP Guerrero Date: Mon, 5 Dec 2016 12:58:35 +0100 Subject: [PATCH] Minor style cleaning --- handlers/animations.lua | 3 ++- handlers/nodeboxes.lua | 19 ++++++++------- handlers/registration.lua | 8 +++---- src/cooking.lua | 2 +- src/enchanting.lua | 50 ++++++++++++++++++++------------------- src/mailbox.lua | 28 ++++++++++------------ src/workbench.lua | 12 ++++++---- 7 files changed, 62 insertions(+), 60 deletions(-) diff --git a/handlers/animations.lua b/handlers/animations.lua index 831ec8b..6cfb098 100644 --- a/handlers/animations.lua +++ b/handlers/animations.lua @@ -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 diff --git a/handlers/nodeboxes.lua b/handlers/nodeboxes.lua index ceb2dc7..63da57e 100644 --- a/handlers/nodeboxes.lua +++ b/handlers/nodeboxes.lua @@ -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 diff --git a/handlers/registration.lua b/handlers/registration.lua index 680c202..fc6409e 100644 --- a/handlers/registration.lua +++ b/handlers/registration.lua @@ -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 diff --git a/src/cooking.lua b/src/cooking.lua index 46629ec..a14e30e 100644 --- a/src/cooking.lua +++ b/src/cooking.lua @@ -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 diff --git a/src/enchanting.lua b/src/enchanting.lua index c4f1da8..117861f 100644 --- a/src/enchanting.lua +++ b/src/enchanting.lua @@ -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 diff --git a/src/mailbox.lua b/src/mailbox.lua index dba667b..edcbbfc 100644 --- a/src/mailbox.lua +++ b/src/mailbox.lua @@ -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 diff --git a/src/workbench.lua b/src/workbench.lua index 6b762a4..4b63469 100644 --- a/src/workbench.lua +++ b/src/workbench.lua @@ -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], { -- 2.44.0