Skip to content

Commit

Permalink
Add LuaCheck workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 25, 2024
1 parent 67926f2 commit d0fbaab
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 16 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -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: <https://luacheck.readthedocs.io/en/stable/warnings.html>
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" }
3 changes: 2 additions & 1 deletion mods/default/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions mods/default/mapgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mods/default/mapgen_setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"}
Expand Down
25 changes: 13 additions & 12 deletions mods/default/sao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d0fbaab

Please sign in to comment.