cleanup
parent
7fd7891720
commit
eeca8aa78a
31
abm.lua
31
abm.lua
|
@ -121,29 +121,28 @@ minetest.register_abm({
|
|||
end
|
||||
end
|
||||
-- if math.random(0,100) < 1 then
|
||||
local node_temp=minetest.get_heat(pos)
|
||||
local node_hum=minetest.get_humidity(pos)
|
||||
local node_y=pos.y
|
||||
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)
|
||||
if line.y_min<=node_y and line.y_max>=node_y then
|
||||
local node_temp=minetest.get_heat(pos)
|
||||
if line.temp_min<=node_temp and line.temp_max>=node_temp then
|
||||
local node_hum=minetest.get_humidity(pos)
|
||||
if line.hum_min<=node_hum and line.hum_max>=node_hum then
|
||||
if line.light_min<=ptlight and line.light_max >= ptlight then
|
||||
for k=1,line.base_rate do
|
||||
table.insert(sc,line.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #sc > 0 then
|
||||
-- print("ping")
|
||||
|
||||
local rand_plant = math.random(1,#sc)
|
||||
minetest.add_node(ptabove, {name=sc[rand_plant],param2=1})
|
||||
-- local rand_plant = math.random(1,#sc)
|
||||
minetest.add_node(ptabove, {name=sc[math.random(1,#sc)],param2=1})
|
||||
minetest.get_node_timer(ptabove):start(math.random(10, 15))
|
||||
local starttime=os.clock()
|
||||
-- local starttime=os.clock()
|
||||
farming.set_node_metadata(ptabove)
|
||||
-- print("place time: "..(1000*(os.clock()-starttime)))
|
||||
end
|
||||
|
@ -156,7 +155,7 @@ minetest.register_abm({
|
|||
minetest.register_on_shutdown(function()
|
||||
if #farming.time_farming > 0 then
|
||||
table.sort(farming.time_farming)
|
||||
print("farming median "..farming.time_farming[math.ceil(#farming.time_farming/2)])
|
||||
print("farming median "..farming.time_farming[math.ceil(#farming.time_farming*0.25)].." - "..farming.time_farming[math.ceil(#farming.time_farming/2)].." - "..farming.time_farming[math.ceil(#farming.time_farming*.75)])
|
||||
-- print(dump(farming.time_farming))
|
||||
end
|
||||
if #farming.time_ill > 0 then
|
||||
|
@ -166,7 +165,7 @@ minetest.register_on_shutdown(function()
|
|||
end
|
||||
if #farming.time_planting >0 then
|
||||
table.sort(farming.time_planting)
|
||||
print("planting median "..farming.time_planting[math.ceil(#farming.time_planting/2)])
|
||||
print("planting median "..farming.time_planting[math.ceil(#farming.time_planting*0.25)].." - "..farming.time_planting[math.ceil(#farming.time_planting/2)].." - "..farming.time_planting[math.ceil(#farming.time_planting*0.75)])
|
||||
end
|
||||
--[[
|
||||
for _,colu in ipairs({"time_plantinfect","time_plantcured","time_plantpunch",
|
||||
|
|
|
@ -1,479 +1,3 @@
|
|||
local S = farming.intllib
|
||||
-- fallback default definition, if no defaults given by configuration
|
||||
local farming_default_env={temperature_min=0,temperature_max=100,humidity_min=0,humidity_max=100,
|
||||
elevation_min=0,elevation_max=31000,light_min=10,light_max=default.LIGHT_MAX,rarety=10,
|
||||
grow_time_mean=120,spread_rate=1e-5,infect_rate_base=1e-5,infect_rate_monoculture=1e-3,
|
||||
harvest_max=2,place_param2 = 3,}
|
||||
local step_node_def = {
|
||||
drawtype = "plantlike",
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
selection_box = {type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
groups = {snappy = 3, flammable = 2,flora=1, plant = 1, not_in_creative_inventory = 1, attached_node = 1},
|
||||
}
|
||||
|
||||
-- function to check definition for a plant
|
||||
-- and set to defaults values
|
||||
local register_plant_check_def = function(def) -- time optimised
|
||||
local starttime=os.clock()
|
||||
local actmodname=minetest.get_current_modname()
|
||||
local base_name=actmodname..":"..def.name
|
||||
def.mod_name=actmodname
|
||||
def.plant_name=def.name
|
||||
def.base_name=base_name
|
||||
def.basepng=base_name:gsub(":","_")
|
||||
|
||||
for dn,dv in pairs(farming_default_env) do
|
||||
if def[dn] == nil then
|
||||
def[dn] = dv
|
||||
end
|
||||
end
|
||||
if not def.description then
|
||||
def.description = def.name:gsub("^%l", string.upper)
|
||||
end
|
||||
if not def.fertility then
|
||||
def.fertility = {"grassland"}
|
||||
end
|
||||
if def.groups.seed_grindable ~= nil then
|
||||
if not def.grind then
|
||||
def.grind = base_name.."_grinded"
|
||||
end
|
||||
end
|
||||
if def.groups.seed_roastable ~= nil then
|
||||
if not def.roast then
|
||||
def.roast = base_name.."_roasted"
|
||||
end
|
||||
end
|
||||
-- check if seed_drop is set and check if it is a node name
|
||||
if def.seed_drop then
|
||||
if not string.match(def.seed_drop,":") then
|
||||
def.seed_drop=actmodname..":"..def.seed_drop
|
||||
end
|
||||
def.groups["has_harvest"] = 1
|
||||
end
|
||||
if def.groups.wiltable then
|
||||
if not def.wilt_time then
|
||||
def.wilt_time = farming.wilt_time
|
||||
end
|
||||
end
|
||||
def.grow_time_min=math.floor(def.grow_time_mean*0.75)
|
||||
def.grow_time_max=math.floor(def.grow_time_mean*1.2)
|
||||
-- print("time check definition "..1000*(os.clock()-starttime))
|
||||
return def
|
||||
end
|
||||
|
||||
-- Register plants
|
||||
farming.register_plant = function(def)
|
||||
-- Check def table
|
||||
if not def.steps then
|
||||
return nil
|
||||
end
|
||||
-- check definition
|
||||
def = register_plant_check_def(def)
|
||||
-- local definitions
|
||||
def.step_name=def.mod_name..":"..def.name
|
||||
def.seed_name=def.mod_name..":seed_"..def.name
|
||||
def.plant_name = def.name
|
||||
-- if plant has harvest then registering
|
||||
if def.groups["has_harvest"] ~= nil then
|
||||
-- if plant drops seed of wild crop, set the wild seed as harvest
|
||||
if def.seed_drop ~= nil then
|
||||
def.harvest_name = def.seed_drop
|
||||
else
|
||||
def.harvest_name = def.step_name
|
||||
end
|
||||
farming.register_harvest(def)
|
||||
else
|
||||
def.harvest_name=def.seed_name
|
||||
end
|
||||
|
||||
if def.groups["wiltable"] == 2 then
|
||||
def.wilt_name=def.mod_name..":wilt_"..def.name
|
||||
farming.register_wilt(def)
|
||||
end
|
||||
|
||||
farming.register_seed(def)
|
||||
|
||||
farming.register_steps(def)
|
||||
|
||||
if (not def.groups["to_culture"]) then
|
||||
local edef=def
|
||||
local spread_def={name=def.step_name.."_1",
|
||||
temp_min=edef.temperature_min,temp_max=edef.temperature_max,
|
||||
hum_min=edef.humidity_min,hum_max=edef.humidity_max,
|
||||
y_min=edef.elevation_min,y_max=edef.elevation_max,base_rate = def.spread_rate,
|
||||
light_min=edef.light_min,light_max=edef.light_max}
|
||||
farming.min_light = math.min(farming.min_light,edef.light_min)
|
||||
--table.insert(farming.spreading_crops,1,spread_def)
|
||||
end
|
||||
|
||||
if def.groups["infectable"] then
|
||||
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
|
||||
def.straw_name=def.straw
|
||||
end
|
||||
farming.craft_seed(def)
|
||||
end
|
||||
if def.groups["use_trellis"] then
|
||||
farming.trellis_seed(def)
|
||||
end
|
||||
if def.groups["seed_grindable"] then
|
||||
farming.register_grind(def)
|
||||
end
|
||||
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) --time optimised
|
||||
-- base definition of harvest
|
||||
local harvest_def={
|
||||
description = S(hdef.description),
|
||||
inventory_image = hdef.mod_name.."_"..hdef.plant_name..".png",
|
||||
groups = {flammable = 2,farming_harvest=1},
|
||||
plant_name=hdef.plant_name,
|
||||
}
|
||||
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 starttime=os.clock()
|
||||
local infectpng=idef.mod_name.."_"..idef.plant_name.."_ill.png"
|
||||
local infect_def={
|
||||
description = S(idef.description),
|
||||
tiles = {infectpng},
|
||||
drawtype = "plantlike",
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
on_dig = farming.plant_cured , -- why digging fails?
|
||||
selection_box = {type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
on_timer=farming.timer_infect,
|
||||
groups = {snappy = 3, attached_node = 1, flammable = 2,farming_infect=2},
|
||||
}
|
||||
for _,coln in ipairs({"name","seed_name","plant_name",
|
||||
"infect_rate_base","infect_rate_monoculture"}) do
|
||||
infect_def[coln] = idef[coln]
|
||||
end
|
||||
|
||||
infect_def.groups[idef.plant_name] = 0
|
||||
minetest.register_node(":" .. idef.name.."_infected", infect_def)
|
||||
-- print("time register infect "..1000*(os.clock()-starttime))
|
||||
end
|
||||
farming.register_wilt=function(idef)
|
||||
-- local starttime=os.clock()
|
||||
if not idef.wilt_name then
|
||||
return
|
||||
end
|
||||
local wilt_def={
|
||||
description = S(idef.description:gsub("^%l", string.upper).." wilted"),
|
||||
tiles = {idef.basepng.."_wilt.png"},
|
||||
drawtype = "plantlike",
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
selection_box = {type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
on_timer = farming.timer_wilt,
|
||||
groups = {snappy = 3, attached_node = 1, flammable = 2,farming_wilt=1},
|
||||
}
|
||||
|
||||
if idef.straw then
|
||||
wilt_def.drop={items={{items={idef.straw}}}}
|
||||
end
|
||||
for _,coln in ipairs({"name","seed_name","plant_name","fertility"}) do
|
||||
wilt_def[coln] = idef[coln]
|
||||
end
|
||||
|
||||
if idef.groups.wiltable then
|
||||
wilt_def.groups["wiltable"]=idef.groups.wiltable
|
||||
end
|
||||
minetest.register_node(":" .. idef.wilt_name, wilt_def)
|
||||
-- print("time register wilt "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
|
||||
farming.register_seed=function(sdef) --time optimised
|
||||
-- local starttime=os.clock()
|
||||
local seed_def = {
|
||||
description=S(sdef.name:gsub("^%l", string.upper).." Seed"),
|
||||
next_step = sdef.step_name .. "_1",
|
||||
drawtype = "signlike",
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
walkable = false,
|
||||
sunlight_propagates = true,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
|
||||
},
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
dig = {name = "", gain = 0},
|
||||
dug = {name = "default_grass_footstep", gain = 0.2},
|
||||
place = {name = "default_place_node", gain = 0.25},
|
||||
}),
|
||||
on_place = farming.seed_on_place,
|
||||
on_timer = farming.timer_seed,
|
||||
groups = {farming_seed = 1, snappy = 3, attached_node = 1, flammable = 2},
|
||||
}
|
||||
for i,colu in ipairs({"fertility","plant_name","grow_time_min","grow_time_max","light_min"}) do
|
||||
seed_def[colu] = sdef[colu]
|
||||
end
|
||||
local invimage=sdef.basepng.."_seed.png"
|
||||
seed_def.inventory_image = invimage
|
||||
seed_def.tiles = {invimage}
|
||||
seed_def.wield_image = {invimage}
|
||||
seed_def.groups[sdef.mod_name] = 1
|
||||
for k, v in pairs(sdef.fertility) do
|
||||
seed_def.groups[v] = 1
|
||||
end
|
||||
for i,colu in ipairs({"on_soil","for_flour"}) do
|
||||
if sdef.groups[colu] then
|
||||
seed_def.groups[colu] = sdef.groups[colu]
|
||||
end
|
||||
end
|
||||
if sdef.eat_hp then
|
||||
seed_def.on_use=minetest.item_eat(sdef.eat_hp)
|
||||
end
|
||||
minetest.register_node(":" .. sdef.seed_name, seed_def)
|
||||
-- print("time register seed "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
farming.register_steps = function(sdef)
|
||||
-- local starttime=os.clock()
|
||||
-- base configuration of all steps
|
||||
-- copy some plant definition into definition of this steps
|
||||
-- define drop item: normal drop the seed
|
||||
local dropitem=sdef.seed_name
|
||||
-- if plant has to be harvested, drop harvest instead
|
||||
if sdef.groups.has_harvest then
|
||||
if sdef.seed_drop then
|
||||
dropitem = sdef.seed_drop
|
||||
else
|
||||
dropitem = sdef.step_name
|
||||
end
|
||||
end
|
||||
local is_hurting=(sdef.groups.damage_per_second~=nil)
|
||||
local damage=0
|
||||
if is_hurting then
|
||||
damate=sdef.groups.damage_per_second
|
||||
end
|
||||
local is_viscos=(sdef.groups.liquid_viscosity and farming.config:get_int("viscosity") > 0)
|
||||
local viscosity=0
|
||||
if is_viscos then
|
||||
viscosity=sdef.groups.liquid_viscosity
|
||||
end
|
||||
local max_step=sdef.steps
|
||||
local stepname=sdef.step_name.."_"
|
||||
for i=1,max_step do
|
||||
local reli=i/max_step
|
||||
local ndef={description=stepname..i,
|
||||
drawtype = "plantlike",
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
selection_box = {type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
drop_item=dropitem,
|
||||
drop={items={{items={dropitem}}}},
|
||||
tiles={sdef.basepng.."_"..i..".png"},
|
||||
groups = {snappy = 3, flammable = 2,flora=1, plant = 1,
|
||||
not_in_creative_inventory = 1, attached_node = 1,
|
||||
step=i,
|
||||
},
|
||||
}
|
||||
for _,colu in ipairs({"grow_time_min","grow_time_max","light_min","plant_name"}) do
|
||||
ndef[colu]=sdef[colu]
|
||||
end
|
||||
for _,colu in ipairs({"infectable","snappy","punchable","damage_per_second","liquid_viscosity","wiltable"}) do
|
||||
if sdef.groups[colu] then
|
||||
ndef.groups[colu] = sdef.groups[colu]
|
||||
end
|
||||
end
|
||||
ndef.groups[sdef.mod_name]=1
|
||||
ndef.groups[sdef.plant_name]=1
|
||||
if sdef.groups.use_trellis then
|
||||
--table.insert(ndef.drop.items,1,{items={"farming:trellis"}})
|
||||
end
|
||||
if i < max_step then
|
||||
ndef.groups["farming_grows"]=1 -- plant is growing
|
||||
ndef.next_step=stepname.. (i + 1)
|
||||
ndef.on_timer = farming.timer_step
|
||||
ndef.grow_time_min=sdef.grow_time_min
|
||||
ndef.grow_time_max=sdef.grow_time_max
|
||||
end
|
||||
-- hurting and viscosity not for first step, which is used for random generation
|
||||
if i > 1 then
|
||||
-- check if plant hurts while going through
|
||||
if is_hurting then
|
||||
-- calculate damage as part of growing: Full damage only for full grown plant
|
||||
local step_damage=math.ceil(damage*reli)
|
||||
if step_damage > 0 then
|
||||
ndef.damage_per_second = step_damage
|
||||
end
|
||||
end
|
||||
-- for some crops you should walk slowly through like a wheat field
|
||||
if is_viscos then
|
||||
local step_viscosity=math.ceil(viscosity*reli)
|
||||
if step_viscosity > 0 then
|
||||
ndef.liquid_viscosity= step_viscosity
|
||||
ndef.liquidtype="source"
|
||||
ndef.liquid_alternative_source=ndef.description
|
||||
ndef.liquid_alternative_flowing=ndef.description
|
||||
ndef.liquid_renewable=false
|
||||
ndef.liquid_range=0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- with higher grow levels you harvest more
|
||||
local step_harvest = math.floor(reli*sdef.harvest_max + 0.05)
|
||||
if step_harvest > 1 then
|
||||
for h = 2,step_harvest do
|
||||
--table.insert(ndef.drop.items,1,{items={dropitem},rarity=(max_step - i + 1)*h})
|
||||
end
|
||||
end
|
||||
if i == max_step then
|
||||
ndef.groups["farming_fullgrown"]=1
|
||||
ndef.on_dig = farming.dig_harvest
|
||||
if sdef.groups.wiltable then
|
||||
local nowilt=sdef.groups.wiltable
|
||||
if nowilt == 2 then
|
||||
ndef.next_step=sdef.wilt_name
|
||||
elseif nowilt == 1 then
|
||||
ndef.next_step = stepname .. (i - 1)
|
||||
elseif nowilt == 3 then
|
||||
ndef.pre_step = stepname .. (i - 1)
|
||||
ndef.seed_name=sdef.seed_name
|
||||
end
|
||||
ndef.on_timer = farming.timer_step
|
||||
ndef.grow_time_min=sdef.wilt_time or 10
|
||||
ndef.grow_time_max=math.ceil(ndef.grow_time_min*1.1)
|
||||
end
|
||||
-- at the end stage you can harvest by change a cultured seed (if defined)
|
||||
if sdef.next_plant then
|
||||
local next_plant_rarity = (max_step - i + 1)*2
|
||||
--table.insert(ndef.drop.items,1,{items={sdef.next_plant},rarity=next_plant_rarity})
|
||||
end
|
||||
if sdef.groups.punchable and i > 1 then
|
||||
ndef.pre_step = stepname.. (i - 1)
|
||||
ndef.on_punch = farming.punch_step
|
||||
end
|
||||
end
|
||||
-- print(dump(ndef))
|
||||
minetest.register_node(":" .. ndef.description, ndef)
|
||||
end
|
||||
-- print("time register step "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
farming.register_billhook = function(name,def)
|
||||
if not def.groups["billhook"] then
|
||||
def.groups["billhook"]=1
|
||||
end
|
||||
if not def.material then
|
||||
return
|
||||
end
|
||||
if def.max_uses == nil then
|
||||
def.max_uses = 30
|
||||
end
|
||||
if def.on_use == nil then
|
||||
def.on_use = function(itemstack, user, pointed_thing)
|
||||
return farming.use_billhook(itemstack, user, pointed_thing, def.max_uses)
|
||||
end
|
||||
end
|
||||
if not def.recipe then
|
||||
def.recipe = {
|
||||
{"", def.material, def.material},
|
||||
{"", "group:stick", ""},
|
||||
{"group:stick", "", ""} }
|
||||
end
|
||||
farming.register_tool(name,def)
|
||||
end
|
||||
|
||||
farming.register_scythe = function(name,def)
|
||||
if not def.groups["scythe"] then
|
||||
def.groups["scythe"]=1
|
||||
end
|
||||
if not def.material then
|
||||
return
|
||||
end
|
||||
if not def.recipe then
|
||||
def.recipe = {
|
||||
{def.material, def.material, "group:stick"},
|
||||
{def.material, "group:stick", ""},
|
||||
{"group:stick", "", ""} }
|
||||
end
|
||||
farming.register_tool(name,def)
|
||||
end
|
||||
|
||||
-- Register new Scythes
|
||||
farming.register_tool = function(name, def)
|
||||
-- recipe has to be provided
|
||||
if not def.recipe then
|
||||
return
|
||||
end
|
||||
-- Check for : prefix (register new hoes in your mod's namespace)
|
||||
if name:sub(1,1) ~= ":" then
|
||||
name = ":" .. name
|
||||
end
|
||||
-- Check def table
|
||||
if def.description == nil then
|
||||
def.description = "Farming tool"
|
||||
end
|
||||
if def.inventory_image == nil then
|
||||
def.inventory_image = "unknown_item.png"
|
||||
end
|
||||
if def.max_uses == nil then
|
||||
def.max_uses = 30
|
||||
end
|
||||
def.sound={breaks = "default_tool_breaks"}
|
||||
|
||||
-- Register the tool
|
||||
minetest.register_tool(name, def)
|
||||
-- Register its recipe
|
||||
minetest.register_craft({
|
||||
output = name:sub(2),
|
||||
recipe = def.recipe
|
||||
})
|
||||
end
|
||||
|
||||
farming.plant_infect = function(pos)
|
||||
local starttime=os.clock()
|
||||
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
|
@ -497,6 +21,7 @@ farming.plant_infect = function(pos)
|
|||
minetest.get_node_timer(pos):start(math.random(farming.wait_min,farming.wait_max))
|
||||
--table.insert(farming.time_plantinfect,1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
farming.plant_cured = function(pos)
|
||||
local starttime=os.clock()
|
||||
local node = minetest.get_node(pos)
|
||||
|
@ -534,7 +59,8 @@ farming.punch_step = function(pos, node, puncher, pointed_thing)
|
|||
-- give one item only if no billhook is used
|
||||
puncher:get_inventory():add_item('main',def.drop_item)
|
||||
end
|
||||
minetest.swap_node(pos, {name=def.pre_step})
|
||||
minetest.swap_node(pos, {name=def.pre_step,
|
||||
param2=def.place_param2 or 3})
|
||||
|
||||
-- new timer needed?
|
||||
local pre_def=minetest.registered_nodes[def.pre_step]
|
||||
|
@ -629,7 +155,8 @@ farming.timer_step = function(pos, elapsed)
|
|||
end
|
||||
-- grow
|
||||
local next_def=minetest.registered_nodes[def.next_step]
|
||||
minetest.swap_node(pos, {name=def.next_step})
|
||||
minetest.swap_node(pos, {name=def.next_step,
|
||||
param2=def.place_param2 or 3})
|
||||
local meta = minetest.get_meta(pos)
|
||||
if next_def.groups.farming_wilt ~= nil then
|
||||
if meta:get_int("farming:weakness") == nil then
|
||||
|
@ -770,7 +297,7 @@ farming.timer_seed = function(pos, elapsed)
|
|||
-- omitted is a check for light, we assume seeds can germinate in the dark.
|
||||
local placenode = {name = def.next_step}
|
||||
if def.place_param2 then
|
||||
placenode.param2 = def.place_param2
|
||||
placenode.param2 = def.place_param2 or 3
|
||||
end
|
||||
minetest.swap_node(pos, placenode)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
@ -920,123 +447,6 @@ farming.trellis_seed = function(gdef)
|
|||
})
|
||||
end
|
||||
|
||||
-- define seed crafting out of harvest, releasing kind of straw
|
||||
function farming.craft_seed(gdef)
|
||||
if gdef.seed_name == nil then
|
||||
return
|
||||
end
|
||||
if gdef.harvest_name == nil then
|
||||
return
|
||||
end
|
||||
local straw_name = "farming:straw"
|
||||
if gdef.straw_name ~= nil then
|
||||
straw_name = gdef.straw_name
|
||||
end
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = gdef.seed_name.." 1",
|
||||
recipe = {
|
||||
farming.modname..":flail",gdef.harvest_name
|
||||
},
|
||||
replacements = {{"group:farming_flail", farming.modname..":flail"},
|
||||
{gdef.harvest_name,straw_name}},
|
||||
})
|
||||
end
|
||||
|
||||
function farming.register_coffee(cdef)
|
||||
|
||||
end
|
||||
|
||||
-- registering roast items if needed for plant
|
||||
function farming.register_roast(rdef)
|
||||
local starttime=os.clock()
|
||||
if not rdef.seed_name then
|
||||
return
|
||||
end
|
||||
if not rdef.roast then
|
||||
return
|
||||
end
|
||||
local roastitem=rdef.roast
|
||||
-- if no roast defined in config, register an own roast item
|
||||
if minetest.registered_craftitems[roastitem] == nil then
|
||||
local roast_png = roastitem:gsub(":","_")..".png"
|
||||
local rn = roastitem:split(":")[2]
|
||||
rn=rn:gsub("_"," ")
|
||||
local roast_def={
|
||||
description = S(rdef.description:gsub("^%l", string.upper)),
|
||||
inventory_image = roast_png,
|
||||
groups = {flammable = 2},
|
||||
plant_name=rdef.plant_name,
|
||||
}
|
||||
|
||||
if rdef.groups.seed_roastable then
|
||||
roast_def.groups["seed_roastable"] = rdef.groups.seed_roastable
|
||||
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
|
||||
|
||||
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 = seedname
|
||||
})
|
||||
-- print("time register roast "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
-- registering grind items
|
||||
function farming.register_grind(rdef)
|
||||
local starttime=os.clock()
|
||||
if rdef.seed_name == nil then
|
||||
return
|
||||
end
|
||||
if rdef.step_name == nil then
|
||||
return
|
||||
end
|
||||
local grinditem = rdef.step_name.."_flour"
|
||||
if rdef.grind then
|
||||
grinditem = rdef.grind
|
||||
end
|
||||
local desc = grinditem:split(":")[2]
|
||||
desc = desc:gsub("_"," ")
|
||||
local grind_png = grinditem:gsub(":","_")..".png"
|
||||
|
||||
local grind_def={
|
||||
description = S(desc:gsub("^%l", string.upper).." roasted"),
|
||||
inventory_image = grind_png,
|
||||
groups = {flammable = 2},
|
||||
plant_name=rdef.plant_name,
|
||||
}
|
||||
|
||||
if rdef.eat_hp then
|
||||
grind_def.on_use=minetest.item_eat(rdef.eat_hp)
|
||||
end
|
||||
|
||||
minetest.register_craftitem(":" .. grinditem, grind_def)
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = grinditem,
|
||||
recipe = {rdef.seed_name.." "..rdef.groups["seed_grindable"],
|
||||
farming.modname..":mortar_pestle"},
|
||||
replacements = {{"group:food_mortar_pestle", farming.modname..":mortar_pestle"}},
|
||||
|
||||
})
|
||||
-- print("time register grind "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
-- function for using billhook on punchable fruits
|
||||
-- add wear to billhook and give player by change one more fruit
|
||||
farming.use_billhook = function(itemstack, user, pointed_thing, uses)
|
||||
|
@ -1150,5 +560,3 @@ farming.set_node_metadata=function(pos)
|
|||
meta:set_int("farming:lightamount",lightcalc.light_amount)
|
||||
--table.insert(farming.time_setmeta,1000*(os.clock()-starttime))
|
||||
end
|
||||
-- local starttime=os.clock()
|
||||
-- print("time define infect "..1000*(os.clock()-starttime))
|
6
init.lua
6
init.lua
|
@ -17,8 +17,10 @@ dofile(farming.path .. "/functions.lua")
|
|||
dofile(farming.path .. "/config.lua")
|
||||
|
||||
dofile(farming.path .. "/api.lua")
|
||||
dofile(farming.path .. "/register.lua")
|
||||
dofile(farming.path .. "/actions_register.lua") -- several actions defined
|
||||
dofile(farming.path .. "/nodes_register.lua") -- registering of nodes and items
|
||||
dofile(farming.path .. "/nodes.lua")
|
||||
dofile(farming.path .. "/tools_register.lua")
|
||||
dofile(farming.path .. "/tools.lua")
|
||||
dofile(farming.path .. "/utensils.lua")
|
||||
dofile(farming.path .. "/craft.lua")
|
||||
|
@ -74,6 +76,6 @@ light_min day_start amount
|
|||
13 60 912
|
||||
14 63 870
|
||||
]]
|
||||
print(dump(farming.change_soil))
|
||||
--print(dump(farming.change_soil))
|
||||
--print(dump(farming.spreading_crops))
|
||||
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded ")
|
||||
|
|
|
@ -0,0 +1,523 @@
|
|||
local S = farming.intllib
|
||||
-- fallback default definition, if no defaults given by configuration
|
||||
local farming_default_env={temperature_min=0,temperature_max=100,humidity_min=0,humidity_max=100,
|
||||
elevation_min=0,elevation_max=31000,light_min=10,light_max=default.LIGHT_MAX,rarety=10,
|
||||
grow_time_mean=120,spread_rate=1e-5,infect_rate_base=1e-5,infect_rate_monoculture=1e-3,
|
||||
harvest_max=2,place_param2 = 3,}
|
||||
|
||||
-- function to check definition for a plant
|
||||
-- and set to defaults values
|
||||
local register_plant_check_def = function(def) -- time optimised
|
||||
-- local starttime=os.clock()
|
||||
local actmodname=minetest.get_current_modname()
|
||||
local base_name=actmodname..":"..def.name
|
||||
def.mod_name=actmodname
|
||||
def.plant_name=def.name
|
||||
def.base_name=base_name
|
||||
def.basepng=base_name:gsub(":","_")
|
||||
|
||||
for dn,dv in pairs(farming_default_env) do
|
||||
if def[dn] == nil then
|
||||
def[dn] = dv
|
||||
end
|
||||
end
|
||||
if not def.description then
|
||||
def.description = def.name:gsub("^%l", string.upper)
|
||||
end
|
||||
if not def.fertility then
|
||||
def.fertility = {"grassland"}
|
||||
end
|
||||
if def.groups.seed_grindable ~= nil then
|
||||
if not def.grind then
|
||||
def.grind = base_name.."_grinded"
|
||||
end
|
||||
end
|
||||
if def.groups.seed_roastable ~= nil then
|
||||
if not def.roast then
|
||||
def.roast = base_name.."_roasted"
|
||||
end
|
||||
end
|
||||
-- check if seed_drop is set and check if it is a node name
|
||||
if def.seed_drop then
|
||||
if not string.match(def.seed_drop,":") then
|
||||
def.seed_drop=actmodname..":"..def.seed_drop
|
||||
end
|
||||
def.groups["has_harvest"] = 1
|
||||
end
|
||||
if def.groups.wiltable then
|
||||
if not def.wilt_time then
|
||||
def.wilt_time = farming.wilt_time
|
||||
end
|
||||
end
|
||||
if not def.place_param2 then
|
||||
def.place_param2 = 3
|
||||
end
|
||||
def.grow_time_min=math.floor(def.grow_time_mean*0.75)
|
||||
def.grow_time_max=math.floor(def.grow_time_mean*1.2)
|
||||
-- print("time check definition "..1000*(os.clock()-starttime))
|
||||
return def
|
||||
end
|
||||
|
||||
-- Register plants
|
||||
farming.register_plant = function(def)
|
||||
-- Check def table
|
||||
if not def.steps then
|
||||
return nil
|
||||
end
|
||||
-- check definition
|
||||
def = register_plant_check_def(def)
|
||||
-- local definitions
|
||||
def.step_name=def.mod_name..":"..def.name
|
||||
def.seed_name=def.mod_name..":seed_"..def.name
|
||||
def.plant_name = def.name
|
||||
-- if plant has harvest then registering
|
||||
if def.groups["has_harvest"] ~= nil then
|
||||
-- if plant drops seed of wild crop, set the wild seed as harvest
|
||||
if def.seed_drop ~= nil then
|
||||
def.harvest_name = def.seed_drop
|
||||
else
|
||||
def.harvest_name = def.step_name
|
||||
end
|
||||
farming.register_harvest(def)
|
||||
else
|
||||
def.harvest_name=def.seed_name
|
||||
end
|
||||
|
||||
if def.groups["wiltable"] == 2 then
|
||||
def.wilt_name=def.mod_name..":wilt_"..def.name
|
||||
farming.register_wilt(def)
|
||||
end
|
||||
|
||||
farming.register_seed(def)
|
||||
|
||||
farming.register_steps(def)
|
||||
|
||||
if (not def.groups["to_culture"]) then
|
||||
local edef=def
|
||||
local spread_def={name=def.step_name.."_1",
|
||||
temp_min=edef.temperature_min,temp_max=edef.temperature_max,
|
||||
hum_min=edef.humidity_min,hum_max=edef.humidity_max,
|
||||
y_min=edef.elevation_min,y_max=edef.elevation_max,base_rate = math.floor(math.log(def.spread_rate*1e10)),
|
||||
light_min=edef.light_min,light_max=edef.light_max}
|
||||
farming.min_light = math.min(farming.min_light,edef.light_min)
|
||||
table.insert(farming.spreading_crops,1,spread_def)
|
||||
end
|
||||
|
||||
if def.groups["infectable"] then
|
||||
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
|
||||
def.straw_name=def.straw
|
||||
end
|
||||
farming.craft_seed(def)
|
||||
end
|
||||
if def.groups["use_trellis"] then
|
||||
farming.trellis_seed(def)
|
||||
end
|
||||
if def.groups["seed_grindable"] then
|
||||
farming.register_grind(def)
|
||||
end
|
||||
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) --time optimised
|
||||
-- base definition of harvest
|
||||
local harvest_def={
|
||||
description = S(hdef.description),
|
||||
inventory_image = hdef.mod_name.."_"..hdef.plant_name..".png",
|
||||
groups = {flammable = 2,farming_harvest=1},
|
||||
plant_name=hdef.plant_name,
|
||||
}
|
||||
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 starttime=os.clock()
|
||||
local infectpng=idef.mod_name.."_"..idef.plant_name.."_ill.png"
|
||||
local infect_def={
|
||||
description = S(idef.description),
|
||||
tiles = {infectpng},
|
||||
drawtype = "plantlike",
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
on_dig = farming.plant_cured , -- why digging fails?
|
||||
selection_box = {type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
on_timer=farming.timer_infect,
|
||||
place_param2=idef.place_param2,
|
||||
groups = {snappy = 3, attached_node = 1, flammable = 2,farming_infect=2},
|
||||
}
|
||||
for _,coln in ipairs({"name","seed_name","plant_name",
|
||||
"infect_rate_base","infect_rate_monoculture"}) do
|
||||
infect_def[coln] = idef[coln]
|
||||
end
|
||||
|
||||
infect_def.groups[idef.plant_name] = 0
|
||||
minetest.register_node(":" .. idef.name.."_infected", infect_def)
|
||||
-- print("time register infect "..1000*(os.clock()-starttime))
|
||||
end
|
||||
farming.register_wilt=function(idef)
|
||||
-- local starttime=os.clock()
|
||||
if not idef.wilt_name then
|
||||
return
|
||||
end
|
||||
local wilt_def={
|
||||
description = S(idef.description:gsub("^%l", string.upper).." wilted"),
|
||||
tiles = {idef.basepng.."_wilt.png"},
|
||||
drawtype = "plantlike",
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
selection_box = {type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
on_timer = farming.timer_wilt,
|
||||
place_param2=idef.place_param2,
|
||||
groups = {snappy = 3, attached_node = 1, flammable = 2,farming_wilt=1},
|
||||
}
|
||||
|
||||
if idef.straw then
|
||||
wilt_def.drop={items={{items={idef.straw}}}}
|
||||
end
|
||||
for _,coln in ipairs({"name","seed_name","plant_name","fertility"}) do
|
||||
wilt_def[coln] = idef[coln]
|
||||
end
|
||||
|
||||
if idef.groups.wiltable then
|
||||
wilt_def.groups["wiltable"]=idef.groups.wiltable
|
||||
end
|
||||
minetest.register_node(":" .. idef.wilt_name, wilt_def)
|
||||
-- print("time register wilt "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
|
||||
farming.register_seed=function(sdef) --time optimised
|
||||
-- local starttime=os.clock()
|
||||
local seed_def = {
|
||||
description=S(sdef.name:gsub("^%l", string.upper).." Seed"),
|
||||
next_step = sdef.step_name .. "_1",
|
||||
drawtype = "signlike",
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
walkable = false,
|
||||
sunlight_propagates = true,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
|
||||
},
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
dig = {name = "", gain = 0},
|
||||
dug = {name = "default_grass_footstep", gain = 0.2},
|
||||
place = {name = "default_place_node", gain = 0.25},
|
||||
}),
|
||||
on_place = farming.seed_on_place,
|
||||
on_timer = farming.timer_seed,
|
||||
place_param2=sdef.place_param2,
|
||||
groups = {farming_seed = 1, snappy = 3, attached_node = 1, flammable = 2},
|
||||
}
|
||||
for i,colu in ipairs({"fertility","plant_name","grow_time_min","grow_time_max","light_min"}) do
|
||||
seed_def[colu] = sdef[colu]
|
||||
end
|
||||
local invimage=sdef.basepng.."_seed.png"
|
||||
seed_def.inventory_image = invimage
|
||||
seed_def.tiles = {invimage}
|
||||
seed_def.wield_image = {invimage}
|
||||
seed_def.groups[sdef.mod_name] = 1
|
||||
for k, v in pairs(sdef.fertility) do
|
||||
seed_def.groups[v] = 1
|
||||
end
|
||||
for i,colu in ipairs({"on_soil","for_flour"}) do
|
||||
if sdef.groups[colu] then
|
||||
seed_def.groups[colu] = sdef.groups[colu]
|
||||
end
|
||||
end
|
||||
if sdef.eat_hp then
|
||||
seed_def.on_use=minetest.item_eat(sdef.eat_hp)
|
||||
end
|
||||
minetest.register_node(":" .. sdef.seed_name, seed_def)
|
||||
-- print("time register seed "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
farming.register_steps = function(sdef)
|
||||
-- local starttime=os.clock()
|
||||
-- base configuration of all steps
|
||||
-- copy some plant definition into definition of this steps
|
||||
-- define drop item: normal drop the seed
|
||||
local dropitem=sdef.seed_name
|
||||
-- if plant has to be harvested, drop harvest instead
|
||||
if sdef.groups.has_harvest then
|
||||
if sdef.seed_drop then
|
||||
dropitem = sdef.seed_drop
|
||||
else
|
||||
dropitem = sdef.step_name
|
||||
end
|
||||
end
|
||||
local is_hurting=(sdef.groups.damage_per_second~=nil)
|
||||
local damage=0
|
||||
if is_hurting then
|
||||
damate=sdef.groups.damage_per_second
|
||||
end
|
||||
local is_viscos=(sdef.groups.liquid_viscosity and farming.config:get_int("viscosity") > 0)
|
||||
local viscosity=0
|
||||
if is_viscos then
|
||||
viscosity=sdef.groups.liquid_viscosity
|
||||
end
|
||||
local max_step=sdef.steps
|
||||
local stepname=sdef.step_name.."_"
|
||||
for i=1,max_step do
|
||||
local reli=i/max_step
|
||||
local ndef={description=stepname..i,
|
||||
drawtype = "plantlike",
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
selection_box = {type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
drop_item=dropitem,
|
||||
drop={items={{items={dropitem}}}},
|
||||
tiles={sdef.basepng.."_"..i..".png"},
|
||||
place_param2=sdef.place_param2,
|
||||
groups = {snappy = 3, flammable = 2,flora=1, plant = 1,
|
||||
not_in_creative_inventory = 1, attached_node = 1,
|
||||
step=i,
|
||||
},
|
||||
}
|
||||
for _,colu in ipairs({"grow_time_min","grow_time_max","light_min","plant_name"}) do
|
||||
ndef[colu]=sdef[colu]
|
||||
end
|
||||
for _,colu in ipairs({"infectable","snappy","punchable","damage_per_second","liquid_viscosity","wiltable"}) do
|
||||
if sdef.groups[colu] then
|
||||
ndef.groups[colu] = sdef.groups[colu]
|
||||
end
|
||||
end
|
||||
ndef.groups[sdef.mod_name]=1
|
||||
ndef.groups[sdef.plant_name]=1
|
||||
if sdef.groups.use_trellis then
|
||||
--table.insert(ndef.drop.items,1,{items={"farming:trellis"}})
|
||||
end
|
||||
if i < max_step then
|
||||
ndef.groups["farming_grows"]=1 -- plant is growing
|
||||
ndef.next_step=stepname.. (i + 1)
|
||||
ndef.on_timer = farming.timer_step
|
||||
ndef.grow_time_min=sdef.grow_time_min
|
||||
ndef.grow_time_max=sdef.grow_time_max
|
||||
end
|
||||
-- hurting and viscosity not for first step, which is used for random generation
|
||||
if i > 1 then
|
||||
-- check if plant hurts while going through
|
||||
if is_hurting then
|
||||
-- calculate damage as part of growing: Full damage only for full grown plant
|
||||
local step_damage=math.ceil(damage*reli)
|
||||
if step_damage > 0 then
|
||||
ndef.damage_per_second = step_damage
|
||||
end
|
||||
end
|
||||
-- for some crops you should walk slowly through like a wheat field
|
||||
if is_viscos then
|
||||
local step_viscosity=math.ceil(viscosity*reli)
|
||||
if step_viscosity > 0 then
|
||||
ndef.liquid_viscosity= step_viscosity
|
||||
ndef.liquidtype="source"
|
||||
ndef.liquid_alternative_source=ndef.description
|
||||
ndef.liquid_alternative_flowing=ndef.description
|
||||
ndef.liquid_renewable=false
|
||||
ndef.liquid_range=0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- with higher grow levels you harvest more
|
||||
local step_harvest = math.floor(reli*sdef.harvest_max + 0.05)
|
||||
if step_harvest > 1 then
|
||||
for h = 2,step_harvest do
|
||||
--table.insert(ndef.drop.items,1,{items={dropitem},rarity=(max_step - i + 1)*h})
|
||||
end
|
||||
end
|
||||
if i == max_step then
|
||||
ndef.groups["farming_fullgrown"]=1
|
||||
ndef.on_dig = farming.dig_harvest
|
||||
if sdef.groups.wiltable then
|
||||
local nowilt=sdef.groups.wiltable
|
||||
if nowilt == 2 then
|
||||
ndef.next_step=sdef.wilt_name
|
||||
elseif nowilt == 1 then
|
||||
ndef.next_step = stepname .. (i - 1)
|
||||
elseif nowilt == 3 then
|
||||
ndef.pre_step = stepname .. (i - 1)
|
||||
ndef.seed_name=sdef.seed_name
|
||||
end
|
||||
ndef.on_timer = farming.timer_step
|
||||
ndef.grow_time_min=sdef.wilt_time or 10
|
||||
ndef.grow_time_max=math.ceil(ndef.grow_time_min*1.1)
|
||||
end
|
||||
-- at the end stage you can harvest by change a cultured seed (if defined)
|
||||
if sdef.next_plant then
|
||||
local next_plant_rarity = (max_step - i + 1)*2
|
||||
--table.insert(ndef.drop.items,1,{items={sdef.next_plant},rarity=next_plant_rarity})
|
||||
end
|
||||
if sdef.groups.punchable and i > 1 then
|
||||
ndef.pre_step = stepname.. (i - 1)
|
||||
ndef.on_punch = farming.punch_step
|
||||
end
|
||||
end
|
||||
-- print(dump(ndef))
|
||||
minetest.register_node(":" .. ndef.description, ndef)
|
||||
end
|
||||
-- print("time register step "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- define seed crafting out of harvest, releasing kind of straw
|
||||
function farming.craft_seed(gdef)
|
||||
if gdef.seed_name == nil then
|
||||
return
|
||||
end
|
||||
if gdef.harvest_name == nil then
|
||||
return
|
||||
end
|
||||
local straw_name = "farming:straw"
|
||||
if gdef.straw_name ~= nil then
|
||||
straw_name = gdef.straw_name
|
||||
end
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = gdef.seed_name.." 1",
|
||||
recipe = {
|
||||
farming.modname..":flail",gdef.harvest_name
|
||||
},
|
||||
replacements = {{"group:farming_flail", farming.modname..":flail"},
|
||||
{gdef.harvest_name,straw_name}},
|
||||
})
|
||||
end
|
||||
|
||||
function farming.register_coffee(cdef)
|
||||
|
||||
end
|
||||
|
||||
-- registering roast items if needed for plant
|
||||
function farming.register_roast(rdef)
|
||||
local starttime=os.clock()
|
||||
if not rdef.seed_name then
|
||||
return
|
||||
end
|
||||
if not rdef.roast then
|
||||
return
|
||||
end
|
||||
local roastitem=rdef.roast
|
||||
-- if no roast defined in config, register an own roast item
|
||||
if minetest.registered_craftitems[roastitem] == nil then
|
||||
local roast_png = roastitem:gsub(":","_")..".png"
|
||||
local rn = roastitem:split(":")[2]
|
||||
rn=rn:gsub("_"," ")
|
||||
local roast_def={
|
||||
description = S(rdef.description:gsub("^%l", string.upper)),
|
||||
inventory_image = roast_png,
|
||||
groups = {flammable = 2},
|
||||
plant_name=rdef.plant_name,
|
||||
}
|
||||
|
||||
if rdef.groups.seed_roastable then
|
||||
roast_def.groups["seed_roastable"] = rdef.groups.seed_roastable
|
||||
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
|
||||
|
||||
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 = seedname
|
||||
})
|
||||
-- print("time register roast "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
-- registering grind items
|
||||
function farming.register_grind(rdef)
|
||||
local starttime=os.clock()
|
||||
if rdef.seed_name == nil then
|
||||
return
|
||||
end
|
||||
if rdef.step_name == nil then
|
||||
return
|
||||
end
|
||||
local grinditem = rdef.step_name.."_flour"
|
||||
if rdef.grind then
|
||||
grinditem = rdef.grind
|
||||
end
|
||||
local desc = grinditem:split(":")[2]
|
||||
desc = desc:gsub("_"," ")
|
||||
local grind_png = grinditem:gsub(":","_")..".png"
|
||||
|
||||
local grind_def={
|
||||
description = S(desc:gsub("^%l", string.upper).." roasted"),
|
||||
inventory_image = grind_png,
|
||||
groups = {flammable = 2},
|
||||
plant_name=rdef.plant_name,
|
||||
}
|
||||
|
||||
if rdef.eat_hp then
|
||||
grind_def.on_use=minetest.item_eat(rdef.eat_hp)
|
||||
end
|
||||
|
||||
minetest.register_craftitem(":" .. grinditem, grind_def)
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = grinditem,
|
||||
recipe = {rdef.seed_name.." "..rdef.groups["seed_grindable"],
|
||||
farming.modname..":mortar_pestle"},
|
||||
replacements = {{"group:food_mortar_pestle", farming.modname..":mortar_pestle"}},
|
||||
|
||||
})
|
||||
-- print("time register grind "..1000*(os.clock()-starttime))
|
||||
end
|
||||
|
||||
-- local starttime=os.clock()
|
||||
-- print("time define infect "..1000*(os.clock()-starttime))
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
local S = farming.intllib
|
||||
|
||||
farming.register_billhook = function(name,def)
|
||||
if not def.groups["billhook"] then
|
||||
def.groups["billhook"]=1
|
||||
end
|
||||
if not def.material then
|
||||
return
|
||||
end
|
||||
if def.max_uses == nil then
|
||||
def.max_uses = 30
|
||||
end
|
||||
if def.on_use == nil then
|
||||
def.on_use = function(itemstack, user, pointed_thing)
|
||||
return farming.use_billhook(itemstack, user, pointed_thing, def.max_uses)
|
||||
end
|
||||
end
|
||||
if not def.recipe then
|
||||
def.recipe = {
|
||||
{"", def.material, def.material},
|
||||
{"", "group:stick", ""},
|
||||
{"group:stick", "", ""} }
|
||||
end
|
||||
farming.register_tool(name,def)
|
||||
end
|
||||
|
||||
farming.register_scythe = function(name,def)
|
||||
if not def.groups["scythe"] then
|
||||
def.groups["scythe"]=1
|
||||
end
|
||||
if not def.material then
|
||||
return
|
||||
end
|
||||
if not def.recipe then
|
||||
def.recipe = {
|
||||
{def.material, def.material, "group:stick"},
|
||||
{def.material, "group:stick", ""},
|
||||
{"group:stick", "", ""} }
|
||||
end
|
||||
farming.register_tool(name,def)
|
||||
end
|
||||
|
||||
-- Register new Scythes
|
||||
farming.register_tool = function(name, def)
|
||||
-- recipe has to be provided
|
||||
if not def.recipe then
|
||||
return
|
||||
end
|
||||
-- Check for : prefix (register new hoes in your mod's namespace)
|
||||
if name:sub(1,1) ~= ":" then
|
||||
name = ":" .. name
|
||||
end
|
||||
-- Check def table
|
||||
if def.description == nil then
|
||||
def.description = "Farming tool"
|
||||
end
|
||||
if def.inventory_image == nil then
|
||||
def.inventory_image = "unknown_item.png"
|
||||
end
|
||||
if def.max_uses == nil then
|
||||
def.max_uses = 30
|
||||
end
|
||||
def.sound={breaks = "default_tool_breaks"}
|
||||
|
||||
-- Register the tool
|
||||
minetest.register_tool(name, def)
|
||||
-- Register its recipe
|
||||
minetest.register_craft({
|
||||
output = name:sub(2),
|
||||
recipe = def.recipe
|
||||
})
|
||||
end
|
Loading…
Reference in New Issue