forked from minetest/minetest_game
Fix some farming stuff
This commit is contained in:
parent
a1aee9a68f
commit
ef1f66a64e
|
@ -44,7 +44,10 @@ farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
|
||||||
pos = pt.under,
|
pos = pt.under,
|
||||||
gain = 0.5,
|
gain = 0.5,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:add_wear(65535/(uses-1))
|
itemstack:add_wear(65535/(uses-1))
|
||||||
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -135,25 +138,27 @@ end
|
||||||
farming.register_plant = function(name, def)
|
farming.register_plant = function(name, def)
|
||||||
local mname = name:split(":")[1]
|
local mname = name:split(":")[1]
|
||||||
local pname = name:split(":")[2]
|
local pname = name:split(":")[2]
|
||||||
|
|
||||||
-- Check def table
|
-- Check def table
|
||||||
if def.description == nil then
|
if not def.description then
|
||||||
def.description = "Seed"
|
def.description = "Seed"
|
||||||
end
|
end
|
||||||
if def.inventory_image == nil then
|
if not def.inventory_image then
|
||||||
def.inventory_image = "unknown_item.png"
|
def.inventory_image = "unknown_item.png"
|
||||||
end
|
end
|
||||||
if def.steps == nil then
|
if not def.steps then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if def.minlight == nil then
|
if not def.minlight then
|
||||||
def.minlight = 1
|
def.minlight = 1
|
||||||
end
|
end
|
||||||
if def.maxlight == nil then
|
if not def.maxlight then
|
||||||
def.maxlight = 14
|
def.maxlight = 14
|
||||||
end
|
end
|
||||||
if not def.fertility then
|
if not def.fertility then
|
||||||
def.fertility = {}
|
def.fertility = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register seed
|
-- Register seed
|
||||||
local g = {seed = 1, snappy = 3, attached_node = 1}
|
local g = {seed = 1, snappy = 3, attached_node = 1}
|
||||||
for k, v in pairs(def.fertility) do
|
for k, v in pairs(def.fertility) do
|
||||||
|
@ -179,40 +184,13 @@ farming.register_plant = function(name, def)
|
||||||
return farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname)
|
return farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
-- Seed -> plant
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"group:seed"},
|
|
||||||
neighbors = {"group:soil"},
|
|
||||||
interval = 90,
|
|
||||||
chance = 2,
|
|
||||||
action = function(pos, node)
|
|
||||||
local seedferts = minetest.registered_nodes[node.name].fertility
|
|
||||||
local soilferts = {}
|
|
||||||
-- Collect fertilities of soil
|
|
||||||
for k, v in pairs(minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name].groups) do
|
|
||||||
if k == "grassland" or k == "desert" then
|
|
||||||
soilferts[k] = k
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Cannot grow if no fertility match found
|
|
||||||
local fertmatch = false
|
|
||||||
for k, v in pairs(seedferts) do
|
|
||||||
if soilferts[v] ~= nil then
|
|
||||||
fertmatch = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fertmatch == true and minetest.get_item_group(minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name, "wet") ~= 0 then
|
|
||||||
minetest.set_node(pos, {name = node.name:gsub("seed_", "") .. "_1"})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
-- Register harvest
|
-- Register harvest
|
||||||
minetest.register_craftitem(":" .. mname .. ":" .. pname, {
|
minetest.register_craftitem(":" .. mname .. ":" .. pname, {
|
||||||
description = pname:gsub("^%l", string.upper),
|
description = pname:gsub("^%l", string.upper),
|
||||||
inventory_image = mname .. "_" .. pname .. ".png",
|
inventory_image = mname .. "_" .. pname .. ".png",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Register growing steps
|
-- Register growing steps
|
||||||
for i=1,def.steps do
|
for i=1,def.steps do
|
||||||
local drop = {
|
local drop = {
|
||||||
|
@ -242,15 +220,35 @@ farming.register_plant = function(name, def)
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
sounds = default.node_sound_leaves_defaults(),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Growing ABM
|
-- Growing ABM
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"group:" .. pname},
|
nodenames = {"group:" .. pname, "group:seed"},
|
||||||
neighbors = {"group:soil"},
|
neighbors = {"group:soil"},
|
||||||
interval = 90,
|
interval = 90,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
local plant_height = minetest.get_item_group(node.name, pname)
|
||||||
|
|
||||||
-- return if already full grown
|
-- return if already full grown
|
||||||
if minetest.get_item_group(node.name, pname) == def.steps then
|
if plant_height == def.steps then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local node_def = minetest.registered_items[node.name] or nil
|
||||||
|
|
||||||
|
-- grow seed
|
||||||
|
if minetest.get_item_group(node.name, "seed") and node_def.fertility then
|
||||||
|
local can_grow = false
|
||||||
|
local soil_node = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||||
|
for _, v in pairs(node_def.fertility) do
|
||||||
|
if minetest.get_item_group(soil_node.name, v) ~= 0 then
|
||||||
|
can_grow = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if can_grow then
|
||||||
|
minetest.set_node(pos, {name = node.name:gsub("seed_", "") .. "_1"})
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -263,18 +261,17 @@ farming.register_plant = function(name, def)
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
|
|
||||||
-- check light
|
-- check light
|
||||||
if not minetest.get_node_light(pos) then
|
local ll = minetest.get_node_light(pos)
|
||||||
return
|
|
||||||
end
|
if not ll or ll < def.minlight or ll > def.maxlight then
|
||||||
if minetest.get_node_light(pos) < def.minlight or minetest.get_node_light(pos) > def.maxlight then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- grow
|
-- grow
|
||||||
local height = minetest.get_item_group(node.name, pname) + 1
|
minetest.set_node(pos, {name = mname .. ":" .. pname .. "_" .. plant_height + 1})
|
||||||
minetest.set_node(pos, {name = mname .. ":" .. pname .. "_" .. height})
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Return
|
-- Return
|
||||||
local r = {
|
local r = {
|
||||||
seed = mname .. ":seed_" .. pname,
|
seed = mname .. ":seed_" .. pname,
|
||||||
|
|
|
@ -21,7 +21,7 @@ minetest.register_node("farming:soil", {
|
||||||
tiles = {"farming_soil.png", "default_dirt.png"},
|
tiles = {"farming_soil.png", "default_dirt.png"},
|
||||||
drop = "default:dirt",
|
drop = "default:dirt",
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
groups = {crumbly=3, not_in_creative_inventory=1, soil=2, grassland = 1},
|
groups = {crumbly=3, not_in_creative_inventory=1, soil=2, grassland = 1, field = 1},
|
||||||
sounds = default.node_sound_dirt_defaults(),
|
sounds = default.node_sound_dirt_defaults(),
|
||||||
soil = {
|
soil = {
|
||||||
base = "default:dirt",
|
base = "default:dirt",
|
||||||
|
@ -35,7 +35,7 @@ minetest.register_node("farming:soil_wet", {
|
||||||
tiles = {"farming_soil_wet.png", "farming_soil_wet_side.png"},
|
tiles = {"farming_soil_wet.png", "farming_soil_wet_side.png"},
|
||||||
drop = "default:dirt",
|
drop = "default:dirt",
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
groups = {crumbly=3, not_in_creative_inventory=1, soil=3, wet = 1, grassland = 1},
|
groups = {crumbly=3, not_in_creative_inventory=1, soil=3, wet = 1, grassland = 1, field = 1},
|
||||||
sounds = default.node_sound_dirt_defaults(),
|
sounds = default.node_sound_dirt_defaults(),
|
||||||
soil = {
|
soil = {
|
||||||
base = "default:dirt",
|
base = "default:dirt",
|
||||||
|
@ -57,7 +57,7 @@ minetest.register_node("farming:desert_sand_soil", {
|
||||||
drop = "default:desert_sand",
|
drop = "default:desert_sand",
|
||||||
tiles = {"farming_desert_sand_soil.png", "default_desert_sand.png"},
|
tiles = {"farming_desert_sand_soil.png", "default_desert_sand.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
groups = {crumbly=3, not_in_creative_inventory = 1, falling_node=1, sand=1, soil = 2, desert = 1},
|
groups = {crumbly=3, not_in_creative_inventory = 1, falling_node=1, sand=1, soil = 2, desert = 1, field = 1},
|
||||||
sounds = default.node_sound_sand_defaults(),
|
sounds = default.node_sound_sand_defaults(),
|
||||||
soil = {
|
soil = {
|
||||||
base = "default:desert_sand",
|
base = "default:desert_sand",
|
||||||
|
@ -71,7 +71,7 @@ minetest.register_node("farming:desert_sand_soil_wet", {
|
||||||
drop = "default:desert_sand",
|
drop = "default:desert_sand",
|
||||||
tiles = {"farming_desert_sand_soil_wet.png", "farming_desert_sand_soil_wet_side.png"},
|
tiles = {"farming_desert_sand_soil_wet.png", "farming_desert_sand_soil_wet_side.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
groups = {crumbly=3, falling_node=1, sand=1, not_in_creative_inventory=1, soil=3, wet = 1, desert = 1},
|
groups = {crumbly=3, falling_node=1, sand=1, not_in_creative_inventory=1, soil=3, wet = 1, desert = 1, field = 1},
|
||||||
sounds = default.node_sound_sand_defaults(),
|
sounds = default.node_sound_sand_defaults(),
|
||||||
soil = {
|
soil = {
|
||||||
base = "default:desert_sand",
|
base = "default:desert_sand",
|
||||||
|
@ -81,39 +81,48 @@ minetest.register_node("farming:desert_sand_soil_wet", {
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"group:soil", "group:wet"},
|
nodenames = {"group:field"},
|
||||||
interval = 5,
|
interval = 15,
|
||||||
chance = 10,
|
chance = 4,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
pos.y = pos.y+1
|
local n_def = minetest.registered_nodes[node.name] or nil
|
||||||
local nn = minetest.get_node(pos).name
|
local wet = n_def.soil.wet or nil
|
||||||
node = minetest.registered_nodes[node.name]
|
local base = n_def.soil.base or nil
|
||||||
pos.y = pos.y-1
|
local dry = n_def.soil.dry or nil
|
||||||
|
if not n_def or not n_def.soil or not wet or not base or not dry then
|
||||||
if node.soil == nil or node.soil.wet == nil or node.soil.base == nil or node.soil.dry == nil then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].walkable and minetest.get_item_group(nn, "plant") == 0 and node.name ~= node.soil.base then
|
pos.y = pos.y + 1
|
||||||
minetest.set_node(pos, {name = node.soil.base})
|
local nn = minetest.get_node_or_nil(pos)
|
||||||
|
if not nn or not nn.name then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local nn_def = minetest.registered_nodes[nn.name] or nil
|
||||||
|
pos.y = pos.y - 1
|
||||||
|
|
||||||
|
if nn_def and nn_def.walkable and minetest.get_item_group(nn.name, "plant") == 0 then
|
||||||
|
minetest.set_node(pos, {name = base})
|
||||||
|
return
|
||||||
end
|
end
|
||||||
-- check if there is water nearby
|
-- check if there is water nearby
|
||||||
if minetest.find_node_near(pos, 3, {"group:water"}) then
|
if minetest.find_node_near(pos, 3, {"group:water"}) then
|
||||||
|
local wet_lvl = minetest.get_item_group(node.name, "wet")
|
||||||
-- if it is dry soil and not base node, turn it into wet soil
|
-- if it is dry soil and not base node, turn it into wet soil
|
||||||
if node.name ~= node.soil.base and minetest.get_item_group(node.name, "wet") == 0 then
|
if wet_lvl == 0 then
|
||||||
minetest.set_node(pos, {name = node.soil.wet})
|
minetest.set_node(pos, {name = wet})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- turn it back into base if it is already dry
|
-- turn it back into base if it is already dry
|
||||||
if minetest.get_item_group(node.name, "wet") == 0 then
|
if wet_lvl == 0 then
|
||||||
-- only turn it back if there is no plant/seed on top of it
|
-- only turn it back if there is no plant/seed on top of it
|
||||||
if minetest.get_item_group(nn, "plant") == 0 and minetest.get_item_group(nn, "seed") == 0 then
|
if minetest.get_item_group(nn.name, "plant") == 0 and minetest.get_item_group(nn.name, "seed") == 0 then
|
||||||
minetest.set_node(pos, {name = node.soil.base})
|
minetest.set_node(pos, {name = base})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if its wet turn it back into dry soil
|
-- if its wet turn it back into dry soil
|
||||||
elseif minetest.get_item_group(node.name, "wet") == 1 then
|
elseif wet_lvl == 1 then
|
||||||
minetest.set_node(pos, {name = node.soil.dry})
|
minetest.set_node(pos, {name = dry})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user