fixed roasting
parent
bccb15ecdc
commit
7a5b849024
|
@ -0,0 +1,138 @@
|
|||
minetest.register_abm({
|
||||
label = "Farming soil",
|
||||
nodenames = {"group:field"},
|
||||
interval = 15,
|
||||
chance = 4,
|
||||
action = function(pos, node)
|
||||
local n_def = minetest.registered_nodes[node.name] or nil
|
||||
local wet = n_def.soil.wet or nil
|
||||
local base = n_def.soil.base or nil
|
||||
local dry = n_def.soil.dry or nil
|
||||
if not n_def or not n_def.soil or not wet or not base or not dry then
|
||||
return
|
||||
end
|
||||
|
||||
pos.y = pos.y + 1
|
||||
local nn = minetest.get_node_or_nil(pos)
|
||||
if not nn or not nn.name then
|
||||
return
|
||||
end
|
||||
local nn_def = minetest.registered_nodes[nn.name] or nil
|
||||
pos.y = pos.y - 1
|
||||
|
||||
if nn_def and nn_def.walkable and minetest.get_item_group(nn.name, "plant") == 0 then
|
||||
minetest.set_node(pos, {name = base})
|
||||
return
|
||||
end
|
||||
-- check if there is water nearby
|
||||
local wet_lvl = minetest.get_item_group(node.name, "wet")
|
||||
if minetest.find_node_near(pos, 3, {"group:water"}) then
|
||||
-- if it is dry soil and not base node, turn it into wet soil
|
||||
if wet_lvl == 0 then
|
||||
minetest.set_node(pos, {name = wet})
|
||||
end
|
||||
else
|
||||
-- only turn back if there are no unloaded blocks (and therefore
|
||||
-- possible water sources) nearby
|
||||
if not minetest.find_node_near(pos, 3, {"ignore"}) then
|
||||
-- turn it back into base if it is already dry
|
||||
if wet_lvl == 0 then
|
||||
-- only turn it back if there is no plant/seed on top of it
|
||||
if minetest.get_item_group(nn.name, "plant") == 0 and minetest.get_item_group(nn.name, "seed") == 0 then
|
||||
minetest.set_node(pos, {name = base})
|
||||
end
|
||||
|
||||
-- if its wet turn it back into dry soil
|
||||
elseif wet_lvl == 1 then
|
||||
minetest.set_node(pos, {name = dry})
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_abm({
|
||||
label="crops getting ill",
|
||||
nodenames="group:infectable",
|
||||
intervall = 5,
|
||||
change=5,
|
||||
action = function(pos)
|
||||
local starttime=os.time()
|
||||
local node=minetest.get_node(pos)
|
||||
if node.name == "air" or node.name == "ignore" then
|
||||
return
|
||||
end
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
if ndef.groups.infectable == nil then
|
||||
return
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local ill_rate=meta:get_int("farming:weakness")
|
||||
if ill_rate == nil then
|
||||
return
|
||||
end
|
||||
if math.random(1,ill_rate)==1 then
|
||||
farming.plant_infect(pos)
|
||||
end
|
||||
-- print("infect time: "..os.time()-starttime)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
label="Planting crops",
|
||||
nodenames = farming.change_soil,
|
||||
neighbors = {"air"},
|
||||
interval = 15+math.random(-1,1), -- little noise
|
||||
chance = 200,
|
||||
action = function(pos)
|
||||
local starttime=os.clock()
|
||||
local ptabove={x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local above = minetest.get_node(ptabove)
|
||||
if above.name ~= "air" then
|
||||
return
|
||||
end
|
||||
local ptlight=minetest.get_node_light(ptabove)
|
||||
if ptlight < farming.min_light then
|
||||
return
|
||||
end
|
||||
local ptlight=minetest.get_node_light(ptabove,.5)
|
||||
if ptlight < farming.min_light then
|
||||
return
|
||||
end
|
||||
-- only for positions, where not too many plants are nearby
|
||||
-- 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
|
||||
if #minetest.find_nodes_in_area(vector.subtract(pos,4),vector.add(pos,4),"group:farming") > 2 then
|
||||
return
|
||||
end
|
||||
end
|
||||
-- if math.random(0,100) < 1 then
|
||||
local node_temp=minetest.get_heat(pos)
|
||||
local node_hum=minetest.get_humidity(pos)
|
||||
local sc={}
|
||||
for _,line in ipairs(farming.spreading_crops) do
|
||||
if line.temp_min<=node_temp and line.temp_max>=node_temp then
|
||||
if line.hum_min<=node_hum and line.hum_max>=node_hum then
|
||||
if line.y_min<=pos.y and line.y_max>=pos.y then
|
||||
if line.light_min<=ptlight and line.light_max >= ptlight then
|
||||
for k=1,math.floor(math.log(line.base_rate*1e10)) do
|
||||
table.insert(sc,1,line.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #sc > 0 then
|
||||
local rand_plant = math.random(1,#sc)
|
||||
minetest.add_node(ptabove, {name=sc[rand_plant],param2=1})
|
||||
minetest.get_node_timer(ptabove):start(math.random(10, 15))
|
||||
local starttime=os.clock()
|
||||
farming.set_node_metadata(ptabove)
|
||||
-- print("place time: "..(1000*(os.clock()-starttime)))
|
||||
end
|
||||
-- end
|
||||
end,
|
||||
})
|
|
@ -55,4 +55,3 @@ 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))
|
||||
|
|
|
@ -67,6 +67,12 @@ minetest.register_craftitem("farming:flour", {
|
|||
groups = {food_flour = 1, flammable = 1},
|
||||
})
|
||||
|
||||
minetest.register_craftitem("farming:grain_roasted", {
|
||||
description = "Grain Roaste",
|
||||
inventory_image = "farming_grain_roasted.png",
|
||||
groups = {food_roasted = 1, flammable = 1},
|
||||
})
|
||||
|
||||
minetest.register_craftitem(modname..":nettle_water",{
|
||||
description = "Nettle Water",
|
||||
inventory_image = "farming_tool_glass_nettle.png",
|
||||
|
|
|
@ -122,8 +122,9 @@ for i,tdef in pairs(crop_definition) do
|
|||
if i ~= "default" then
|
||||
-- only register when crop is enabled
|
||||
if tdef.enabled then
|
||||
print("farming registering "..tdef.name)
|
||||
local starttime=os.clock()
|
||||
farming.register_plant(tdef)
|
||||
print("farming registering "..tdef.name.." in "..(math.floor(1000000*(os.clock()-starttime))/1000).." milliseconds")
|
||||
else
|
||||
print("farming "..tdef.name.." disabled")
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ rhubarb,1,,10,3,2,2,,1,,1,,,,,,,,,,,,,3,,,,,,,,,9,,,,,,,,,,,
|
|||
spelt,1,,10,7,2,,,,1,1,,2,1,,,,1,,,3,,1,3,,2,,,,,,,,,,,,,,farming:straw,,,farming:flour,farming:grain_roasted
|
||||
strawberry,1,,10,4,2,1,,,,,1,1,,,,,,,,,,,3,,,,,,,,,9,,,,,,,,,,,
|
||||
sugarbeet,1,,10,5,2,2,,1,,1,,,,,,,,,,,,,3,,,35,,30,,,,9,,,,,,,,,,,
|
||||
tea,1,,20,8,2,1,,,,1,1,,,,1,,,,,4,,,3,,,30,70,30,70,,,,,,,,,,,,farming:tea_leaves,,
|
||||
tea,1,,20,8,2,1,,,,1,1,,,,1,,,,,4,,,3,,,30,70,30,70,,,,,,,,,,,,farming:tea_leaves,,farming:black_tea
|
||||
tobaco,1,,10,8,2,,,,,1,1,,,2,1,,,,,4,,,3,,,,,,,,,,,,,,,,,,farming:tobaco_leaves,,
|
||||
tomato,,,10,8,2,1,,,1,1,1,1,1,,,,,1,,,,,3,,,,,,,,,,,,,,,,,,,,
|
||||
nettle,1,,10,5,2,1,,,1,,,3,,1,,,1,,,2,,,3,1,3,5,150,0,100,,2000,8,,,,0.1,7,,farming:nettle_fibre,,,,
|
||||
|
|
85
init.lua
85
init.lua
|
@ -23,6 +23,7 @@ dofile(farming.path .. "/tools.lua")
|
|||
dofile(farming.path .. "/utensils.lua")
|
||||
dofile(farming.path .. "/craft.lua")
|
||||
dofile(farming.path .. "/crops.lua")
|
||||
dofile(farming.path .. "/abm.lua")
|
||||
|
||||
--print("dump registered plants")
|
||||
--print(dump(farming.registered_plants))
|
||||
|
@ -74,89 +75,5 @@ light_min day_start amount
|
|||
14 63 870
|
||||
]]
|
||||
|
||||
minetest.register_abm({
|
||||
label="crops getting ill",
|
||||
nodenames="group:infectable",
|
||||
intervall = 5,
|
||||
change=5,
|
||||
action = function(pos)
|
||||
local starttime=os.time()
|
||||
local node=minetest.get_node(pos)
|
||||
if node.name == "air" or node.name == "ignore" then
|
||||
return
|
||||
end
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
if ndef.groups.infectable == nil then
|
||||
return
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local ill_rate=meta:get_int("farming:weakness")
|
||||
if ill_rate == nil then
|
||||
return
|
||||
end
|
||||
if math.random(1,ill_rate)==1 then
|
||||
farming.plant_infect(pos)
|
||||
end
|
||||
-- print("infect time: "..os.time()-starttime)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
label="Planting crops",
|
||||
nodenames = farming.change_soil,
|
||||
neighbors = {"air"},
|
||||
interval = 15+math.random(-1,1), -- little noise
|
||||
chance = 200,
|
||||
action = function(pos)
|
||||
local starttime=os.clock()
|
||||
local ptabove={x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local above = minetest.get_node(ptabove)
|
||||
if above.name ~= "air" then
|
||||
return
|
||||
end
|
||||
local ptlight=minetest.get_node_light(ptabove)
|
||||
if ptlight < farming.min_light then
|
||||
return
|
||||
end
|
||||
local ptlight=minetest.get_node_light(ptabove,.5)
|
||||
if ptlight < farming.min_light then
|
||||
return
|
||||
end
|
||||
-- only for positions, where not too many plants are nearby
|
||||
-- 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
|
||||
if #minetest.find_nodes_in_area(vector.subtract(pos,4),vector.add(pos,4),"group:farming") > 2 then
|
||||
return
|
||||
end
|
||||
end
|
||||
-- if math.random(0,100) < 1 then
|
||||
local node_temp=minetest.get_heat(pos)
|
||||
local node_hum=minetest.get_humidity(pos)
|
||||
local sc={}
|
||||
for _,line in ipairs(farming.spreading_crops) do
|
||||
if line.temp_min<=node_temp and line.temp_max>=node_temp then
|
||||
if line.hum_min<=node_hum and line.hum_max>=node_hum then
|
||||
if line.y_min<=pos.y and line.y_max>=pos.y then
|
||||
if line.light_min<=ptlight and line.light_max >= ptlight then
|
||||
for k=1,math.floor(math.log(line.base_rate*1e10)) do
|
||||
table.insert(sc,1,line.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #sc > 0 then
|
||||
local rand_plant = math.random(1,#sc)
|
||||
minetest.add_node(ptabove, {name=sc[rand_plant],param2=1})
|
||||
minetest.get_node_timer(ptabove):start(math.random(10, 15))
|
||||
local starttime=os.clock()
|
||||
farming.set_node_metadata(ptabove)
|
||||
-- print("place time: "..(1000*(os.clock()-starttime)))
|
||||
end
|
||||
-- end
|
||||
end,
|
||||
})
|
||||
--print(dump(farming.spreading_crops))
|
||||
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded ")
|
||||
|
|
53
nodes.lua
53
nodes.lua
|
@ -105,56 +105,3 @@ minetest.register_node("farming:nettle_fibre", {
|
|||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
label = "Farming soil",
|
||||
nodenames = {"group:field"},
|
||||
interval = 15,
|
||||
chance = 4,
|
||||
action = function(pos, node)
|
||||
local n_def = minetest.registered_nodes[node.name] or nil
|
||||
local wet = n_def.soil.wet or nil
|
||||
local base = n_def.soil.base or nil
|
||||
local dry = n_def.soil.dry or nil
|
||||
if not n_def or not n_def.soil or not wet or not base or not dry then
|
||||
return
|
||||
end
|
||||
|
||||
pos.y = pos.y + 1
|
||||
local nn = minetest.get_node_or_nil(pos)
|
||||
if not nn or not nn.name then
|
||||
return
|
||||
end
|
||||
local nn_def = minetest.registered_nodes[nn.name] or nil
|
||||
pos.y = pos.y - 1
|
||||
|
||||
if nn_def and nn_def.walkable and minetest.get_item_group(nn.name, "plant") == 0 then
|
||||
minetest.set_node(pos, {name = base})
|
||||
return
|
||||
end
|
||||
-- check if there is water nearby
|
||||
local wet_lvl = minetest.get_item_group(node.name, "wet")
|
||||
if minetest.find_node_near(pos, 3, {"group:water"}) then
|
||||
-- if it is dry soil and not base node, turn it into wet soil
|
||||
if wet_lvl == 0 then
|
||||
minetest.set_node(pos, {name = wet})
|
||||
end
|
||||
else
|
||||
-- only turn back if there are no unloaded blocks (and therefore
|
||||
-- possible water sources) nearby
|
||||
if not minetest.find_node_near(pos, 3, {"ignore"}) then
|
||||
-- turn it back into base if it is already dry
|
||||
if wet_lvl == 0 then
|
||||
-- only turn it back if there is no plant/seed on top of it
|
||||
if minetest.get_item_group(nn.name, "plant") == 0 and minetest.get_item_group(nn.name, "seed") == 0 then
|
||||
minetest.set_node(pos, {name = base})
|
||||
end
|
||||
|
||||
-- if its wet turn it back into dry soil
|
||||
elseif wet_lvl == 1 then
|
||||
minetest.set_node(pos, {name = dry})
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
88
register.lua
88
register.lua
|
@ -84,7 +84,6 @@ farming.register_plant = function(def)
|
|||
def.wilt_name=def.mod_name..":wilt_"..def.name
|
||||
farming.register_wilt(def)
|
||||
end
|
||||
farming.registered_plants[def.name] = def
|
||||
|
||||
farming.register_seed(def)
|
||||
|
||||
|
@ -105,6 +104,13 @@ farming.register_plant = function(def)
|
|||
farming.register_infect(def)
|
||||
end
|
||||
|
||||
for _,it in ipairs({"roast","grind","seed_drop"}) do
|
||||
if def[it] ~= nil then
|
||||
if minetest.registered_craftitems[def[it]] == nil then
|
||||
farming.register_craftitem(def[it])
|
||||
end
|
||||
end
|
||||
end
|
||||
if def.groups["use_flail"] then
|
||||
def.straw_name="farming:straw"
|
||||
if def.straw then
|
||||
|
@ -121,6 +127,11 @@ farming.register_plant = function(def)
|
|||
if def.groups["seed_roastable"] then
|
||||
farming.register_roast(def)
|
||||
end
|
||||
if def.groups["for_coffee"] then
|
||||
farming.register_coffee(def)
|
||||
end
|
||||
|
||||
farming.registered_plants[def.name] = def
|
||||
end
|
||||
|
||||
farming.register_harvest=function(hdef)
|
||||
|
@ -134,14 +145,17 @@ farming.register_harvest=function(hdef)
|
|||
for _,coln in ipairs({"plant_name"}) do
|
||||
harvest_def[coln] = hdef[coln]
|
||||
end
|
||||
-- some existing groups are copied
|
||||
-- for _,coln in ipairs({"use_flail","use_trellis"}) do
|
||||
-- if hdef.groups[coln] then
|
||||
-- harvest_def.groups[coln] = hdef.groups[coln]
|
||||
-- end
|
||||
-- end
|
||||
minetest.register_craftitem(":" .. hdef.step_name, harvest_def)
|
||||
end
|
||||
farming.register_craftitem = function(itemname)
|
||||
local desc = itemname:split(":")[2]
|
||||
local item_def={
|
||||
description = S(desc:gsub("^%l", string.upper)),
|
||||
inventory_image = itemname:gsub(":","_")..".png",
|
||||
groups = {flammable = 2},
|
||||
}
|
||||
minetest.register_craftitem(":"..itemname,item_def)
|
||||
end
|
||||
|
||||
farming.register_infect=function(idef)
|
||||
local infect_def={
|
||||
|
@ -882,51 +896,59 @@ function farming.seed_craft(gdef)
|
|||
})
|
||||
end
|
||||
|
||||
function farming.register_coffee(cdef)
|
||||
|
||||
end
|
||||
|
||||
function farming.register_roast(rdef)
|
||||
if rdef.seed_name == nil then
|
||||
return
|
||||
end
|
||||
if rdef.step_name == nil then
|
||||
if rdef.roast == nil then
|
||||
return
|
||||
end
|
||||
local roastitem = rdef.step_name.."_roasted"
|
||||
if rdef.roast then
|
||||
roastitem = rdef.roast
|
||||
end
|
||||
-- local mname = minetest.get_current_modname()
|
||||
-- if rdef.mod_name then
|
||||
-- mname = rdef.mod_name
|
||||
-- end
|
||||
local roast_png = roastitem:gsub(":","_")..".png"
|
||||
|
||||
local roast_def={
|
||||
description = S(rdef.description:gsub("^%l", string.upper).." roasted"),
|
||||
inventory_image = roast_png,
|
||||
groups = rdef.groups or {flammable = 2},
|
||||
}
|
||||
for _,coln in ipairs({"plant_name"}) do
|
||||
roast_def[coln] = rdef[coln]
|
||||
end
|
||||
for _,coln in ipairs({"seed_roastable"}) do
|
||||
if rdef.groups[coln] then
|
||||
roast_def.groups[coln] = rdef.groups[coln]
|
||||
-- if no roast defined in config, register an own roast item
|
||||
if minetest.registered_craftitems[roastitem] == nil then
|
||||
-- if rdef.roast == nil then
|
||||
local roast_png = roastitem:gsub(":","_")..".png"
|
||||
|
||||
local roast_def={
|
||||
description = S(rdef.description:gsub("^%l", string.upper).." roasted"),
|
||||
inventory_image = roast_png,
|
||||
groups = rdef.groups or {flammable = 2},
|
||||
}
|
||||
for _,coln in ipairs({"plant_name"}) do
|
||||
roast_def[coln] = rdef[coln]
|
||||
end
|
||||
for _,coln in ipairs({"seed_roastable"}) do
|
||||
if rdef.groups[coln] then
|
||||
roast_def.groups[coln] = rdef.groups[coln]
|
||||
end
|
||||
end
|
||||
if rdef.eat_hp then
|
||||
roast_def.on_use=minetest.item_eat(rdef.eat_hp*2)
|
||||
end
|
||||
|
||||
minetest.register_craftitem(":" .. roastitem, roast_def)
|
||||
end
|
||||
if rdef.eat_hp then
|
||||
roast_def.on_use=minetest.item_eat(rdef.eat_hp*2)
|
||||
end
|
||||
|
||||
minetest.register_craftitem(":" .. roastitem, roast_def)
|
||||
|
||||
local cooktime = 3
|
||||
if rdef.groups.seed_roastable then
|
||||
cooktime = rdef.groups.seed_roastable
|
||||
end
|
||||
local seedname=rdef.seed_name
|
||||
if rdef.seed_drop ~= nil then
|
||||
seedname=rdef.seed_drop
|
||||
end
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
cooktime = cooktime or 3,
|
||||
output = roastitem,
|
||||
recipe = rdef.seed_name
|
||||
recipe = seedname
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -943,10 +965,6 @@ function farming.register_grind(rdef)
|
|||
end
|
||||
local desc = grinditem:split(":")[2]
|
||||
desc = desc:gsub("_"," ")
|
||||
-- local mname = minetest.get_current_modname()
|
||||
-- if rdef.mod_name then
|
||||
-- mname = rdef.mod_name
|
||||
-- end
|
||||
local grind_png = grinditem:gsub(":","_")..".png"
|
||||
|
||||
local grind_def={
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 141 B |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 141 B |
Loading…
Reference in New Issue