Fix spawn logic

- Fix broken probability function
- Make sure custom prob functions don't spawn longcat pieces
- Make cats fall upon hatching
This commit is contained in:
Aaron Suen 2023-06-05 19:19:53 -04:00
parent b8e6b4fca3
commit 3a1f27aa48

View File

@ -79,15 +79,17 @@ local function checksnake(pos, node)
return findhead(pos, node)
end
local function catspawn(pos)
local prob = 1
for _, np in ipairs(nodecore.find_nodes_around(pos,
{"group:" .. modname .. "_cat"}, 2)) do
if getcatid(minetest.get_node(np)) == id then
prob = prob * 1.2
function myapi.default_spawn_probability_function(id)
return function(pos)
local prob = 1
for _, np in ipairs(nodecore.find_nodes_around(pos,
{"group:" .. modname .. "_cat"}, 2)) do
if getcatid(minetest.get_node(np)) == id then
prob = prob * 1.2
end
end
return prob
end
return prob
end
local function fuzztiles(tiles)
@ -97,8 +99,6 @@ local function fuzztiles(tiles)
return tiles
end
local function desc2name(s) return string_gsub(string_lower(s), "%W+", "_") end
local default_overlays = {
ears = "^nc_cats_ears.png",
paws = "^nc_cats_paws_front.png^nc_cats_paws_back.png",
@ -109,6 +109,8 @@ local default_overlays = {
paws_back = "^nc_cats_paws_back.png",
}
local function desc2name(s) return string_gsub(string_lower(s), "%W+", "_") end
function myapi.register_cat(desc, basetiles, basedef, overlays)
local id = basedef and basedef[cat_type_key] or desc2name(desc)
@ -132,6 +134,7 @@ function myapi.register_cat(desc, basetiles, basedef, overlays)
basetiles[6] .. overlays.face,
}),
[cat_type_key] = id,
[modname .. "_spawn_probability"] = myapi.default_spawn_probability_function(id),
groups = {
snappy = 1,
falling_node = 1,
@ -168,18 +171,16 @@ function myapi.register_cat(desc, basetiles, basedef, overlays)
end
})
minetest.register_node(":" .. modname .. ":cat_" .. id, nodecore.underride(
nodecore.underride({
groups = {
[modname .. "_face"] = 1
},
}, basedef), {
[modname .. "_spawn_probability"] = catspawn
}))
minetest.register_node(":" .. modname .. ":cat_" .. id, nodecore.underride({
groups = {
[modname .. "_face"] = 1
},
}, basedef))
minetest.register_node(":" .. modname .. ":longcat_front_" .. id,
nodecore.underride({
description = desc .. " LongCat Head",
[modname .. "_spawn_probability"] = false,
tiles = fuzztiles({
basetiles[1] .. overlays.ears,
basetiles[2] .. overlays.paws_front,
@ -198,6 +199,7 @@ function myapi.register_cat(desc, basetiles, basedef, overlays)
minetest.register_node(":" .. modname .. ":longcat_mid_" .. id,
nodecore.underride({
description = desc .. " LongCat Midsection",
[modname .. "_spawn_probability"] = false,
tiles = fuzztiles({
basetiles[1],
basetiles[2] .. overlays.paws_middle,
@ -215,6 +217,7 @@ function myapi.register_cat(desc, basetiles, basedef, overlays)
minetest.register_node(":" .. modname .. ":longcat_back_" .. id,
nodecore.underride({
description = desc .. " LongCat Tail",
[modname .. "_spawn_probability"] = false,
tiles = fuzztiles({
basetiles[1],
basetiles[2] .. overlays.paws_back,
@ -262,4 +265,6 @@ function myapi.makecat(pos, param2, creator)
myapi.setname(meta)
checkfacedir(pos)
nodecore.fallcheck(pos)
end