Skip to content

Commit

Permalink
Correct (almost) all luacheck warnings
Browse files Browse the repository at this point in the history
Also includes a few code opimizations:
- Combined mining drill functions
- Shorter alias registration (unused?)
- Add TODOs to address later
  • Loading branch information
SmallJoker committed Jun 6, 2022
1 parent 0211c58 commit 0f6bdb1
Show file tree
Hide file tree
Showing 22 changed files with 254 additions and 244 deletions.
24 changes: 7 additions & 17 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
unused_args = false
allow_defined_top = true
max_line_length = 999
max_line_length = 150
-- Allow shadowed variables (callbacks in callbacks)
redefined = false

globals = {
"technic", "minetest",
Expand Down Expand Up @@ -32,19 +34,7 @@ read_globals = {
"craftguide", "i3"
}

files["concrete/init.lua"].ignore = { "steel_ingot" }
files["technic/machines/MV/tool_workshop.lua"].ignore = { "pos" }
files["technic/machines/other/frames.lua"].ignore = { "item_texture", "item_type", "adj", "connected", "" }
files["technic/machines/register/battery_box.lua"].ignore = { "pos", "tube_upgrade" }
files["technic/machines/register/cables.lua"].ignore = { "name", "from_below", "p" }
files["technic/machines/register/common.lua"].ignore = { "result" }

files["technic/machines/register/generator.lua"].ignore = { "node" }
files["technic/machines/switching_station.lua"].ignore = { "pos1", "tier", "poshash" }
files["technic/radiation.lua"].ignore = { "LAVA_VISC" }
files["technic/tools/chainsaw.lua"].ignore = { "pos" }
files["technic/tools/mining_drill.lua"].ignore = { "mode" }
files["technic_chests/register.lua"].ignore = { "fs_helpers", "name", "locked_after_place" }

files["technic_cnc/cnc.lua"].ignore = { "multiplier" }
files["wrench/init.lua"].ignore = { "name", "stack" }
-- Loop warning
files["technic/machines/other/frames.lua"].ignore = { "" }
-- Long lines
files["technic_cnc/cnc_api.lua"].ignore = { "" }
7 changes: 0 additions & 7 deletions concrete/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ for i = 32, 63 do
"technic:concrete_post_with_platform")
end

local steel_ingot
if minetest.get_modpath("technic_worldgen") then
steel_ingot = "technic:carbon_steel_ingot"
else
steel_ingot = "default:steel_ingot"
end

