From 8cbab18044ed88fdcd9288dc36fa46899e5da56f Mon Sep 17 00:00:00 2001 From: NathanSalapat Date: Sat, 5 Nov 2016 12:42:29 -0500 Subject: [PATCH] improved flowers spawning, and some other code cleanup. --- README | 18 +++++----- depends.txt | 3 +- flowers.lua | 43 ++++++---------------- grass.lua | 2 +- init.lua | 94 ++++++++++++++++++++----------------------------- leaves.lua | 75 ++++++++++++++------------------------- pre-flowers.lua | 19 ++++++++++ 7 files changed, 107 insertions(+), 147 deletions(-) create mode 100644 pre-flowers.lua diff --git a/README b/README index a1ebf27..5e0f0d8 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Mod is by Don and Nathan +Mod is by Don, Nathan with optimizations from Snoopy. Mymonths is licenced as DWYWPL @@ -13,25 +13,25 @@ by Jeija - Rain / Snow: CC-BY-SA 3.0, credit goes to TeddyDesTodes, from his weather branch at https://github.com/TeddyDesTodes/minetest/tree/weather - Sound Effects: - mymonths_rain & mymonths_rain1: CC0 by Q.K. - -This mod adds months, weeks and days to Minetest. -A Minetest year has 12 months with 2 weeks per month. Each week has 7 days. -The weather is depended on the time of year. If it is winter then it will snow spring has rain etc. -Leaves turn color in the fall and the the tree will have no leaves or apples through the winter. +This mod adds months, weeks and days to Minetest. +A Minetest year has 12 months with 2 weeks per month. Each week has 7 days. + +The weather is depended on the time of year. If it is winter then it will snow spring has rain etc. +Leaves turn color in the fall and the the tree will have no leaves or apples through the winter. The leaves grow back in the spring and the apples later in the year. Acacia trees will bloom in January The desert and savannah biomes do not get rain or snow but do have sand storms. The snow biomes do not get rain. -The trees in these biomes do not loose their leaves. +The trees in these biomes do not loose their leaves. Each morning at 6am a chat message will say the date. If the day is a holiday it will show in chat with the morning date. -If you are caught in a storm you will need to seek shelter. Rain or snow does nothingbut if you are in a storm, snowstorm, -sandstorm or hail you will recieve damage. You need to cover yourself so you do not recieve damage. +If you are caught in a storm you will need to seek shelter. Rain or snow does nothing but if you are in a storm, snowstorm, +sandstorm or hail you will receive damage. You need to cover yourself so you do not receive damage. Chat Commands diff --git a/depends.txt b/depends.txt index ceea950..7840293 100644 --- a/depends.txt +++ b/depends.txt @@ -1,3 +1,4 @@ default -thirsty? lightning? +flowers? +bakedclay? diff --git a/flowers.lua b/flowers.lua index fd61190..e572342 100644 --- a/flowers.lua +++ b/flowers.lua @@ -2,7 +2,7 @@ -- Flowers die in late fall minetest.register_abm({ nodenames = {'group:flower'}, - interval = 10, + interval = 10, chance = 10, action = function (pos) @@ -22,7 +22,10 @@ minetest.register_abm({ interval = 240, chance = 100, - action = function (pos) + action = function (pos, node) + if node.name == 'default:desert_sand' then + return + end -- return if not march or april if mymonths.month_counter ~= 3 @@ -30,44 +33,20 @@ minetest.register_abm({ return end - local pos0 = {x = pos.x - 4, y = pos.y - 4, z = pos.z - 4} - local pos1 = {x = pos.x + 4, y = pos.y + 4, z = pos.z + 4} + local pos0 = {x = pos.x - 4, y = pos.y - 2, z = pos.z - 4} + local pos1 = {x = pos.x + 4, y = pos.y + 2, z = pos.z + 4} local flowers = minetest.find_nodes_in_area(pos0, pos1, "group:flower") - if #flowers > 2 then + if #flowers > 1 then return end pos.y = pos.y + 1 if minetest.get_node(pos).name == 'air' then - - local key = math.random(1, 6) - - if key == 1 then - - minetest.set_node(pos, {name = 'flowers:dandelion_white'}) - - elseif key == 2 then - - minetest.set_node(pos, {name = "flowers:dandelion_yellow"}) - - elseif key == 3 then - - minetest.set_node(pos, {name = "flowers:geranium"}) - - elseif key == 4 then - - minetest.set_node(pos, {name = "flowers:rose"}) - - elseif key == 5 then - - minetest.set_node(pos, {name = "flowers:tulip"}) - - elseif key == 6 then - - minetest.set_node(pos, {name = "flowers:viola"}) - end + local key = math.random(1, mymonths.flower_number) + local placed_flower = mymonths.flowers[key] + minetest.set_node(pos, {name = placed_flower}) end end }) diff --git a/grass.lua b/grass.lua index b457d62..730edfb 100644 --- a/grass.lua +++ b/grass.lua @@ -1,7 +1,7 @@ minetest.register_node("mymonths:fall_grass", { description = "Dirt with Grass", tiles = {"default_grass.png^[colorize:brown:50", "default_dirt.png", - {name = "default_dirt.png^default_grass_side.png^[colorize:brown:50", + {name = "default_dirt.png^(default_grass_side.png^[colorize:brown:50)", tileable_vertical = false}}, groups = {crumbly = 3, soil = 1, spreading_dirt_type = 1}, drop = 'default:dirt', diff --git a/init.lua b/init.lua index e412671..66d276b 100644 --- a/init.lua +++ b/init.lua @@ -1,10 +1,10 @@ --Settings mymonths = {} ---Turn damage on or off. This will make storms and hail cause damage +--Turn damage on or off. This will make storms and hail cause damage to players mymonths.damage = false ---You can turn weather off +--You can turn weather off; this will put snow and puddles off too mymonths.use_weather = true --Leaves change color in the fall. @@ -22,79 +22,63 @@ mymonths.flowers_die = true --Grass changes color in fall, and spring mymonths.grass_change = true -if minetest.get_modpath("lightning") then - lightning.auto = false +if minetest.get_modpath("lightning") then + lightning.auto = false end - local modpath = minetest.get_modpath("mymonths") -local input = io.open(modpath.."/settings.txt", "r") +local input = io.open(modpath .. "/settings.txt", "r") if input then - dofile(modpath.."/settings.txt") - input:close() - input = nil -else - mymonths.damage = false - mymonths.use_weather = true - mymonths.leaves = true - mymonths.snow_on_ground = true - mymonths.use_puddles = true + dofile(modpath .. "/settings.txt") + input:close() + input = nil + end -dofile(minetest.get_modpath("mymonths") .. "/functions.lua") -dofile(minetest.get_modpath("mymonths") .. "/abms.lua") -dofile(minetest.get_modpath("mymonths") .. "/command.lua") -dofile(minetest.get_modpath("mymonths") .. "/months.lua") +dofile(modpath .. "/functions.lua") +dofile(modpath .. "/abms.lua") +dofile(modpath .. "/command.lua") +dofile(modpath .. "/months.lua") if mymonths.use_weather == true then - dofile(minetest.get_modpath("mymonths").."/weather.lua") -end - -if mymonths.grass_change == true then - dofile(minetest.get_modpath("mymonths").."/grass.lua") -end - -if mymonths.use_weather == false then - minetest.register_alias("mymonths:puddle", "air") - minetest.register_alias("mymonths:snow_cover_1", "air") - minetest.register_alias("mymonths:snow_cover_2", "air") - minetest.register_alias("mymonths:snow_cover_3", "air") - minetest.register_alias("mymonths:snow_cover_4", "air") - minetest.register_alias("mymonths:snow_cover_5", "air") + dofile(modpath .. "/weather.lua") +else + mymonths.snow_on_ground = false + mymonths.use_puddles = false end if mymonths.snow_on_ground == false then - - minetest.register_alias("mymonths:snow_cover_1", "air") - minetest.register_alias("mymonths:snow_cover_2", "air") - minetest.register_alias("mymonths:snow_cover_3", "air") - minetest.register_alias("mymonths:snow_cover_4", "air") - minetest.register_alias("mymonths:snow_cover_5", "air") + minetest.register_alias("mymonths:snow_cover_1", "air") + minetest.register_alias("mymonths:snow_cover_2", "air") + minetest.register_alias("mymonths:snow_cover_3", "air") + minetest.register_alias("mymonths:snow_cover_4", "air") + minetest.register_alias("mymonths:snow_cover_5", "air") end if mymonths.use_puddles == false then - minetest.register_alias("mymonths:puddle", "air") + minetest.register_alias("mymonths:puddle", "air") +end + +if mymonths.grass_change == true then + dofile(modpath .. "/grass.lua") end if mymonths.leaves == true then - dofile(minetest.get_modpath("mymonths") .. "/leaves.lua") -end - -if mymonths.leaves == false then - - minetest.register_alias("mymonths:leaves_pale_green", "default:leaves") - minetest.register_alias("mymonths:leaves_orange", "default:leaves") - minetest.register_alias("mymonths:leaves_red", "default:leaves") - minetest.register_alias("mymonths:sticks_default", "default:leaves") - minetest.register_alias("mymonths:sticks_aspen", "default:aspen_leaves") + dofile(modpath .. "/leaves.lua") +else + minetest.register_alias("mymonths:leaves_pale_green", "default:leaves") + minetest.register_alias("mymonths:leaves_orange", "default:leaves") + minetest.register_alias("mymonths:leaves_red", "default:leaves") + minetest.register_alias("mymonths:sticks_default", "default:leaves") + minetest.register_alias("mymonths:sticks_aspen", "default:aspen_leaves") + minetest.register_alias("mymonths:leaves_yellow_aspen", "default:aspen_leaves") + minetest.register_alias("mymonths:leaves_orange_aspen", "default:aspen_leaves") + minetest.register_alias("mymonths:leaves_red_aspen", "default:aspen_leaves") end if mymonths.flowers_die == true then - dofile(minetest.get_modpath("mymonths") .. "/flowers.lua") -end - -if minetest.get_modpath("thirsty") then - thirst = true + dofile(modpath .. '/pre-flowers.lua') + dofile(modpath .. "/flowers.lua") end diff --git a/leaves.lua b/leaves.lua index db9ce46..9774123 100644 --- a/leaves.lua +++ b/leaves.lua @@ -24,7 +24,7 @@ for i, name in pairs(leaves_table) do end for i, name in pairs(sticks_table) do - + minetest.register_node('mymonths:sticks_' .. name, { description = 'Sticks', drawtype = 'allfaces_optional', @@ -85,7 +85,7 @@ minetest.register_abm({ --leaves 'falling/dying' in October minetest.register_abm({ nodenames = {'mymonths:leaves_red', 'mymonths:leaves_red_aspen'}, - interval = 60, + interval = 60, chance = 40, action = function (pos, node, active_object_count, active_object_count_wider) @@ -107,7 +107,7 @@ minetest.register_abm({ --New growth in spring minetest.register_abm({ nodenames = {'mymonths:sticks_default', 'mymonths:leaves_blooms', 'mymonths:sticks_aspen', 'mymonths:leaves_aspen_blooms'}, - interval = 60, + interval = 60, chance = 40, action = function (pos, node, active_object_count, active_object_count_wider) @@ -135,62 +135,39 @@ minetest.register_abm({ end }) ---apples die in November +-- apples die in November minetest.register_abm({ - nodenames = {'default:apple'}, - interval = 15, - chance = 10, + nodenames = {'default:apple'}, + interval = 15, + chance = 10, + action = function (pos) - action = function (pos, node, active_object_count, active_object_count_wider) + if mymonths.month_counter == 11 then - local nodeu1 = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}) - local nodeu2 = minetest.get_node({x = pos.x, y = pos.y - 2, z = pos.z}) - local nodeu3 = minetest.get_node({x = pos.x, y = pos.y - 3, z = pos.z}) - local nodeu4 = minetest.get_node({x = pos.x, y = pos.y - 4, z = pos.z}) + minetest.set_node(pos,{name = 'mymonths:sticks_default'}) - if mymonths.month_counter == 11 then + local i = 1 - if nodeu1.name == "air" then + repeat - minetest.spawn_item({ - x = pos.x, - y = pos.y - 1, - z = pos.z}, 'default:apple') + local n = minetest.get_node({x = pos.x, y = pos.y - i, z = pos.z}) - minetest.set_node(pos,{name = 'mymonths:sticks_default'}) + if n.name == "air" then - elseif nodeu2.name == "air" then + minetest.spawn_item({ + x = pos.x, + y = pos.y - i, + z = pos.z}, + 'default:apple') - minetest.spawn_item({ - x = pos.x, - y = pos.y - 2, - z = pos.z}, 'default:apple') + end - minetest.set_node(pos,{name = 'mymonths:sticks_default'}) + i = i + 1 - elseif nodeu3.name == "air" then + until n.name == "air" or i == 4 - minetest.spawn_item({ - x = pos.x, - y = pos.y - 3, - z = pos.z}, 'default:apple') - - minetest.set_node(pos,{name = 'mymonths:sticks_default'}) - - elseif nodeu4.name == "air" then - - minetest.spawn_item({ - x = pos.x, - y = pos.y - 4, - z = pos.z}, 'default:apple') - - minetest.set_node(pos,{name = 'mymonths:sticks_default'}) - - else - minetest.set_node(pos,{name = 'mymonths:sticks_default'}) - end - end - end + end + end }) @@ -637,7 +614,7 @@ minetest.register_lbm({ if day >= 1 and day <=7 then - if n == 'mymonths:sticks_default' + if n == 'mymonths:sticks_default' or n == 'default:leaves' or n == 'mymonths:leaves_pale_green' then @@ -664,7 +641,7 @@ minetest.register_lbm({ if day >= 1 and day <=7 then - if n == 'mymonths:sticks_aspen' + if n == 'mymonths:sticks_aspen' or n == 'mymonths:leaves_yellow_aspen' or n == 'mymonths:leaves_aspen_blooms' or n == 'default:aspen_leaves' then diff --git a/pre-flowers.lua b/pre-flowers.lua new file mode 100644 index 0000000..e74ee17 --- /dev/null +++ b/pre-flowers.lua @@ -0,0 +1,19 @@ +mymonths.flowers = {} + +if minetest.get_modpath('flowers') then + table.insert(mymonths.flowers,'flowers:dandelion_white') + table.insert(mymonths.flowers,'flowers:dandelion_yellow') + table.insert(mymonths.flowers,'flowers:geranium') + table.insert(mymonths.flowers,'flowers:rose') + table.insert(mymonths.flowers,'flowers:tulip') + table.insert(mymonths.flowers,'flowers:viola') +end + +if minetest.get_modpath('bakedclay') then + table.insert(mymonths.flowers,'bakedclay:delphinium') + table.insert(mymonths.flowers,'bakedclay:lazarus') + table.insert(mymonths.flowers,'bakedclay:mannagrass') + table.insert(mymonths.flowers,'bakedclay:thistle') +end + +mymonths.flower_number = table.getn(mymonths.flowers)