Generate chorus plants in the End

This commit is contained in:
Wuzzy 2019-03-09 21:02:40 +01:00
parent 895b9e7e3a
commit 7a4aeb6625
3 changed files with 182 additions and 98 deletions

View File

@ -3,6 +3,8 @@
local S = minetest.get_translator("mcl_end") local S = minetest.get_translator("mcl_end")
mcl_end = {}
--- Plant parts --- --- Plant parts ---
local MAX_FLOWER_AGE = 5 -- Maximum age of chorus flower before it dies local MAX_FLOWER_AGE = 5 -- Maximum age of chorus flower before it dies
@ -168,14 +170,40 @@ minetest.register_node("mcl_end:chorus_plant", {
_mcl_hardness = 0.4, _mcl_hardness = 0.4,
}) })
-- Grow a complete chorus plant at pos
mcl_end.grow_chorus_plant = function(pos, node)
local flowers = { pos }
-- Plant initial flower (if it isn't there already)
if not node then
node = minetest.get_node(pos)
end
if node.name ~= "mcl_end:chorus_flower" then
minetest.set_node(pos, { name = "mcl_end:chorus_flower" })
end
while true do
local new_flowers_list = {}
for f=1, #flowers do
local new_flowers = mcl_end.grow_chorus_plant_step(flowers[f], minetest.get_node(flowers[f]))
if #new_flowers > 0 then
table.insert(new_flowers_list, new_flowers)
end
end
if #new_flowers_list == 0 then
return
end
flowers = {}
for l=1, #new_flowers_list do
for f=1, #new_flowers_list[l] do
table.insert(flowers, new_flowers_list[l][f])
end
end
end
end
--- ABM --- -- Grow a single step of a chorus plant at pos.
minetest.register_abm({ -- Pos must be a chorus flower.
label = "Chorus plant growth", mcl_end.grow_chorus_plant_step = function(pos, node)
nodenames = { "mcl_end:chorus_flower" }, local new_flower_buds = {}
interval = 35.0,
chance = 4.0,
action = function(pos, node, active_object_count, active_object_count_wider)
local above = { x = pos.x, y = pos.y + 1, z = pos.z } local above = { x = pos.x, y = pos.y + 1, z = pos.z }
local node_above = minetest.get_node(above) local node_above = minetest.get_node(above)
local around = { local around = {
@ -259,6 +287,7 @@ minetest.register_abm({
grown = true grown = true
else else
minetest.set_node(f, {name="mcl_end:chorus_flower", param2 = age}) minetest.set_node(f, {name="mcl_end:chorus_flower", param2 = age})
table.insert(new_flower_buds, f)
grown = true grown = true
end end
end end
@ -271,6 +300,17 @@ minetest.register_abm({
if not grown then if not grown then
minetest.set_node(pos, {name = "mcl_end:chorus_flower_dead"}) minetest.set_node(pos, {name = "mcl_end:chorus_flower_dead"})
end end
return new_flower_buds
end
--- ABM ---
minetest.register_abm({
label = "Chorus plant growth",
nodenames = { "mcl_end:chorus_flower" },
interval = 35.0,
chance = 4.0,
action = function(pos, node, active_object_count, active_object_count_wider)
mcl_end.grow_chorus_plant_step(pos, node)
end, end,
}) })

View File

@ -3,3 +3,4 @@ mcl_core
mcl_worlds mcl_worlds
mcl_farming mcl_farming
mcl_flowers mcl_flowers
mcl_end

View File

@ -9,6 +9,8 @@ local generate_fallen_logs = minetest.settings:get_bool("mcl_generate_fallen_log
-- Jungle bush schematic. In PC/Java Edition it's Jungle Wood + Oak Leaves -- Jungle bush schematic. In PC/Java Edition it's Jungle Wood + Oak Leaves
local jungle_bush_schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_jungle_bush_oak_leaves.mts" local jungle_bush_schematic = minetest.get_modpath("mcl_core").."/schematics/mcl_core_jungle_bush_oak_leaves.mts"
local chorus_plant_deco_id
-- --
-- Register biomes -- Register biomes
-- --
@ -1697,8 +1699,6 @@ local function register_dimension_ores()
clust_scarcity = 1, clust_scarcity = 1,
}) })
end end
@ -3240,7 +3240,38 @@ end
-- Decorations in non-Overworld dimensions -- Decorations in non-Overworld dimensions
local function register_dimension_decorations() local function register_dimension_decorations()
-- TODO --[[ NETHER ]]
-- TODO: Nether
--[[ THE END ]]
-- Chorus plant
minetest.register_decoration({
name = "mcl_biomes:chorus_plant",
deco_type = "simple",
place_on = {"mcl_end:end_stone", "air"},
flags = "all_floors",
sidelen = 16,
noise_params = {
offset = -0.012,
scale = 0.024,
spread = {x = 100, y = 100, z = 100},
seed = 257,
octaves = 3,
persist = 0.6
},
y_min = mcl_vars.mg_end_min,
y_max = mcl_vars.mg_end_max,
decoration = "mcl_end:chorus_flower",
height = 1,
biomes = { "End" },
})
deco_id_chorus_plant = minetest.get_decoration_id("mcl_biomes:chorus_plant")
minetest.set_gen_notify({decoration=true}, { deco_id_chorus_plant })
-- TODO: End cities
end end
@ -3273,5 +3304,17 @@ if mg_name ~= "singlenode" then
register_dimension_decorations() register_dimension_decorations()
-- Overworld decorations for v6 are handled in mcl_mapgen_core -- Overworld decorations for v6 are handled in mcl_mapgen_core
if deco_id_chorus_plant then
minetest.register_on_generated(function(minp, maxp, blockseed)
local gennotify = minetest.get_mapgen_object("gennotify")
local poslist = {}
for _, pos in ipairs(gennotify["decoration#"..deco_id_chorus_plant] or {}) do
local realpos = { x = pos.x, y = pos.y + 1, z = pos.z }
mcl_end.grow_chorus_plant(realpos)
end
end)
end
end end