code cleaning

master
ademant 2018-10-31 14:51:09 +01:00
parent d7a132941a
commit 125f45389a
8 changed files with 176 additions and 38 deletions

View File

@ -4,10 +4,18 @@ See license.txt for license information.
Mod for extending the farming capabilities of minetest.
You have wild crops, which you can cultivate to get faster and more harvest.
(TODO) The crops can be infected, where you get nothing. And the infection spreads to nearby crops.
(TODO) A culture of crops can be destroyed by the infection, where the cultured variant of crops
The crops can be infected, where you get nothing. And the infection spreads to nearby crops.
A culture of crops can be destroyed by the infection, where the cultured variant of crops
are easier infected than the wild form.
With special plants you can make a curing mixture. And other plants can protect the culture.
With special plants (right now nettles) you can make a curing mixture. And other plants can protect the culture.
You should use special devices to get more fruits:
- With a scythe you dig the node and by change get one more harvest. The change is better for a steel scythe than for stone or wood
- With a billhook you punch for example berries to get by change one berry more.
Booth are weared out by each harvest.
For each crop you can define the count of step. In the last step the crop is full-grown, where the crops are punchable.
The defined grow time is modified by the amount of light the crop would see and the place: The less light at
the position will be (under a tree for example), the longer the crop needs to reach the next step.
The code is written to enable extension by other mods.
You have only one txt file to configure the crops. It's read in a table. Not defined fields are filled,
@ -28,6 +36,9 @@ Based on the definition the behauvior is defined:
- Crops with trellis: For creating seedable items you have to craft out of the harvest the seed with a trellis.
Diggin any step will release the trellis for further usage. By using the option "use_trellis" the craft
is direct registered.
- crops with extractable seed: The normal harvest are the leaves of the plant, which you can punch out of the box.
To get a seed of the fruit, you have to use a seed picker. The plant goes back one step and need to regrow booth
leaves and seed.
Authors of source code
----------------------

View File

@ -236,39 +236,43 @@ farming.timer_step = function(pos, elapsed)
else
meta:set_int("farming:step",next_def.groups.step)
end
if next_def.groups.farming_fullgrown ~= nil then
meta:set_int("farming:seeds",1)
else
meta:set_int("farming:seeds",0)
end
-- new timer needed?
if def.next_step then
local wait_factor = 1
-- check for config values
local lightamount=meta:get_int("farming:lightamount")
local wait_factor = 1
-- check for config values
local lightamount=meta:get_int("farming:lightamount")
if lightamount ~= nil then
local ls = farming.light_stat[def.light_min]
if ls.amount ~= nil and lightamount > 0 then
-- time till next step is stretched. Less light means longer growing time
wait_factor = ls.amount / lightamount
end
else
wait_factor = math.max(0.75,def.light_min/minetest.get_node_light(pos,0.5))
if lightamount ~= nil then
local ls = farming.light_stat[def.light_min]
if ls.amount ~= nil and lightamount > 0 then
-- time till next step is stretched. Less light means longer growing time
wait_factor = ls.amount / lightamount
end
-- using light at midday to increase or decrease growing time
local wait_min = math.ceil(def.grow_time_min * wait_factor)
local wait_max = math.ceil(def.grow_time_max * wait_factor)
if wait_max <= wait_min then wait_max = 2*wait_min end
local timespeed=minetest.settings:get("time_speed")
local time_wait=math.random(wait_min,wait_max)
local local_rwt=time_wait*timespeed/(86400)
local daystart=meta:get_float("farming:daystart")
local acttime=minetest.get_timeofday()
if math.abs(acttime+local_rwt-0.5)>(0.5-daystart) then
time_wait=86400*(1+daystart-acttime)/timespeed
end
minetest.get_node_timer(pos):start(time_wait)
else
wait_factor = math.max(0.75,def.light_min/minetest.get_node_light(pos,0.5))
end
-- using light at midday to increase or decrease growing time
local wait_min = math.ceil(def.grow_time_min * wait_factor)
local wait_max = math.ceil(def.grow_time_max * wait_factor)
if wait_max <= wait_min then wait_max = 2*wait_min end
local timespeed=minetest.settings:get("time_speed")
local time_wait=math.random(wait_min,wait_max)
local local_rwt=time_wait*timespeed/(86400)
local daystart=meta:get_float("farming:daystart")
local acttime=minetest.get_timeofday()
if math.abs(acttime+local_rwt-0.5)>(0.5-daystart) then
time_wait=86400*(1+daystart-acttime)/timespeed
end
minetest.get_node_timer(pos):start(time_wait)
--table.insert(farming.time_steptimer,1000*(os.clock()-starttime))
return
end
@ -536,8 +540,72 @@ farming.dig_by_tool = function(itemstack, user, pointed_thing, uses)
return itemstack
end
-- generate "seed" out of harvest and trellis
farming.use_picker = function(itemstack, user, pointed_thing,uses)
local starttime=os.clock()
-- check if pointing at a node
if not pointed_thing then
return
end
if pointed_thing.type ~= "node" then
return
end
local under = minetest.get_node(pointed_thing.under)
-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name] then
return
end
local pdef=minetest.registered_nodes[under.name]
-- check if pointing at punchable crop
if pdef.groups.punchable == nil then
return
end
-- check if plant is full grown
if pdef.groups.farming_fullgrown == nil then
return
end
-- check if seeds can be extracted
if pdef.groups.seed_extractable == nil then
return
end
-- check if seeds are available
local meta = minetest.get_meta(pos)
if meta:get_int("farming:seeds") == nil then
meta:set_int("farming:seeds",0)
return
else
if meta:get_int("farming:seeds")==0 then
return
end
end
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
minetest.record_protection_violation(pointed_thing.under, user:get_player_name())
return
end
local tdef=itemstack:get_definition()
if not (creative and creative.is_enabled_for
and creative.is_enabled_for(user:get_player_name())) then
-- wear tool
itemstack:add_wear(65535/(uses-1))
-- tool break sound
if itemstack:get_count() == 0 and tdef.sound and tdef.sound.breaks then
minetest.sound_play(tdef.sound.breaks, {pos = pointed_thing.above, gain = 0.5})
end
end
user:get_inventory():add_item('main',pdef.seed_name)
if math.random(1,3)==1 then
user:get_inventory():add_item('main',pdef.seed_name)
end
-- call punching function of crop: normally go back one step and start timer
minetest.punch_node(pointed_thing.under)
local meta = minetest.get_meta(pos)
meta:set_int("farming:seeds",0)
--table.insert(farming.time_usehook,1000*(os.clock()-starttime))
return itemstack
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)
@ -662,5 +730,7 @@ farming.set_node_metadata=function(pos)
meta:set_float("farming:daystart",lightcalc.day_start/240)
-- amount of light the crop gets till midday
meta:set_int("farming:lightamount",lightcalc.light_amount)
-- init the amount of seed available at the crop
meta:set_int("farming:seeds",0)
--table.insert(farming.time_setmeta,1000*(os.clock()-starttime))
end

