updated harvest

master
Brett O'Donnell 2012-08-22 02:50:09 +09:30
parent 960a5ea898
commit 58a280f6d4
45 changed files with 100 additions and 211 deletions

View File

@ -1,245 +1,134 @@
-- Must have
--Growing abm for soil. checking if water nearby and if crop is ontop.
--Grow in different terrains for example
--cliffs
--near water
--in open fields far from trees
--in dessert environtments
--beneath trees
--next to stone
--near sand
--near dessert
--in dessert?
--Should do
--Function which gives possibilty to add crops
--Harvest
--A simple farming mod
--A extended plant spawning mod
--mod name
--register alias to avoid unknown plants from previous harvest version
--variable and function definitions
local mod_name = "harvest"
local mod_update = 40 --amount of seconds between growing plants on dirt
local crop_names = {
"cotton",
"potato",
"wheat",
"corn",
"lavender",
"weed",
}
local crop_phases = {
"seedling",
"sapling",
"plant",
"harvest",
"wild"
}
local grow_surfaces = {
"default:dirt",
"default:dirt_with_grass"
}
--Variable and function definitions
local mod_name = "plants"
local wild_crops = {}
local wild_crop_count = 1
local wild_crop_count = 0
local name = 1
local phase = 1
local node_name
local node_tile
local is_node_in_cube = function(nodenames, node_pos, radius)
local name = 1
repeat
if minetest.env:find_node_near(node_pos, radius, nodenames[name]) ~= nil then
return true
end
name = name + 1
until nodenames[name] == nil
local function arrayContains(array, value)
for _,v in pairs(array) do
if v == value then
return true
end
end
return false
end
local add_farm_plant = function(name_plant, spacing, spawning, grow_nodes, near_nodes, near_distance, growing_speed) --register a farming plant
local function generate(node, surfaces, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes)
if maxp.y < height_min or minp.y > height_max then
return
end
local y_min = math.max(minp.y, height_min)
local y_max = math.min(maxp.y, height_max)
local width = maxp.x-minp.x
local length = maxp.z-minp.z
local height = height_max-height_min
local name = mod_name..":"..name_plant
local img = mod_name.."_"..name_plant
minetest.register_node(name.."_wild", {--register wild plant
tile_images = {img.."_wild.png"},
drawtype = "plantlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
groups = { snappy = 3},
drop = { items = { name.."_seedling"},
max_items = 1,
items = {
{
items = {name.."_seedling"},
rarity = 30,
},
}
},
})
minetest.register_node(name.."_seedling", {--register seedling
tile_images = {img.."_seedling.png"},
wield_image = img.."_seeds.png",
inventory_image = img.."_seeds.png",
drawtype = "plantlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
groups = { snappy = 3},
drop = "",
})
minetest.register_node(name.."_sapling", {--register sapling
tile_images = {img.."_sapling.png"},
drawtype = "plantlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
groups = { snappy = 3},
drop = "",
})
minetest.register_node(name.."_plant", {--register plant
tile_images = {img.."_plant.png"},
drawtype = "plantlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
groups = { snappy = 3},
drop = "",
})
minetest.register_node(name.."_harvest", {--register plant
tile_images = {img.."_harvest.png"},
drawtype = "plantlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
groups = { snappy = 3},
drop = "",
})
minetest.register_abm({
nodenames = grow_nodes,
interval = mod_update,
chance = spawning,
action = function(pos, node)
local p = {x=pos.x, y=pos.y+1, z=pos.z}
local n = minetest.env:get_node(p)
local y_current
local x_current
local z_current
local x_deviation
local z_deviation
--apperently nested while loops don't work!
for x_current = spread/2, width, spread do
for z_current = spread/2, length, spread do
if n.name == "air" then
if is_node_in_cube(near_nodes, pos, near_distance) and is_node_in_cube({name.."_wild"}, pos, spacing)==false then
minetest.env:add_node(p, {name=name.."_wild"})
end
end
x_deviation = math.floor(math.random(spread))-spread/2
z_deviation = math.floor(math.random(spread))-spread/2
for y_current = height_max, height_min, -1 do
local p = {x=minp.x+x_current+x_deviation, y=y_current, z=minp.z+z_current+z_deviation}
local n = minetest.env:get_node(p)
local p_top = {x=p.x, y=p.y+1, z=p.z}
local n_top = minetest.env:get_node(p_top)
if n_top.name == "air" then
if arrayContains(surfaces, n.name) then
if minetest.env:find_node_near(p_top, habitat_size, habitat_nodes) ~= nil then
minetest.env:add_node(p_top, {name=node})
end
end
end
end
--randomize positioning a little and then check if the surface(grow on) node is beneath it. If so check if habitat node is within the habitat_size. If so create the node.
z_current = z_current + spread
end
})
end
end
local add_plant = function(name_plant, spacing, spawning, grow_nodes, near_nodes, near_distance) -- register a wild plant
local add_plant = function(name_plant) -- register a wild plant
local name = mod_name..":"..name_plant
local img = mod_name.."_"..name_plant
minetest.register_node(name.."_wild", {--register wild plant
tile_images = {img.."_wild.png"},
inventory_image = img.."_wild.png",
description = name_plant,
drawtype = "plantlike",
inventory_image = "",
paramtype = "light",
sunlight_propagates = true,
paramtype = "light",
walkable = false,
groups = { snappy = 3},
drop = "",
groups = { snappy = 3,flammable=2 },
sounds = default.node_sound_leaves_defaults(),
})
minetest.register_abm({
nodenames = grow_nodes,
interval = mod_update,
chance = spawning,
action = function(pos, node)
local p = {x=pos.x, y=pos.y+1, z=pos.z}
local n = minetest.env:get_node(p)
if n.name == "air" then
if is_node_in_cube(near_nodes, pos, near_distance) and is_node_in_cube({name.."_wild"}, pos, spacing)==false then
minetest.env:add_node(p, {name=name.."_wild"})
end
end
end
})
end
--plant registration
--Just wild plant
--node registration
--make tools with which dirt can be prepared for growing
minetest.register_tool(mod_name..":hoe_wood", {
description = "Sickle",
inventory_image = "harvest_hoe_wood.png",
on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to node
if pointed_thing.type ~= "node" then
return
end
-- Check if pointing to dirt or dirt_with_grass
n = minetest.env:get_node(pointed_thing.under)
if n.name == "default:dirt" or n.name == "default:dirt_with_grass" then
minetest.env:add_node(pointed_thing.under, {name=mod_name..":soil"})
end
end,
})
minetest.register_alias("harvest:lavender_wild", "plants:lavender_wild")
minetest.register_alias("harvest:redshroom_wild", "plants:redshroom_wild")
minetest.register_alias("harvest:corn_wild", "plants:corn_wild")
minetest.register_alias("harvest:cotton_wild", "plants:cotton_wild")
minetest.register_alias("harvest:brownshroom_wild", "plants:brownshroom_wild")
minetest.register_alias("harvest:chamomile_wild", "plants:chamomile_wild")
minetest.register_alias("harvest:colchicum_wild", "plants:colchicum_wild")
minetest.register_alias("harvest:poppy_wild", "plants:poppy_wild")
minetest.register_alias("harvest:grasstall_wild", "plants:grasstall_wild")
minetest.register_alias("harvest:grass_wild", "plants:grass_wild")
--Make node in which dirt changes after hoe preperation
minetest.register_node(mod_name..":soil", {
description = "Soil",
tile_images = {"harvest_soil.png", "default_dirt.png"},
groups = {crumbly=3},
drop = 'default:dirt',
after_dig_node = function(pos)
end,
})
--ABM's for placing wild versions of the plant on dirt tiles
--test()
add_farm_plant("cotton", 4, 40, {"default:dirt_with_grass"}, {"default:desert_sand"}, 5)
add_farm_plant("corn", 4, 50, {"default:dirt_with_grass"}, {"default:water_source"}, 3,10)
add_plant("lavender", 1, 5, {"default:dirt_with_grass"}, {"default:sand"}, 2)
add_plant("potato", 8, 20, {"default:desert_sand"}, {"default:dirt_with_grass"}, 16)
add_plant("redshroom", 10, 10, {"default:dirt_with_grass"}, {"default:leaves"}, 3)
add_plant("cacao", 10, 20, {"default:dirt_with_grass"}, {"snow:dirt_with_snow"}, 16)
--create plant nodes. Not all plants spawn in the wild for this you have to define it on the generate on function
add_plant("cotton")
add_plant("corn")
add_plant("lavender")
add_plant("potato")
add_plant("redshroom")
add_plant("cacao")
add_plant("brownshroom")
add_plant("chamomile")
add_plant("colchicum")
add_plant("poppy")
add_plant("grasstall")
add_plant("grass")
--generate(node, surface, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes)
--For the plants that do spawn on the lang we have the generate function. This makes sure that plants are placed when new peaces of the level are loaded.
minetest.register_on_generated(function(minp, maxp, seed)
generate("plants:lavender_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 4, 4, {"default:sand",})
generate("plants:redshroom_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 20, 8, {"default:leaves",})
generate("plants:corn_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 8, 10, {"default:water_source",})
generate("plants:cotton_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 8, 10, {"default:desert_sand",})
generate("plants:brownshroom_wild", {"default:stone"}, minp, maxp, -40, 10, 2, 10, {"default:water_source",})
generate("plants:chamomile_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 40, 8, 4, {"default:stone_with_coal",})
generate("plants:colchicum_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 40, 4, 10, {"default:stone_with_iron",})
generate("plants:poppy_wild", {"defaultw:desert_sand"}, minp, maxp, -10, 20, 4, 10, {"default:water_source",})
generate("plants:grasstall_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 20, 3, 3, {"default:water_source",})
generate("plants:grass_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 20, 3, 3, {"default:water_source",})
end)
print("[Harvest] Loaded!")

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 674 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 549 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 B