Add luacheck and fix warnings

This commit is contained in:
Louis Royer 2020-08-26 02:11:18 +02:00
parent dd36f8b63e
commit ea92403fa3
9 changed files with 124 additions and 59 deletions

View File

@ -1,17 +1,30 @@
std = "lua51+minetest"
unused_args = false unused_args = false
allow_defined_top = true allow_defined_top = true
max_line_length = 999
max_comment_line_length = 999
read_globals = { stds.minetest = {
"DIR_DELIM", read_globals = {
"minetest", "core", "minetest",
"dump", "vector",
"vector", "nodeupdate", "VoxelManip",
"VoxelManip", "VoxelArea", "VoxelArea",
"PseudoRandom", "ItemStack", "PseudoRandom",
"intllib", "ItemStack",
"default", "default",
table = { fields = { "copy", "getn" } }, table = {
"biome_lib", fields = {
"stairs", "stairsplus", "copy",
},
},
"dump",
}
} }
read_globals = {
"biome_lib",
"stairsplus",
"stairs",
"doors",
}

View File

@ -23,7 +23,11 @@ end
ftrunk.drop = "moretrees:palm_trunk" ftrunk.drop = "moretrees:palm_trunk"
gftrunk.drop = "moretrees:palm_trunk" gftrunk.drop = "moretrees:palm_trunk"
ftrunk.after_destruct = function(pos, oldnode) ftrunk.after_destruct = function(pos, oldnode)
local coconuts = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, {"group:moretrees_coconut"}) local coconuts = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y, z=pos.z-1},
{x=pos.x+1, y=pos.y, z=pos.z+1},
{"group:moretrees_coconut"}
)
for _,coconutpos in pairs(coconuts) do for _,coconutpos in pairs(coconuts) do
-- minetest.dig_node(coconutpos) does not cause nearby coconuts to be dropped :-( ... -- minetest.dig_node(coconutpos) does not cause nearby coconuts to be dropped :-( ...
--minetest.dig_node(coconutpos) --minetest.dig_node(coconutpos)
@ -46,7 +50,11 @@ local coconut_regrow_abm_spec = {
interval = moretrees.coconut_flower_interval, interval = moretrees.coconut_flower_interval,
chance = moretrees.coconut_flower_chance, chance = moretrees.coconut_flower_chance,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local coconuts = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, "group:moretrees_coconut") local coconuts = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y, z=pos.z-1},
{x=pos.x+1, y=pos.y, z=pos.z+1},
"group:moretrees_coconut"
)
-- Expected growth interval increases exponentially with number of coconuts already hanging. -- Expected growth interval increases exponentially with number of coconuts already hanging.
-- Also: if more coconuts are hanging, the chance of picking an empty spot decreases as well... -- Also: if more coconuts are hanging, the chance of picking an empty spot decreases as well...
if math.random(2^#coconuts) <= 2 then if math.random(2^#coconuts) <= 2 then
@ -76,15 +84,18 @@ minetest.register_abm({
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
minetest.swap_node(pos, {name="moretrees:palm_fruit_trunk"}) minetest.swap_node(pos, {name="moretrees:palm_fruit_trunk"})
local poslist = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, "air") local poslist = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y, z=pos.z-1},
{x=pos.x+1, y=pos.y, z=pos.z+1},
"air"
)
local genlist = {} local genlist = {}
for k,v in pairs(poslist) do for k,v in pairs(poslist) do
genlist[k] = {x = math.random(100), pos = v} genlist[k] = {x = math.random(100), pos = v}
end end
table.sort(genlist, function(a, b) return a.x < b.x; end) table.sort(genlist, function(a, b) return a.x < b.x; end)
local gen
local count = 0 local count = 0
for _,gen in pairs(genlist) do for _, gen in pairs(genlist) do
minetest.swap_node(gen.pos, {name = "moretrees:coconut_3"}) minetest.swap_node(gen.pos, {name = "moretrees:coconut_3"})
count = count + 1 count = count + 1
if count == 4 then if count == 4 then
@ -109,7 +120,8 @@ local coconut_growfn = function(pos, elapsed)
-- Drop coconuts (i.e. remove them), so that new coconuts can grow. -- Drop coconuts (i.e. remove them), so that new coconuts can grow.
-- Coconuts will drop as items with a small chance -- Coconuts will drop as items with a small chance
if math.random(coconut_drop_ichance) == 1 then if math.random(coconut_drop_ichance) == 1 then
if moretrees.coconut_item_drop_ichance > 0 and math.random(moretrees.coconut_item_drop_ichance) == 1 then if moretrees.coconut_item_drop_ichance > 0
and math.random(moretrees.coconut_item_drop_ichance) == 1 then
local items = minetest.get_node_drops(minetest.get_node(pos).name) local items = minetest.get_node_drops(minetest.get_node(pos).name)
for _, itemname in pairs(items) do for _, itemname in pairs(items) do
minetest.add_item(pos, itemname) minetest.add_item(pos, itemname)
@ -190,55 +202,95 @@ if moretrees.coconuts_convert_existing_palms then
local leaves local leaves
local coconuts local coconuts
-- One regular trunk must be adjacent to the coconut -- One regular trunk must be adjacent to the coconut
trunks = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, "moretrees:palm_trunk") trunks = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y, z=pos.z-1},
{x=pos.x+1, y=pos.y, z=pos.z+1},
"moretrees:palm_trunk"
)
if #trunks ~= 1 then if #trunks ~= 1 then
return return
end end
local tpos = trunks[1] local tpos = trunks[1]
-- 1 or 2 other trunks must be one level below to the trunk being converted. -- 1 or 2 other trunks must be one level below to the trunk being converted.
trunks = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y-1, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y-1, z=tpos.z+1}, "moretrees:palm_trunk") trunks = minetest.find_nodes_in_area(
{x=tpos.x-1, y=tpos.y-1, z=tpos.z-1},
{x=tpos.x+1, y=tpos.y-1, z=tpos.z+1},
"moretrees:palm_trunk"
)
if #trunks < 1 or #trunks > 2 then if #trunks < 1 or #trunks > 2 then
return return
end end
-- 1 or 2 other trunks must be two levels below to the trunk being converted. -- 1 or 2 other trunks must be two levels below to the trunk being converted.
trunks = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y-2, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y-2, z=tpos.z+1}, "moretrees:palm_trunk") trunks = minetest.find_nodes_in_area(
{x=tpos.x-1, y=tpos.y-2, z=tpos.z-1},
{x=tpos.x+1, y=tpos.y-2, z=tpos.z+1},
"moretrees:palm_trunk"
)
if #trunks < 1 or #trunks > 2 then if #trunks < 1 or #trunks > 2 then
return return
end end
-- 1 or 2 trunks must at the level of the trunk being converted. -- 1 or 2 trunks must at the level of the trunk being converted.
cvtrunks = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y, z=tpos.z+1}, "moretrees:palm_trunk") cvtrunks = minetest.find_nodes_in_area(
{x=tpos.x-1, y=tpos.y, z=tpos.z-1},
{x=tpos.x+1, y=tpos.y, z=tpos.z+1},
"moretrees:palm_trunk"
)
if #cvtrunks < 1 or #cvtrunks > 2 then if #cvtrunks < 1 or #cvtrunks > 2 then
return return
end end
-- No trunks may be one level above the trunk being converted. -- No trunks may be one level above the trunk being converted.
trunks = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y+1, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y+1, z=tpos.z+1}, "moretrees:palm_trunk") trunks = minetest.find_nodes_in_area(
{x=tpos.x-1, y=tpos.y+1, z=tpos.z-1},
{x=tpos.x+1, y=tpos.y+1, z=tpos.z+1},
"moretrees:palm_trunk"
)
if #trunks ~= 0 then if #trunks ~= 0 then
return return
end end
-- Leaves must be one level above the trunk being converted. -- Leaves must be one level above the trunk being converted.
leaves = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y+1, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y+1, z=tpos.z+1}, "moretrees:palm_leaves") leaves = minetest.find_nodes_in_area(
{x=tpos.x-1, y=tpos.y+1, z=tpos.z-1},
{x=tpos.x+1, y=tpos.y+1, z=tpos.z+1},
"moretrees:palm_leaves"
)
if #leaves == 0 then if #leaves == 0 then
return return
end end
-- Leaves must be two levels above the trunk being converted. -- Leaves must be two levels above the trunk being converted.
leaves = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y+2, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y+2, z=tpos.z+1}, "moretrees:palm_leaves") leaves = minetest.find_nodes_in_area(
{x=tpos.x-1, y=tpos.y+2, z=tpos.z-1},
{x=tpos.x+1, y=tpos.y+2, z=tpos.z+1},
"moretrees:palm_leaves"
)
if #leaves == 0 then if #leaves == 0 then
return return
end end
-- No cocos fruit trunk may already be adjacent to the coconut -- No cocos fruit trunk may already be adjacent to the coconut
trunks = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, "moretrees:palm_fruit_trunk") trunks = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y, z=pos.z-1},
{x=pos.x+1, y=pos.y, z=pos.z+1},
"moretrees:palm_fruit_trunk"
)
if #trunks ~= 0 then if #trunks ~= 0 then
return return
end end
-- No cocos fruit trunk may be adjacent to or below the trunk being converted. -- No cocos fruit trunk may be adjacent to or below the trunk being converted.
trunks = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y-2, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y, z=tpos.z+1}, "moretrees:palm_fruit_trunk") trunks = minetest.find_nodes_in_area(
{x=tpos.x-1, y=tpos.y-2, z=tpos.z-1},
{x=tpos.x+1, y=tpos.y, z=tpos.z+1},
"moretrees:palm_fruit_trunk"
)
if #trunks ~= 0 then if #trunks ~= 0 then
return return
end end
-- Convert trunk and all coconuts nearby. Maybe convert 2 trunks, just in case... -- Convert trunk and all coconuts nearby. Maybe convert 2 trunks, just in case...
for _, tpos in pairs(cvtrunks) do for _, tpos_1 in pairs(cvtrunks) do
minetest.swap_node(tpos, {name = "moretrees:palm_fruit_trunk"}) minetest.swap_node(tpos_1, {name = "moretrees:palm_fruit_trunk"})
coconuts = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y, z=tpos.z+1}, "moretrees:coconut") coconuts = minetest.find_nodes_in_area(
{x=tpos_1.x-1, y=tpos_1.y, z=tpos_1.z-1},
{x=tpos_1.x+1, y=tpos_1.y, z=tpos_1.z+1},
"moretrees:coconut"
)
for _, coconutpos in pairs(coconuts) do for _, coconutpos in pairs(coconuts) do
minetest.swap_node(coconutpos, {name = "moretrees:coconut_3"}) minetest.swap_node(coconutpos, {name = "moretrees:coconut_3"})
end end

