Compare commits

...

5 Commits

Author SHA1 Message Date
Izzy ca23461697 typo fix 2019-07-24 15:31:33 -06:00
Izzy 5c6a99392a fix leaf decay 2019-07-24 13:20:08 -06:00
Izzy c2ee043dd2 external api helper 2019-06-12 19:36:44 -06:00
Izzy 9ad36fec03 added storms support 2019-06-09 15:16:07 -06:00
Izzy 02cc6c4fe8 update from integrated version 2019-06-07 19:55:01 -06:00
5 changed files with 189 additions and 20 deletions

View File

@ -1,2 +1,3 @@
default
flowers
storms?

208
init.lua
View File

@ -1,10 +1,13 @@
seasons = {}
function deepclone(t)
if type(t) ~= "table" then
return t
end
local meta = getmetatable(t)
-- local meta = getmetatable(t)
local target = {}
for k, v in pairs(t) do
@ -15,14 +18,14 @@ function deepclone(t)
end
end
setmetatable(target, meta)
--setmetatable(target, meta)
return target
end
local SEASONS_YEARLEN = 60 * 2
local SEASONS_YEARLEN = 60 * 60 * 2
@ -42,11 +45,16 @@ local changes_lookup = {
winter = {},
}
local function splitname(name)
local c = string.find(name, ":", 1)
return string.sub(name, 1, c - 1), string.sub(name, c + 1, string.len(name))
end
function reg_changes(ssn, oldmod, oldname)
local old = oldmod..":"..oldname
local new = "seasons:"..ssn.."_"..oldname
local new = "seasons:"..ssn.."_"..oldmod.."_"..oldname
core_lookup[old] = old
if ssn == "summer" then -- minetest is in "summer" by default
@ -61,6 +69,19 @@ function reg_changes(ssn, oldmod, oldname)
end
function reg_custom(ssn, old, new)
core_lookup[old] = old
if ssn == "summer" then -- minetest is in "summer" by default
changes_lookup[ssn][old] = old
table.insert(abm_list, old)
else
print(dump(core_lookup))
core_lookup[new] = old
changes_lookup[ssn][old] = new
table.insert(abm_list, new)
end
end
seasons.reg_custom = reg_custom
@ -68,7 +89,7 @@ function reg_generic(oldmod, oldname, tiles, drops, default_season)
local old = oldmod..":"..oldname
local ds = default_season or "summer"
function reg(ssn)
local function reg(ssn)
local new
if ssn == ds then -- minetest is in "summer" by default
new = old
@ -88,13 +109,18 @@ function reg_generic(oldmod, oldname, tiles, drops, default_season)
end
if drops and drops[ssn] then
def.drops = drops[ssn]
def.drop = drops[ssn]
end
if oldname == "dirt_with_grass" then
print(dump(def))
end
minetest.register_node(new, def)
end
-- print("new: "..new.." old: "..old)
core_lookup[new] = old
changes_lookup[ssn][old] = new
table.insert(abm_list, new)
@ -128,8 +154,32 @@ reg_generic("default", "bush_leaves", {
nil)
reg_generic("default", "jungleleaves", nil, nil)
default.register_leafdecay({
trunks = {"default:jungletree"},
leaves = {
"default:jungleleaves",
"seasons:winter_default_jungleleaves",
"seasons:fall_default_jungleleaves",
"seasons:spring_default_jungleleaves",
},
radius = 3,
})
reg_generic("default", "acacia_leaves", nil, nil)
default.register_leafdecay({
trunks = {"default:acacia_tree"},
leaves = {
"default:acacia_leaves",
"seasons:winter_default_acacia_leaves",
"seasons:fall_default_acacia_leaves",
"seasons:spring_default_acacia_leaves",
},
radius = 2,
})
reg_generic("default", "aspen_leaves", nil, nil)
--[[
saplings
@ -153,7 +203,7 @@ falling leaf particles
function reg_leaves(ssn)
reg_changes(ssn, "default", "leaves")
minetest.register_node("seasons:"..ssn.."_leaves", {
minetest.register_node("seasons:"..ssn.."_default_leaves", {
description = "Apple Tree Leaves",
drawtype = "allfaces_optional",
waving = 1,
@ -174,7 +224,7 @@ function reg_leaves(ssn)
{
-- player will get leaves only if he get no saplings,
-- this is because max_items is 1
items = {'seasons:'..ssn..'_leaves'},
items = {'seasons:'..ssn..'_default_leaves'},
}
}
},
@ -182,6 +232,12 @@ function reg_leaves(ssn)
after_place_node = default.after_place_leaves,
})
-- default.register_leafdecay({
-- trunks = {"default:tree"},
-- leaves = {"seasons:"..ssn.."_default_leaves"},
-- radius = 2,
-- })
end
reg_leaves("spring")
reg_leaves("fall")
@ -192,7 +248,7 @@ reg_changes("summer", "default", "leaves")
function reg_aspen_leaves(ssn)
reg_changes(ssn, "default", "aspen_leaves")
minetest.register_node("seasons:"..ssn.."_aspen_leaves", {
minetest.register_node("seasons:"..ssn.."_default_aspen_leaves", {
description = "Aspen Tree Leaves",
drawtype = "allfaces_optional",
tiles = {"seasons_"..ssn.."_aspen_leaves.png"},
@ -205,13 +261,19 @@ function reg_aspen_leaves(ssn)
max_items = 1,
items = {
{items = {"default:aspen_sapling"}, rarity = 20},
{items = {"seasons:"..ssn.."_aspen_leaves"}}
{items = {"seasons:"..ssn.."_default_aspen_leaves"}}
}
},
sounds = default.node_sound_leaves_defaults(),
after_place_node = default.after_place_leaves,
})
-- default.register_leafdecay({
-- trunks = {"default:aspen_tree"},
-- leaves = {"seasons:"..ssn.."_default_aspen_leaves"},
-- radius = 3,
-- })
end
reg_aspen_leaves("spring")
@ -249,6 +311,7 @@ reg_generic("flowers", "tulip",
},
"spring")
--[[
reg_generic("flowers", "tulip_black",
{
summer = {"seasons_summer_flowers_tulip.png"},
@ -262,7 +325,7 @@ reg_generic("flowers", "tulip_black",
winter = {}, -- TODO: bulb
},
"spring")
]]
local def
-- dandelions are done manually because the default ones represent two seasons
@ -326,6 +389,7 @@ end
local get_season = function()
local season, time
local t = minetest.get_gametime()
local s = (t % SEASONS_YEARLEN) / SEASONS_YEARLEN
@ -344,17 +408,18 @@ local get_season = function()
time = (s - .7) / .3
end
return season, time
return season, time, s
end
seasons.get_season = get_season
minetest.register_abm({
label = "Leaf Change",
nodenames = abm_list,
interval = 1,
chance = 5,
interval = 5,
chance = 180,
catch_up = true,
action = function(pos, node)
local s, progress = get_season()
@ -421,8 +486,8 @@ minetest.register_abm({
"default:river_water_flowing",
},
neighbors = "air",
interval = 1,
chance = 5,
interval = 5,
chance = 180,
catch_up = true,
action = function(pos, node)
local s, progress = get_season()
@ -444,8 +509,8 @@ minetest.register_abm({
"seasons:ice_river_water_source",
"seasons:ice_river_water_flowing",
},
interval = 1,
chance = 5,
interval = 5,
chance = 180,
catch_up = true,
action = function(pos, node)
local s, progress = get_season()
@ -459,3 +524,106 @@ minetest.register_abm({
end,
})
local last_season = {
spring = "winter",
summer = "spring",
fall = "summer",
winter = "fall",
}
minetest.register_lbm({
name = "seasons:catchup",
nodenames = abm_list,
run_at_every_load = true,
action = function(pos, node)
local s, progress = get_season()
if math.random() > (progress * 1.2) then
-- use last season's node
s = last_season[s]
end
--local name = changes[s][node.name]
local core = core_lookup[node.name]
local name = changes_lookup[s][core]
if name == nil or name == node.name then return end
minetest.set_node(pos, {name = name})
end,
})
if minetest.global_exists("storms") then
storms.register_heat_bias(function(pos, orig)
local season, stime, spin = get_season()
spin = math.sin(spin * 2 * math.pi) * 20
-- print("heat bias: ".. spin)
return spin
end)
--[[
storms.register_freq_bias(function(pos, orig)
local season, stime, spin = get_season()
spin = math.sin(spin * 2 * math.pi)
print("freq bias: ".. spin)
return spin
end)
]]
end
default.register_leafdecay({
trunks = {"default:tree"},
leaves = {
"default:apple",
"default:leaves",
"seasons:winter_default_leaves",
"seasons:fall_default_leaves",
"seasons:spring_default_leaves",
},
radius = 2,
})
default.register_leafdecay({
trunks = {"default:aspen_tree"},
leaves = {
"default:aspen_leaves",
"seasons:winter_default_acacia_leaves",
"seasons:fall_default_acacia_leaves",
"seasons:spring_default_acacia_leaves",
},
radius = 3,
})
default.register_leafdecay({
trunks = {"default:bush_stem"},
leaves = {
"default:bush_leaves",
"seasons:winter_default_bush_leaves",
"seasons:fall_default_bush_leaves",
"seasons:spring_default_bush_leaves",
},
radius = 1,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

BIN
textures/flowers_viola.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B