minetest.register_craft({
output = 'technic:concrete_post_platform 6',
recipe = {
Expand Down
71 changes: 41 additions & 30 deletions extranodes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,47 @@ if minetest.get_modpath("moreblocks") then
tiles={"technic_stainless_steel_block.png"},
})

function register_technic_stairs_alias(modname, origname, newmod, newname)
minetest.register_alias(modname .. ":slab_" .. origname, newmod..":slab_" .. newname)
minetest.register_alias(modname .. ":slab_" .. origname .. "_inverted", newmod..":slab_" .. newname .. "_inverted")
minetest.register_alias(modname .. ":slab_" .. origname .. "_wall", newmod..":slab_" .. newname .. "_wall")
minetest.register_alias(modname .. ":slab_" .. origname .. "_quarter", newmod..":slab_" .. newname .. "_quarter")
minetest.register_alias(modname .. ":slab_" .. origname .. "_quarter_inverted", newmod..":slab_" .. newname .. "_quarter_inverted")
minetest.register_alias(modname .. ":slab_" .. origname .. "_quarter_wall", newmod..":slab_" .. newname .. "_quarter_wall")
minetest.register_alias(modname .. ":slab_" .. origname .. "_three_quarter", newmod..":slab_" .. newname .. "_three_quarter")
minetest.register_alias(modname .. ":slab_" .. origname .. "_three_quarter_inverted", newmod..":slab_" .. newname .. "_three_quarter_inverted")
minetest.register_alias(modname .. ":slab_" .. origname .. "_three_quarter_wall", newmod..":slab_" .. newname .. "_three_quarter_wall")
minetest.register_alias(modname .. ":stair_" .. origname, newmod..":stair_" .. newname)
minetest.register_alias(modname .. ":stair_" .. origname .. "_inverted", newmod..":stair_" .. newname .. "_inverted")
minetest.register_alias(modname .. ":stair_" .. origname .. "_wall", newmod..":stair_" .. newname .. "_wall")
minetest.register_alias(modname .. ":stair_" .. origname .. "_wall_half", newmod..":stair_" .. newname .. "_wall_half")
minetest.register_alias(modname .. ":stair_" .. origname .. "_wall_half_inverted", newmod..":stair_" .. newname .. "_wall_half_inverted")
minetest.register_alias(modname .. ":stair_" .. origname .. "_half", newmod..":stair_" .. newname .. "_half")
minetest.register_alias(modname .. ":stair_" .. origname .. "_half_inverted", newmod..":stair_" .. newname .. "_half_inverted")
minetest.register_alias(modname .. ":stair_" .. origname .. "_right_half", newmod..":stair_" .. newname .. "_right_half")
minetest.register_alias(modname .. ":stair_" .. origname .. "_right_half_inverted", newmod..":stair_" .. newname .. "_right_half_inverted")
minetest.register_alias(modname .. ":stair_" .. origname .. "_wall_half", newmod..":stair_" .. newname .. "_wall_half")
minetest.register_alias(modname .. ":stair_" .. origname .. "_wall_half_inverted", newmod..":stair_" .. newname .. "_wall_half_inverted")
minetest.register_alias(modname .. ":stair_" .. origname .. "_inner", newmod..":stair_" .. newname .. "_inner")
minetest.register_alias(modname .. ":stair_" .. origname .. "_inner_inverted", newmod..":stair_" .. newname .. "_inner_inverted")
minetest.register_alias(modname .. ":stair_" .. origname .. "_outer", newmod..":stair_" .. newname .. "_outer")
minetest.register_alias(modname .. ":stair_" .. origname .. "_outer_inverted", newmod..":stair_" .. newname .. "_outer_inverted")
minetest.register_alias(modname .. ":panel_" .. origname .. "_bottom", newmod..":panel_" .. newname .. "_bottom")
minetest.register_alias(modname .. ":panel_" .. origname .. "_top", newmod..":panel_" .. newname .. "_top")
minetest.register_alias(modname .. ":panel_" .. origname .. "_vertical", newmod..":panel_" .. newname .. "_vertical")
minetest.register_alias(modname .. ":micro_" .. origname .. "_bottom", newmod..":micro_" .. newname .. "_bottom")
minetest.register_alias(modname .. ":micro_" .. origname .. "_top", newmod..":micro_" .. newname .. "_top")
function register_technic_stairs_alias(origmod, origname, newmod, newname)
local func = minetest.register_alias
local function remap(kind, suffix)
-- Old: stairsplus:slab_concrete_wall
-- New: technic:slab_concrete_wall
func(("%s:%s_%s%s"):format(origmod, kind, origname, suffix),
("%s:%s_%s%s"):format(newmod, kind, newname, suffix))
end

-- Slabs
remap("slab", "")
remap("slab", "_inverted")
remap("slab", "_wall")
remap("slab", "_quarter")
remap("slab", "_quarter_inverted")
remap("slab", "_quarter_wall")
remap("slab", "_three_quarter")
remap("slab", "_three_quarter_inverted")
remap("slab", "_three_quarter_wall")

-- Stairs
remap("stair", "")
remap("stair", "_inverted")
remap("stair", "_wall")
remap("stair", "_wall_half")
remap("stair", "_wall_half_inverted")
remap("stair", "_half")
remap("stair", "_half_inverted")
remap("stair", "_right_half")
remap("stair", "_right_half_inverted")
remap("stair", "_inner")
remap("stair", "_inner_inverted")
remap("stair", "_outer")
remap("stair", "_outer_inverted")

-- Other
remap("panel", "_bottom")
remap("panel", "_top")
remap("panel", "_vertical")
remap("micro", "_bottom")
remap("micro", "_top")
end

register_technic_stairs_alias("stairsplus", "concrete", "technic", "concrete")
Expand Down
12 changes: 11 additions & 1 deletion technic/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ technic.modpath = modpath
if rawget(_G, "intllib") then
technic.getter = intllib.Getter()
else
technic.getter = function(s,a,...)if a==nil then return s end a={a,...}return s:gsub("(@?)@(%(?)(%d+)(%)?)",function(e,o,n,c)if e==""then return a[tonumber(n)]..(o==""and c or"")else return"@"..o..n..c end end) end
-- Intllib copypasta: TODO replace with the client-side translation API
technic.getter = function(s,a,...)
if a==nil then return s end
a={a,...}
return s:gsub("(@?)@(%(?)(%d+)(%)?)", function(e,o,n,c)
if e==""then
return a[tonumber(n)]..(o==""and c or"")
end
return "@"..o..n..c
end)
end
end
local S = technic.getter

Expand Down
7 changes: 5 additions & 2 deletions technic/machines/HV/forcefield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ local function set_forcefield_formspec(meta)
else
formspec = formspec.."button[0,1;5,1;mesecon_mode_0;"..S("Controlled by Mesecon Signal").."]"
end
-- TODO: String replacement with %s will stop working with client-side translations
if meta:get_int("enabled") == 0 then
formspec = formspec.."button[0,1.75;5,1;enable;"..S("%s Disabled"):format(S("%s Forcefield Emitter"):format("HV")).."]"
formspec = formspec.."button[0,1.75;5,1;enable;"..
S("%s Disabled"):format(S("%s Forcefield Emitter"):format("HV")).."]"
else
formspec = formspec.."button[0,1.75;5,1;disable;"..S("%s Enabled"):format(S("%s Forcefield Emitter"):format("HV")).."]"
formspec = formspec.."button[0,1.75;5,1;disable;"..
S("%s Enabled"):format(S("%s Forcefield Emitter"):format("HV")).."]"
end
meta:set_string("formspec", formspec)
end
Expand Down
11 changes: 8 additions & 3 deletions technic/machines/HV/quarry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ local function set_quarry_demand(meta)
local radius = meta:get_int("size")
local diameter = radius*2 + 1
local machine_name = S("%s Quarry"):format("HV")
if meta:get_int("enabled") == 0 or meta:get_int("purge_on") == 1 then
meta:set_string("infotext", S(meta:get_int("purge_on") == 1 and "%s purging cache" or "%s Disabled"):format(machine_name))
local do_purge = meta:get_int("purge_on") == 1
if meta:get_int("enabled") == 0 or do_purge then
local infotext = do_purge and
S("%s purging cache") or S("%s Disabled")
meta:set_string("infotext", infotext:format(machine_name))
meta:set_int("HV_EU_demand", 0)
elseif meta:get_int("dug") == diameter*diameter * (quarry_dig_above_nodes+1+quarry_max_depth) then
meta:set_string("infotext", S("%s Finished"):format(machine_name))
meta:set_int("HV_EU_demand", 0)
else
meta:set_string("infotext", S(meta:get_int("HV_EU_input") >= quarry_demand and "%s Active" or "%s Unpowered"):format(machine_name))
local infotext = meta:get_int("HV_EU_input") >= quarry_demand
and S("%s Active") or S("%s Unpowered")
meta:set_string("infotext", infotext:format(machine_name))
meta:set_int("HV_EU_demand", quarry_demand)
end
end
Expand Down
3 changes: 2 additions & 1 deletion technic/machines/MV/power_radiator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ technic.register_inductive_machine = function(name)
end

-- Appliances:
-- has_supply: pos of supply node if the appliance has a power radiator near with sufficient power for the demand else ""
-- has_supply: pos of supply node if the appliance has a power radiator near
-- with sufficient power for the demand else ""
-- EU_demand: The power demand of the device.
-- EU_charge: Actual use. set to EU_demand if active==1
-- active: set to 1 if the device is on
Expand Down
28 changes: 18 additions & 10 deletions technic/machines/other/anchor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ local function forceload_on(pos, meta)
end

local function set_display(pos, meta)
local ESC = minetest.formspec_escape
meta:set_string("infotext", S(meta:get_int("enabled") ~= 0 and "%s Enabled" or "%s Disabled"):format(desc))
meta:set_string("formspec",
"size[5,3.5]"..
"item_image[0,0;1,1;technic:admin_anchor]"..
"label[1,0;"..minetest.formspec_escape(desc).."]"..
"label[0,1;"..minetest.formspec_escape(S("Owner:").." "..meta:get_string("owner")).."]"..
"label[1,0;"..ESC(desc).."]"..
"label[0,1;"..ESC(S("Owner:").." "..meta:get_string("owner")).."]"..
(meta:get_int("locked") == 0 and
"button[3,1;2,1;lock;"..minetest.formspec_escape(S("Unlocked")).."]" or
"button[3,1;2,1;unlock;"..minetest.formspec_escape(S("Locked")).."]")..
"field[0.25,2.3;1,1;radius;"..minetest.formspec_escape(S("Radius:"))..";"..meta:get_int("radius").."]"..
"button[3,1;2,1;lock;"..ESC(S("Unlocked")).."]" or
"button[3,1;2,1;unlock;"..ESC(S("Locked")).."]")..
"field[0.25,2.3;1,1;radius;"..ESC(S("Radius:"))..";"..meta:get_int("radius").."]"..
(meta:get_int("enabled") == 0 and
"button[3,2;2,1;enable;"..minetest.formspec_escape(S("Disabled")).."]" or
"button[3,2;2,1;disable;"..minetest.formspec_escape(S("Enabled")).."]")..
"label[0,3;"..minetest.formspec_escape(S("Keeping %d/%d map blocks loaded"):format(#currently_forceloaded_positions(meta), #compute_forceload_positions(pos, meta))).."]")
"button[3,2;2,1;enable;"..ESC(S("Disabled")).."]" or
"button[3,2;2,1;disable;"..ESC(S("Enabled")).."]")..
"label[0,3;"..ESC(S("Keeping %d/%d map blocks loaded"):format(
#currently_forceloaded_positions(meta), #compute_forceload_positions(pos, meta)
)).."]")
end

minetest.register_node("technic:admin_anchor", {
Expand All @@ -80,7 +83,8 @@ minetest.register_node("technic:admin_anchor", {
end,
can_dig = function (pos, player)
local meta = minetest.get_meta(pos)
return meta:get_int("locked") == 0 or (player and player:is_player() and player:get_player_name() == meta:get_string("owner"))
return meta:get_int("locked") == 0 or
(player and player:is_player() and player:get_player_name() == meta:get_string("owner"))
end,
on_destruct = function (pos)
local meta = minetest.get_meta(pos)
Expand All @@ -99,7 +103,11 @@ minetest.register_node("technic:admin_anchor", {
forceload_off(meta)
if fields.disable then meta:set_int("enabled", 0) end
if fields.enable then meta:set_int("enabled", 1) end
if fields.radius and string.find(fields.radius, "^[0-9]+$") and tonumber(fields.radius) < 256 then meta:set_int("radius", fields.radius) end
if fields.radius
and string.find(fields.radius, "^[0-9]+$")
and tonumber(fields.radius) < 256 then
meta:set_int("radius", fields.radius)
end
if meta:get_int("enabled") ~= 0 then
forceload_on(pos, meta)
end
Expand Down
24 changes: 5 additions & 19 deletions technic/machines/other/frames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ local function pos_in_list(l, pos)
return false
end

local function table_empty(table)
for _, __ in pairs(table) do
local function table_empty(what)
for _ in pairs(what) do
return false
end
return true
end

local function add_table(table, toadd)
local function add_table(what, toadd)
local i = 1
while true do
local o = table[i]
local o = what[i]
if o == toadd then return end
if o == nil then break end
i = i + 1
end
table[i] = toadd
what[i] = toadd
end

local function move_nodes_vect(poslist, vect, must_not_move, owner)
Expand Down Expand Up @@ -398,20 +398,6 @@ minetest.register_entity("technic:frame_entity", {
local pos = vector.round(self.object:getpos())
frames_pos[pos_to_string(pos)] = node.name

local stack = ItemStack(node.name)
local itemtable = stack:to_table()
local itemname = nil

if itemtable then
itemname = stack:to_table().name
end

local item_texture = nil
local item_type = ""
if minetest.registered_items[itemname] then
item_texture = minetest.registered_items[itemname].inventory_image
item_type = minetest.registered_items[itemname].type
end
local prop = {
is_visible = true,
textures = { node.name },
Expand Down
8 changes: 4 additions & 4 deletions technic/machines/register/battery_box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ function technic.register_battery_box(data)
drop = "technic:"..ltier.."_battery_box0",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local EU_upgrade, tube_upgrade = 0, 0
local EU_upgrade, _ = 0
if data.upgrade then
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
EU_upgrade, _ = technic.handle_machine_upgrades(meta)
end
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
local charge = meta:get_int("internal_EU_charge")
Expand Down Expand Up @@ -345,9 +345,9 @@ function technic.register_battery_box(data)
meta = minetest.get_meta(pos)
if not pipeworks.may_configure(pos, sender) then return end
fs_helpers.on_receive_fields(pos, fields)
local EU_upgrade, tube_upgrade = 0, 0
local EU_upgrade, _ = 0
if data.upgrade then
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
EU_upgrade, _ = technic.handle_machine_upgrades(meta)
end
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
local charge = meta:get_int("internal_EU_charge")
Expand Down
21 changes: 13 additions & 8 deletions technic/machines/register/cables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,27 @@ local function clear_networks(pos)
-- This is similar to check_node_subp
technic.cables[minetest.hash_node_position(pos)] = network_id
pos.visited = 1
if technic.is_tier_cable(name, tier) then
if technic.is_tier_cable(node.name, tier) then
-- Found a cable
table.insert(network.all_nodes,pos)
elseif technic.machines[tier][node.name] then
meta:set_string(tier.."_network",minetest.pos_to_string(sw_pos))
if technic.machines[tier][node.name] == technic.producer then
-- Found a machine
local eu_type = technic.machines[tier][node.name]
meta:set_string(tier.."_network", minetest.pos_to_string(sw_pos))
if eu_type == technic.producer then
table.insert(network.PR_nodes,pos)
elseif technic.machines[tier][node.name] == technic.receiver then
elseif eu_type == technic.receiver then
table.insert(network.RE_nodes,pos)
elseif technic.machines[tier][node.name] == technic.producer_receiver then
elseif eu_type == technic.producer_receiver then
table.insert(network.PR_nodes,pos)
table.insert(network.RE_nodes,pos)
elseif technic.machines[tier][node.name] == "SPECIAL" and
elseif eu_type == "SPECIAL" and
(pos.x ~= sw_pos.x or pos.y ~= sw_pos.y or pos.z ~= sw_pos.z) and
from_below then
nil then
-- TODO: This case was never executed. Needs testing!
-- Supply converter.
table.insert(network.SP_nodes,pos)
elseif technic.machines[tier][node.name] == technic.battery then
elseif eu_type == technic.battery then
table.insert(network.BA_nodes,pos)
end
end
Expand Down
9 changes: 2 additions & 7 deletions technic/machines/switching_station.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ minetest.register_node("technic:switching_station",{
meta:set_string("active", 1)
meta:set_string("channel", "switching_station"..minetest.pos_to_string(pos))
meta:set_string("formspec", "field[channel;Channel;${channel}]")
local poshash = minetest.hash_node_position(pos)
technic.redundant_warn.poshash = nil
end,
after_dig_node = function(pos)
minetest.forceload_free_block(pos)
pos.y = pos.y - 1
minetest.forceload_free_block(pos)
local poshash = minetest.hash_node_position(pos)
technic.redundant_warn.poshash = nil
end,
on_receive_fields = function(pos, formname, fields, sender)
Expand Down Expand Up @@ -248,18 +246,15 @@ minetest.register_abm({
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if not technic.powerctrl_state then return end
local meta = minetest.get_meta(pos)
local meta = minetest.get_meta(pos)
local meta1
local pos1 = {}

local tier = ""
local PR_nodes
local BA_nodes
local RE_nodes
local machine_name = S("Switching Station")

-- Which kind of network are we on:
pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
local pos1 = {x=pos.x, y=pos.y-1, z=pos.z}

--Disable if necessary
if meta:get_int("active") ~= 1 then
Expand Down
Loading

0 comments on commit 0f6bdb1

Please sign in to comment.