Better integration with other mods.

This commit is contained in:
SFENCE 2021-09-18 13:37:37 +02:00
parent 0c7b525a2f
commit f259808f47
4 changed files with 166 additions and 71 deletions

View File

@ -6,6 +6,26 @@ local time_divider = composting.settings.composting_time_divider;
local base_production_time = ((365*24*3600)/amount_limit)/time_divider;
local function composter_update_timer(pos, C, N, amount, produced)
if (amount>0) then
local ratio = C/N;
local speed = 1/(((amount+produced)/amount_limit)^4);
if ratio>32.5 then
speed = speed*math.exp(ratio/500);
else
speed = speed*math.exp(ratio/25);
end
local timer = minetest.get_node_timer(pos);
if timer:is_started() then
timer:set(base_production_time*speed, timer:get_elapsed());
else
timer:start(base_production_time*speed);
end
end
end
local function composter_update_node(pos, node)
local meta = minetest.get_meta(pos)
local amount = meta:get_int("amount");
@ -29,10 +49,7 @@ local function composter_update_node(pos, node)
node.name = "composting:composter_filled";
node.param2 = line*16+done;
minetest.swap_node(pos, node);
local timer = minetest.get_node_timer(pos);
if not timer:is_started() then
timer:start(base_production_time);
end
composter_update_timer(pos, C, N, amount, produced)
if (produced>=produced_per_clod) then
meta:set_string("infotext", S("Compost clod."));
@ -59,10 +76,11 @@ local function composter_on_punch(pos, node, puncher, pointed_thing)
if item_def and item_def._compost then
local meta = minetest.get_meta(pos);
local amount = meta:get_int("amount");
local C = meta:get_int("C");
local N = meta:get_int("N");
local produced = meta:get_int("produced");
amount = amount + item_def._compost.amount;
if (amount<amount_limit) then
if ((amount+produced)<amount_limit) then
local C = meta:get_int("C");
local N = meta:get_int("N");
C = C + item_def._compost.C;
N = N + item_def._compost.N;
meta:set_int("amount", amount);
@ -127,16 +145,6 @@ function composter_on_timer(pos, elapsed)
local ratio = C/N;
local speed = 1/(((amount+produced)/amount_limit)^4);
if ratio>32.5 then
speed = speed*math.exp(ratio/500);
else
speed = speed*math.exp(ratio/25);
end
if (amount>0) then
local timer = minetest.get_node_timer(pos);
timer:start(base_production_time*speed, 0);
end
composter_update_node(pos, node, meta);
return false; -- timer:start force timer to continue, return true will erase new timer setting
@ -144,7 +152,7 @@ end
local short_desc = S("Composter");
local desc = short_desc;
local tt_help = S("Punch me with compostable item in hand to fill me.");
local tt_help = S("Fill me by punching me with compostable item in hand.").."\n"..S("Use shovel to get compost clod.");
if (minetest.get_modpath("tt")==nil) then
desc = desc.."\n"..tt_help;
end
@ -175,14 +183,6 @@ minetest.register_node("composting:composter", {
},
on_punch = composter_on_punch,
on_construct = function (pos)
local meta = minetest.get_meta(pos);
print("on_construct: "..dump(meta:to_table()))
meta:set_int("amount", 0)
meta:set_int("N", 0)
meta:set_int("C", 0)
meta:set_int("production", 0)
end,
})
minetest.register_node("composting:composter_filled", {
@ -200,6 +200,7 @@ minetest.register_node("composting:composter_filled", {
"composting_composter_filled.png",
},
palette = "composting_composter_palette.png",
drop = "composting:composter",
on_punch = composter_on_punch,
on_timer = composter_on_timer,

View File

@ -75,9 +75,14 @@ local function effect_of_flora(pos)
end
end
local drop_dirt = "default:dirt";
if minetest.get_modpath("hades_core") then
drop_dirt = "hades_core:dirt"
end
local short_desc = S("Garden Soil");
local desc = short_desc;
local tt_help = S("Punch me with water bucket/wateringcan to make me wet.");
local tt_help = S("Punch me with water bucket/wateringcan to make me wet.").."\n"..S("Punch me with compost clod to make me more fertile.");
if (minetest.get_modpath("tt")==nil) then
desc = desc.."\n"..tt_help;
end
@ -104,7 +109,7 @@ minetest.register_node("composting:garden_soil", {
overlay_tiles = garden_soil_tiles,
-- soil have to be 2, because farming code detect wet soil via soil value
groups = {crumbly = 3, soil = 2, grassland = 1},
drop = "default:dirt",
drop = drop_dirt,
sounds = node_sounds,
on_construct = function(pos)
local node = minetest.get_node(pos);
@ -173,7 +178,7 @@ minetest.register_node("composting:garden_soil_wet", {
tiles = {"composting_garden_soil_wet.png"},
overlay_tiles = garden_soil_wet_tiles,
groups = {crumbly = 3, soil = 5, grassland = 1, wet = 1, not_in_creative_inventory = 1},
drop = "default:dirt",
drop = drop_dirt,
sounds = node_sounds,
on_construct = function(pos)
local node = minetest.get_node(pos);

View File

@ -1,9 +1,15 @@
function composting.add_composting_data(item_name, compost_data)
-- ratio -> C:N -> ratio:1
function composting.add_composting_data(item_name, amount, ratio)
if minetest.registered_items[item_name] then
local C = math.floor(amount*1000*ratio/(ratio+1));
local N = amount*1000-C;
minetest.override_item(item_name, {
_compost = compost_data
_compost = {
amount = amount,
C = C,
N = N,
}
})
else
minetest.log("error", "Adding composting data to item "..item_name.." failed. Item doesn't exist.");
@ -11,12 +17,16 @@ function composting.add_composting_data(item_name, compost_data)
end
local leaves = {};
local dry_leaves = {};
local needles = {};
local stems = {};
local grass_1 = {};
local grass_3 = {};
local grass_5 = {};
local dry_grass_5 = {};
local vines = {}
local compostable = {}
if minetest.get_modpath("default") then
-- leaves
@ -45,7 +55,14 @@ if minetest.get_modpath("default") then
table.insert(grass_5, "default:grass_");
table.insert(dry_grass_5, "default:dry_grass_");
end
if minetest.get_modpath("hades_core") then
if minetest.get_modpath("farming") then
compostable["farming:wheat"] = {amount=4,ratio=120}
compostable["farming:straw"] = {amount=16,ratio=120}
end
if minetest.get_modpath("darkage") then
compostable["darkage:straw_bale"] = {amount=64,ratio=120}
end
if minetest.get_modpath("hades_trees") then
-- leaves
table.insert(leaves, "hades_trees:banana_leaves");
table.insert(leaves, "hades_trees:birch_leaves");
@ -56,6 +73,9 @@ if minetest.get_modpath("hades_core") then
table.insert(leaves, "hades_trees:olive_leaves");
table.insert(leaves, "hades_trees:orange_leaves");
table.insert(leaves, "hades_trees:pale_leaves");
table.insert(stems, "hades_trees:burned_branches")
end
if minetest.get_modpath("hades_grass") then
-- grass 1
table.insert(grass_1, "hades_grass:junglegrass");
-- grass 3
@ -63,66 +83,135 @@ if minetest.get_modpath("hades_core") then
table.insert(grass_5, "hades_grass:grass_");
table.insert(dry_grass_5, "hades_grass:dead_grass_");
end
if minetest.get_modpath("hades_vines") then
-- vines
table.insert(vines, "hades_vines:cave")
table.insert(vines, "hades_vines:cave_rotten")
table.insert(vines, "hades_vines:jungle")
table.insert(vines, "hades_vines:jungle_rotten")
table.insert(vines, "hades_vines:willow")
table.insert(vines, "hades_vines:willow_rotten")
table.insert(vines, "hades_vines:root")
end
if minetest.get_modpath("baldcypress") or minetest.get_modpath("hades_baldcypress") then
table.insert(leaves, "baldcypress:leaves");
table.insert(vines, "baldcypress:liana")
table.insert(stems, "baldcypress:dry_branches")
end
if minetest.get_modpath("bamboo") or minetest.get_modpath("hades_bamboo") then
table.insert(leaves, "bamboo:leaves");
end
if minetest.get_modpath("birch") or minetest.get_modpath("hades_birch") then
table.insert(leaves, "birch:leaves");
end
if minetest.get_modpath("cherrytree") or minetest.get_modpath("hades_cherrytree") then
table.insert(leaves, "cherrytree:leaves");
compostable["cherrytree:blossom_leaves"] = {amount=15,ratio=170}
end
if minetest.get_modpath("chesnuttree") or minetest.get_modpath("hades_chesnuttree") then
table.insert(leaves, "chesnuttree:leaves");
end
if minetest.get_modpath("clementinetree") or minetest.get_modpath("hades_clementinetree") then
table.insert(leaves, "clementinetree:leaves");
end
if minetest.get_modpath("ebony") or minetest.get_modpath("hades_ebony") then
table.insert(leaves, "ebony:leaves");
table.insert(vines, "ebony:liana")
compostable["ebony:creeper"] = {amount=5,ratio=70}
compostable["ebony:creeper_leaves"] = {amount=6,ratio=50}
end
if minetest.get_modpath("canvas") or minetest.get_modpath("hades_canvas") then
table.insert(leaves, "canvas:leaves");
end
if minetest.get_modpath("hollytree") or minetest.get_modpath("hades_hollytree") then
table.insert(leaves, "hollytree:leaves");
end
if minetest.get_modpath("jacaranda") or minetest.get_modpath("hades_jacaranda") then
compostable["jacaranda:blossom_leaves"] = {amount=15,ratio=170}
end
if minetest.get_modpath("larch") or minetest.get_modpath("hades_larch") then
table.insert(leaves, "larch:leaves");
end
if minetest.get_modpath("lemontree") or minetest.get_modpath("hades_lemontree") then
table.insert(leaves, "lemontree:leaves");
end
if minetest.get_modpath("mahogany") or minetest.get_modpath("hades_mahogany") then
table.insert(leaves, "mahogany:leaves");
end
if minetest.get_modpath("maple") or minetest.get_modpath("hades_maple") then
table.insert(leaves, "maple:leaves");
end
if minetest.get_modpath("oak") or minetest.get_modpath("hades_oak") then
table.insert(leaves, "oak:leaves");
end
if minetest.get_modpath("palm") or minetest.get_modpath("hades_palm") then
compostable["palm:leaves"] = {amount=8,ratio=150}
end
if minetest.get_modpath("plumtree") or minetest.get_modpath("hades_plumtree") then
table.insert(leaves, "plumtree:leaves");
end
if minetest.get_modpath("pomegranate") or minetest.get_modpath("hades_pomegranate") then
table.insert(leaves, "pomegranate:leaves");
end
if minetest.get_modpath("willow") or minetest.get_modpath("hades_willow") then
table.insert(leaves, "willow:leaves");
end
if minetest.get_modpath("technic") or minetest.get_modpath("hades_technic") or minetest.get_modpath("moretrees") then
table.insert(leaves, "moretrees:rubber_tree_leaves");
end
if minetest.get_modpath("hades_farming") then
compostable["hades_farming:wheat"] = {amount=4,ratio=120}
compostable["hades_farming:straw"] = {amount=16,ratio=120}
end
if minetest.get_modpath("hades_darkage") then
compostable["hades_darkage:straw_bale"] = {amount=64,ratio=120}
end
-- leaves
for _,item_name in pairs(leaves) do
composting.add_composting_data(item_name, {
amount = 15,
C = 14921, -- 190:1 branches with leaves
N = 79,
})
-- 190:1 branches with leaves
composting.add_composting_data(item_name, 15, 190);
end
for _,item_name in pairs(dry_leaves) do
-- 195:1 branches with leaves
composting.add_composting_data(item_name, 15, 195);
end
-- needles
for _,item_name in pairs(needles) do
composting.add_composting_data(item_name, {
amount = 15,
C = 14925, -- 200:1 branches with needles
N = 75,
})
-- 200:1 branches with needles
composting.add_composting_data(item_name, 15, 200);
end
-- stems
for _,item_name in pairs(stems) do
composting.add_composting_data(item_name, {
amount = 7,
C = 6969, -- 226:1 wood mass
N = 31,
})
-- 226:1 wood mass
composting.add_composting_data(item_name, 7, 226);
end
-- grass 1
for _,item_name in pairs(stems) do
composting.add_composting_data("default:junglegrass", {
amount = 3,
C = math.floor(2833), -- 17:1
N = math.floor(167),
})
for _,item_name in pairs(grass_1) do
composting.add_composting_data(item_name, 3, 17);
end
-- grass 3
for i=1,3 do
local part = i/3;
for _,item_name in pairs(grass_3) do
composting.add_composting_data(item_name..i, {
amount = 1+math.floor(2*part),
C = math.floor(2833*part), -- 17:1
N = math.floor(167*part),
})
composting.add_composting_data(item_name..i, 1+math.floor(2*part), 17);
end
end
-- grass 5
for i=1,5 do
local part = i/5;
for _,item_name in pairs(grass_5) do
composting.add_composting_data(item_name..i, {
amount = 1+math.floor(2*part),
C = math.floor(2833*part), -- 17:1
N = math.floor(167*part),
})
composting.add_composting_data(item_name..i, 1+math.floor(2*part), 17);
end
for _,item_name in pairs(dry_grass_5) do
composting.add_composting_data(item_name..i, {
amount = 1+math.floor(2*part),
C = math.floor(2885*part), -- 25:1
N = math.floor(115*part),
})
composting.add_composting_data(item_name..i, 1+math.floor(2*part), 25);
end
end
-- vines
for _,item_name in pairs(vines) do
composting.add_composting_data(item_name, 6, 60);
end
-- compostable
for item_name,item_data in pairs(compostable) do
composting.add_composting_data(item_name, item_data.amount, item_data.ratio);
end

View File

@ -1,4 +1,4 @@
name = composting
description = Compost and composter machines
depends =
optional_depends = default, farming, bucket, hades_farming, hades_bucket, wateringcan, sounds, hades_sounds, hades_core
optional_depends = default, farming, bucket, hades_farming, hades_bucket, wateringcan, sounds, hades_sounds, hades_core, baldcypress, bamboo, birch, cherrytree, clementinetree, ebony, hollytree, larch, lemontree, mahogany, maple, oak, palm, plumtree, pomegranate, willow, darkage, technic, moretrees, hades_baldcypress, hades_bamboo, hades_birch, hades_cherrytree, hades_clementinetree, hades_ebony, hades_hollytree, hades_larch, hades_lemontree, hades_mahogany, hades_maple, hades_oak, hades_palm, hades_plumtree, hades_pomegranate, hades_willow, hades_darkage, hades_technic