forked from mtcontrib/riesenpilz
Add a .luacheckrc and some code style changes
This commit is contained in:
parent
6b259b94ad
commit
4e32b5e9a0
3
.luacheckrc
Normal file
3
.luacheckrc
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
read_globals = {"minetest", "vector", "PseudoRandom", "ItemStack", "VoxelArea",
|
||||||
|
"table", "dump", "default"}
|
||||||
|
globals = {"riesenpilz"}
|
@ -24,12 +24,11 @@ function riesenpilz.circle(r)
|
|||||||
if circle then
|
if circle then
|
||||||
return circle
|
return circle
|
||||||
end
|
end
|
||||||
local circle, n = {}, 1
|
circle = {}
|
||||||
for i = -r, r do
|
for i = -r, r do
|
||||||
for j = -r, r do
|
for j = -r, r do
|
||||||
if math.floor(math.sqrt(i * i + j * j) + 0.5) == r then
|
if math.floor(math.sqrt(i * i + j * j) + 0.5) == r then
|
||||||
circle[n] = {x=i, y=0, z=j}
|
circle[#circle+1] = {x=i, y=0, z=j}
|
||||||
n = n+1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
114
init.lua
114
init.lua
@ -69,15 +69,15 @@ local function set_vm_data(manip, pznodes, pos, t1, name)
|
|||||||
manip:write_to_map()
|
manip:write_to_map()
|
||||||
riesenpilz.inform("a giant " .. name .. " mushroom grew at " ..
|
riesenpilz.inform("a giant " .. name .. " mushroom grew at " ..
|
||||||
minetest.pos_to_string(pos), 3, t1)
|
minetest.pos_to_string(pos), 3, t1)
|
||||||
local t1 = os.clock()
|
local t2 = os.clock()
|
||||||
manip:update_map()
|
manip:update_map()
|
||||||
riesenpilz.inform("map updated", 3, t1)
|
riesenpilz.inform("map updated", 3, t2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function riesenpilz.red(pos, nodes, area, w)
|
function riesenpilz.red(pos, nodes, area, w)
|
||||||
local w = w or math.random(MAX_SIZE)
|
w = w or math.random(MAX_SIZE)
|
||||||
local h = w+2
|
local h = w + 2
|
||||||
|
|
||||||
for i = 0, h do
|
for i = 0, h do
|
||||||
nodes[area:index(pos.x, pos.y+i, pos.z)] = c.stem
|
nodes[area:index(pos.x, pos.y+i, pos.z)] = c.stem
|
||||||
@ -115,8 +115,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function riesenpilz.brown(pos, nodes, area, br)
|
function riesenpilz.brown(pos, nodes, area, br)
|
||||||
local br = br or math.random(MAX_SIZE-1)+1
|
br = br or math.random(MAX_SIZE-1)+1
|
||||||
local h = br+2
|
local h = br + 2
|
||||||
|
|
||||||
for i in area:iterp(pos, {x=pos.x, y=pos.y+h, z=pos.z}) do
|
for i in area:iterp(pos, {x=pos.x, y=pos.y+h, z=pos.z}) do
|
||||||
nodes[i] = c.stem
|
nodes[i] = c.stem
|
||||||
@ -205,7 +205,7 @@ local function ran_node(a, b, ran)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function riesenpilz.lavashroom(pos, nodes, area, h)
|
function riesenpilz.lavashroom(pos, nodes, area, h)
|
||||||
local h = h or 3+math.random(MAX_SIZE-2)
|
h = h or 3 + math.random(MAX_SIZE - 2)
|
||||||
|
|
||||||
-- remove the mushroom
|
-- remove the mushroom
|
||||||
nodes[area:indexp(pos)] = c.air
|
nodes[area:indexp(pos)] = c.air
|
||||||
@ -274,7 +274,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function riesenpilz.glowshroom(pos, nodes, area, h)
|
function riesenpilz.glowshroom(pos, nodes, area, h)
|
||||||
local h = h or 2+math.random(MAX_SIZE)
|
h = h or 2 + math.random(MAX_SIZE)
|
||||||
|
|
||||||
for i = 0, h do
|
for i = 0, h do
|
||||||
nodes[area:index(pos.x, pos.y+i, pos.z)] = c.stem_blue
|
nodes[area:index(pos.x, pos.y+i, pos.z)] = c.stem_blue
|
||||||
@ -323,14 +323,14 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function riesenpilz.parasol(pos, nodes, area, w, h)
|
function riesenpilz.parasol(pos, nodes, area, w, h)
|
||||||
local h = h or 6+math.random(MAX_SIZE)
|
h = h or 6 + math.random(MAX_SIZE)
|
||||||
|
|
||||||
--stem
|
--stem
|
||||||
for i in area:iterp(pos, {x=pos.x, y=pos.y+h-2, z=pos.z}) do
|
for i in area:iterp(pos, {x=pos.x, y=pos.y+h-2, z=pos.z}) do
|
||||||
nodes[i] = c.stem
|
nodes[i] = c.stem
|
||||||
end
|
end
|
||||||
|
|
||||||
local w = w or MAX_SIZE+math.random(2)
|
w = w or MAX_SIZE + math.random(2)
|
||||||
local bhead1 = w-1
|
local bhead1 = w-1
|
||||||
local bhead2 = math.random(1,w-2)
|
local bhead2 = math.random(1,w-2)
|
||||||
|
|
||||||
@ -418,13 +418,15 @@ function riesenpilz.red45(pos, nodes, area, h1, h2)
|
|||||||
or math.random(4) ~= 2 then
|
or math.random(4) ~= 2 then
|
||||||
nodes[area:index(pos.x+x*j, pos.y+h, pos.z+z*i)] = c.head_red
|
nodes[area:index(pos.x+x*j, pos.y+h, pos.z+z*i)] = c.head_red
|
||||||
end
|
end
|
||||||
local z = z+1
|
local zo = z+1
|
||||||
x = x+1
|
local xo = x+1
|
||||||
nodes[area:index(pos.x+x*j, pos.y+walkspace+2, pos.z+z*i)] = c.head_red
|
nodes[area:index(pos.x + xo * j, pos.y + walkspace + 2,
|
||||||
if z ~= 3
|
pos.z + zo * i)] = c.head_red
|
||||||
or x ~= 3
|
if zo ~= 3
|
||||||
|
or xo ~= 3
|
||||||
or math.random(2) == 1 then
|
or math.random(2) == 1 then
|
||||||
nodes[area:index(pos.x+x*j, pos.y+walkspace+3, pos.z+z*i)] = c.head_red
|
nodes[area:index(pos.x + xo * j, pos.y + walkspace + 3,
|
||||||
|
pos.z + zo * i)] = c.head_red
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -540,7 +542,7 @@ end
|
|||||||
local abm_allowed = true
|
local abm_allowed = true
|
||||||
local disallowed_ps = {}
|
local disallowed_ps = {}
|
||||||
|
|
||||||
for name,i in pairs({
|
for name, ndata in pairs({
|
||||||
brown = {
|
brown = {
|
||||||
description = "brown mushroom",
|
description = "brown mushroom",
|
||||||
box = {
|
box = {
|
||||||
@ -706,21 +708,21 @@ for name,i in pairs({
|
|||||||
hp = 1,
|
hp = 1,
|
||||||
},
|
},
|
||||||
}) do
|
}) do
|
||||||
local burntime = i.burntime or 1
|
local burntime = ndata.burntime or 1
|
||||||
local box = {
|
local box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = i.box
|
fixed = ndata.box
|
||||||
}
|
}
|
||||||
local nd = "riesenpilz:"..name
|
local nd = "riesenpilz:" .. name
|
||||||
minetest.register_node(nd, {
|
minetest.register_node(nd, {
|
||||||
description = i.description,
|
description = ndata.description,
|
||||||
tiles = {
|
tiles = {
|
||||||
--~ {name = "riesenpilz_"..name.."_top.png", tileable_vertical = false},
|
--~ {name = "riesenpilz_"..name.."_top.png", tileable_vertical = false},
|
||||||
--~ {name = "riesenpilz_"..name.."_bottom.png", tileable_vertical = false},
|
--~ {name = "riesenpilz_"..name.."_bottom.png", tileable_vertical = false},
|
||||||
--~ {name = "riesenpilz_"..name.."_side.png", tileable_vertical = false},
|
--~ {name = "riesenpilz_"..name.."_side.png", tileable_vertical = false},
|
||||||
"riesenpilz_"..name.."_top.png",
|
"riesenpilz_" .. name .. "_top.png",
|
||||||
"riesenpilz_"..name.."_bottom.png",
|
"riesenpilz_" .. name .. "_bottom.png",
|
||||||
"riesenpilz_"..name.."_side.png",
|
"riesenpilz_" .. name .. "_side.png",
|
||||||
},
|
},
|
||||||
use_texture_alpha = "opaque",
|
use_texture_alpha = "opaque",
|
||||||
inventory_image = "riesenpilz_"..name.."_side.png",
|
inventory_image = "riesenpilz_"..name.."_side.png",
|
||||||
@ -733,10 +735,10 @@ for name,i in pairs({
|
|||||||
node_box = box,
|
node_box = box,
|
||||||
selection_box = box,
|
selection_box = box,
|
||||||
furnace_burntime = burntime,
|
furnace_burntime = burntime,
|
||||||
on_secondary_use = minetest.item_eat(i.hp),
|
on_secondary_use = minetest.item_eat(ndata.hp),
|
||||||
})
|
})
|
||||||
|
|
||||||
local g = i.growing
|
local g = ndata.growing
|
||||||
|
|
||||||
if g then
|
if g then
|
||||||
local grounds = g.grounds
|
local grounds = g.grounds
|
||||||
@ -798,8 +800,8 @@ for name,i in pairs({
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local groups = data.groups
|
local groups = data.groups
|
||||||
for n,i in pairs(grounds) do
|
for groupname, groupvalue in pairs(grounds) do
|
||||||
if groups[n] ~= i then
|
if groups[groupname] ~= groupvalue then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -819,31 +821,31 @@ for name,i in pairs({
|
|||||||
-- witch circles
|
-- witch circles
|
||||||
local ps = {}
|
local ps = {}
|
||||||
for _,p in pairs(riesenpilz.circle(math.random(rmin, rmax))) do
|
for _,p in pairs(riesenpilz.circle(math.random(rmin, rmax))) do
|
||||||
local p = vector.add(pos, p)
|
p = vector.add(pos, p)
|
||||||
|
|
||||||
-- currently 3 is used here, approved by its use in the mapgen
|
-- currently 3 is used here, approved by its use in the mapgen
|
||||||
if math.random(3) == 1 then
|
if math.random(3) == 1 then
|
||||||
|
|
||||||
-- don't only use the current y for them
|
-- don't only use the current y for them
|
||||||
for y = 1,-1,-1 do
|
for y = 1,-1,-1 do
|
||||||
local pos = {x=p.x, y=p.y+y, z=p.z}
|
local pos_above = {x=p.x, y=p.y+y, z=p.z}
|
||||||
if minetest.get_node(pos).name ~= "air" then
|
if minetest.get_node(pos_above).name ~= "air" then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
local f = minetest.get_node({x=p.x, y=p.y+y-1, z=p.z}).name
|
local f = minetest.get_node({x=p.x, y=p.y+y-1, z=p.z}).name
|
||||||
if f ~= "air" then
|
if f ~= "air" then
|
||||||
|
|
||||||
-- they grown on specific nodes
|
-- they grown on specific nodes
|
||||||
local data = minetest.registered_nodes[f]
|
local data_ground = minetest.registered_nodes[f]
|
||||||
if data
|
if data_ground
|
||||||
and data.walkable
|
and data_ground.walkable
|
||||||
and data.groups
|
and data_ground.groups
|
||||||
and (not data.drawtype
|
and (not data_ground.drawtype
|
||||||
or data.drawtype == "normal"
|
or data_ground.drawtype == "normal"
|
||||||
) then
|
) then
|
||||||
local ground_disallowed
|
local ground_disallowed
|
||||||
for n,i in pairs(grounds) do
|
for n,i in pairs(grounds) do
|
||||||
if data.groups[n] ~= i then
|
if data_ground.groups[n] ~= i then
|
||||||
ground_disallowed = true
|
ground_disallowed = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -851,10 +853,11 @@ for name,i in pairs({
|
|||||||
if not ground_disallowed then
|
if not ground_disallowed then
|
||||||
|
|
||||||
-- they also need specific light strengths
|
-- they also need specific light strengths
|
||||||
local light = minetest.get_node_light(pos, 0.5)
|
local light = minetest.get_node_light(
|
||||||
|
pos_above, 0.5)
|
||||||
if light >= lmin
|
if light >= lmin
|
||||||
and light <= lmax then
|
and light <= lmax then
|
||||||
ps[#ps+1] = pos
|
ps[#ps+1] = pos_above
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -901,7 +904,7 @@ local head_sounds = default.node_sound_wood_defaults({
|
|||||||
local add_fence = minetest.register_fence
|
local add_fence = minetest.register_fence
|
||||||
local node_groups = {oddly_breakable_by_hand=3, fall_damage_add_percent=-80, bouncy=10}
|
local node_groups = {oddly_breakable_by_hand=3, fall_damage_add_percent=-80, bouncy=10}
|
||||||
|
|
||||||
for _,i in pairs({
|
for _, ndata in ipairs({
|
||||||
{
|
{
|
||||||
typ = "stem",
|
typ = "stem",
|
||||||
description = "white",
|
description = "white",
|
||||||
@ -996,8 +999,8 @@ for _,i in pairs({
|
|||||||
},
|
},
|
||||||
}) do
|
}) do
|
||||||
-- fill missing stuff
|
-- fill missing stuff
|
||||||
local textures = i.textures
|
local textures = ndata.textures
|
||||||
i.description = i.description or i.name
|
ndata.description = ndata.description or ndata.name
|
||||||
if type(textures) == "string" then
|
if type(textures) == "string" then
|
||||||
textures = {textures}
|
textures = {textures}
|
||||||
end
|
end
|
||||||
@ -1006,25 +1009,26 @@ for _,i in pairs({
|
|||||||
end
|
end
|
||||||
local nodename = "riesenpilz:"
|
local nodename = "riesenpilz:"
|
||||||
local desctiption,sounds = "giant mushroom "
|
local desctiption,sounds = "giant mushroom "
|
||||||
if i.typ == "stem" then
|
if ndata.typ == "stem" then
|
||||||
desctiption = desctiption.."stem "..i.description
|
desctiption = desctiption .. "stem " .. ndata.description
|
||||||
nodename = nodename.."stem"..((i.name and "_"..i.name) or "")
|
nodename = nodename .. "stem" ..
|
||||||
|
((ndata.name and "_" .. ndata.name) or "")
|
||||||
sounds = default.node_sound_wood_defaults({
|
sounds = default.node_sound_wood_defaults({
|
||||||
footstep = {name="riesenpilz_stem", gain=0.2},
|
footstep = {name="riesenpilz_stem", gain=0.2},
|
||||||
place = {name="default_place_node", gain=0.5},
|
place = {name="default_place_node", gain=0.5},
|
||||||
dig = {name="riesenpilz_stem", gain=0.4},
|
dig = {name="riesenpilz_stem", gain=0.4},
|
||||||
dug = {name="default_wood_footstep", gain=0.3}
|
dug = {name="default_wood_footstep", gain=0.3}
|
||||||
})
|
})
|
||||||
elseif i.typ == "head" then
|
elseif ndata.typ == "head" then
|
||||||
desctiption = desctiption.."head "..i.description
|
desctiption = desctiption .. "head " .. ndata.description
|
||||||
nodename = nodename.."head_"..i.name
|
nodename = nodename .. "head_" .. ndata.name
|
||||||
sounds = head_sounds
|
sounds = head_sounds
|
||||||
else
|
else
|
||||||
nodename = nodename..i.name
|
nodename = nodename .. ndata.name
|
||||||
desctiption = desctiption..i.description
|
desctiption = desctiption .. ndata.description
|
||||||
end
|
end
|
||||||
local drop = i.sapling and {max_items = 1, items = {
|
local drop = ndata.sapling and {max_items = 1, items = {
|
||||||
{items = {"riesenpilz:"..i.sapling}, rarity = 20},
|
{items = {"riesenpilz:" .. ndata.sapling}, rarity = 20},
|
||||||
{items = {nodename}, rarity = 1}
|
{items = {nodename}, rarity = 1}
|
||||||
}}
|
}}
|
||||||
minetest.register_node(nodename, {
|
minetest.register_node(nodename, {
|
||||||
@ -1036,7 +1040,7 @@ for _,i in pairs({
|
|||||||
})
|
})
|
||||||
|
|
||||||
if add_fence
|
if add_fence
|
||||||
and i.fence ~= false then
|
and ndata.fence ~= false then
|
||||||
add_fence({fence_of = nodename})
|
add_fence({fence_of = nodename})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1149,7 +1153,7 @@ local function get_grow(name)
|
|||||||
if def.on_timer then
|
if def.on_timer then
|
||||||
func = def.on_timer
|
func = def.on_timer
|
||||||
else
|
else
|
||||||
func = function(pos, node, player)
|
func = function(pos, _, player)
|
||||||
if def.on_place then
|
if def.on_place then
|
||||||
def.on_place(ItemStack(name), player, {
|
def.on_place(ItemStack(name), player, {
|
||||||
type = "node",
|
type = "node",
|
||||||
|
@ -128,7 +128,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local t1 = os.clock()
|
local t1 = os.clock()
|
||||||
riesenpilz.inform("tries to generate a giant mushroom biome at: x=["..minp.x.."; "..maxp.x.."]; y=["..minp.y.."; "..maxp.y.."]; z=["..minp.z.."; "..maxp.z.."]", 2)
|
riesenpilz.inform(("tries to generate a giant mushroom biome at: " ..
|
||||||
|
"x=[%d; %d]; y=[%d; %d]; z=[%d; %d]"):format(minp.x, maxp.x, minp.y,
|
||||||
|
maxp.y, minp.z, maxp.z), 2)
|
||||||
|
|
||||||
if not contents_defined then
|
if not contents_defined then
|
||||||
define_contents()
|
define_contents()
|
||||||
@ -217,8 +219,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
if ground_y then
|
if ground_y then
|
||||||
-- add ground and dirt below if needed
|
-- add ground and dirt below if needed
|
||||||
data[vi] = c.ground
|
data[vi] = c.ground
|
||||||
for i = -1,-5,-1 do
|
for off = -1,-5,-1 do
|
||||||
local p_pos = vi + i * area.ystride
|
local p_pos = vi + off * area.ystride
|
||||||
if not is_ground(data[p_pos])
|
if not is_ground(data[p_pos])
|
||||||
or data[p_pos] == c.dirt then
|
or data[p_pos] == c.dirt then
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user