1
0
mirror of https://codeberg.org/tenplus1/farming.git synced 2025-06-30 23:30:43 +02:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
2023-11-22 23:32:31 +01:00
86 changed files with 2660 additions and 3330 deletions

139
init.lua
View File

@ -7,7 +7,7 @@
farming = {
mod = "redo",
version = "20230407",
version = "20230915",
path = minetest.get_modpath("farming"),
select = {
type = "fixed",
@ -20,10 +20,25 @@ farming = {
registered_plants = {},
min_light = 12,
max_light = 15,
mapgen = minetest.get_mapgen_setting("mg_name")
mapgen = minetest.get_mapgen_setting("mg_name"),
use_utensils = minetest.settings:get_bool("farming_use_utensils") ~= false,
mtg = minetest.get_modpath("default"),
mcl = minetest.get_modpath("mcl_core"),
sounds = {}
}
-- default sound functions just incase
function farming.sounds.node_sound_defaults() end
function farming.sounds.node_sound_leaves_defaults() end
function farming.sounds.node_sound_glass_defaults() end
function farming.sounds.node_sound_wood_defaults() end
function farming.sounds.node_sound_gravel_defaults() end
-- sounds check
if farming.mtg then farming.sounds = default end
if farming.mcl then farming.sounds = mcl_sounds end
-- check for creative mode or priv
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
function farming.is_creative(name)
@ -33,31 +48,14 @@ end
local statistics = dofile(farming.path .. "/statistics.lua")
-- Intllib
local S
if minetest.get_translator ~= nil then
S = minetest.get_translator("farming") -- 5.x translation function
else
if minetest.get_modpath("intllib") then
dofile(minetest.get_modpath("intllib") .. "/init.lua")
if intllib.make_gettext_pair then
gettext, ngettext = intllib.make_gettext_pair() -- new gettext method
else
gettext = intllib.Getter() -- old text file method
end
S = gettext
else -- boilerplate function
S = function(str, ...)
local args = {...}
return str:gsub("@%d+", function(match)
return args[tonumber(match:sub(2))]
end)
end
end
end
-- Translation support
local S = minetest.get_translator("farming")
farming.intllib = S
farming.translate = S
-- localise
local random = math.random
local floor = math.floor
-- Utility Function
local time_speed = tonumber(minetest.settings:get("time_speed")) or 72
@ -97,7 +95,7 @@ local function day_or_night_time(dt, count_day)
local dt_c = clamp(t2_c, 0, 0.5) - clamp(t1_c, 0, 0.5) -- this cycle
if t1_c < -0.5 then
local nc = math.floor(-t1_c)
local nc = floor(-t1_c)
t1_c = t1_c + nc
dt_c = dt_c + 0.5 * nc + clamp(-t1_c - 0.5, 0, 0.5)
end
@ -112,6 +110,16 @@ local STAGE_LENGTH_AVG = tonumber(
local STAGE_LENGTH_DEV = STAGE_LENGTH_AVG / 6
-- quick start seed timer
farming.start_seed_timer = function(pos)
local timer = minetest.get_node_timer(pos)
local grow_time = floor(random(STAGE_LENGTH_DEV, STAGE_LENGTH_AVG))
timer:start(grow_time)
end
-- return plant name and stage from node provided
local function plant_name_stage(node)
@ -272,7 +280,7 @@ local function set_growing(pos, stages_left)
stage_length = clamp(stage_length, 0.5 * STAGE_LENGTH_AVG, 3.0 * STAGE_LENGTH_AVG)
timer:set(stage_length, -0.5 * math.random() * STAGE_LENGTH_AVG)
timer:set(stage_length, -0.5 * random() * STAGE_LENGTH_AVG)
end
elseif timer:is_started() then
@ -314,16 +322,29 @@ minetest.register_abm({
catch_up = false,
action = function(pos, node)
-- skip if node timer already active
if minetest.get_node_timer(pos):is_started() then
return
end
-- check if group:growing node is a seed
local def = minetest.registered_nodes[node.name]
if def and def.groups and def.groups.seed then
-- start node timer if found
if def.on_timer then
farming.start_seed_timer(pos)
return
end
local next_stage = def.next_plant
def = minetest.registered_nodes[next_stage]
-- change seed to stage_1 or crop
-- switch seed without timer to stage_1 of crop
if def then
local p2 = def.place_param2 or 1
@ -331,6 +352,7 @@ minetest.register_abm({
minetest.set_node(pos, {name = next_stage, param2 = p2})
end
else
-- start normal crop timer
farming.handle_growth(pos, node)
end
end
@ -357,7 +379,7 @@ function farming.plant_growth_timer(pos, elapsed, node_name)
if chk then
if chk(pos, node_name) then
if not chk(pos, node_name) then
return true
end
@ -420,7 +442,7 @@ function farming.plant_growth_timer(pos, elapsed, node_name)
local p2 = minetest.registered_nodes[stages.stages_left[growth] ].place_param2 or 1
minetest.swap_node(pos, {name = stages.stages_left[growth], param2 = p2})
minetest.set_node(pos, {name = stages.stages_left[growth], param2 = p2})
else
return true
end
@ -508,6 +530,7 @@ function farming.place_seed(itemstack, placer, pointed_thing, plantname)
minetest.set_node(pt.above, {name = plantname, param2 = p2})
farming.start_seed_timer(pt.above)
--minetest.get_node_timer(pt.above):start(1)
--farming.handle_growth(pt.above)--, node)
@ -561,7 +584,10 @@ farming.register_plant = function(name, def)
inventory_image = def.inventory_image,
wield_image = def.inventory_image,
drawtype = "signlike",
groups = {seed = 1, snappy = 3, attached_node = 1, flammable = 2, growing = 1},
groups = {
seed = 1, snappy = 3, attached_node = 1, flammable = 2, growing = 1,
compostability = 65
},
paramtype = "light",
paramtype2 = "wallmounted",
walkable = false,
@ -570,6 +596,18 @@ farming.register_plant = function(name, def)
place_param2 = 1, -- place seed flat
next_plant = mname .. ":" .. pname .. "_1",
on_timer = function(pos, elapsed)
local def = minetest.registered_nodes[mname .. ":" .. pname .. "_1"]
if def then
minetest.swap_node(pos, {
name = def.next_plant,
param2 = def.place_param2
})
end
end,
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing,
mname .. ":seed_" .. pname)
@ -587,9 +625,11 @@ farming.register_plant = function(name, def)
for i = 1, def.steps do
local base_rarity = 1
if def.steps ~= 1 then
base_rarity = 8 - (i - 1) * 7 / (def.steps - 1)
end
local drop = {
items = {
{items = {mname .. ":" .. pname}, rarity = base_rarity},
@ -601,7 +641,7 @@ farming.register_plant = function(name, def)
local sel = farming.select
local g = {
snappy = 3, flammable = 2, plant = 1, growing = 1,
handy = 1, snappy = 3, flammable = 2, plant = 1, growing = 1,
attached_node = 1, not_in_creative_inventory = 1,
}
@ -633,7 +673,7 @@ farming.register_plant = function(name, def)
drop = drop,
selection_box = sel,
groups = g,
sounds = default.node_sound_leaves_defaults(),
sounds = farming.sounds.node_sound_leaves_defaults(),
minlight = def.minlight,
maxlight = def.maxlight,
next_plant = next_plant
@ -697,7 +737,7 @@ farming.rice = true
-- Load new global settings if found inside mod folder
local input = io.open(farming.path.."/farming.conf", "r")
local input = io.open(farming.path .. "/farming.conf", "r")
if input then
dofile(farming.path .. "/farming.conf")
input:close()
@ -705,23 +745,41 @@ end
-- load new world-specific settings if found inside world folder
local worldpath = minetest.get_worldpath()
input = io.open(worldpath.."/farming.conf", "r")
input = io.open(worldpath .. "/farming.conf", "r")
if input then
dofile(worldpath .. "/farming.conf")
input:close()
end
-- recipe items
dofile(farming.path .. "/items.lua")
-- important items
dofile(farming.path.."/soil.lua")
dofile(farming.path.."/hoes.lua")
if not farming.mcl then
dofile(farming.path .. "/soil.lua")
dofile(farming.path .. "/hoes.lua")
end
dofile(farming.path.."/grass.lua")
dofile(farming.path.."/utensils.lua")
-- default crops
dofile(farming.path.."/crops/wheat.lua")
if not farming.mcl then
dofile(farming.path.."/crops/wheat.lua")
end
dofile(farming.path.."/crops/cotton.lua")
-- disable crops Mineclone already has
if farming.mcl then
farming.carrot = nil
farming.potato = nil
farming.melon = nil
farming.cocoa = nil
farming.beetroot = nil
farming.sunflower = nil
farming.pumpkin = nil
end
-- helper function
local function ddoo(file, check)
@ -773,7 +831,10 @@ ddoo("spinach.lua", farming.eggplant)
ddoo("ginger.lua", farming.ginger)
dofile(farming.path .. "/food.lua")
dofile(farming.path .. "/compatibility.lua") -- Farming Plus compatibility
if not farming.mcl then
dofile(farming.path .. "/compatibility.lua") -- Farming Plus compatibility
end
if minetest.get_modpath("lucky_block") then
dofile(farming.path .. "/lucky_block.lua")
end