Upload files to 'mods/farming'

This commit is contained in:
thunderdog1138 2020-07-17 12:39:11 +00:00
parent 823a210462
commit 154d23ecdb
5 changed files with 433 additions and 0 deletions

70
mods/farming/README.md Normal file
View File

@ -0,0 +1,70 @@
# Farming Redo Mod
### by TenPlus1
https://forum.minetest.net/viewtopic.php?id=9019
Farming Redo is a simplified version of the built-in farming mod in minetest and comes with wheat, cotton, carrot, cucumber, potato and tomato to start out with which spawn throughout the map... new foods need only be planted on tilled soil so no seeds are required, original wheat and cotton will require seeds which are found inside normal and jungle grass...
This mod works by adding your new plant to the {growing=1} group and numbering the stages from _1 to as many stages as you like, but the underscore MUST be used only once in the node name to separate plant from stage number e.g.
"farming:cotton_1" through to "farming:cotton_8"
"farming:wheat_1" through to "farming:wheat_8"
"farming:cucumber_4" through to "farming:cucumber_4"
### Changelog:
- 1.45 - Dirt and Hoes are more in line with default by using dry/wet/base, added cactus juice, added pasta, spaghetti, cabbage, korean bibimbap, code tidy
options, onion soup added (thanks edcrypt), Added apple pie, added wild cotton to savanna
- 1.44 - Added 'farming_stage_length' in mod settings for speed of crop growth, also thanks to TheDarkTiger for translation updates
- 1.43 - Scythe works on use instead of right-click, added seed=1 groups to actual seeds and seed=2 group for plantable food items.
- 1.42 - Soil needs water to be present within 3 blocks horizontally and 1 below to make wet soil, Jack 'o Lanterns now check protection, add chocolate block.
- 1.41 - Each crop has it's own spawn rate (can be changed in farming.conf)
- 1.40 - Added Mithril Scythe to quick harvest and replant crops on right-click. Added Hoe's for MoreOres with Toolrank support.
- 1.39 - Added Rice, Rye and Oats thanks to Ademants Grains mod. Added Jaffa Cake and multigrain bread.
- 1.38 - Pumpkin grows into block, use chopping board to cut into 4x slices, same with melon block, 2x2 slices makes a block, cocoa pods are no longer walkable
- 1.37 - Added custom 'growth_check(pos, nodename) function for crop nodes to use (check cocoa.lua for example)
- 1.36 - Added Beetroot, Beetroot Soup (6x beetroot, 1x bowl), fix register_plant() issue, add new recipes
- 1.35 - Deprecated bronze/mese/diamond hoe's, added hoe bomb and deprecated hoe's as lucky block prizes
- 1.34 - Added scarecrow Base (5x sticks in a cross shape)
- 1.33 - Added cooking utensils (wooden bowl, saucepan, cooking pot, baking tray, skillet, cutting board, mortar & pestle, juicer, glass mixing bowl) for easier food crafts.
- 1.32 - Added Pea plant (textures by Andrey01) - also added Wooden Bowl and Pea Soup crafts
- 1.31 - Added Pineapple which can be found growing in savannah areas (place pineapple in crafting to obtain 5x rings to eat and a top for re-planting), also Salt which is made from cooking a bucket of water, added food groups so it's more compatible with Ruben's food mods.
- 1.30 - Added Garlic, Pepper and Onions thanks to Grizzly Adam for sharing textures
- 1.29 - Updating functions so requires Minetest 0.4.16 and above to run
- 1.28 - Added chili peppers and bowl of chili, optimized code and fixed a few bugs, added porridge
- 1.27 - Added meshoptions to api and wheat plants, added farming.rarity setting to spawn more/less crops on map, have separate cotton/string items (4x cotton = 1x wool, 2x cotton = 2x string)
- 1.26 - Added support for [toolranks] mod when using hoe's
- 1.25 - Added check for farming.conf setting file to disable specific crops globally (inside mod folder) or world specific (inside world folder)
- 1.24 - Added Hemp which can be crafted into fibre, paper, string, rope and oil.
- 1.23 - Huge code tweak and tidy done and added barley seeds to be found in dry grass, barley can make flour for bread also.
- 1.22 - Added grape bushes at high climates which can be cultivated into grape vines using trellis (9 sticks).
- 1.21 - Added auto-refill code for planting crops (thanks crabman77), also fixed a few bugs
- 1.20b - Tidied code, made api compatible with new 0.4.13 changes and changed to soil texture overlays
- 1.20 - NEW growing routine added that allows crops to grow while player is away doing other things (thanks prestidigitator)
- 1.14 - Added Green Beans from Crops mod (thanks sofar), little bushels in the wild but need to be grown using beanpoles crafted with 4 sticks (2 either side)
- 1.13 - Fixed seed double-placement glitch. Mapgen now uses 0.4.12+ for plant generation
- 1.12 - Player cannot place seeds in protected area, also growing speeds changed to match defaults
- 1.11 - Added Straw Bale, streamlined growing abm a little, fixed melon rotation bug with screwdriver
- 1.10 - Added Blueberry Bush and Blueberry Muffins, also Pumpkin/Melon easier to pick up, added check for unloaded map
- 1.09 - Corn now uses single nodes instead of 1 ontop of the other, Ethanol recipe is more expensive (requires 5 corn) and some code cleanup.
- 1.08 - Added Farming Plus compatibility, plus can be removed and no more missing nodes
- 1.07 - Added Rhubarb and Rhubarb Pie
- 1.06 - register_hoe and register_plant added for compatibility with default farming mod, although any plants registered will use farming redo to grow
- 1.05 - Added Raspberry Bushels and Raspberry Smoothie
- 1.04 - Added Donuts... normal, chocolate and apple... and a few code cleanups and now compatible with jungletree's from MoreTrees mod
- 1.03 - Bug fixes and more compatibility as drop-in replacement for built-in farming mod
- 1.02 - Added farming.mod string to help other mods identify which farming mod is running, if it returns "redo" then you're using this one, "" empty is built-in mod
- 1.01 - Crafting coffee or ethanol returns empty bucket/bottle, also Cocoa spawns a little rarer
- 1.0 - Added Cocoa which randomly grows on jungle tree's, pods give cocoa beans which can be used to farm more pods on a jungle trunk or make Cookies which have been added (or other treats)
- 0.9 - Added Pumpkin, Jack 'O Lantern, Pumpkin Slice and Sugar (a huge thanks to painterly.net for allowing me to use their textures)
- 0.8 - Added Watermelon and Melon Slice
- 0.7 - Added Coffee, Coffee Beans, Drinking Cup, Cold and Hot Cup of Coffee
- 0.6 - Added Corn, Corn on the Cob... Also reworked Abm
- 0.5 - Added Carrot, Cucumber, Potato (and Baked Potato), Tomato
- 0.4 - Checks for Protection, also performance changes
- 0.3 - Added Diamond and Mese hoe
- 0.2 - Fixed check for wet soil
- 0.1 - Fixed growing bug
- 0.0 - Initial release
### Lucky Blocks: 39

