tweaked around plant spreading.

master
NathanSalapat 2019-05-11 16:00:20 -05:00
parent fcc040daad
commit efee25f407
14 changed files with 91 additions and 73 deletions

View File

@ -1,47 +1,49 @@
function common.plant_spread(nodename, pos, spread, undernode, replacing, needed_air)
-- This function does random spreading of plants, designed specifically to use with grasses and weeds.
-- It's mostly self explanitory, but the fill ratio can be tricky, so I'll explain how that works.
-- Maxspread is how far the child node can be from the parent in either direction.
-- Needed_air is how much air space should be preserved. Calculate this value in the following manner.
-- Double maxspread, add one, then square. How much air do you want in that space, fill that value in the needed_air variable.
function common.plant_spread(baby_plant, parent_plant, pos, maxspread, undernode, replacing, needed_air)
local ran_num = math.random(1,8)
local spreadx = math.random(0,maxspread)
local spready = math.random(0,maxspread)
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}
location = {x=pos.x+spreadx, y=pos.y, z=pos.z}
elseif ran_num == 2 then
location = {x=pos.x+spreadx, y=pos.y, z=pos.z+spready}
elseif ran_num == 3 then
location = {x=pos.x, y=pos.y, z=pos.z+spready}
elseif ran_num == 4 then
location = {x=pos.x-spreadx, y=pos.y, z=pos.z+spready}
elseif ran_num == 5 then
location = {x=pos.x-spreadx, y=pos.y, z=pos.z}
elseif ran_num == 6 then
location = {x=pos.x-spreadx, y=pos.y, z=pos.z-spready}
elseif ran_num == 7 then
location = {x=pos.x, y=pos.y, z=pos.z-spready}
elseif ran_num == 8 then
location = {x=pos.x+spreadx, y=pos.y, z=pos.z-spready}
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
print 'node does not exist'
return -- Should under_name somehow not be a node this will keep the script from crashing.
end
if under_name.name == undernode then
print 'name matches.'
if location_name.name == replacing then
local diff = spread + 1
local diff = maxspread
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})
local air = minetest.find_nodes_in_area(pos0, pos1, replacing) --looking for item that is being replaced. Usually air
local open_spaces = #air
if open_spaces > needed_air then
minetest.set_node(location, {name = baby_plant})
minetest.set_node(pos, {name = parent_plant})
end
end
end

View File

@ -45,7 +45,7 @@ function creative.update_creative_inventory(player_name, tab_content)
end
for name, def in pairs(tab_content) do
if not (def.groups.not_in_creative_inventory == 1) and
if not (def.groups.not_in_creative == 1) and
def.description and def.description ~= "" and
(def.name:find(inv.filter, 1, true) or
def.description:lower():find(inv.filter, 1, true)) then

View File

