Configuration - persistent config file

This allows a server admin to tweak the mods growth rate, chance
and required light level. For convenience I've made 3 sets of
"easy", "normal" and "difficult" settings so that it's easy to
understand what the difference is and what good starting values
are.
This commit is contained in:
Auke Kok 2015-04-23 22:51:27 -07:00
parent 9e2f05283c
commit baf1b9ce6a
7 changed files with 91 additions and 57 deletions

View File

@ -10,9 +10,6 @@ of the license, or (at your option) any later version.
--]]
local interval = crops_interval
local chance = crops_chance
minetest.register_node("crops:corn", {
description = "corn",
inventory_image = "crops_corn.png",
@ -87,10 +84,10 @@ minetest.register_node("crops:corn_base_seed", {
minetest.register_abm({
nodenames = { "crops:corn_base_seed" },
neighbors = { "group:soil" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
minetest.set_node(pos, { name = "crops:corn_base_1" })
@ -115,10 +112,10 @@ minetest.register_node("crops:corn_base_1", {
minetest.register_abm({
nodenames = { "crops:corn_base_1" },
neighbors = { "group:soil" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
if not minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name == "air" then
@ -211,10 +208,10 @@ minetest.register_node("crops:corn_top_1", {
minetest.register_abm({
nodenames = { "crops:corn_top_1" },
neighbors = { "crops:corn_base_2" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
minetest.set_node(pos, { name = "crops:corn_top_2" })
@ -247,10 +244,10 @@ minetest.register_node("crops:corn_top_2", {
minetest.register_abm({
nodenames = { "crops:corn_top_2" },
neighbors = { "crops:corn_base_2" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
minetest.set_node(pos, { name = "crops:corn_top_3" })

26
crops_settings.txt Normal file
View File

@ -0,0 +1,26 @@
--
-- crops_settings.txt
--
-- These are the default difficulty settings for the crops mod. You can uncomment
-- the "easy" or "difficult" settings if you wish, or come up with your own values.
--
--[[
-- easy --
crops.chance = 4
crops.interval = 30
crops.light = 8
--]]
-- normal --
crops.chance = 8
crops.interval = 30
crops.light = 10
--[[
-- difficult --
crops.chance = 16
crops.interval = 30
crops.light = 13
--]]

View File

@ -10,15 +10,38 @@ of the license, or (at your option) any later version.
--]]
crops_interval = 30
crops_chance = 8
crops = {}
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/melon.lua")
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/corn.lua")
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/tomato.lua")
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/potato.lua")
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/polebean.lua")
local worldpath = minetest.get_worldpath()
local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/cooking.lua")
dofile(modpath .. "/crops_settings.txt")
if io.open(worldpath .. "/crops_settings.txt", "r") == nil then
io.input(modpath .. "/crops_settings.txt")
io.output(worldpath .. "/crops_settings.txt")
local size = 4096
while true do
local buf = io.read(size)
if not buf then
io.close()
break
end
io.write(buf)
end
else
dofile(worldpath .. "/crops_settings.txt")
end
-- crop nodes, crafts, craftitems
dofile(modpath .. "/melon.lua")
dofile(modpath .. "/corn.lua")
dofile(modpath .. "/tomato.lua")
dofile(modpath .. "/potato.lua")
dofile(modpath .. "/polebean.lua")
-- cooking recipes that mix craftitems
dofile(modpath .. "/cooking.lua")
minetest.log("action", "[crops] loaded.")

View File

@ -17,9 +17,6 @@ local faces = {
[4] = { x = 0, z = 1, r = 0, o = 2, m = 11 }
}
local interval = crops_interval
local chance = crops_chance
minetest.register_node("crops:melon_seed", {
description = "melon seed",
inventory_image = "crops_melon_seed.png",
@ -141,10 +138,10 @@ minetest.register_node("crops:melon", {
minetest.register_abm({
nodenames = { "crops:melon_plant_1", "crops:melon_plant_2", "crops:melon_plant_3","crops:melon_plant_4" },
neighbors = { "group:soil" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
local n = string.gsub(node.name, "4", "5")
@ -161,10 +158,10 @@ minetest.register_abm({
minetest.register_abm({
nodenames = { "crops:melon_plant_5" },
neighbors = { "group:soil" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
for face = 1, 4 do
@ -199,7 +196,7 @@ minetest.register_abm({
--
minetest.register_abm({
nodenames = { "crops:melon_plant_5_attached" },
interval = interval,
interval = crops.interval,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
for face = 1, 4 do

View File

@ -10,9 +10,6 @@ of the license, or (at your option) any later version.
--]]
local interval = crops_interval
local chance = crops_chance
minetest.register_craft({
output = "crops:beanpoles",
recipe = {
@ -238,11 +235,11 @@ end
minetest.register_abm({
nodenames = { "crops:beanpole_plant_base_1", "crops:beanpole_plant_base_2", "crops:beanpole_plant_base_3", "crops:beanpole_plant_base_4" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
neighbors = { "group:soil" },
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
if node.name == "crops:beanpole_plant_base_1" then

View File

@ -10,9 +10,6 @@ of the license, or (at your option) any later version.
--]]
local interval = crops_interval
local chance = crops_chance
minetest.register_node("crops:potato_eyes", {
description = "potato eyes",
inventory_image = "crops_potato_eyes.png",
@ -110,14 +107,14 @@ minetest.register_node("crops:soil_with_potatoes", {
minetest.register_abm({
nodenames = { "crops:potato_plant_1", "crops:potato_plant_2", "crops:potato_plant_3" },
neighbors = { "group:soil" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
local below = { x = pos.x, y = pos.y - 1, z = pos.z }
if not minetest.registered_nodes[minetest.get_node(below).name].groups.soil then
return
end
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
local n = string.gsub(node.name, "3", "4")
@ -133,10 +130,10 @@ minetest.register_abm({
minetest.register_abm({
nodenames = { "crops:potato_plant_4" },
neighbors = { "group:soil" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
local below = { x = pos.x, y = pos.y - 1, z = pos.z }

View File

@ -10,9 +10,6 @@ of the license, or (at your option) any later version.
--]]
local interval = crops_interval
local chance = crops_chance
minetest.register_node("crops:tomato_seed", {
description = "tomato seed",
inventory_image = "crops_tomato_seed.png",
@ -124,10 +121,10 @@ minetest.register_craft({
minetest.register_abm({
nodenames = { "crops:tomato_plant_1", "crops:tomato_plant_2", "crops:tomato_plant_3" },
neighbors = { "group:soil" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
local n = string.gsub(node.name, "4", "5")
@ -144,10 +141,10 @@ minetest.register_abm({
minetest.register_abm({
nodenames = { "crops:tomato_plant_4" },
neighbors = { "group:soil" },
interval = interval,
chance = chance,
interval = crops.interval,
chance = crops.chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.get_node_light(pos, nil) < 13 then
if minetest.get_node_light(pos, nil) < crops.light then
return
end
local meta = minetest.get_meta(pos)