forked from MineClone5/MineClone5
Refactor plant growth, improve bone meal on plants
This commit is contained in:
parent
a7504781c4
commit
d3e2a21d5f
|
@ -127,76 +127,39 @@ mcl_dye.apply_bone_meal = function(pointed_thing)
|
||||||
pos = pointed_thing.under
|
pos = pointed_thing.under
|
||||||
n = minetest.get_node(pos)
|
n = minetest.get_node(pos)
|
||||||
if n.name == "" then return false end
|
if n.name == "" then return false end
|
||||||
local stage = ""
|
|
||||||
if minetest.get_item_group(n.name, "sapling") >= 1 then
|
if minetest.get_item_group(n.name, "sapling") >= 1 then
|
||||||
-- 45% chance to advance growth stage of sapling
|
-- Saplings: 45% chance to advance growth stage
|
||||||
if math.random(1,100) <= 45 then
|
if math.random(1,100) <= 45 then
|
||||||
return mcl_core.grow_sapling(pos, n)
|
return mcl_core.grow_sapling(pos, n)
|
||||||
end
|
end
|
||||||
|
-- Wheat, Potato, Carrot, Pumpkin Stem, Melon Stem: Advance by 2-5 stages
|
||||||
elseif string.find(n.name, "mcl_farming:wheat_") ~= nil then
|
elseif string.find(n.name, "mcl_farming:wheat_") ~= nil then
|
||||||
stage = string.sub(n.name, -1)
|
local stages = math.random(2, 5)
|
||||||
if stage == "3" then
|
return mcl_farming:grow_plant("plant_wheat", pos, n, stages)
|
||||||
minetest.add_node(pos, {name="mcl_farming:wheat", param = n.param, param2 = n.param2})
|
|
||||||
elseif math.random(1,5) < 3 then
|
|
||||||
minetest.add_node(pos, {name="mcl_farming:wheat", param = n.param, param2 = n.param2})
|
|
||||||
else
|
|
||||||
minetest.add_node(pos, {name="mcl_farming:wheat_"..math.random(2,3), param = n.param, param2 = n.param2})
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
elseif string.find(n.name, "mcl_farming:potato_") ~= nil then
|
elseif string.find(n.name, "mcl_farming:potato_") ~= nil then
|
||||||
stage = tonumber(string.sub(n.name, -1))
|
local stages = math.random(2, 5)
|
||||||
if stage == 1 then
|
return mcl_farming:grow_plant("plant_potato", pos, n, stages)
|
||||||
minetest.add_node(pos, {name="mcl_farming:potato_"..math.random(stage,2), param = n.param, param2 = n.param2})
|
|
||||||
else
|
|
||||||
minetest.add_node(pos, {name="mcl_farming:potato", param = n.param, param2 = n.param2})
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
elseif string.find(n.name, "mcl_farming:beetroot_") ~= nil then
|
|
||||||
stage = tonumber(string.sub(n.name, -1))
|
|
||||||
if stage == 1 then
|
|
||||||
minetest.add_node(pos, {name="mcl_farming:beetroot_"..math.random(stage,2), param = n.param, param2 = n.param2})
|
|
||||||
else
|
|
||||||
minetest.add_node(pos, {name="mcl_farming:beetroot", param = n.param, param2 = n.param2})
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
elseif string.find(n.name, "mcl_farming:carrot_") ~= nil then
|
elseif string.find(n.name, "mcl_farming:carrot_") ~= nil then
|
||||||
stage = tonumber(string.sub(n.name, -1))
|
local stages = math.random(2, 5)
|
||||||
if stage == 1 then
|
return mcl_farming:grow_plant("plant_carrot", pos, n, stages)
|
||||||
minetest.add_node(pos, {name="mcl_farming:carrot_"..math.random(stage,2), param = n.param, param2 = n.param2})
|
|
||||||
else
|
|
||||||
minetest.add_node(pos, {name="mcl_farming:carrot", param = n.param, param2 = n.param2})
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
elseif string.find(n.name, "mcl_farming:pumpkin_") ~= nil then
|
elseif string.find(n.name, "mcl_farming:pumpkin_") ~= nil then
|
||||||
stage = tonumber(string.sub(n.name, -1))
|
local stages = math.random(2, 5)
|
||||||
if stage then
|
return mcl_farming:grow_plant("plant_pumpkin_stem", pos, n, stages)
|
||||||
stage = stage + math.random(2,5)
|
|
||||||
if stage >= 8 then
|
|
||||||
minetest.add_node(pos, {name="mcl_farming:pumpkintige_unconnect"})
|
|
||||||
else
|
|
||||||
minetest.add_node(pos, {name="mcl_farming:pumpkin_"..stage})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
elseif string.find(n.name, "mcl_farming:melontige_") ~= nil then
|
elseif string.find(n.name, "mcl_farming:melontige_") ~= nil then
|
||||||
stage = tonumber(string.sub(n.name, -1))
|
local stages = math.random(2, 5)
|
||||||
if stage then
|
return mcl_farming:grow_plant("plant_melon_stem", pos, n, stages)
|
||||||
stage = stage + math.random(2,5)
|
|
||||||
if stage >= 8 then
|
elseif string.find(n.name, "mcl_farming:beetroot_") ~= nil then
|
||||||
minetest.add_node(pos, {name="mcl_farming:melontige_unconnect"})
|
-- Beetroot: 75% chance to advance to next stage
|
||||||
else
|
if math.random(1,100) <= 75 then
|
||||||
minetest.add_node(pos, {name="mcl_farming:melontige_"..stage})
|
return mcl_farming:grow_plant("plant_beetroot", pos, n)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
elseif n.name == "mcl_cocoas:cocoa_1" or n.name == "mcl_cocoas:cocoa_2" then
|
elseif n.name == "mcl_cocoas:cocoa_1" or n.name == "mcl_cocoas:cocoa_2" then
|
||||||
|
-- Cocoa: Advance by 1 stage
|
||||||
mcl_cocoas.grow(pos)
|
mcl_cocoas.grow(pos)
|
||||||
return true
|
return true
|
||||||
elseif n.name ~= "" and n.name == "mcl_core:junglesapling" then
|
|
||||||
minetest.add_node(pos, {name="air"})
|
|
||||||
mcl_core.generate_tree(pos, "mcl_core:jungletree", "mcl_core:jungleleaves", 2)
|
|
||||||
return true
|
|
||||||
elseif n.name == "mcl_core:dirt_with_grass" then
|
elseif n.name == "mcl_core:dirt_with_grass" then
|
||||||
|
-- Grass Block: Generate tall grass and random flowers all over the place
|
||||||
for i = -2, 3, 1 do
|
for i = -2, 3, 1 do
|
||||||
for j = -3, 2, 1 do
|
for j = -3, 2, 1 do
|
||||||
pos = pointed_thing.above
|
pos = pointed_thing.above
|
||||||
|
@ -230,8 +193,8 @@ mcl_dye.apply_bone_meal = function(pointed_thing)
|
||||||
minetest.add_item(pos, "mcl_flowers:sunflower")
|
minetest.add_item(pos, "mcl_flowers:sunflower")
|
||||||
return true
|
return true
|
||||||
|
|
||||||
-- Grow tall grass into double tallgrass
|
|
||||||
elseif n.name == "mcl_flowers:tallgrass" then
|
elseif n.name == "mcl_flowers:tallgrass" then
|
||||||
|
-- Tall Grass: Grow into double tallgrass
|
||||||
local toppos = { x=pos.x, y=pos.y+1, z=pos.z }
|
local toppos = { x=pos.x, y=pos.y+1, z=pos.z }
|
||||||
local topnode = minetest.get_node(toppos)
|
local topnode = minetest.get_node(toppos)
|
||||||
if minetest.registered_nodes[topnode.name].buildable_to then
|
if minetest.registered_nodes[topnode.name].buildable_to then
|
||||||
|
@ -240,8 +203,8 @@ mcl_dye.apply_bone_meal = function(pointed_thing)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Grow fern into large fern
|
|
||||||
elseif n.name == "mcl_flowers:fern" then
|
elseif n.name == "mcl_flowers:fern" then
|
||||||
|
-- Fern: Grow into large fern
|
||||||
local toppos = { x=pos.x, y=pos.y+1, z=pos.z }
|
local toppos = { x=pos.x, y=pos.y+1, z=pos.z }
|
||||||
local topnode = minetest.get_node(toppos)
|
local topnode = minetest.get_node(toppos)
|
||||||
if minetest.registered_nodes[topnode.name].buildable_to then
|
if minetest.registered_nodes[topnode.name].buildable_to then
|
||||||
|
|
|
@ -103,7 +103,7 @@ minetest.register_node("mcl_farming:beetroot", {
|
||||||
{-0.5, -0.5, -0.5, 0.5, -0.125, 0.5}
|
{-0.5, -0.5, -0.5, 0.5, -0.125, 0.5}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
groups = {dig_immediate=3, not_in_creative_inventory=1,dig_by_water=1,dig_by_piston=1},
|
groups = {dig_immediate=3, not_in_creative_inventory=1,dig_by_water=1,dig_by_piston=1,beetroot=4},
|
||||||
sounds = mcl_sounds.node_sound_leaves_defaults(),
|
sounds = mcl_sounds.node_sound_leaves_defaults(),
|
||||||
_mcl_blast_resistance = 0,
|
_mcl_blast_resistance = 0,
|
||||||
})
|
})
|
||||||
|
@ -139,7 +139,7 @@ minetest.register_craft({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
mcl_farming:add_plant("mcl_farming:beetroot", {"mcl_farming:beetroot_0", "mcl_farming:beetroot_1", "mcl_farming:beetroot_2"}, 68, 3)
|
mcl_farming:add_plant("plant_beetroot", "mcl_farming:beetroot", {"mcl_farming:beetroot_0", "mcl_farming:beetroot_1", "mcl_farming:beetroot_2"}, 68, 3)
|
||||||
|
|
||||||
if minetest.get_modpath("doc") then
|
if minetest.get_modpath("doc") then
|
||||||
for i=1,2 do
|
for i=1,2 do
|
||||||
|
|
|
@ -124,7 +124,7 @@ minetest.register_craft({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mcl_farming:add_plant("mcl_farming:carrot", {"mcl_farming:carrot_1", "mcl_farming:carrot_2", "mcl_farming:carrot_3"}, 50, 20)
|
mcl_farming:add_plant("plant_carrot", "mcl_farming:carrot", {"mcl_farming:carrot_1", "mcl_farming:carrot_2", "mcl_farming:carrot_3"}, 50, 20)
|
||||||
|
|
||||||
if minetest.get_modpath("doc") then
|
if minetest.get_modpath("doc") then
|
||||||
for i=2,3 do
|
for i=2,3 do
|
||||||
|
|
|
@ -84,7 +84,7 @@ for s=1,7 do
|
||||||
{-0.15, -0.5, -0.15, 0.15, -0.5+h, 0.15}
|
{-0.15, -0.5, -0.15, 0.15, -0.5+h, 0.15}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
groups = {dig_immediate=3, not_in_creative_inventory=1, attached_node=1, dig_by_water=1},
|
groups = {dig_immediate=3, not_in_creative_inventory=1, attached_node=1, dig_by_water=1, plant_melon_stem=s},
|
||||||
sounds = mcl_sounds.node_sound_leaves_defaults(),
|
sounds = mcl_sounds.node_sound_leaves_defaults(),
|
||||||
_mcl_blast_resistance = 0,
|
_mcl_blast_resistance = 0,
|
||||||
})
|
})
|
||||||
|
@ -99,7 +99,7 @@ local stem_def = {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Register stem growth
|
-- Register stem growth
|
||||||
mcl_farming:add_plant("mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 30, 5)
|
mcl_farming:add_plant("plant_melon_stem", "mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 30, 5)
|
||||||
|
|
||||||
-- Register actual melon, connected stems and stem-to-melon growth
|
-- Register actual melon, connected stems and stem-to-melon growth
|
||||||
mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stem_drop, "mcl_farming:melon", melon_base_def, 25, 15)
|
mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stem_drop, "mcl_farming:melon", melon_base_def, 25, 15)
|
||||||
|
|
|
@ -114,7 +114,7 @@ minetest.register_craft({
|
||||||
cooktime = 10,
|
cooktime = 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
mcl_farming:add_plant("mcl_farming:potato", {"mcl_farming:potato_1", "mcl_farming:potato_2"}, 50, 20)
|
mcl_farming:add_plant("plant_potato", "mcl_farming:potato", {"mcl_farming:potato_1", "mcl_farming:potato_2"}, 50, 20)
|
||||||
|
|
||||||
if minetest.get_modpath("doc") then
|
if minetest.get_modpath("doc") then
|
||||||
doc.add_entry_alias("nodes", "mcl_farming:potato_1", "nodes", "mcl_farming:potato_2")
|
doc.add_entry_alias("nodes", "mcl_farming:potato_1", "nodes", "mcl_farming:potato_2")
|
||||||
|
|
|
@ -86,7 +86,7 @@ local pumpkin_base_def = {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Register stem growth
|
-- Register stem growth
|
||||||
mcl_farming:add_plant("mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 30, 5)
|
mcl_farming:add_plant("plant_pumpkin_stem", "mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 30, 5)
|
||||||
|
|
||||||
-- Register actual pumpkin, connected stems and stem-to-pumpkin growth
|
-- Register actual pumpkin, connected stems and stem-to-pumpkin growth
|
||||||
mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin_face", pumpkin_base_def, 30, 15)
|
mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin_face", pumpkin_base_def, 30, 15)
|
||||||
|
|
|
@ -1,41 +1,60 @@
|
||||||
function mcl_farming:add_plant(full_grown, names, interval, chance)
|
local plant_lists = {}
|
||||||
|
|
||||||
|
function mcl_farming:add_plant(identifier, full_grown, names, interval, chance)
|
||||||
|
plant_lists[identifier] = {}
|
||||||
|
plant_lists[identifier].full_grown = full_grown
|
||||||
|
plant_lists[identifier].names = names
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = names,
|
nodenames = names,
|
||||||
interval = interval,
|
interval = interval,
|
||||||
chance = chance,
|
chance = chance,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
pos.y = pos.y-1
|
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name ~= "mcl_farming:soil_wet" and math.random(0, 9) > 0 then
|
||||||
if minetest.get_node(pos).name ~= "mcl_farming:soil_wet" and math.random(0, 9) > 0 then
|
|
||||||
return
|
return
|
||||||
|
else
|
||||||
|
mcl_farming:grow_plant(identifier, pos, node)
|
||||||
end
|
end
|
||||||
pos.y = pos.y+1
|
end,
|
||||||
if not minetest.get_node_light(pos) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if minetest.get_node_light(pos) < 10 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local step = nil
|
|
||||||
for i,name in ipairs(names) do
|
|
||||||
if name == node.name then
|
|
||||||
step = i
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if step == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local new_node = {name=names[step+1]}
|
|
||||||
if new_node.name == nil then
|
|
||||||
new_node.name = full_grown
|
|
||||||
end
|
|
||||||
new_node.param = node.param
|
|
||||||
new_node.param2 = node.param2
|
|
||||||
minetest.set_node(pos, new_node)
|
|
||||||
end
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Attempts to advance a plant at pos by one or more growth stages (if possible)
|
||||||
|
-- identifier: Identifier of plant as defined by mcl_farming:add_plant
|
||||||
|
-- pos: Position
|
||||||
|
-- node: Node table
|
||||||
|
-- stages: Number of stages to advance (optional, defaults to 1)
|
||||||
|
function mcl_farming:grow_plant(identifier, pos, node, stages)
|
||||||
|
if not minetest.get_node_light(pos) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if minetest.get_node_light(pos) < 10 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local plant_info = plant_lists[identifier]
|
||||||
|
local step = nil
|
||||||
|
|
||||||
|
for i, name in ipairs(plant_info.names) do
|
||||||
|
if name == node.name then
|
||||||
|
step = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if step == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not stages then
|
||||||
|
stages = 1
|
||||||
|
end
|
||||||
|
local new_node = {name = plant_info.names[step+stages]}
|
||||||
|
if new_node.name == nil then
|
||||||
|
new_node.name = plant_info.full_grown
|
||||||
|
end
|
||||||
|
new_node.param = node.param
|
||||||
|
new_node.param2 = node.param2
|
||||||
|
minetest.set_node(pos, new_node)
|
||||||
|
end
|
||||||
|
|
||||||
function mcl_farming:place_seed(itemstack, placer, pointed_thing, plantname)
|
function mcl_farming:place_seed(itemstack, placer, pointed_thing, plantname)
|
||||||
local pt = pointed_thing
|
local pt = pointed_thing
|
||||||
if not pt then
|
if not pt then
|
||||||
|
|
|
@ -115,7 +115,7 @@ minetest.register_node("mcl_farming:wheat", {
|
||||||
_mcl_blast_resistance = 0,
|
_mcl_blast_resistance = 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
mcl_farming:add_plant("mcl_farming:wheat", {"mcl_farming:wheat_1", "mcl_farming:wheat_2", "mcl_farming:wheat_3"}, 50, 20)
|
mcl_farming:add_plant("plant_wheat", "mcl_farming:wheat", {"mcl_farming:wheat_1", "mcl_farming:wheat_2", "mcl_farming:wheat_3"}, 50, 20)
|
||||||
|
|
||||||
minetest.register_craftitem("mcl_farming:wheat_item", {
|
minetest.register_craftitem("mcl_farming:wheat_item", {
|
||||||
description = "Wheat",
|
description = "Wheat",
|
||||||
|
|
Loading…
Reference in New Issue