added a few ABMs for plants.
parent
40f17d3679
commit
fcc040daad
|
@ -0,0 +1,48 @@
|
|||
function common.plant_spread(nodename, pos, spread, undernode, replacing, needed_air)
|
||||
local ran_num = math.random(1,8)
|
||||
local location = {}
|
||||
if ran_num == 1 then
|
||||
location = {x=pos.x+spread, y=pos.y, z=pos.z}
|
||||
end
|
||||
if ran_num == 2 then
|
||||
location = {x=pos.x+spread, y=pos.y, z=pos.z+spread}
|
||||
end
|
||||
if ran_num == 3 then
|
||||
location = {x=pos.x, y=pos.y, z=pos.z+spread}
|
||||
end
|
||||
if ran_num == 4 then
|
||||
location = {x=pos.x-spread, y=pos.y, z=pos.z+spread}
|
||||
end
|
||||
if ran_num == 5 then
|
||||
location = {x=pos.x-spread, y=pos.y, z=pos.z}
|
||||
end
|
||||
if ran_num == 6 then
|
||||
location = {x=pos.x-spread, y=pos.y, z=pos.z-spread}
|
||||
end
|
||||
if ran_num == 7 then
|
||||
location = {x=pos.x, y=pos.y, z=pos.z-spread}
|
||||
end
|
||||
if ran_num == 8 then
|
||||
location = {x=pos.x+spread, y=pos.y, z=pos.z-spread}
|
||||
end
|
||||
local under_location = ({x=location.x, y=location.y-1, z=location.z})
|
||||
local under_name = minetest.get_node_or_nil(under_location)
|
||||
local location_name = minetest.get_node_or_nil(location)
|
||||
if under_name == nil then
|
||||
return -- Should under_name somehow not be a node this will keep the script from crashing.
|
||||
end
|
||||
if under_name.name == undernode then
|
||||
if location_name.name == replacing then
|
||||
local diff = spread + 1
|
||||
local pos1 = {x=location.x+diff, y=location.y, z=location.z+diff}
|
||||
local pos0 = {x=location.x-diff, y=location.y, z=location.z-diff}
|
||||
local can_replace = minetest.find_nodes_in_area(pos0, pos1, nodename)
|
||||
local replace_num = #can_replace
|
||||
print (replace_num)
|
||||
if replace_num <= needed_air then --increase to decrease number of plants.
|
||||
local face_ran = math.random(0,3)
|
||||
minetest.set_node(location, {name = nodename, param2 = face_ran})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,3 +2,4 @@ common = {}
|
|||
|
||||
dofile(minetest.get_modpath('common')..'/colbox.lua')
|
||||
dofile(minetest.get_modpath('common')..'/formspec.lua')
|
||||
dofile(minetest.get_modpath('common')..'/functions.lua')
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
minetest.register_abm({
|
||||
label = 'grass spread',
|
||||
nodenames = {'ground:dirt'},
|
||||
neighbors = {'ground:dirt_with_grass'},
|
||||
interval = 3,
|
||||
chance = 2,
|
||||
action = function(pos)
|
||||
local above_node = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local above_node_name = minetest.get_node_or_nil(above_node).name
|
||||
local nodedef = minetest.registered_nodes[above_node_name]
|
||||
if nodedef.sunlight_propagates then
|
||||
minetest.add_node(pos, {name = 'ground:dirt_with_grass'})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {'ground:dirt_with_grass'},
|
||||
interval = 3,
|
||||
chance = 2,
|
||||
action = function(pos)
|
||||
local above_node = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local above_node_name = minetest.get_node_or_nil(above_node).name
|
||||
local nodedef = minetest.registered_nodes[above_node_name]
|
||||
if not nodedef.sunlight_propagates then
|
||||
minetest.add_node(pos, {name = 'ground:dirt'})
|
||||
end
|
||||
end,
|
||||
})
|
|
@ -1,2 +1,3 @@
|
|||
dofile(minetest.get_modpath('ground')..'/nodes.lua')
|
||||
dofile(minetest.get_modpath('ground')..'/mapgen.lua')
|
||||
dofile(minetest.get_modpath('ground')..'/ABMs.lua')
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
minetest.register_abm{
|
||||
nodenames = {'group:grass'},
|
||||
interval = 2,
|
||||
chance = 2,
|
||||
action = function(pos)
|
||||
local month = mymonths.month_counter
|
||||
local node_name = minetest.get_node_or_nil(pos).name
|
||||
local nodedef = minetest.registered_nodes[node_name]
|
||||
local thing_that_grows = nodedef.grows_to
|
||||
local time_of_growing = nodedef.grows_in_month
|
||||
if tonumber(month) == time_of_growing then
|
||||
if thing_that_grows ~= 'spread' then
|
||||
minetest.set_node(pos, {name = thing_that_grows})
|
||||
elseif thing_that_grows == 'spread' then
|
||||
common.plant_spread('plants:grass_4', pos, 2, 'ground:dirt_with_grass', 'air', 16)
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
|
@ -16,7 +16,9 @@ minetest.register_node('plants:grass_1', {
|
|||
local stack = ItemStack('plants:grass_' .. math.random(1,4))
|
||||
local ret = minetest.item_place(stack, placer, pointed_thing)
|
||||
return ItemStack('plants:grass_1 '.. itemstack:get_count() - (1 - ret:get_count()))
|
||||
end
|
||||
end,
|
||||
grows_in_month = 5,
|
||||
grows_to = 'plants:grass_2',
|
||||
})
|
||||
|
||||
minetest.register_node('plants:grass_2', {
|
||||
|
@ -31,6 +33,8 @@ minetest.register_node('plants:grass_2', {
|
|||
buildable_to = true,
|
||||
paramtype = 'light',
|
||||
selection_box = plants.grass_sel,
|
||||
grows_in_month = 5,
|
||||
grows_to = 'plants:grass_3',
|
||||
})
|
||||
|
||||
minetest.register_node('plants:grass_3', {
|
||||
|
@ -45,6 +49,8 @@ minetest.register_node('plants:grass_3', {
|
|||
buildable_to = true,
|
||||
paramtype = 'light',
|
||||
selection_box = plants.grass_sel,
|
||||
grows_in_month = 5,
|
||||
grows_to = 'plants:grass_4',
|
||||
})
|
||||
|
||||
minetest.register_node('plants:grass_4', {
|
||||
|
@ -59,4 +65,6 @@ minetest.register_node('plants:grass_4', {
|
|||
buildable_to = true,
|
||||
paramtype = 'light',
|
||||
selection_box = plants.grass_sel,
|
||||
grows_to = 'spread',
|
||||
grows_in_month = 5,
|
||||
})
|
||||
|
|
|
@ -3,3 +3,5 @@ plants.grass_sel = {type = 'fixed',
|
|||
fixed = {{-0.4, -0.5, -0.4, 0.4, -0.3, 0.4},}}
|
||||
|
||||
dofile(minetest.get_modpath('plants')..'/grasses.lua')
|
||||
dofile(minetest.get_modpath('plants')..'/mapgen.lua')
|
||||
dofile(minetest.get_modpath('plants')..'/ABMs.lua')
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = {"ground:dirt_with_grass"},
|
||||
sidelen = 16,
|
||||
noise_params = {
|
||||
offset = 0,
|
||||
scale = 0.02,
|
||||
spread = {x = 100, y = 100, z = 100},
|
||||
seed = 219,
|
||||
octaves = 3,
|
||||
persist = 0.6
|
||||
},
|
||||
y_min = 1,
|
||||
y_max = 30,
|
||||
decoration = "plants:grass_1",
|
||||
})
|
Loading…
Reference in New Issue