BIN
mods/farming/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -0,0 +1,2 @@
# Contains a value used for speed of crop growth in seconds
farming_stage_length (Farming Stage Length) float 160.0

176
mods/farming/soil.lua Normal file
View File

@ -0,0 +1,176 @@
local S = farming.intllib
-- add soil types to existing dirt blocks
minetest.override_item("default:dirt", {
soil = {
base = "default:dirt",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
minetest.override_item("default:dirt_with_grass", {
soil = {
base = "default:dirt_with_grass",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
minetest.override_item("default:dirt_with_dry_grass", {
soil = {
base = "default:dirt_with_dry_grass",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
minetest.override_item("default:dirt_with_rainforest_litter", {
soil = {
base = "default:dirt_with_rainforest_litter",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
minetest.override_item("default:dirt_with_coniferous_litter", {
soil = {
base = "default:dirt_with_coniferous_litter",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
minetest.override_item("default:dry_dirt", {
soil = {
base = "default:dry_dirt",
dry = "farming:dry_soil",
wet = "farming:dry_soil_wet"
}
})
minetest.override_item("default:dry_dirt_with_dry_grass", {
soil = {
base = "default:dry_dirt_with_dry_grass",
dry = "farming:dry_soil",
wet = "farming:dry_soil_wet"
}
})
-- normal soil
minetest.register_node("farming:soil", {
description = S("Soil"),
tiles = {"default_dirt.png^farming_soil.png", "default_dirt.png"},
drop = "default:dirt",
groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 2, field = 1},
sounds = default.node_sound_dirt_defaults(),
soil = {
base = "default:dirt",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
-- wet soil
minetest.register_node("farming:soil_wet", {
description = S("Wet Soil"),
tiles = {
"default_dirt.png^farming_soil_wet.png",
"default_dirt.png^farming_soil_wet_side.png"},
drop = "default:dirt",
groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 3, field = 1},
sounds = default.node_sound_dirt_defaults(),
soil = {
base = "default:dirt",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
-- savanna soil
if minetest.registered_nodes["default:dry_dirt"] then
minetest.register_node("farming:dry_soil", {
description = S("Savanna Soil"),
tiles = {
"default_dry_dirt.png^farming_soil.png",
"default_dry_dirt.png"},
drop = "default:dry_dirt",
groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 2, field = 1},
sounds = default.node_sound_dirt_defaults(),
soil = {
base = "default:dry_dirt",
dry = "farming:dry_soil",
wet = "farming:dry_soil_wet"
}
})
minetest.register_node("farming:dry_soil_wet", {
description = S("Wet Savanna Soil"),
tiles = {
"default_dry_dirt.png^farming_soil_wet.png",
"default_dry_dirt.png^farming_soil_wet_side.png"},
drop = "default:dry_dirt",
groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 3, field = 1},
sounds = default.node_sound_dirt_defaults(),
soil = {
base = "default:dry_dirt",
dry = "farming:dry_soil",
wet = "farming:dry_soil_wet"
}
})
end
-- sand is not soil, change existing sand-soil to use dry soil
minetest.register_alias("farming:desert_sand_soil", "farming:dry_soil")
minetest.register_alias("farming:desert_sand_soil_wet", "farming:dry_soil_wet")
-- if water near soil then change to wet soil
minetest.register_abm({
nodenames = {"group:field"},
interval = 15,
chance = 4,
catch_up = false,
action = function(pos, node)
local ndef = minetest.registered_nodes[node.name]
if not ndef or not ndef.soil or not ndef.soil.wet
or not ndef.soil.base or not ndef.soil.dry then return end
pos.y = pos.y + 1
local nn = minetest.get_node_or_nil(pos)
pos.y = pos.y - 1
if nn then nn = nn.name else return end
-- what's on top of soil, if solid/not plant change soil to dirt
if minetest.registered_nodes[nn]
and minetest.registered_nodes[nn].walkable
and minetest.get_item_group(nn, "plant") == 0 then
minetest.set_node(pos, {name = "default:dirt"})
return
end
-- if map around soil not loaded then skip until loaded
if minetest.find_node_near(pos, 3, {"ignore"}) then
return
end
-- check if water is within 3 nodes horizontally and 1 below
if #minetest.find_nodes_in_area(
{x = pos.x + 3, y = pos.y - 1, z = pos.z + 3},
{x = pos.x - 3, y = pos.y , z = pos.z - 3},
{"group:water"}) > 0 then
minetest.set_node(pos, {name = ndef.soil.wet})
elseif node.name == ndef.soil.wet then
minetest.set_node(pos, {name = ndef.soil.dry})
elseif node.name == ndef.soil.dry
and minetest.get_item_group(nn, "plant") == 0 then
minetest.set_node(pos, {name = ndef.soil.base})
end
end
})

185
mods/farming/statistics.lua Normal file
View File

@ -0,0 +1,185 @@
local statistics = {}
local ROOT_2 = math.sqrt(2.0)
-- Approximations for erf(x) and erfInv(x) from
-- https://en.wikipedia.org/wiki/Error_function
local erf
local erf_inv
local A = 8 * (math.pi - 3.0)/(3.0 * math.pi * (4.0 - math.pi))
local B = 4.0 / math.pi
local C = 2.0/(math.pi * A)
local D = 1.0 / A
erf = function(x)
if x == 0 then return 0; end
local xSq = x * x
local aXSq = A * xSq
local v = math.sqrt(1.0 - math.exp(-xSq * (B + aXSq) / (1.0 + aXSq)))
return (x > 0 and v) or -v
end
erf_inv = function(x)
if x == 0 then return 0; end
if x <= -1 or x >= 1 then return nil; end
local y = math.log(1 - x * x)
local u = C + 0.5 * y
local v = math.sqrt(math.sqrt(u * u - D * y) - u)
return (x > 0 and v) or -v
end
local function std_normal(u)
return ROOT_2 * erf_inv(2.0 * u - 1.0)
end
local poisson
local cdf_table = {}
local function generate_cdf(lambda_index, lambda)
local max = math.ceil(4 * lambda)
local pdf = math.exp(-lambda)
local cdf = pdf
local t = { [0] = pdf }
for i = 1, max - 1 do
pdf = pdf * lambda / i
cdf = cdf + pdf
t[i] = cdf
end
return t
end
for li = 1, 100 do
cdf_table[li] = generate_cdf(li, 0.25 * li)
end
poisson = function(lambda, max)
if max < 2 then
return (math.random() < math.exp(-lambda) and 0) or 1
elseif lambda >= 2 * max then
return max
end
local u = math.random()
local lambda_index = math.floor(4 * lambda + 0.5)
local cdfs = cdf_table[lambda_index]
if cdfs then
lambda = 0.25 * lambda_index
if u < cdfs[0] then return 0; end
if max > #cdfs then max = #cdfs + 1 else max = math.floor(max); end
if u >= cdfs[max - 1] then return max; end
if max > 4 then -- Binary search
local s = 0
while s + 1 < max do
local m = math.floor(0.5 * (s + max))
if u < cdfs[m] then max = m; else s = m; end
end
else
for i = 1, max - 1 do
if u < cdfs[i] then return i; end
end
end
return max
else
local x = lambda + math.sqrt(lambda) * std_normal(u)
return (x < 0.5 and 0) or (x >= max - 0.5 and max) or math.floor(x + 0.5)
end
end
-- Error function.
statistics.erf = erf
-- Inverse error function.
statistics.erf_inv = erf_inv
--- Standard normal distribution function (mean 0, standard deviation 1).
--
-- @return
-- Any real number (actually between -3.0 and 3.0).
statistics.std_normal = function()
local u = math.random()
if u < 0.001 then
return -3.0
elseif u > 0.999 then
return 3.0
end
return std_normal(u)
end
--- Standard normal distribution function (mean 0, standard deviation 1).
--
-- @param mu
-- The distribution mean.
-- @param sigma
-- The distribution standard deviation.
-- @return
-- Any real number (actually between -3*sigma and 3*sigma).
statistics.normal = function(mu, sigma)
local u = math.random()
if u < 0.001 then
return mu - 3.0 * sigma
elseif u > 0.999 then
return mu + 3.0 * sigma
end
return mu + sigma * std_normal(u)
end
--- Poisson distribution function.
--
-- @param lambda
-- The distribution mean and variance.
-- @param max
-- The distribution maximum.
-- @return
-- An integer between 0 and max (both inclusive).
statistics.poisson = function(lambda, max)
lambda, max = tonumber(lambda), tonumber(max)
if not lambda or not max or lambda <= 0 or max < 1 then return 0; end
return poisson(lambda, max)
end
return statistics