@ -110,7 +110,7 @@ minetest.register_on_joinplayer(function(player)
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
-- set GUI
if not minetest.setting_getbool('creative_mode') then
if not minetest.settings:get_bool('creative_mode') then
player:set_inventory_formspec(common.gui_survival_form)
end
player:hud_set_hotbar_image('gui_hotbar.png')

View File

@ -29,7 +29,7 @@ minetest.register_node('ground:dirt_with_grass', {
tiles = {'ground_grass.png', 'ground_dirt.png',
{name = 'ground_dirt.png^ground_grass_overlay.png',
tileable_vertical = false}},
groups = {crumbly=3, soil=1, spreading_dirt_type=1},
groups = {crumbly=3, soil=1},
drop = 'ground:dirt',
})
@ -38,7 +38,7 @@ minetest.register_node('ground:dirt_with_snow', {
tiles = {'ground_snow.png', 'ground_dirt.png',
{name = 'ground_dirt.png^ground_snow_overlay.png',
tileable_vertical = false}},
groups = {crumbly=3, soil=1, spreading_dirt_type=1},
groups = {crumbly=3,},
drop = 'ground:dirt',
})

View File

@ -3,7 +3,7 @@ local function is_inside(pos)
if minetest.get_node_light({x=pos.x,y=pos.y+1,z=pos.z}, 0.5) ~= 15 then
return true
end
local temp_node = minetest.get_node_or_nil({x=pos.x,y=pos.y+1,z=pos.z})
for i = 2,50 do
@ -30,8 +30,8 @@ minetest.register_globalstep(function(dtime)
end
t = 0
if minetest.get_modpath("lightning") then
if minetest.get_modpath("lightning") then
if mymonths.weather == "storm" then
lightning.strike()
end
@ -222,11 +222,11 @@ mymonths.active_particlespawners={}
--used to determine if to remove old and add new particle spawners
mymonths.last_weather2="none"
function mymonths.update_weather_particles(player)
mymonths.remove_weather_particles(player)
local name=player:get_player_name()
local minp = {x = -20, y = 7, z = -20}
local maxp = {x = 20, y = 7, z = 20}
local minps = {x =-20, y = 0, z = -20}
@ -239,9 +239,9 @@ function mymonths.update_weather_particles(player)
local acc_snow = {x = 0, y = -0.5, z = 0}
local vel_sand = {x = 1, y = -0.1, z = 0}
local acc_sand = {x = 2, y = 0, z = 0}
local l={}
if mymonths.weather2 == "storm" then
l[1] = minetest.add_particlespawner({
@ -280,7 +280,7 @@ function mymonths.update_weather_particles(player)
minsize = 25,
maxsize = 25,
collisiondetection = false,
vertical = true,
vertical = true,
texture = "weather_rain.png",
playername = name,
attached = player
@ -442,12 +442,12 @@ minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos()
local ppos = player:get_pos()
local hp = player:get_hp()
local name = player:get_player_name()
local nodein = minetest.get_node(ppos)
local nodeu = minetest.get_node({x = ppos.x, y = ppos.y - 1, z = ppos.z})
local biome_jungle = minetest.find_node_near(ppos, 8, "default:jungletree", "default:junglegrass")
local biome_desert = minetest.find_node_near(ppos, 8, "default:desert_sand", "default:desert_stone")
local biome_snow = minetest.find_node_near(ppos, 8, "default:snow", "default:snowblock", "default:dirt_with_snow",
@ -531,12 +531,12 @@ minetest.register_globalstep(function(dtime)
else
mymonths.weather2 = mymonths.weather
end
if mymonths.weather2 ~= mymonths.last_weather2 then
mymonths.update_weather_particles(player)
mymonths.last_weather2 = mymonths.weather2
end
if mymonths.weather2 == "storm" then
if not is_inside(ppos) and mymonths.damage == true then
@ -597,7 +597,7 @@ minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos()
local ppos = player:get_pos()
t2 = t2 + dtime

View File

@ -1,6 +1,6 @@
minetest.register_abm{
nodenames = {'group:grass'},
interval = 2,
interval = 1,
chance = 2,
action = function(pos)
local month = mymonths.month_counter
@ -12,7 +12,7 @@ minetest.register_abm{
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)
common.plant_spread('plants:grass_1', 'plants:grass_4', pos, 2, 'ground:dirt_with_grass', 'air', 20)
end
end
end,

View File

@ -1,70 +1,85 @@
local grasses_group = {flora=1, grass=1, dig_immediate=3, attached_node=1, flamable=3, not_in_creative=1}
minetest.register_node('plants:grass_1', {
description = 'grass',
description = 'Grass',
tiles = {'plants_grass_1.png'},
drawtype = 'plantlike',
inventory_image = "plants_grass_4.png",
wield_image = "plants_grass_4.png",
groups = {flora=1, grass=1, oddly_breakable_by_hand=1, attached_node=1},
drop = 'plants:grass_1',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
on_place = function(itemstack, placer, pointed_thing)
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,
grows_in_month = 5,
grows_to = 'plants:grass_2',
})
minetest.register_node('plants:grass_2', {
description = 'grass',
description = 'Grass',
tiles = {'plants_grass_2.png'},
drawtype = 'plantlike',
groups = {flora=1, grass=1, oddly_breakable_by_hand=1, attached_node=1},
drop = 'plants:grass_1',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_in_month = 5,
grows_in_month = 6,
grows_to = 'plants:grass_3',
})
minetest.register_node('plants:grass_3', {
description = 'grass',
description = 'Grass',
tiles = {'plants_grass_3.png'},
drawtype = 'plantlike',
groups = {flora=1, grass=1, oddly_breakable_by_hand=1, attached_node=1},
drop = 'plants:grass_1',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_in_month = 5,
grows_in_month = 7,
grows_to = 'plants:grass_4',
})
minetest.register_node('plants:grass_4', {
description = 'grass',
description = 'Grass',
tiles = {'plants_grass_4.png'},
drawtype = 'plantlike',
groups = {flora=1, grass=1, oddly_breakable_by_hand=1, attached_node=1},
drop = 'plants:grass_1',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_to = 'spread',
grows_in_month = 5,
grows_in_month = 7,
grows_to = 'plants:grass_5',
})
minetest.register_node('plants:grass_5', {
description = 'Seeding Grass',
tiles = {'plants_grass_5.png'},
drawtype = 'plantlike',
groups = grasses_group,
drop = 'plants:fiber',
waving = 1,
walkable = false,
sunlight_propagates = true,
buildable_to = true,
paramtype = 'light',
selection_box = plants.grass_sel,
grows_in_month = 8,
grows_to = 'spread',
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 455 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 469 B

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 433 B

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 457 B

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -98,9 +98,9 @@ for i in ipairs (ship_parts_colors) do
{shipcol..' Walkway Edge', shipdesc..'es', 'edge_straight', '(spawn_ship_floor.png^['..shipval..')', colbox_floor_edge},
{shipcol..' Floor Angle', shipdesc..'fa', 'floor_angle', '(spawn_ship_floor_angle.png^['..shipval..')', colbox_floor_angle},
{shipcol..' Floor Square', shipdesc..'fs', 'floor_square', '(spawn_ship_floor_double.png^['..shipval..')', colbox_floor_square},
{shipcol..' Ramp Top Right', shipdesc..'r2r', 'ramp-2', '(spawn_ship_floor.png^['..shipval..')^[transform2', colbox_ramp_2},
{shipcol..' Ramp Top Right', shipdesc..'r2r', 'ramp-2', '(spawn_ship_floor.png^['..shipval..')^[transform2', common.colbox_stair},
{shipcol..' Ramp Bottom Right', shipdesc..'r1r', 'ramp-1', '(spawn_ship_floor.png^['..shipval..')^[transform2', colbox_ramp_1},
{shipcol..' Ramp Top Left', shipdesc..'r2l', 'ramp-2', '(spawn_ship_floor.png^['..shipval..')', colbox_ramp_2},
{shipcol..' Ramp Top Left', shipdesc..'r2l', 'ramp-2', '(spawn_ship_floor.png^['..shipval..')', common.colbox_stair},
{shipcol..' Ramp Bottom Left', shipdesc..'r1l', 'ramp-1', '(spawn_ship_floor.png^['..shipval..')', colbox_ramp_1}
}

View File

@ -138,6 +138,7 @@ minetest.register_node('spawn:dongle', {
mesh = 'dongle.obj',
paramtype = 'light',
paramtype2 = 'facedir',
sunlight_propagates = true,
tiles = {'dongle.png'},
groups = {spawn=1},
selection_box = {