View File

@ -44,7 +44,11 @@ for k,v in pairs(trunk.tiles) do
end end
ftrunk.drop = "moretrees:date_palm_trunk" ftrunk.drop = "moretrees:date_palm_trunk"
ftrunk.after_destruct = function(pos, oldnode) ftrunk.after_destruct = function(pos, oldnode)
local dates = minetest.find_nodes_in_area({x=pos.x-2, y=pos.y, z=pos.z-2}, {x=pos.x+2, y=pos.y, z=pos.z+2}, {"group:moretrees_dates"}) local dates = minetest.find_nodes_in_area(
{x=pos.x-2, y=pos.y, z=pos.z-2},
{x=pos.x+2, y=pos.y, z=pos.z+2},
{"group:moretrees_dates"}
)
for _,datespos in pairs(dates) do for _,datespos in pairs(dates) do
-- minetest.dig_node(datespos) does not cause nearby dates to be dropped :-( ... -- minetest.dig_node(datespos) does not cause nearby dates to be dropped :-( ...
local items = minetest.get_node_drops(minetest.get_node(datespos).name) local items = minetest.get_node_drops(minetest.get_node(datespos).name)
@ -120,8 +124,11 @@ minetest.register_abm({
type = "m" type = "m"
minetest.swap_node(pos, {name="moretrees:date_palm_mfruit_trunk"}) minetest.swap_node(pos, {name="moretrees:date_palm_mfruit_trunk"})
end end
local dates1 = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, "air") local dates1 = minetest.find_nodes_in_area(
local genpos {x=pos.x-1, y=pos.y, z=pos.z-1},
{x=pos.x+1, y=pos.y, z=pos.z+1},
"air"
)
for _,genpos in pairs(dates1) do for _,genpos in pairs(dates1) do
if math.random(100) <= 20 then if math.random(100) <= 20 then
if type == "m" then if type == "m" then
@ -131,7 +138,11 @@ minetest.register_abm({
end end
end end
end end
local dates2 = minetest.find_nodes_in_area({x=pos.x-2, y=pos.y, z=pos.z-2}, {x=pos.x+2, y=pos.y, z=pos.z+2}, "air") local dates2 = minetest.find_nodes_in_area(
{x=pos.x-2, y=pos.y, z=pos.z-2},
{x=pos.x+2, y=pos.y, z=pos.z+2},
"air"
)
for _,genpos in pairs(dates2) do for _,genpos in pairs(dates2) do
if math.random(100) <= 5 then if math.random(100) <= 5 then
if type == "m" then if type == "m" then
@ -195,7 +206,7 @@ local function find_fruit_trunks_near(ftpos, sect)
local r = moretrees.dates_pollination_distance + 2 * math.sqrt(2) local r = moretrees.dates_pollination_distance + 2 * math.sqrt(2)
local sect_hr = math.floor(r / 3 + 0.9999) local sect_hr = math.floor(r / 3 + 0.9999)
local sect_vr = math.floor(r / 2 + 0.9999) local sect_vr = math.floor(r / 2 + 0.9999)
local t0us = core.get_us_time() local t0us = minetest.get_us_time()
local t0s = os.time() local t0s = os.time()
-- Compute elapsed time since last search. -- Compute elapsed time since last search.
@ -266,7 +277,7 @@ local function find_fruit_trunks_near(ftpos, sect)
end end
-- Update search statistics -- Update search statistics
local t1us = core.get_us_time() local t1us = minetest.get_us_time()
if t1us < t0us then if t1us < t0us then
-- Wraparound. Assume the search lasted less than 2^32 microseconds (~71 min) -- Wraparound. Assume the search lasted less than 2^32 microseconds (~71 min)
-- (so no need to apply another correction) -- (so no need to apply another correction)
@ -306,7 +317,7 @@ minetest.register_chatcommand("dates_stats", {
params = "|chat|log|reset", params = "|chat|log|reset",
privs = { server = true }, privs = { server = true },
func = function(name, param) func = function(name, param)
param = string.lower(string.trim(param)) param = string.lower(param:gsub("%s+", ""))
if param == "" or param == "chat" then if param == "" or param == "chat" then
return dates_print_search_stats(false) return dates_print_search_stats(false)
elseif param == "log" then elseif param == "log" then
@ -526,7 +537,6 @@ end
local dates_growfn = function(pos, elapsed) local dates_growfn = function(pos, elapsed)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local delay = moretrees.dates_grow_interval local delay = moretrees.dates_grow_interval
local r = moretrees.dates_pollination_distance
local action local action
if not node then if not node then
return return
@ -594,15 +604,16 @@ local dates_growfn = function(pos, elapsed)
return action return action
end end
--[[
-- Alternate growth function for dates. -- Alternate growth function for dates.
-- It calls the primary growth function, but also measures CPU time consumed. -- It calls the primary growth function, but also measures CPU time consumed.
-- Use this function to analyze date growing performance. -- Use this function to analyze date growing performance.
local stat = {} local stat = {}
stat.count = 0 stat.count = 0
local dates_growfn_profiling = function(pos, elapsed) local dates_growfn_profiling = function(pos, elapsed)
local t0 = core.get_us_time() local t0 = minetest.get_us_time()
local action = dates_growfn(pos, elapsed) local action = dates_growfn(pos, elapsed)
local t1 = core.get_us_time() local t1 = minetest.get_us_time()
if t1 < t0 then if t1 < t0 then
t1 = t1 + 2^32 t1 = t1 + 2^32
end end
@ -656,6 +667,7 @@ local dates_growfn_profiling = function(pos, elapsed)
"TOTAL", count, sum/count)) "TOTAL", count, sum/count))
end end
end end
--]]
-- Register dates -- Register dates

View File

@ -1,9 +0,0 @@
default
biome_lib
vessels
doors?
stairs?
moreblocks?
intllib?
farming?

View File

@ -1 +0,0 @@
This mod adds a whole bunch of new types of trees to the game

View File

@ -1,4 +1,4 @@
name = moretrees name = moretrees
depends = default, biome_lib, vessels depends = default, biome_lib, vessels
optional_depends = doors, stairs, moreblocks, intllib, farming optional_depends = doors, stairs, moreblocks, farming
min_minetest_version = 5.2.0 min_minetest_version = 5.2.0

View File

@ -327,7 +327,7 @@ for i in ipairs(moretrees.treelist) do
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local fdir = node.param2 or 0 local fdir = node.param2 or 0
nfdir = dirs2[fdir+1] local nfdir = dirs2[fdir+1]
minetest.add_node(pos, {name = "moretrees:"..treename.."_trunk", param2 = nfdir}) minetest.add_node(pos, {name = "moretrees:"..treename.."_trunk", param2 = nfdir})
end, end,
}) })
@ -490,7 +490,6 @@ minetest.register_node("moretrees:rubber_tree_trunk_empty", {
"moretrees_rubber_tree_trunk_top.png", "moretrees_rubber_tree_trunk_top.png",
"moretrees_rubber_tree_trunk_empty.png" "moretrees_rubber_tree_trunk_empty.png"
}, },
is_ground_content = true,
groups = {tree=1,snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2}, groups = {tree=1,snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir", paramtype2 = "facedir",
@ -504,7 +503,7 @@ minetest.register_abm({
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local fdir = node.param2 or 0 local fdir = node.param2 or 0
nfdir = dirs2[fdir+1] local nfdir = dirs2[fdir+1]
minetest.add_node(pos, {name = "moretrees:rubber_tree_trunk_empty", param2 = nfdir}) minetest.add_node(pos, {name = "moretrees:rubber_tree_trunk_empty", param2 = nfdir})
end, end,
}) })

