diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..766d435 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,14 @@ +name: "Check" +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: apt + run: sudo apt-get update && sudo apt-get install -y luarocks + - name: luacheck install + run: luarocks install --local luacheck + - name: luacheck run + run: ~/.luarocks/bin/luacheck mods diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..7138ea4 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,29 @@ +unused_args = false +allow_defined_top = true + +globals = { + "default" +} + +read_globals = { + "minetest", + "dump", + "vector", + "VoxelManip", "VoxelArea", + "PseudoRandom", "PcgRandom", + "ItemStack", + "Settings", + -- Minetest specifics + math = { fields = { "round" } }, + string = { fields = { "split" } }, + table = { fields = { "shuffle", "copy", "indexof" } }, +} + +-- reference: +ignore = { + "312", "411", "412", "421", "422", "631", +} + +-- Overwrites fields in minetest +files["mods/default/init.lua"].globals = { "minetest" } +files["mods/creative/init.lua"].globals = { "minetest" } diff --git a/mods/default/init.lua b/mods/default/init.lua index 171586c..304ffb2 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -128,6 +128,7 @@ end -- polyfill: vector.combine (5.6) if vector.combine == nil then + -- luacheck: ignore 122 vector.combine = function(a, b, func) return vector.new(func(a.x, b.x), func(a.y, b.y), func(a.z, b.z)) end @@ -211,7 +212,7 @@ minetest.register_lbm({ }) minetest.register_on_newplayer(function(player) - if not core.settings:get_bool("give_initial_stuff") then + if not minetest.settings:get_bool("give_initial_stuff") then return end if minetest.is_creative_enabled(player:get_player_name()) then diff --git a/mods/default/mapgen.lua b/mods/default/mapgen.lua index b12b610..eec2783 100644 --- a/mods/default/mapgen.lua +++ b/mods/default/mapgen.lua @@ -302,7 +302,7 @@ default.on_generated = function(vmanip, minp, maxp, blockseed) local sminp = vector.offset(minp, 0, ii * 16, 0) local smaxp = vector.new(maxp.x, sminp.y + 15, maxp.z) if sminp.y <= -3 then - for ii = 1, (chunksize * chunksize) do + for n = 1, (chunksize * chunksize) do if ncrandom:next(0, 1000) == 0 then make_nc(self, ncrandom, sminp, smaxp) end @@ -314,6 +314,7 @@ default.on_generated = function(vmanip, minp, maxp, blockseed) -- The condition for clay is as follows: -- (0, 1 or 2 nodes below water level) and (at the surface or one node deep) -- and (where sand is) and (noise comparison suceeds) + local c_air = minetest.CONTENT_AIR local c_sand = minetest.get_content_id("default:sand") local c_clay = minetest.get_content_id("default:clay") local c_water = minetest.get_content_id("default:water_source") @@ -337,7 +338,7 @@ default.on_generated = function(vmanip, minp, maxp, blockseed) self.data[idx] = c_clay end end - if depth > 0 and self.data[idx] ~= core.CONTENT_AIR and self.data[idx] ~= c_water then + if depth > 0 and self.data[idx] ~= c_air and self.data[idx] ~= c_water then depth = depth + 1 end end diff --git a/mods/default/mapgen_setup.lua b/mods/default/mapgen_setup.lua index e336f3a..57a0831 100644 --- a/mods/default/mapgen_setup.lua +++ b/mods/default/mapgen_setup.lua @@ -32,7 +32,6 @@ for k, v in pairs({ mapgen_stone = "default:stone", mapgen_water_source = "default:water_source", mapgen_lava_source = "default:lava_source", - mapgen_cobble = "default:cobble", mapgen_dirt = "default:dirt", mapgen_dirt_with_grass = "default:dirt_with_grass", mapgen_sand = "default:sand", @@ -129,6 +128,7 @@ if minetest.get_mapgen_setting("mg_name") ~= "singlenode" then end -- for mapgen debugging +-- luacheck: ignore 511 if false then minetest.override_item("default:stone", { drawtype = "airlike" }) local hl = {"coalstone", "ironstone", "mese", "clay", "gravel", "nyancat", "nyancat_rainbow"} diff --git a/mods/default/sao.lua b/mods/default/sao.lua index 71b42ad..a3c3e20 100644 --- a/mods/default/sao.lua +++ b/mods/default/sao.lua @@ -209,7 +209,7 @@ local Oerkki1SAO = { } function Oerkki1SAO:on_activate(staticdata, dtime_s) - if core.settings:get("only_peaceful_mobs") then + if minetest.settings:get("only_peaceful_mobs") then self.object:remove() return end @@ -266,19 +266,20 @@ function Oerkki1SAO:on_step(dtime, moveresult) ndir.y = 0 ndir = vector.normalize(ndir) - local yaw = self.object:get_yaw() - local nyaw = math.atan2(ndir.z, ndir.x) - if nyaw < yaw - math.pi then - nyaw = nyaw + 2 * math.pi - elseif nyaw > yaw + math.pi then - nyaw = nyaw - 2 * math.pi + do + local yaw = self.object:get_yaw() + local nyaw = math.atan2(ndir.z, ndir.x) + if nyaw < yaw - math.pi then + nyaw = nyaw + 2 * math.pi + elseif nyaw > yaw + math.pi then + nyaw = nyaw - 2 * math.pi + end + self.object:set_yaw(0.95*yaw + 0.05*nyaw) end - self.object:set_yaw(0.95*yaw + 0.05*nyaw) - yaw = nil local speed = 2 if (moveresult.touching_ground or self.after_jump_timer > 0) and not player_is_too_close then - yaw = self.object:get_yaw() + local yaw = self.object:get_yaw() local dir = vector.new(math.cos(yaw), 0, math.sin(yaw)) target_vel.x = speed * dir.x target_vel.z = speed * dir.z @@ -298,7 +299,7 @@ function Oerkki1SAO:on_step(dtime, moveresult) self.counter2 = self.counter2 - dtime if self.counter2 < 0 then self.counter2 = self.counter2 + math.random(0, 300) / 100 - yaw = self.object:get_yaw() + local yaw = self.object:get_yaw() self.object:set_yaw(yaw + math.random(-100, 100) / 200 * math.pi) end @@ -610,7 +611,7 @@ function MobV2SAO:on_activate(staticdata, dtime_s) for k, v in pairs(my_props) do self.props[k] = v end - if core.settings:get("only_peaceful_mobs") and not self.props.is_peaceful then + if minetest.settings:get("only_peaceful_mobs") and not self.props.is_peaceful then self.object:remove() return end