View File

@ -81,3 +81,22 @@ if farming.has_value(modlist,"vessels") and farming.has_value(modlist,"bucket")
else
print("Mod vessels/bucket not available. Seriously? -> no COFFEE!")
end
if farming.has_value(modlist,"wool") then
minetest.register_craft({
output="wool:white",
type="shapeless",
recipe={"farming:cotton","farming:cotton","farming:cotton","farming:cotton"},
})
minetest.register_craft({
output="wool:dark_green",
type="shapeless",
recipe={"farming:nettle_fibre","farming:nettle_fibre","farming:nettle_fibre","farming:nettle_fibre"},
})
minetest.register_craft({
output="wool:dark_green",
type="shapeless",
recipe={"farming:hemp_fibre","farming:hemp_fibre","farming:hemp_fibre","farming:hemp_fibre"},
})
end

View File

@ -313,7 +313,7 @@ farming.register_steps = function(sdef)
local damage=0
if is_hurting then
damate=sdef.groups.damage_per_second
damage=sdef.groups.damage_per_second
end
local is_viscos=(sdef.groups.liquid_viscosity and farming.config:get_int("viscosity") > 0)
@ -349,7 +349,7 @@ farming.register_steps = function(sdef)
ndef[colu]=sdef[colu]
end
for _,colu in ipairs({"infectable","snappy","punchable","damage_per_second","liquid_viscosity","wiltable"}) do
for _,colu in ipairs({"infectable","snappy","damage_per_second","liquid_viscosity","wiltable"}) do
if sdef.groups[colu] then
ndef.groups[colu] = sdef.groups[colu]
end
@ -404,6 +404,11 @@ farming.register_steps = function(sdef)
if i == max_step then
ndef.groups["farming_fullgrown"]=1
for _,colu in ipairs({"punchable","seed_extractable"}) do
if sdef.groups[colu] then
ndef.groups[colu] = sdef.groups[colu]
end
end
ndef.on_dig = farming.dig_harvest
if sdef.groups.wiltable then

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -11,7 +11,7 @@ for i,line in pairs(tool_definition) do
tool_def={description=line.name:gsub("_"," "),
inventory_image="farming_tool_"..line.name..".png",
max_used=line.max_uses,
max_uses=line.max_uses,
farming_change=line.farming_change,
material = line.material,
groups={flammable = 2},
@ -35,3 +35,36 @@ for i,line in pairs(tool_definition) do
farming.register_hoe("farming:"..line.name,tool_def)
end
end
-- Picker
-- to extract seeds from crops, which usually give harvest, e.g. tea
farming.register_tool("farming:picker", {
description = S("Seed Picker"),
inventory_image = "farming_tool_picker.png",
groups = {farming_picker = 1, flammable = 2},
max_uses=30,
tool_capabilities = {
full_punch_intervall = 1.0,
max_drop_level = 2,
groupcaps = {
snappy = {times={[1]=5,[2]=2,[3]=1.4},},
uses=30,
maxlevel=3,
},
damage_groups = {fleshy = 1},
},
on_use = function(itemstack, user, pointed_thing)
return farming.use_picker(itemstack, user, pointed_thing, 30)
end
})
minetest.register_craft({
output = "farming:picker",
recipe = {
{"", "", "group:stick"},
{"", "group:stick", "group:wool"},
{"group:stick", "", ""},
}
})

View File

@ -71,8 +71,6 @@ farming.register_tool = function(name, def)
})
end
-- copied from farming_redo
farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
local pt = pointed_thing

View File

@ -2,7 +2,7 @@ local S = farming.intllib
local modname=minetest.get_current_modname()
-- coffee grinder
-- to grind roasted grain seed or roasted coffee beans
minetest.register_craftitem(modname..":coffee_grinder", {
description = S("Coffee Grinder"),
inventory_image = "farming_tool_coffee_grinder.png",
@ -18,6 +18,7 @@ minetest.register_craft({
})
-- flail
-- use to extract seed from wheat/hemp/nettle harvest, leaving straw/fiber
minetest.register_craftitem(modname..":flail", {
description = S("Threshing Flail"),
inventory_image = "farming_tool_flail.png",
@ -33,6 +34,7 @@ minetest.register_craft({
}
})
-- Trellis
-- some cultured crops need a trellis to grow
minetest.register_craftitem(modname..":trellis", {
description = S("Trellis"),
inventory_image = "farming_tool_trellis.png",