Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LuaCheck and workflow #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: [push, pull_request]
name: build
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: lint
uses: Roang-zero1/factorio-mod-luacheck@master
with:
luacheckrc_url: ""
9 changes: 9 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
allow_defined_top = true
unused_args = false
max_line_length = false

read_globals = {
"minetest", "mobs", "armor", "vector",
"VoxelManip", "ItemStack", "PseudoRandom",
"VoxelArea", "core", "round"
}
51 changes: 18 additions & 33 deletions api.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
-- set content id's
local c_air = minetest.get_content_id("air")
local c_ignore = minetest.get_content_id("ignore")
local c_obsidian = minetest.get_content_id("default:obsidian")
local c_brick = minetest.get_content_id("default:obsidianbrick")
local c_chest = minetest.get_content_id("default:chest_locked")

function bls_mobs:virulence(mobe)
if not bls_mobs.lessvirulent then
return 0
Expand Down Expand Up @@ -92,8 +85,6 @@ function bls_mobs.check_for_death_hydra(self)
end
return false
end
local pos = self.object:getpos()
local obj = nil
if self.sounds.death ~= nil then
minetest.sound_play(self.sounds.death,{
object = self.object,
Expand Down Expand Up @@ -166,8 +157,7 @@ function bls_mobs.digging_attack(
local n = minetest.env:get_node(pos1).name
--local up = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
if group == nil then
if minetest.get_item_group(n, "unbreakable") == 1 or minetest.is_protected(pos1, "") or (n == "bones:bones" and not bls_mobs:affectbones(self) ) then
else
if minetest.get_item_group(n, "unbreakable") ~= 1 or not minetest.is_protected(pos1, "") or (n ~= "bones:bones" and bls_mobs:affectbones(self) ) then
--minetest.env:set_node(p, {name="air"})
minetest.remove_node(pos1)
end
Expand Down Expand Up @@ -270,14 +260,12 @@ function bls_mobs.midas_ability( --ability to transform every blocks it touches
)
--if math.random(1,bls_mobs:virulence(self)) ~= 1 then return end

local v = self.object:getvelocity()
local pos = self.object:getpos()

if minetest.is_protected(pos, "") then
return
end

local max = 0
local yaw = (self.object:getyaw() + self.rotate) or 0
local x = math.sin(yaw)*-1
local z = math.cos(yaw)
Expand Down Expand Up @@ -307,8 +295,7 @@ function bls_mobs.midas_ability( --ability to transform every blocks it touches
local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.env:get_node(p).name

if minetest.get_item_group(n, "unbreakable") == 1 or minetest.is_protected(p, "") or n=="air" or (n == "bones:bones" and not bls_mobs:affectbones(self)) then
else
if minetest.get_item_group(n, "unbreakable") ~= 1 or not minetest.is_protected(p, "") or n ~= "air" or (n ~= "bones:bones" and bls_mobs:affectbones(self)) then
minetest.env:set_node(p, {name=m_block})
end
end
Expand All @@ -324,8 +311,6 @@ local loss_prob = {}
loss_prob["default:cobble"] = 3
loss_prob["default:dirt"] = 4

local tnt_radius = tonumber(minetest.setting_get("tnt_radius") or 3)

local cid_data = {}
minetest.after(0, function()
for name, def in pairs(minetest.registered_nodes) do
Expand Down Expand Up @@ -472,6 +457,21 @@ local function calc_velocity(pos1, pos2, old_vel, power)
return vel
end

local function add_drop(drops, item)
item = ItemStack(item)
local name = item:get_name()
if loss_prob[name] ~= nil and math.random(1, loss_prob[name]) == 1 then
return
end

local drop = drops[name]
if drop == nil then
drops[name] = item
else
drop:set_count(drop:get_count() + item:get_count())
end
end

local function entity_physics(pos, radius, drops)
local objs = minetest.get_objects_inside_radius(pos, radius)
for _, obj in pairs(objs) do
Expand Down Expand Up @@ -527,21 +527,6 @@ local function entity_physics(pos, radius, drops)
end
end

local function add_drop(drops, item)
item = ItemStack(item)
local name = item:get_name()
if loss_prob[name] ~= nil and math.random(1, loss_prob[name]) == 1 then
return
end

local drop = drops[name]
if drop == nil then
drops[name] = item
else
drop:set_count(drop:get_count() + item:get_count())
end
end

local function destroy(drops, npos, cid, c_air, c_fire, on_blast_queue, ignore_protection, ignore_on_blast)
if not ignore_protection and minetest.is_protected(npos, "") then
return cid
Expand Down Expand Up @@ -645,7 +630,7 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast)
local s = vector.add(pos, rad)
local r = vector.length(rad)
if r / radius < 1.4 then
nodeupdate_single(s)
nodeupdate_single(s) -- luacheck: ignore
end
end
end
Expand Down
14 changes: 5 additions & 9 deletions darts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@ mobs:register_arrow("bls_mobs:phoenix_arrow", {
local dy = math.random(-1,1)
local dz = math.random(-1,1)
local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.env:get_node(p).name
n = minetest.env:get_node(p).name
if n=="air" then
minetest.env:set_node(p, {name="bls_mobs:phoenix_fire"})
end
end

end,
})


mobs:register_arrow("bls_mobs:spine", {
visual = "sprite",
visual_size = {x = 1, y = 1},
Expand All @@ -94,14 +92,13 @@ function bls_mobs:affectbones(mobe) -- as function for adaptable heuristic
return not bls_mobs.safebones
end

function bls_mobs.ice_explosion(pos)
function bls_mobs:ice_explosion(pos)
for i=pos.x-math.random(0, 1), pos.x+math.random(0, 1), 1 do
for j=pos.y-1, pos.y+4, 1 do
for k=pos.z-math.random(0, 1), pos.z+math.random(0, 1), 1 do
local p = {x=i, y=j, z=k}
local n = minetest.env:get_node(p).name
if minetest.get_item_group(n, "unbreakable") == 1 or minetest.is_protected(p, "") or (n == "bones:bones" and not bls_mobs:affectbones(self)) then
else
if minetest.get_item_group(n, "unbreakable") ~= 1 or not minetest.is_protected(p, "") or (n ~= "bones:bones" and bls_mobs:affectbones(self)) then
minetest.set_node({x=i, y=j, z=k}, {name="default:ice"})
end
end
Expand Down Expand Up @@ -129,7 +126,6 @@ mobs:register_arrow("bls_mobs:snow_arrow", {
end,
})


mobs:register_arrow("bls_mobs:webball", {
visual = "sprite",
visual_size = {x = 1, y = 1},
Expand Down Expand Up @@ -165,7 +161,7 @@ function bls_mobs.explosion_web(pos)
for j=pos.y-3, pos.y, 1 do
for k=pos.z-1, pos.z+1, 1 do
local p = {x=i,y=j,z=k}
local k = {x=i,y=j+1,z=k}
k = {x=i,y=j+1,z=k}
local current = minetest.env:get_node(p).name
local ontop = minetest.env:get_node(k).name
if (current ~= "air") and
Expand Down Expand Up @@ -217,7 +213,7 @@ function bls_mobs.explosion_thickweb(pos)
for j=pos.y-2, pos.y, 1 do
for k=pos.z+0, pos.z+0, 1 do
local p = {x=i,y=j,z=k}
local k = {x=i,y=j+1,z=k}
k = {x=i,y=j+1,z=k}
local current = minetest.env:get_node(p).name
local ontop = minetest.env:get_node(k).name
if (current ~= "air") and
Expand Down
1 change: 0 additions & 1 deletion mobs/lava_titan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ mobs:register_mob("bls_mobs:lava_titan", {
light_damage = 0,
lava_damage = 0,
on_rightclick = nil,
floats = 0,
blood_texture="stone_blood.png",
blood_amount=50,
knock_back=0,
Expand Down
2 changes: 1 addition & 1 deletion mobs/mordain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mobs:register_mob("bls_mobs:mordain", {
d.x = p.x + math.random(-m,m)
d.z = p.z + math.random(-m,m)
d.y = p.y
local dist = dist_pos(d, p)
local dist = bls_mobs.dist_pos(d, p)
if dist>=2 then
for j = -3,3 do
ty = d.y + j
Expand Down
17 changes: 7 additions & 10 deletions mobs/morgut.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ mobs:register_mob("bls_mobs:morgut", {

if self.flag == 1 then
self.state = ""
set_animation(self, "run")
mobs.set_animation(self, "run")
self.object:setyaw(self.dir)
set_velocity(self, 4)
mobs.set_velocity(self, 4)

if os.time() - self.morgut_timer > 3 then
self.flag = 0
Expand All @@ -89,7 +89,7 @@ mobs:register_mob("bls_mobs:morgut", {
if self.attack then
local s = self.object:getpos()
local p = self.attack:getpos()
set_animation(self, "punch")
mobs.set_animation(self, "punch")
local m = 2

minetest.add_particlespawner(
Expand All @@ -109,15 +109,13 @@ mobs:register_mob("bls_mobs:morgut", {
"roasted_duck_legs.png" --texture
)

minetest.after(1, function (self)
minetest.after(1, function (self) -- luacheck: ignore
if self then
if self.attack:is_player() then
local pname = self.attack:get_player_name()
local player_inv = minetest.get_inventory({type='player', name = pname})

if player_inv:is_empty('main') then
--minetest.chat_send_all("Inventory empty")
else
if player_inv:is_empty('main') ~= true then
for i = 1,32 do
--minetest.chat_send_all("Inventory is not empty")
local items = player_inv:get_stack('main', i)
Expand Down Expand Up @@ -149,7 +147,7 @@ mobs:register_mob("bls_mobs:morgut", {
end
end
end
set_animation(self, "run")
mobs.set_animation(self, "run")
self.flag = 1
self.morgut_timer = os.time()
self.curr_attack = self.attack
Expand All @@ -158,7 +156,7 @@ mobs:register_mob("bls_mobs:morgut", {
self.dir = pyaw
self.object:setyaw(pyaw)
if self then
set_velocity(self, 4)
mobs.set_velocity(self, 4)
end
end
end
Expand All @@ -169,7 +167,6 @@ mobs:register_mob("bls_mobs:morgut", {
on_die = function(self)
local pos = self.object:getpos()
if (self.inventory ~= nil) then
local elem
for i = 1,32 do
if self.inventory[i].num~=0 then
local items = ItemStack(self.inventory[i].name.." "..self.inventory[i].num)
Expand Down
23 changes: 11 additions & 12 deletions mobs/morlu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ mobs:register_mob("bls_mobs:morlu", {
runaway = true,
jump = true,
sounds = {
random = "morlu1",
random = "morlu2"
random = "morlu1"
},
drops = {
{name = "bls_mobs:life_energy",
Expand Down Expand Up @@ -71,9 +70,9 @@ mobs:register_mob("bls_mobs:morlu", {

if self.flag == 1 then
self.state = ""
set_animation(self, "run")
mobs.set_animation(self, "run")
self.object:setyaw(self.dir)
set_velocity(self, 4)
mobs.set_velocity(self, 4)

if os.time() - self.morlu_timer > 3 then
self.flag = 0
Expand All @@ -91,12 +90,12 @@ mobs:register_mob("bls_mobs:morlu", {

local s = self.object:getpos()
local p = self.attack:getpos()
set_animation(self, "punch")
mobs.set_animation(self, "punch")
local m = 1

if self.attack:is_player() then
if minetest.get_modpath("3d_armor") then
local pname, player_inv, armor_inv, ppos = armor:get_valid_player(self.attack, "[set_player_armor]")
local armor_inv = armor:get_valid_player(self.attack, "[set_player_armor]")
local pname = self.attack:get_player_name()
local player_inv = minetest.get_inventory({type='player', name = pname})
if player_inv:is_empty('armor') then
Expand Down Expand Up @@ -160,7 +159,7 @@ mobs:register_mob("bls_mobs:morlu", {
nname --texture
)

minetest.after(1, function (self)
minetest.after(1, function (self) -- luacheck: ignore
if self then

local armor_stack = player_inv:get_stack("armor", armor_elements[steal_pos].pos)
Expand All @@ -184,7 +183,7 @@ mobs:register_mob("bls_mobs:morlu", {
self.inventory[self.invnum].name = armor_elements[steal_pos].name
end

set_animation(self, "run")
mobs.set_animation(self, "run")
self.flag = 1
self.morlu_timer = os.time()
self.curr_attack = self.attack
Expand All @@ -193,17 +192,17 @@ mobs:register_mob("bls_mobs:morlu", {
self.dir = pyaw
self.object:setyaw(pyaw)
if self then
set_velocity(self, 4)
mobs.set_velocity(self, 4)
end
end
end,self)
end
end
else
local s = self.object:getpos()
local p = self.attack:getpos()
s = self.object:getpos()
p = self.attack:getpos()

set_animation(self, "punch")
mobs.set_animation(self, "punch")

if minetest.line_of_sight({x = p.x, y = p.y +1.5, z = p.z}, {x = s.x, y = s.y +1.5, z = s.z}) == true then
-- play attack sound
Expand Down
Loading