mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-16 23:40:31 +01:00
Merged fire and flowers
- Flowers (including dry shrub, and lilipads) use decorations now
This commit is contained in:
parent
1456906a5b
commit
d44a5b5a79
|
@ -1,4 +1,5 @@
|
||||||
-- minetest/fire/init.lua
|
-- minetest/fire/init.lua
|
||||||
|
|
||||||
fire = {}
|
fire = {}
|
||||||
|
|
||||||
minetest.register_node("fire:basic_flame", {
|
minetest.register_node("fire:basic_flame", {
|
||||||
|
@ -16,16 +17,18 @@ minetest.register_node("fire:basic_flame", {
|
||||||
buildable_to = true,
|
buildable_to = true,
|
||||||
damage_per_second = 4,
|
damage_per_second = 4,
|
||||||
|
|
||||||
on_construct = function(pos, placer)
|
on_construct = function(pos)
|
||||||
fire.on_flame_add_at(pos)
|
minetest.after(0, fire.on_flame_add_at, pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_destruct = function(pos, oldnode, oldmetadata, digger)
|
on_destruct = function(pos)
|
||||||
fire.on_flame_remove_at(pos)
|
minetest.after(0, fire.on_flame_remove_at, pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
-- unaffected by explosions
|
||||||
|
on_blast = function() end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
fire.D = 6
|
fire.D = 6
|
||||||
-- key: position hash of low corner of area
|
-- key: position hash of low corner of area
|
||||||
-- value: {handle=sound handle, name=sound name}
|
-- value: {handle=sound handle, name=sound name}
|
||||||
|
@ -63,7 +66,7 @@ function fire.update_sounds_around(pos)
|
||||||
if not sound then
|
if not sound then
|
||||||
if should_have_sound then
|
if should_have_sound then
|
||||||
fire.sounds[p0_hash] = {
|
fire.sounds[p0_hash] = {
|
||||||
handle = minetest.sound_play(wanted_sound, {pos=cp, loop=true}),
|
handle = minetest.sound_play(wanted_sound, {pos=cp, max_hear_distance = 16, loop=true}),
|
||||||
name = wanted_sound.name,
|
name = wanted_sound.name,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -74,7 +77,7 @@ function fire.update_sounds_around(pos)
|
||||||
elseif sound.name ~= wanted_sound.name then
|
elseif sound.name ~= wanted_sound.name then
|
||||||
minetest.sound_stop(sound.handle)
|
minetest.sound_stop(sound.handle)
|
||||||
fire.sounds[p0_hash] = {
|
fire.sounds[p0_hash] = {
|
||||||
handle = minetest.sound_play(wanted_sound, {pos=cp, loop=true}),
|
handle = minetest.sound_play(wanted_sound, {pos=cp, max_hear_distance = 16, loop=true}),
|
||||||
name = wanted_sound.name,
|
name = wanted_sound.name,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -106,7 +109,7 @@ end
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"group:flammable"},
|
nodenames = {"group:flammable"},
|
||||||
neighbors = {"group:igniter"},
|
neighbors = {"group:igniter"},
|
||||||
interval = 1,
|
interval = 5,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = function(p0, node, _, _)
|
action = function(p0, node, _, _)
|
||||||
-- If there is water or stuff like that around flame, don't ignite
|
-- If there is water or stuff like that around flame, don't ignite
|
||||||
|
@ -124,7 +127,7 @@ minetest.register_abm({
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"group:igniter"},
|
nodenames = {"group:igniter"},
|
||||||
neighbors = {"air"},
|
neighbors = {"air"},
|
||||||
interval = 2,
|
interval = 5,
|
||||||
chance = 10,
|
chance = 10,
|
||||||
action = function(p0, node, _, _)
|
action = function(p0, node, _, _)
|
||||||
local reg = minetest.registered_nodes[node.name]
|
local reg = minetest.registered_nodes[node.name]
|
||||||
|
|
|
@ -1,68 +1,87 @@
|
||||||
minetest.register_on_generated(function(minp, maxp, seed)
|
local function register_flower(name)
|
||||||
if maxp.y >= 2 and minp.y <= 0 then
|
minetest.register_decoration({
|
||||||
-- Generate flowers
|
deco_type = "simple",
|
||||||
local perlin1 = minetest.get_perlin(436, 3, 0.6, 100)
|
place_on = {"default:dirt_with_grass"},
|
||||||
-- Assume X and Z lengths are equal
|
sidelen = 16,
|
||||||
local divlen = 16
|
noise_params = {
|
||||||
local divs = (maxp.x-minp.x)/divlen+1;
|
offset = 0,
|
||||||
for divx=0,divs-1 do
|
scale = 0.006,
|
||||||
for divz=0,divs-1 do
|
spread = {x=100, y=100, z=100},
|
||||||
local x0 = minp.x + math.floor((divx+0)*divlen)
|
seed = 436,
|
||||||
local z0 = minp.z + math.floor((divz+0)*divlen)
|
octaves = 3,
|
||||||
local x1 = minp.x + math.floor((divx+1)*divlen)
|
persist = 0.6
|
||||||
local z1 = minp.z + math.floor((divz+1)*divlen)
|
},
|
||||||
-- Determine flowers amount from perlin noise
|
y_min = 1,
|
||||||
local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9)
|
y_max = 30,
|
||||||
-- Find random positions for flowers based on this random
|
decoration = "flowers:"..name,
|
||||||
local pr = PseudoRandom(seed+456)
|
})
|
||||||
for i=0,grass_amount do
|
end
|
||||||
local x = pr:next(x0, x1)
|
|
||||||
local z = pr:next(z0, z1)
|
|
||||||
-- Find ground level (0...15)
|
|
||||||
local ground_y = nil
|
|
||||||
for y=30,0,-1 do
|
|
||||||
if minetest.get_node({x = x, y = y, z = z}).name ~= "air" then
|
|
||||||
ground_y = y
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if ground_y then
|
function flowers.register_mgv6_decorations()
|
||||||
local p = {x = x, y = ground_y + 1, z = z}
|
register_flower("rose")
|
||||||
local nn = minetest.get_node(p).name
|
register_flower("tulip")
|
||||||
-- Check if the node can be replaced
|
register_flower("dandelion_yellow")
|
||||||
if minetest.registered_nodes[nn] and
|
register_flower("geranium")
|
||||||
minetest.registered_nodes[nn].buildable_to then
|
register_flower("viola")
|
||||||
nn = minetest.get_node({x = x, y = ground_y, z = z}).name
|
register_flower("dandelion_white")
|
||||||
if nn == "default:dirt_with_grass" then
|
end
|
||||||
local flower_choice = pr:next(1, 6)
|
|
||||||
local flower
|
minetest.register_decoration({
|
||||||
if flower_choice == 1 then
|
deco_type = "simple",
|
||||||
flower = "flowers:tulip"
|
place_on = {"default:water_source"},
|
||||||
elseif flower_choice == 2 then
|
sidelen = 16,
|
||||||
flower = "flowers:rose"
|
noise_params = {
|
||||||
elseif flower_choice == 3 then
|
offset = 0,
|
||||||
flower = "flowers:dandelion_yellow"
|
scale = 0.006,
|
||||||
elseif flower_choice == 4 then
|
spread = {x=100, y=100, z=100},
|
||||||
flower = "flowers:dandelion_white"
|
seed = 436,
|
||||||
elseif flower_choice == 5 then
|
octaves = 3,
|
||||||
flower = "flowers:geranium"
|
persist = 0.6
|
||||||
elseif flower_choice == 6 then
|
},
|
||||||
flower = "flowers:viola"
|
y_min = -10,
|
||||||
end
|
y_max = 30,
|
||||||
minetest.set_node(p, {name = flower})
|
decoration = "flowers:lily_pad",
|
||||||
elseif nn == "default:water_source" then
|
})
|
||||||
minetest.set_node(p, {name = "flowers:lily_pad"})
|
|
||||||
elseif nn == "default:sand" then
|
minetest.register_decoration({
|
||||||
minetest.set_node(p, {name = "default:dry_shrub"})
|
deco_type = "simple",
|
||||||
elseif nn == "default:dirt_with_snow" then
|
place_on = {"default:sand"},
|
||||||
minetest.set_node(p, {name = "default:snow"})
|
sidelen = 16,
|
||||||
end
|
noise_params = {
|
||||||
end
|
offset = 0,
|
||||||
end
|
scale = 0.006,
|
||||||
|
spread = {x=100, y=100, z=100},
|
||||||
|
seed = 436,
|
||||||
|
octaves = 3,
|
||||||
|
persist = 0.6
|
||||||
|
},
|
||||||
|
y_min = -400,
|
||||||
|
y_max = 400,
|
||||||
|
decoration = "default:dry_shrub",
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_decoration({
|
||||||
|
deco_type = "simple",
|
||||||
|
place_on = {"default:snow"},
|
||||||
|
sidelen = 16,
|
||||||
|
noise_params = {
|
||||||
|
offset = 0,
|
||||||
|
scale = 0.006,
|
||||||
|
spread = {x=100, y=100, z=100},
|
||||||
|
seed = 436,
|
||||||
|
octaves = 3,
|
||||||
|
persist = 0.6
|
||||||
|
},
|
||||||
|
y_min = -400,
|
||||||
|
y_max = 400,
|
||||||
|
decoration = "default:snow",
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
-- Enable in mapgen v6 only
|
||||||
|
|
||||||
|
local mg_params = minetest.get_mapgen_params()
|
||||||
|
if mg_params.mgname == "v6" then
|
||||||
|
flowers.register_mgv6_decorations()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user