Add luacheck and fix warnings
This commit is contained in:
parent
53669f6fad
commit
5480f4c9df
10
.github/workflows/luacheck.yml
vendored
Normal file
10
.github/workflows/luacheck.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
name: luacheck
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
luacheck:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
- name: Luacheck
|
||||
uses: lunarmodules/luacheck@master
|
12
.luacheckrc
Normal file
12
.luacheckrc
Normal file
@ -0,0 +1,12 @@
|
||||
unused_args = false
|
||||
max_line_length = 150
|
||||
|
||||
read_globals = {
|
||||
"minetest",
|
||||
"vector",
|
||||
"ItemStack",
|
||||
"default",
|
||||
"tnt",
|
||||
"mcl_sounds",
|
||||
"mcl_explosions"
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
-- demand a "Player" object as a parameter and hopefully prevent the mods that have
|
||||
-- registered with those callbacks from crashing on a nil dereference or bad function
|
||||
-- call. This is not supposed to be a remotely functional thing, it's just supposed
|
||||
-- to provide dummy methods and return values of the correct data type for anything that
|
||||
-- to provide dummy methods and return values of the correct data type for anything that
|
||||
-- might ignore the false "is_player()" return and go ahead and try to use this thing
|
||||
-- anyway.
|
||||
|
||||
@ -40,10 +40,10 @@ end
|
||||
function FakePlayer.create(pos, player_name)
|
||||
local self = {}
|
||||
setmetatable(self, FakePlayer)
|
||||
|
||||
|
||||
self.is_fake_player = player_name
|
||||
|
||||
-- ObjectRef
|
||||
-- ObjectRef
|
||||
self.get_pos = return_value(pos)
|
||||
self.set_pos = return_nil
|
||||
self.move_to = return_nil
|
||||
@ -87,7 +87,7 @@ function FakePlayer.create(pos, player_name)
|
||||
self.get_luaentity = return_nil
|
||||
|
||||
-- Player object
|
||||
|
||||
|
||||
self.get_player_name = return_empty_string
|
||||
self.get_player_velocity = return_nil
|
||||
self.get_look_dir = return_value({x=0,y=1,z=0})
|
||||
@ -112,13 +112,13 @@ function FakePlayer.create(pos, player_name)
|
||||
|
||||
self.set_physics_override = return_nil
|
||||
self.get_physics_override = return_value({speed = 1, jump = 1, gravity = 1, sneak = true, sneak_glitch = false, new_move = true,})
|
||||
|
||||
|
||||
|
||||
|
||||
self.hud_add = return_nil
|
||||
self.hud_remove = return_nil
|
||||
self.hud_change = return_nil
|
||||
self.hud_get = return_nil -- possibly important return value?
|
||||
self.hud_set_flags = return_nil
|
||||
self.hud_set_flags = return_nil
|
||||
self.hud_get_flags = return_value({ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true, minimap=true })
|
||||
self.hud_set_hotbar_itemcount = return_nil
|
||||
self.hud_get_hotbar_itemcount = return_zero
|
||||
@ -128,19 +128,19 @@ function FakePlayer.create(pos, player_name)
|
||||
self.hud_get_hotbar_selected_image = return_empty_string
|
||||
self.set_sky = return_nil
|
||||
self.get_sky = return_empty_table -- may need members on this table
|
||||
|
||||
|
||||
self.set_clouds = return_nil
|
||||
self.get_clouds = return_value({density = 0, color = "#fff0f0e5", ambient = "#000000", height = 120, thickness = 16, speed = {x=0, y=-2}})
|
||||
|
||||
|
||||
self.override_day_night_ratio = return_nil
|
||||
self.get_day_night_ratio = return_nil
|
||||
|
||||
|
||||
self.set_local_animation = return_nil
|
||||
self.get_local_animation = return_empty_table
|
||||
|
||||
|
||||
self.set_eye_offset = return_nil
|
||||
self.get_eye_offset = return_value({x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
112
init.lua
112
init.lua
@ -56,12 +56,6 @@ local crossbow_range = tonumber(minetest.settings:get("torch_bomb_base_crossbow_
|
||||
local enable_crossbows = minetest.settings:get_bool("torch_bomb_enable_crossbows", true)
|
||||
local torch_bow_uses = tonumber(minetest.settings:get("torch_bomb_base_crossbow_uses")) or 30
|
||||
|
||||
-- Detect creative mod
|
||||
local creative_mod = minetest.get_modpath("creative")
|
||||
-- Cache creative mode setting as fallback if creative mod not present
|
||||
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
||||
|
||||
|
||||
-- 12 torches grenade
|
||||
local ico1 = {
|
||||
vector.new(0.000000, -1.000000, 0.000000),
|
||||
@ -134,7 +128,7 @@ end
|
||||
|
||||
-- 162 torches, 3* bomb_range
|
||||
local ico3 = {
|
||||
vector.new(0.000000, -1.000000, 0.000000),
|
||||
vector.new(0.000000, -1.000000, 0.000000),
|
||||
vector.new(0.723607, -0.447220, 0.525725),
|
||||
vector.new(-0.276388, -0.447220, 0.850649),
|
||||
vector.new(-0.894426, -0.447216, 0.000000),
|
||||
@ -315,7 +309,7 @@ local function find_target(raycast)
|
||||
if above_def.buildable_to and ((under_def and not under_def.buildable_to) or not under_def) then
|
||||
return next_pointed
|
||||
end
|
||||
|
||||
|
||||
next_pointed = raycast:next(next_pointed)
|
||||
end
|
||||
end
|
||||
@ -336,7 +330,6 @@ local function embed_torch(target, placer, pos)
|
||||
torch_def_on_place(ItemStack(torch_item), placer, target)
|
||||
local target_pos = target.above
|
||||
local dir_back = vector.normalize(vector.subtract(pos, target_pos))
|
||||
local vel_back = vector.multiply(dir_back, 10)
|
||||
minetest.add_particlespawner({
|
||||
amount = math.random(1,6),
|
||||
time = 0.1,
|
||||
@ -374,13 +367,13 @@ local function kerblam(pos, placer, dirs, min_range)
|
||||
placer = fakeplayer
|
||||
fakeplayer:update(pos, "torch_bomb")
|
||||
end
|
||||
|
||||
|
||||
minetest.log("action", placer:get_player_name() .. " detonated a torch bomb at " ..
|
||||
minetest.pos_to_string(pos) .. " and placed " .. #targets .. " torches.")
|
||||
|
||||
for _, target in ipairs(targets) do
|
||||
embed_torch(target, placer, pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local player_setting_fuse_at = {}
|
||||
@ -421,7 +414,7 @@ if enable_rockets then
|
||||
local player_name = player:get_player_name()
|
||||
local pos = player_setting_fuse_at[player_name]
|
||||
local seconds = tonumber(fields.seconds or "")
|
||||
|
||||
|
||||
if not pos or not seconds then
|
||||
player_setting_fuse_at[player_name] = nil
|
||||
return
|
||||
@ -445,7 +438,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
|
||||
minetest.register_node("torch_bomb:" .. name, {
|
||||
description = desc,
|
||||
drawtype = "normal",
|
||||
drawtype = "normal",
|
||||
tiles = {"torch_bomb_top.png", "torch_bomb_bottom.png", side_texture},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
@ -453,7 +446,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
groups = {tnt = 1, oddly_breakable_by_hand = 1, handy = 1, axey = 1},
|
||||
_mcl_blast_resistance = 1,
|
||||
_mcl_hardness = 0.8,
|
||||
|
||||
|
||||
on_punch = function(pos, node, puncher)
|
||||
if puncher:get_wielded_item():get_name() == torch_item then
|
||||
minetest.set_node(pos, {name = "torch_bomb:"..name.."_burning"})
|
||||
@ -462,12 +455,12 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
minetest.pos_to_string(pos))
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
on_ignite = function(pos) -- used by TNT mod
|
||||
minetest.set_node(pos, {name = "torch_bomb:"..name.."_burning"})
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("torch_bomb:"..name.."_burning", {
|
||||
description = desc,
|
||||
drawtype = "normal", -- See "Node drawtypes"
|
||||
@ -487,7 +480,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
paramtype2 = "facedir",
|
||||
light_source = 6,
|
||||
drop = "torch_bomb:" .. name,
|
||||
|
||||
|
||||
on_construct = function(pos)
|
||||
if tnt_modpath or mcl_tnt_modpath then
|
||||
minetest.sound_play({name="tnt_ignite", gain=1}, {pos = pos, max_hear_distance=16}, true)
|
||||
@ -495,7 +488,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
minetest.get_node_timer(pos):start(3)
|
||||
minetest.check_for_falling(pos)
|
||||
end,
|
||||
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local ignitor_name = minetest.get_meta(pos):get("torch_bomb_ignitor")
|
||||
local puncher
|
||||
@ -512,14 +505,14 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
kerblam(pos, puncher, dirs, min_range)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
if not enable_rockets then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local rocket_bottom_texture = "torch_bomb_bottom.png^torch_bomb_rocket_bottom.png"
|
||||
local rocket_side_texture = side_texture .. "^torch_bomb_rocket_side.png"
|
||||
|
||||
|
||||
local function entity_detonate(player_name, target)
|
||||
--minetest.chat_send_all("entity detonate " .. (player_name or "") .. " " .. minetest.pos_to_string(target))
|
||||
local player
|
||||
@ -534,7 +527,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
end
|
||||
kerblam(target, player, dirs, min_range)
|
||||
end
|
||||
|
||||
|
||||
minetest.register_entity("torch_bomb:"..name.."_rocket_entity", {
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
@ -551,7 +544,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
get_staticdata = function(self)
|
||||
local target = self.target
|
||||
if target then
|
||||
@ -566,11 +559,11 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
return "detonated"
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
on_step = function(self, dtime)
|
||||
local object = self.object
|
||||
local lastpos = self.lastpos
|
||||
|
||||
|
||||
local pos = object:get_pos()
|
||||
local node = minetest.get_node(pos)
|
||||
local luaentity = object:get_luaentity()
|
||||
@ -585,7 +578,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
max_hear_distance = 32,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
if lastpos and (node.name ~= "air" or luaentity.fuse < 0) then
|
||||
lastpos = vector.round(lastpos)
|
||||
local player_name = luaentity.player_name
|
||||
@ -598,7 +591,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
|
||||
minetest.register_node("torch_bomb:"..name.."_rocket", {
|
||||
description = S("@1 Rocket", desc),
|
||||
drawtype = "normal",
|
||||
drawtype = "normal",
|
||||
tiles = {"torch_bomb_top.png", rocket_bottom_texture, rocket_side_texture},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
@ -606,7 +599,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
groups = {tnt = 1, oddly_breakable_by_hand = 1, torch_bomb_rocket = 1, handy = 1, axey = 1},
|
||||
_mcl_blast_resistance = 1,
|
||||
_mcl_hardness = 0.8,
|
||||
|
||||
|
||||
on_punch = function(pos, node, puncher)
|
||||
if puncher:get_wielded_item():get_name() == torch_item then
|
||||
local fuse = minetest.get_meta(pos):get("fuse")
|
||||
@ -618,7 +611,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
minetest.pos_to_string(pos))
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local fuse_length = tonumber(meta:get_string("fuse")) or default_fuse
|
||||
@ -633,7 +626,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
minetest.get_meta(pos):set_string("fuse", fuse)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("torch_bomb:"..name.."_rocket_burning", {
|
||||
description = S("@1 Rocket", desc),
|
||||
drawtype = "normal",
|
||||
@ -653,7 +646,7 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
paramtype2 = "facedir",
|
||||
light_source = 6,
|
||||
drop = "torch_bomb:"..name.."_rocket",
|
||||
|
||||
|
||||
on_construct = function(pos)
|
||||
if tnt_modpath then
|
||||
minetest.sound_play("tnt_ignite", {pos = pos, max_hear_distance=16}, true)
|
||||
@ -661,19 +654,19 @@ local function register_torch_bomb(name, desc, dirs, min_range, blast_radius, te
|
||||
minetest.get_node_timer(pos):start(3)
|
||||
minetest.check_for_falling(pos)
|
||||
end,
|
||||
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local ignitor_name = meta:get("torch_bomb_ignitor")
|
||||
local fuse = tonumber(meta:get_string("fuse")) or default_fuse
|
||||
minetest.set_node(pos, {name="air"})
|
||||
|
||||
|
||||
local obj = minetest.add_entity(pos, "torch_bomb:"..name.."_rocket_entity")
|
||||
obj:set_acceleration({x=0, y=1, z=0})
|
||||
local lua_entity = obj:get_luaentity()
|
||||
lua_entity.player_name = ignitor_name
|
||||
lua_entity.fuse = fuse
|
||||
|
||||
|
||||
local range = 0.5 * fuse * fuse -- s = vi * t + (1/2)*a*t*t
|
||||
pos.y = pos.y + range
|
||||
lua_entity.target = pos
|
||||
@ -692,7 +685,7 @@ if enable_grenade then
|
||||
|
||||
local throw_velocity = 20
|
||||
local gravity = {x=0, y=-9.81, z=0}
|
||||
|
||||
|
||||
minetest.register_craftitem("torch_bomb:torch_grenade", {
|
||||
description = S("Torch Grenade"),
|
||||
inventory_image = "torch_bomb_torch_grenade.png",
|
||||
@ -705,25 +698,21 @@ if enable_grenade then
|
||||
obj:set_yaw(user:get_look_horizontal()+math.pi)
|
||||
local lua_entity = obj:get_luaentity()
|
||||
lua_entity.player_name = user:get_player_name()
|
||||
|
||||
minetest.sound_play({name="tnt_ignite"},
|
||||
{
|
||||
pos=player_pos,
|
||||
object = object,
|
||||
|
||||
minetest.sound_play({name="tnt_ignite"}, {
|
||||
pos = player_pos,
|
||||
gain = 1.0,
|
||||
max_hear_distance = 32,
|
||||
},
|
||||
true)
|
||||
|
||||
if not ((creative_mod and creative.is_enabled_for(user:get_player_name())) or
|
||||
creative_mode_cache) then
|
||||
}, true)
|
||||
|
||||
if not minetest.is_creative_enabled(user:get_player_name()) then
|
||||
itemstack:set_count(itemstack:get_count() - 1)
|
||||
end
|
||||
|
||||
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
minetest.register_entity("torch_bomb:torch_grenade_entity", {
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
@ -733,21 +722,21 @@ if enable_grenade then
|
||||
collisionbox = {0,0,0,0,0,0},
|
||||
glow = 8,
|
||||
},
|
||||
|
||||
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
self.player_name = staticdata
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
return self.player_name
|
||||
end,
|
||||
|
||||
|
||||
on_step = function(self, dtime)
|
||||
local object = self.object
|
||||
local lastpos = self.lastpos
|
||||
|
||||
|
||||
local pos = object:get_pos()
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
|
||||
if lastpos ~= nil and node.name ~= "air" then
|
||||
lastpos = vector.round(lastpos)
|
||||
local luaentity = object:get_luaentity()
|
||||
@ -773,7 +762,7 @@ end
|
||||
----------------------------------------------------------------------
|
||||
-- Torch crossbows
|
||||
|
||||
local function register_torch_bow(name, desc, material, image, torch_bow_range, torch_bow_uses)
|
||||
local function register_torch_bow(name, desc, material, image, torch_bow_range, local_torch_bow_uses)
|
||||
minetest.register_tool("torch_bomb:torch_crossbow_" .. name, {
|
||||
description = S("@1 Torch Crossbow", desc),
|
||||
inventory_image = image,
|
||||
@ -794,16 +783,15 @@ local function register_torch_bow(name, desc, material, image, torch_bow_range,
|
||||
return
|
||||
end
|
||||
|
||||
if not ((creative_mod and creative.is_enabled_for(user:get_player_name())) or
|
||||
creative_mode_cache) then
|
||||
if not minetest.is_creative_enabled(user:get_player_name()) then
|
||||
inv:remove_item("main", {name=torch_item, count=1})
|
||||
itemstack:add_wear(65535/(torch_bow_uses-1))
|
||||
itemstack:add_wear(65535/(local_torch_bow_uses-1))
|
||||
end
|
||||
|
||||
local dir = user:get_look_dir()
|
||||
|
||||
local target = vector.add(playerpos, vector.multiply(dir, torch_bow_range))
|
||||
|
||||
|
||||
local raycast = minetest.raycast(playerpos, target, false, true)
|
||||
local target_pointed = find_target(raycast)
|
||||
if target_pointed then
|
||||
@ -871,19 +859,19 @@ if enable_tnt and tnt_modpath then
|
||||
{'tnt:tnt_stick', 'tnt:tnt_stick', 'tnt:tnt_stick'},
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "torch_bomb:mega_torch_bomb",
|
||||
recipe = {"torch_bomb:torch_bomb", "torch_bomb:torch_bomb", "torch_bomb:torch_bomb"},
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "torch_bomb:torch_bomb 3",
|
||||
recipe = {"torch_bomb:mega_torch_bomb"},
|
||||
})
|
||||
|
||||
|
||||
if enable_grenade then
|
||||
|
||||
minetest.register_craft({
|
||||
@ -891,14 +879,14 @@ if enable_tnt and tnt_modpath then
|
||||
output = "torch_bomb:torch_bomb",
|
||||
recipe = {"torch_bomb:torch_grenade", "torch_bomb:torch_grenade", "torch_bomb:torch_grenade"},
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "torch_bomb:torch_grenade 3",
|
||||
recipe = {"torch_bomb:torch_bomb"},
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
if enable_rockets then
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
@ -910,7 +898,7 @@ if enable_tnt and tnt_modpath then
|
||||
type = "shapeless",
|
||||
output = "torch_bomb:mega_torch_bomb_rocket",
|
||||
recipe = {"torch_bomb:mega_torch_bomb", "tnt:tnt"},
|
||||
})
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
4
mod.conf
4
mod.conf
@ -1,4 +1,4 @@
|
||||
name = torch_bomb
|
||||
description = Place torches throughout your entire surroundings with a torch bomb
|
||||
depends =
|
||||
optional_depends = mcl_core, mcl_sounds, mcl_explosions, mcl_tnt, default, tnt, creative, farming
|
||||
optional_depends = mcl_core, mcl_sounds, mcl_explosions, mcl_tnt, default, tnt, creative, farming
|
||||
min_minetest_version = 5.3.0
|
Loading…
x
Reference in New Issue
Block a user