added light_stat for recalculation of grow time depend on local light

master
ademant 2018-10-25 07:19:59 +02:00
parent a43f2ea9c8
commit 201b967101
4 changed files with 63 additions and 21 deletions

View File

@ -53,3 +53,6 @@ end
-- register for crops, which are spreading by abm
farming.spreading_crops = {}
farming.light_stat = farming.import_csv(farming.path.."/light_stat.txt",{
col_num={"day_start","amount","name"}})
print(dump(farming.light_stat))

View File

@ -13,8 +13,8 @@ minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- start loadi
-- Load files
dofile(farming.path .. "/config.lua")
dofile(farming.path .. "/functions.lua")
dofile(farming.path .. "/config.lua")
dofile(farming.path .. "/api.lua")
dofile(farming.path .. "/register.lua")
@ -46,7 +46,31 @@ minetest.register_lbm({
minetest.get_node_timer(pos):start(math.random(farming.wait_min,farming.wait_max))
end,
})
--[[
minetest.register_abm({
nodenames="air",
intervall=1,
change=1000,
action = function(pos)
print(dump(farming.calc_light(pos,{light_min=15})))
end
})
]]
--[[
light_min day_start amount
4 51 988
5 53 978
6 54 972
7 55 965
8 56 957
9 57 948
10 57 948
11 58 937
12 59 925
13 60 912
14 63 870
]]
minetest.register_abm({
label="crops getting ill",
nodenames="group:infectable",
@ -54,7 +78,6 @@ minetest.register_abm({
change=5,
action = function(pos)
local node=minetest.get_node(pos)
-- print(dump(node))
if node.name == "air" or node.name == "ignore" then
return
end
@ -97,9 +120,7 @@ minetest.register_abm({
-- first check if any crops are nearby, because the counting
-- of nearby crops is time consuming
if minetest.find_node_near(pos,4,"group:farming") ~= nil then
local pos0 = vector.subtract(pos,4)
local pos1 = vector.add(pos,4)
if #minetest.find_nodes_in_area(pos0,pos1,"group:farming") > 2 then
if #minetest.find_nodes_in_area(vector.subtract(pos,4),vector.add(pos,4),"group:farming") > 2 then
return
end
end

12
light_stat.txt Normal file
View File

@ -0,0 +1,12 @@
name,day_start,amount
4,51,988
5,53,978
6,54,972
7,55,965
8,56,957
9,57,948
10,57,948
11,58,937
12,59,925
13,60,912
14,63,870

View File

@ -1017,6 +1017,23 @@ farming.billhook_on_use = function(itemstack, user, pointed_thing, uses)
return itemstack
end
farming.calc_light=function(pos,pdef)
-- calculating
print(dump(pos))
local outdata={day_start=99999,
light_amount=0,
}
for i=50,120 do
if minetest.get_node_light(pos,(i)/240)>pdef.light_min then
outdata.light_amount=outdata.light_amount+minetest.get_node_light(pos,i/240)
outdata.day_start=math.min(outdata.day_start,i)
end
end
if outdata.day_start > 240 then
outdata.day_start=120
end
return outdata
end
farming.set_node_metadata=function(pos)
local base_rate = 5
local node = minetest.get_node(pos)
@ -1042,21 +1059,10 @@ farming.set_node_metadata=function(pos)
ill_rate = math.ceil((ill_rate + ill_temp + ill_hum)/infect_rate)
local meta = minetest.get_meta(pos)
meta:set_int("farming:weakness",ill_rate)
-- calculating
local day_start=99999
local light_amount=0
for i=50,120 do
if minetest.get_node_light(pos,(i)/240)>pdef.light_min then
light_amount=light_amount+minetest.get_node_light(pos,i/240)
day_start=math.min(day_start,i)
end
end
if day_start > 240 then
day_start=120
end
local lightcalc=farming.calc_light(pos,pdef)
-- daytime, when light reach light_min
meta:set_float("farming:daystart",day_start/240)
meta:set_float("farming:daystart",lightcalc.day_start/240)
-- amount of light the crop gets till midday
meta:set_int("farming:lightamount",light_amount)
meta:set_int("farming:lightamount",lightcalc.light_amount)
end