View File

@ -31,7 +31,7 @@ index 8189ffd..afd4644 100644
@@ -225,9 +225,12 @@ moretrees.ct_rules_b1 = "[-FBf][+FBf]" @@ -225,9 +225,12 @@ moretrees.ct_rules_b1 = "[-FBf][+FBf]"
moretrees.ct_rules_a2 = "FF[FF][&&-FBF][&&+FBF][&&---FBF][&&+++FBF]F/A" moretrees.ct_rules_a2 = "FF[FF][&&-FBF][&&+FBF][&&---FBF][&&+++FBF]F/A"
moretrees.ct_rules_b2 = "[-fB][+fB]" moretrees.ct_rules_b2 = "[-fB][+fB]"
+local jleaves = 1 +local jleaves = 1
function moretrees.grow_jungletree(pos) function moretrees.grow_jungletree(pos)
local r1 = math.random(2) local r1 = math.random(2)
@ -40,11 +40,11 @@ index 8189ffd..afd4644 100644
+ jleaves = jleaves % 2 + 1 + jleaves = jleaves % 2 + 1
if r1 == 1 then if r1 == 1 then
moretrees.jungletree_model.leaves2 = "moretrees:jungletree_leaves_red" moretrees.jungletree_model.leaves2 = "moretrees:jungletree_leaves_red"
else else
@@ -235,6 +238,7 @@ function moretrees.grow_jungletree(pos) @@ -235,6 +238,7 @@ function moretrees.grow_jungletree(pos)
end end
moretrees.jungletree_model.leaves2_chance = math.random(25, 75) moretrees.jungletree_model.leaves2_chance = math.random(25, 75)
+ r2=3 + r2=3
if r2 == 1 then if r2 == 1 then
moretrees.jungletree_model.trunk_type = "single" moretrees.jungletree_model.trunk_type = "single"
@ -62,7 +62,7 @@ minetest.register_chatcommand("make-scene", {
minetest.place_node({x=780, y=30, z=-276}, {name="default:obsidian"}) minetest.place_node({x=780, y=30, z=-276}, {name="default:obsidian"})
for z = -360, -300 do for z = -360, -300 do
dy=2 local dy=2
for x = 630 + (-z - 360)/3, 660 + (-z - 300)/3 do for x = 630 + (-z - 360)/3, 660 + (-z - 300)/3 do
for y = 5, 22 do for y = 5, 22 do
minetest.place_node({x=x, y=y, z=z}, {name="default:desert_stone"}) minetest.place_node({x=x, y=y, z=z}, {name="default:desert_stone"})

View File

@ -49,7 +49,6 @@ moretrees.poplar_model={
rules_b="[[T]&&G++f++ff++ff++ff++f--]G", rules_b="[[T]&&G++f++ff++ff++ff++f--]G",
rules_c="[[T]&&G++f++ff++ff++ff++f--G++[d]G[d]G++G[d]G[d]G[d]G++G[d]G[d]G[d]G++G[d]G[d]G[d]G++G[d]G]G", rules_c="[[T]&&G++f++ff++ff++ff++f--G++[d]G[d]G++G[d]G[d]G[d]G++G[d]G[d]G[d]G++G[d]G[d]G[d]G++G[d]G]G",
rules_d="f", rules_d="f",
trunk="air",
trunk="moretrees:poplar_trunk", trunk="moretrees:poplar_trunk",
leaves="moretrees:poplar_leaves", leaves="moretrees:poplar_leaves",
angle=45, angle=45,