#373 Grow cactus in inactive areas/during skipped nights

This commit is contained in:
kay27 2022-07-17 03:27:12 +03:00
parent ec00351041
commit 9210e05eba
3 changed files with 122 additions and 137 deletions

View File

@ -17,6 +17,16 @@ local ACACIA_TREE_ID = 4
local JUNGLE_TREE_ID = 5 local JUNGLE_TREE_ID = 5
local BIRCH_TREE_ID = 6 local BIRCH_TREE_ID = 6
local minetest_get_node = minetest.get_node
local minetest_get_node_group = minetest.get_node_group
local minetest_get_node_drops = minetest.get_node_drops
local minetest_get_node_or_nil = minetest.get_node_or_nil
local minetest_get_node_light = minetest.get_node_light
local minetest_get_item_group = minetest.get_item_group
local mcl_time_get_number_of_times_at_pos = mcl_time.get_number_of_times_at_pos
local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius
local minetest_registered_nodes = minetest.registered_nodes
minetest.register_abm({ minetest.register_abm({
label = "Lava cooling", label = "Lava cooling",
nodenames = {"group:lava"}, nodenames = {"group:lava"},
@ -26,11 +36,11 @@ minetest.register_abm({
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local water = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1}, {x=pos.x+1, y=pos.y+1, z=pos.z+1}, "group:water") local water = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1}, {x=pos.x+1, y=pos.y+1, z=pos.z+1}, "group:water")
local lavatype = minetest.registered_nodes[node.name].liquidtype local lavatype = minetest_registered_nodes[node.name].liquidtype
for w=1, #water do for w=1, #water do
--local waternode = minetest.get_node(water[w]) --local waternode = minetest_get_node(water[w])
--local watertype = minetest.registered_nodes[waternode.name].liquidtype --local watertype = minetest_registered_nodes[waternode.name].liquidtype
-- Lava on top of water: Water turns into stone -- Lava on top of water: Water turns into stone
if water[w].y < pos.y and water[w].x == pos.x and water[w].z == pos.z then if water[w].y < pos.y and water[w].x == pos.x and water[w].z == pos.z then
minetest.set_node(water[w], {name="mcl_core:stone"}) minetest.set_node(water[w], {name="mcl_core:stone"})
@ -87,7 +97,7 @@ if lava_spark_limit > 0 then
interval = LAVA_SPARK_ABM_INTERVAL, interval = LAVA_SPARK_ABM_INTERVAL,
chance = 18, chance = 18,
action = function(pos, node) action = function(pos, node)
local above = minetest.get_node(vector.new(pos.x, pos.y + 1, pos.z)) local above = minetest_get_node(vector.new(pos.x, pos.y + 1, pos.z))
if above.name ~= "air" then return end if above.name ~= "air" then return end
lava_spark_abm_census = lava_spark_abm_census + 1 lava_spark_abm_census = lava_spark_abm_census + 1
@ -102,10 +112,10 @@ if lava_spark_limit > 0 then
end end
function mcl_core.lava_spark_add(pos) function mcl_core.lava_spark_add(pos)
local node = minetest.get_node(pos) local node = minetest_get_node(pos)
if minetest.get_node_group(node.name, "lava") == 0 then return end if minetest_get_node_group(node.name, "lava") == 0 then return end
local above = minetest.get_node(vector.new(pos.x, pos.y + 1, pos.z)) local above = minetest_get_node(vector.new(pos.x, pos.y + 1, pos.z))
if above.name ~= "air" then return end if above.name ~= "air" then return end
local pos_addend = vector.new( local pos_addend = vector.new(
@ -185,44 +195,23 @@ minetest.register_entity("mcl_core:lava_spark", {
end end
}) })
--
-- Papyrus and cactus growing
--
-- Functions -- Functions
function mcl_core.grow_cactus(pos, node)
pos.y = pos.y-1
local name = minetest.get_node(pos).name
if minetest.get_item_group(name, "sand") ~= 0 then
pos.y = pos.y+1
local height = 0
while minetest.get_node(pos).name == "mcl_core:cactus" and height < 4 do
height = height+1
pos.y = pos.y+1
end
if height < 3 then
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="mcl_core:cactus"})
end
end
end
end
function mcl_core.grow_reeds(pos, node) function mcl_core.grow_reeds(pos, node)
pos.y = pos.y-1 pos.y = pos.y-1
local name = minetest.get_node(pos).name local name = minetest_get_node(pos).name
if minetest.get_item_group(name, "soil_sugarcane") ~= 0 then if minetest_get_item_group(name, "soil_sugarcane") ~= 0 then
if minetest.find_node_near(pos, 1, {"group:water"}) == nil and minetest.find_node_near(pos, 1, {"group:frosted_ice"}) == nil then if minetest.find_node_near(pos, 1, {"group:water"}) == nil and minetest.find_node_near(pos, 1, {"group:frosted_ice"}) == nil then
return return
end end
pos.y = pos.y+1 pos.y = pos.y+1
local height = 0 local height = 0
while minetest.get_node(pos).name == "mcl_core:reeds" and height < 3 do while minetest_get_node(pos).name == "mcl_core:reeds" and height < 3 do
height = height+1 height = height+1
pos.y = pos.y+1 pos.y = pos.y+1
end end
if height < 3 then if height < 3 then
if minetest.get_node(pos).name == "air" then if minetest_get_node(pos).name == "air" then
minetest.set_node(pos, {name="mcl_core:reeds"}) minetest.set_node(pos, {name="mcl_core:reeds"})
end end
end end
@ -231,14 +220,13 @@ end
-- ABMs -- ABMs
local function drop_attached_node(p) local function drop_attached_node(p)
local nn = minetest.get_node(p).name local nn = minetest_get_node(p).name
if nn == "air" or nn == "ignore" then if nn == "air" or nn == "ignore" then
return return
end end
minetest.remove_node(p) minetest.remove_node(p)
for _, item in pairs(minetest.get_node_drops(nn, "")) do for _, item in pairs(minetest_get_node_drops(nn, "")) do
local pos = { local pos = {
x = p.x + math.random()/2 - 0.25, x = p.x + math.random()/2 - 0.25,
y = p.y + math.random()/2 - 0.25, y = p.y + math.random()/2 - 0.25,
@ -254,11 +242,11 @@ end
local function liquid_flow_action(pos, group, action) local function liquid_flow_action(pos, group, action)
local function check_detach(pos, xp, yp, zp) local function check_detach(pos, xp, yp, zp)
local p = {x=pos.x+xp, y=pos.y+yp, z=pos.z+zp} local p = {x=pos.x+xp, y=pos.y+yp, z=pos.z+zp}
local n = minetest.get_node_or_nil(p) local n = minetest_get_node_or_nil(p)
if not n then if not n then
return false return false
end end
local d = minetest.registered_nodes[n.name] local d = minetest_registered_nodes[n.name]
if not d then if not d then
return false return false
end end
@ -267,7 +255,7 @@ local function liquid_flow_action(pos, group, action)
* 2a: If target node is below liquid, always succeed * 2a: If target node is below liquid, always succeed
* 2b: If target node is horizontal to liquid: succeed if source, otherwise check param2 for horizontal flow direction ]] * 2b: If target node is horizontal to liquid: succeed if source, otherwise check param2 for horizontal flow direction ]]
local range = d.liquid_range or 8 local range = d.liquid_range or 8
if (minetest.get_item_group(n.name, group) ~= 0) and if (minetest_get_item_group(n.name, group) ~= 0) and
((yp > 0) or ((yp > 0) or
(yp == 0 and ((d.liquidtype == "source") or (n.param2 > (8-range) and n.param2 < 9)))) then (yp == 0 and ((d.liquidtype == "source") or (n.param2 > (8-range) and n.param2 < 9)))) then
action(pos) action(pos)
@ -316,17 +304,23 @@ minetest.register_abm({
end, end,
}) })
-- Cactus mechanisms local function cactus_grow(pos, node)
minetest.register_abm({ local pos = pos
label = "Cactus growth", local y = pos.y
nodenames = {"mcl_core:cactus"}, pos.y = y - 1
neighbors = {"group:sand"}, local name = minetest_get_node(pos).name
interval = 25, if minetest_get_item_group(name, "sand") == 0 then return end
chance = 10,
action = function(pos) for i = 1, 2 do
mcl_core.grow_cactus(pos) pos.y = y + i
end, name = minetest_get_node(pos).name
}) if name == "air" then
minetest.set_node(pos, {name = "mcl_core:cactus"})
return
end
if name ~= "mcl_core:cactus" then return end
end
end
minetest.register_abm({ minetest.register_abm({
label = "Cactus mechanisms", label = "Cactus mechanisms",
@ -334,39 +328,34 @@ minetest.register_abm({
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
for _, object in pairs(minetest.get_objects_inside_radius(pos, 0.9)) do local pos = pos
local x, y, z = pos.x, pos.y, pos.z
if minetest_registered_nodes[minetest_get_node({x = x + 1, y = y, z = z}).name].walkable
or minetest_registered_nodes[minetest_get_node({x = x - 1, y = y, z = z}).name].walkable
or minetest_registered_nodes[minetest_get_node({x = x, y = y, z = z + 1}).name].walkable
or minetest_registered_nodes[minetest_get_node({x = x, y = y, z = z - 1}).name].walkable
then
while minetest_get_node(pos).name == "mcl_core:cactus" do
minetest.remove_node(pos)
minetest.add_item(vector.offset(pos, math.random(-0.5, 0.5), 0, math.random(-0.5, 0.5)), "mcl_core:cactus")
pos.y = pos.y + 1
end
return
end
for _, object in pairs(minetest_get_objects_inside_radius(pos, 0.9)) do
local entity = object:get_luaentity() local entity = object:get_luaentity()
if entity then if entity then
local entity_name = entity.name local entity_name = entity.name
if entity_name == "__builtin:item" then if entity_name == "__builtin:item" then
object:remove() object:remove()
elseif entity_name == "mcl_minecarts:minecart" then
local pos = object:get_pos()
local driver = entity._driver
if driver then
mcl_player.player_attached[driver] = nil
local player = minetest.get_player_by_name(driver)
player:set_detach()
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
mcl_player.player_set_animation(player, "stand" , 30)
end
minetest.add_item(pos, "mcl_minecarts:minecart")
object:remove()
end end
end end
end end
local posses = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } }
for _, p in pairs(posses) do for i = 1, mcl_time_get_number_of_times_at_pos(pos, 25, 10) do
if minetest.registered_nodes[minetest.get_node(vector.new(pos.x + p[1], pos.y, pos.z + p[2])).name].walkable then cactus_grow(pos)
local posy = pos.y
while minetest.get_node(vector.new(pos.x, posy, pos.z)).name == "mcl_core:cactus" do
local pos = vector.new(pos.x, posy, pos.z)
minetest.remove_node(pos)
minetest.add_item(vector.offset(pos, math.random(-0.5, 0.5), 0, math.random(-0.5, 0.5)), "mcl_core:cactus")
posy = posy + 1
end
break
end
end end
end, end,
}) })
@ -393,7 +382,7 @@ minetest.register_on_dignode(function(pos, node)
local i=1 local i=1
while timber_nodenames[i]~=nil do while timber_nodenames[i]~=nil do
local np={x=pos.x, y=pos.y+1, z=pos.z} local np={x=pos.x, y=pos.y+1, z=pos.z}
while minetest.get_node(np).name==timber_nodenames[i] do while minetest_get_node(np).name==timber_nodenames[i] do
minetest.remove_node(np) minetest.remove_node(np)
minetest.add_item(np, timber_nodenames[i]) minetest.add_item(np, timber_nodenames[i])
np={x=np.x, y=np.y+1, z=np.z} np={x=np.x, y=np.y+1, z=np.z}
@ -417,7 +406,7 @@ local function node_stops_growth(node)
return false return false
end end
local def = minetest.registered_nodes[node.name] local def = minetest_registered_nodes[node.name]
if not def then if not def then
return true return true
end end
@ -450,7 +439,7 @@ local function check_growth_width(pos, width, height)
pos.x + x, pos.x + x,
pos.y + y, pos.y + y,
pos.z + z) pos.z + z)
if node_stops_growth(minetest.get_node(np)) then if node_stops_growth(minetest_get_node(np)) then
return false return false
end end
end end
@ -502,10 +491,10 @@ end
-- oak tree. -- oak tree.
function mcl_core.generate_tree(pos, tree_type, options) function mcl_core.generate_tree(pos, tree_type, options)
pos.y = pos.y-1 pos.y = pos.y-1
--local nodename = minetest.get_node(pos).name --local nodename = minetest_get_node(pos).name
pos.y = pos.y+1 pos.y = pos.y+1
if not minetest.get_node_light(pos) then if not minetest_get_node_light(pos) then
return return
end end
@ -558,7 +547,7 @@ function mcl_core.generate_v6_oak_tree(pos)
local node local node
for dy=1,4 do for dy=1,4 do
pos.y = pos.y+dy pos.y = pos.y+dy
if minetest.get_node(pos).name ~= "air" then if minetest_get_node(pos).name ~= "air" then
return return
end end
pos.y = pos.y-dy pos.y = pos.y-dy
@ -566,7 +555,7 @@ function mcl_core.generate_v6_oak_tree(pos)
node = {name = trunk} node = {name = trunk}
for dy=0,4 do for dy=0,4 do
pos.y = pos.y+dy pos.y = pos.y+dy
if minetest.get_node(pos).name == "air" then if minetest_get_node(pos).name == "air" then
minetest.add_node(pos, node) minetest.add_node(pos, node)
end end
pos.y = pos.y-dy pos.y = pos.y-dy
@ -586,23 +575,23 @@ function mcl_core.generate_v6_oak_tree(pos)
pos.z = pos.z+dz pos.z = pos.z+dz
if dx == 0 and dz == 0 and dy==3 then if dx == 0 and dz == 0 and dy==3 then
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then if minetest_get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node) minetest.add_node(pos, node)
minetest.add_node(pos, air_leaf(leaves)) minetest.add_node(pos, air_leaf(leaves))
end end
elseif dx == 0 and dz == 0 and dy==4 then elseif dx == 0 and dz == 0 and dy==4 then
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then if minetest_get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node) minetest.add_node(pos, node)
minetest.add_node(pos, air_leaf(leaves)) minetest.add_node(pos, air_leaf(leaves))
end end
elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
if minetest.get_node(pos).name == "air" then if minetest_get_node(pos).name == "air" then
minetest.add_node(pos, node) minetest.add_node(pos, node)
minetest.add_node(pos, air_leaf(leaves)) minetest.add_node(pos, air_leaf(leaves))
end end
else else
if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then if minetest_get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node) minetest.add_node(pos, node)
minetest.add_node(pos, air_leaf(leaves)) minetest.add_node(pos, air_leaf(leaves))
end end
@ -954,12 +943,12 @@ minetest.register_abm({
return return
end end
local above = {x=pos.x, y=pos.y+1, z=pos.z} local above = {x=pos.x, y=pos.y+1, z=pos.z}
local abovenode = minetest.get_node(above) local abovenode = minetest_get_node(above)
if minetest.get_item_group(abovenode.name, "liquid") ~= 0 or minetest.get_item_group(abovenode.name, "opaque") == 1 then if minetest_get_item_group(abovenode.name, "liquid") ~= 0 or minetest_get_item_group(abovenode.name, "opaque") == 1 then
-- Never grow directly below liquids or opaque blocks -- Never grow directly below liquids or opaque blocks
return return
end end
local light_self = minetest.get_node_light(above) local light_self = minetest_get_node_light(above)
if not light_self then return end if not light_self then return end
--[[ Try to find a spreading dirt-type block (e.g. grass block or mycelium) --[[ Try to find a spreading dirt-type block (e.g. grass block or mycelium)
within a 3×5×3 area, with the source block being on the 2nd-topmost layer. ]] within a 3×5×3 area, with the source block being on the 2nd-topmost layer. ]]
@ -974,20 +963,20 @@ minetest.register_abm({
-- Found it! Now check light levels! -- Found it! Now check light levels!
local source_above = {x=p2.x, y=p2.y+1, z=p2.z} local source_above = {x=p2.x, y=p2.y+1, z=p2.z}
local light_source = minetest.get_node_light(source_above) local light_source = minetest_get_node_light(source_above)
if not light_source then return end if not light_source then return end
if light_self >= 4 and light_source >= 9 then if light_self >= 4 and light_source >= 9 then
-- All checks passed! Let's spread the grass/mycelium! -- All checks passed! Let's spread the grass/mycelium!
local n2 = minetest.get_node(p2) local n2 = minetest_get_node(p2)
if minetest.get_item_group(n2.name, "grass_block") ~= 0 then if minetest_get_item_group(n2.name, "grass_block") ~= 0 then
n2 = mcl_core.get_grass_block_type(pos) n2 = mcl_core.get_grass_block_type(pos)
end end
minetest.set_node(pos, {name=n2.name}) minetest.set_node(pos, {name=n2.name})
-- If this was mycelium, uproot plant above -- If this was mycelium, uproot plant above
if n2.name == "mcl_core:mycelium" then if n2.name == "mcl_core:mycelium" then
local tad = minetest.registered_nodes[minetest.get_node(above).name] local tad = minetest_registered_nodes[minetest_get_node(above).name]
if tad.groups and tad.groups.non_mycelium_plant then if tad.groups and tad.groups.non_mycelium_plant then
minetest.dig_node(above) minetest.dig_node(above)
end end
@ -1005,9 +994,9 @@ minetest.register_abm({
catch_up = false, catch_up = false,
action = function(pos, node) action = function(pos, node)
local above = {x = pos.x, y = pos.y + 1, z = pos.z} local above = {x = pos.x, y = pos.y + 1, z = pos.z}
local name = minetest.get_node(above).name local name = minetest_get_node(above).name
-- Kill grass/mycelium when below opaque block or liquid -- Kill grass/mycelium when below opaque block or liquid
if name ~= "ignore" and (minetest.get_item_group(name, "opaque") == 1 or minetest.get_item_group(name, "liquid") ~= 0) then if name ~= "ignore" and (minetest_get_item_group(name, "opaque") == 1 or minetest_get_item_group(name, "liquid") ~= 0) then
minetest.set_node(pos, {name = "mcl_core:dirt"}) minetest.set_node(pos, {name = "mcl_core:dirt"})
end end
end end
@ -1015,11 +1004,11 @@ minetest.register_abm({
-- Turn Grass Path and similar nodes to Dirt if a solid node is placed above it -- Turn Grass Path and similar nodes to Dirt if a solid node is placed above it
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
if minetest.get_item_group(newnode.name, "solid") ~= 0 or if minetest_get_item_group(newnode.name, "solid") ~= 0 or
minetest.get_item_group(newnode.name, "dirtifier") ~= 0 then minetest_get_item_group(newnode.name, "dirtifier") ~= 0 then
local below = {x=pos.x, y=pos.y-1, z=pos.z} local below = {x=pos.x, y=pos.y-1, z=pos.z}
local belownode = minetest.get_node(below) local belownode = minetest_get_node(below)
if minetest.get_item_group(belownode.name, "dirtifies_below_solid") == 1 then if minetest_get_item_group(belownode.name, "dirtifies_below_solid") == 1 then
minetest.set_node(below, {name="mcl_core:dirt"}) minetest.set_node(below, {name="mcl_core:dirt"})
end end
end end
@ -1033,8 +1022,8 @@ minetest.register_abm({
chance = 50, chance = 50,
action = function(pos, node) action = function(pos, node)
local above = {x = pos.x, y = pos.y + 1, z = pos.z} local above = {x = pos.x, y = pos.y + 1, z = pos.z}
local name = minetest.get_node(above).name local name = minetest_get_node(above).name
local nodedef = minetest.registered_nodes[name] local nodedef = minetest_registered_nodes[name]
if name ~= "ignore" and nodedef and (nodedef.groups and nodedef.groups.solid) then if name ~= "ignore" and nodedef and (nodedef.groups and nodedef.groups.solid) then
minetest.set_node(pos, {name = "mcl_core:dirt"}) minetest.set_node(pos, {name = "mcl_core:dirt"})
end end
@ -1083,7 +1072,7 @@ local function sapling_grow_action(tree_id, soil_needed, one_by_one, two_by_two,
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if meta:get("grown") then return end if meta:get("grown") then return end
-- Checks if the sapling at pos has enough light and the correct soil -- Checks if the sapling at pos has enough light and the correct soil
local light = minetest.get_node_light(pos) local light = minetest_get_node_light(pos)
if not light then return end if not light then return end
local low_light = (light < treelight) local low_light = (light < treelight)
@ -1101,13 +1090,13 @@ local function sapling_grow_action(tree_id, soil_needed, one_by_one, two_by_two,
if low_light then if low_light then
if delta < 1.2 then return end if delta < 1.2 then return end
if minetest.get_node_light(pos, 0.5) < treelight then return end if minetest_get_node_light(pos, 0.5) < treelight then return end
end end
-- TODO: delta is [days] missed in inactive area. Currently we just add it to stage, which is far from a perfect calculation... -- TODO: delta is [days] missed in inactive area. Currently we just add it to stage, which is far from a perfect calculation...
local soilnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) local soilnode = minetest_get_node({x=pos.x, y=pos.y-1, z=pos.z})
local soiltype = minetest.get_item_group(soilnode.name, "soil_sapling") local soiltype = minetest_get_item_group(soilnode.name, "soil_sapling")
if soiltype < soil_needed then return end if soiltype < soil_needed then return end
-- Increase and check growth stage -- Increase and check growth stage
@ -1121,7 +1110,7 @@ local function sapling_grow_action(tree_id, soil_needed, one_by_one, two_by_two,
if two_by_two then if two_by_two then
-- Check 8 surrounding saplings and try to find a 2×2 pattern -- Check 8 surrounding saplings and try to find a 2×2 pattern
local function is_sapling(pos, sapling) local function is_sapling(pos, sapling)
return minetest.get_node(pos).name == sapling return minetest_get_node(pos).name == sapling
end end
local p2 = {x=pos.x+1, y=pos.y, z=pos.z} local p2 = {x=pos.x+1, y=pos.y, z=pos.z}
local p3 = {x=pos.x, y=pos.y, z=pos.z-1} local p3 = {x=pos.x, y=pos.y, z=pos.z-1}
@ -1205,7 +1194,7 @@ local grow_birch = sapling_grow_action(BIRCH_TREE_ID, 1, true, false)
-- Attempts to grow the sapling at the specified position -- Attempts to grow the sapling at the specified position
-- pos: Position -- pos: Position
-- node: Node table of the node at this position, from minetest.get_node -- node: Node table of the node at this position, from minetest_get_node
-- Returns true on success and false on failure -- Returns true on success and false on failure
function mcl_core.grow_sapling(pos, node) function mcl_core.grow_sapling(pos, node)
local grow local grow
@ -1414,7 +1403,7 @@ minetest.register_abm({
-- Add vines below pos (if empty) -- Add vines below pos (if empty)
local function spread_down(origin, target, dir, node) local function spread_down(origin, target, dir, node)
if math.random(1, 2) == 1 then if math.random(1, 2) == 1 then
if minetest.get_node(target).name == "air" then if minetest_get_node(target).name == "air" then
minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2})
end end
end end
@ -1426,10 +1415,10 @@ minetest.register_abm({
-- Less then 4 vines blocks around the ticked vines block (remember the ticked block is counted by above function as well) -- Less then 4 vines blocks around the ticked vines block (remember the ticked block is counted by above function as well)
if #vines_in_area < 5 then if #vines_in_area < 5 then
if math.random(1, 2) == 1 then if math.random(1, 2) == 1 then
if minetest.get_node(target).name == "air" then if minetest_get_node(target).name == "air" then
local backup_dir = minetest.wallmounted_to_dir(node.param2) local backup_dir = minetest.wallmounted_to_dir(node.param2)
local backup = vector.subtract(target, backup_dir) local backup = vector.subtract(target, backup_dir)
local backupnodename = minetest.get_node(backup).name local backupnodename = minetest_get_node(backup).name
-- Check if the block above is supported -- Check if the block above is supported
if mcl_core.supports_vines(backupnodename) then if mcl_core.supports_vines(backupnodename) then
@ -1447,10 +1436,10 @@ minetest.register_abm({
-- Spread horizontally -- Spread horizontally
local backup_dir = minetest.wallmounted_to_dir(node.param2) local backup_dir = minetest.wallmounted_to_dir(node.param2)
if not vector.equals(backup_dir, dir) then if not vector.equals(backup_dir, dir) then
local target_node = minetest.get_node(target) local target_node = minetest_get_node(target)
if target_node.name == "air" then if target_node.name == "air" then
local backup = vector.add(target, backup_dir) local backup = vector.add(target, backup_dir)
local backupnodename = minetest.get_node(backup).name local backupnodename = minetest_get_node(backup).name
if mcl_core.supports_vines(backupnodename) then if mcl_core.supports_vines(backupnodename) then
minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2})
end end
@ -1478,7 +1467,7 @@ minetest.register_abm({
-- Returns true of the node supports vines -- Returns true of the node supports vines
function mcl_core.supports_vines(nodename) function mcl_core.supports_vines(nodename)
local def = minetest.registered_nodes[nodename] local def = minetest_registered_nodes[nodename]
-- Rules: 1) walkable 2) full cube -- Rules: 1) walkable 2) full cube
return def.walkable and return def.walkable and
(def.node_box == nil or def.node_box.type == "regular") and (def.node_box == nil or def.node_box.type == "regular") and
@ -1516,11 +1505,11 @@ minetest.register_abm({
action = function(p0, node, _, _) action = function(p0, node, _, _)
local do_preserve = false local do_preserve = false
local d = minetest.registered_nodes[node.name].groups.leafdecay local d = minetest_registered_nodes[node.name].groups.leafdecay
if not d or d == 0 then if not d or d == 0 then
return return
end end
local n0 = minetest.get_node(p0) local n0 = minetest_get_node(p0)
if n0.param2 ~= 0 then if n0.param2 ~= 0 then
-- Prevent leafdecay for player-placed leaves. -- Prevent leafdecay for player-placed leaves.
-- param2 is set to 1 after it was placed by the player -- param2 is set to 1 after it was placed by the player
@ -1531,8 +1520,8 @@ minetest.register_abm({
p0_hash = minetest.hash_node_position(p0) p0_hash = minetest.hash_node_position(p0)
local trunkp = mcl_core.leafdecay_trunk_cache[p0_hash] local trunkp = mcl_core.leafdecay_trunk_cache[p0_hash]
if trunkp then if trunkp then
local n = minetest.get_node(trunkp) local n = minetest_get_node(trunkp)
local reg = minetest.registered_nodes[n.name] local reg = minetest_registered_nodes[n.name]
-- Assume ignore is a trunk, to make the thing work at the border of the active area -- Assume ignore is a trunk, to make the thing work at the border of the active area
if n.name == "ignore" or (reg and reg.groups.tree and reg.groups.tree ~= 0) then if n.name == "ignore" or (reg and reg.groups.tree and reg.groups.tree ~= 0) then
return return
@ -1557,7 +1546,7 @@ minetest.register_abm({
end end
if not do_preserve then if not do_preserve then
-- Drop stuff other than the node itself -- Drop stuff other than the node itself
local itemstacks = minetest.get_node_drops(n0.name) local itemstacks = minetest_get_node_drops(n0.name)
for _, itemname in pairs(itemstacks) do for _, itemname in pairs(itemstacks) do
local p_drop = { local p_drop = {
x = p0.x - 0.5 + math.random(), x = p0.x - 0.5 + math.random(),
@ -1581,7 +1570,7 @@ minetest.register_abm({
} }
for s=1, #surround do for s=1, #surround do
local spos = vector.add(p0, surround[s]) local spos = vector.add(p0, surround[s])
local maybe_vine = minetest.get_node(spos) local maybe_vine = minetest_get_node(spos)
--local surround_inverse = vector.multiply(surround[s], -1) --local surround_inverse = vector.multiply(surround[s], -1)
if maybe_vine.name == "mcl_core:vine" and (not mcl_core.check_vines_supported(spos, maybe_vine)) then if maybe_vine.name == "mcl_core:vine" and (not mcl_core.check_vines_supported(spos, maybe_vine)) then
minetest.remove_node(spos) minetest.remove_node(spos)
@ -1622,7 +1611,7 @@ minetest.register_abm({
interval = 16, interval = 16,
chance = 8, chance = 8,
action = function(pos, node) action = function(pos, node)
if minetest.get_node_light(pos, 0) >= 12 then if minetest_get_node_light(pos, 0) >= 12 then
if node.name == "mcl_core:ice" then if node.name == "mcl_core:ice" then
mcl_core.melt_ice(pos) mcl_core.melt_ice(pos)
else else
@ -1640,7 +1629,7 @@ function mcl_core.check_vines_supported(pos, node)
local supported = false local supported = false
local dir = minetest.wallmounted_to_dir(node.param2) local dir = minetest.wallmounted_to_dir(node.param2)
local pos1 = vector.add(pos, dir) local pos1 = vector.add(pos, dir)
local node_neighbor = minetest.get_node(pos1) local node_neighbor = minetest_get_node(pos1)
-- Check if vines are attached to a solid block. -- Check if vines are attached to a solid block.
-- If ignore, we assume its solid. -- If ignore, we assume its solid.
if node_neighbor.name == "ignore" or mcl_core.supports_vines(node_neighbor.name) then if node_neighbor.name == "ignore" or mcl_core.supports_vines(node_neighbor.name) then
@ -1649,7 +1638,7 @@ function mcl_core.check_vines_supported(pos, node)
-- Vines are not attached, now we check if the vines are “hanging” below another vines block -- Vines are not attached, now we check if the vines are “hanging” below another vines block
-- of equal orientation. -- of equal orientation.
local pos2 = vector.add(pos, {x=0, y=1, z=0}) local pos2 = vector.add(pos, {x=0, y=1, z=0})
local node2 = minetest.get_node(pos2) local node2 = minetest_get_node(pos2)
-- Again, ignore means we assume its supported -- Again, ignore means we assume its supported
if node2.name == "ignore" or (node2.name == "mcl_core:vine" and node2.param2 == node.param2) then if node2.name == "ignore" or (node2.name == "mcl_core:vine" and node2.param2 == node.param2) then
supported = true supported = true
@ -1662,7 +1651,7 @@ end
function mcl_core.melt_ice(pos) function mcl_core.melt_ice(pos)
-- Create a water source if ice is destroyed and there was something below it -- Create a water source if ice is destroyed and there was something below it
local below = {x=pos.x, y=pos.y-1, z=pos.z} local below = {x=pos.x, y=pos.y-1, z=pos.z}
local belownode = minetest.get_node(below) local belownode = minetest_get_node(below)
local dim = mcl_worlds.pos_to_dimension(below) local dim = mcl_worlds.pos_to_dimension(below)
if dim ~= "nether" and belownode.name ~= "air" and belownode.name ~= "ignore" and belownode.name ~= "mcl_core:void" then if dim ~= "nether" and belownode.name ~= "air" and belownode.name ~= "ignore" and belownode.name ~= "mcl_core:void" then
minetest.set_node(pos, {name="mcl_core:water_source"}) minetest.set_node(pos, {name="mcl_core:water_source"})
@ -1697,7 +1686,7 @@ end
-- The snowable nodes also MUST have _mcl_snowed defined to contain the name -- The snowable nodes also MUST have _mcl_snowed defined to contain the name
-- of the snowed node. -- of the snowed node.
function mcl_core.register_snowed_node(itemstring_snowed, itemstring_clear, tiles, sounds, clear_colorization, desc) function mcl_core.register_snowed_node(itemstring_snowed, itemstring_clear, tiles, sounds, clear_colorization, desc)
local def = table.copy(minetest.registered_nodes[itemstring_clear]) local def = table.copy(minetest_registered_nodes[itemstring_clear])
local create_doc_alias local create_doc_alias
if def.description then if def.description then
create_doc_alias = true create_doc_alias = true
@ -1760,7 +1749,7 @@ end
-- This function assumes there is no snow cover node above. This function -- This function assumes there is no snow cover node above. This function
-- MUST NOT be called if there is a snow cover node above pos. -- MUST NOT be called if there is a snow cover node above pos.
function mcl_core.clear_snow_dirt(pos, node) function mcl_core.clear_snow_dirt(pos, node)
local def = minetest.registered_nodes[node.name] local def = minetest_registered_nodes[node.name]
if def._mcl_snowless then if def._mcl_snowless then
minetest.swap_node(pos, {name = def._mcl_snowless, param2=node.param2}) minetest.swap_node(pos, {name = def._mcl_snowless, param2=node.param2})
end end
@ -1773,15 +1762,15 @@ end
-- Makes constructed snowable node snowed if placed below a snow cover node. -- Makes constructed snowable node snowed if placed below a snow cover node.
function mcl_core.on_snowable_construct(pos) function mcl_core.on_snowable_construct(pos)
-- Myself -- Myself
local node = minetest.get_node(pos) local node = minetest_get_node(pos)
-- Above -- Above
local apos = {x=pos.x, y=pos.y+1, z=pos.z} local apos = {x=pos.x, y=pos.y+1, z=pos.z}
local anode = minetest.get_node(apos) local anode = minetest_get_node(apos)
-- Make snowed if needed -- Make snowed if needed
if minetest.get_item_group(anode.name, "snow_cover") == 1 then if minetest_get_item_group(anode.name, "snow_cover") == 1 then
local def = minetest.registered_nodes[node.name] local def = minetest_registered_nodes[node.name]
if def._mcl_snowed then if def._mcl_snowed then
minetest.swap_node(pos, {name = def._mcl_snowed, param2=node.param2}) minetest.swap_node(pos, {name = def._mcl_snowed, param2=node.param2})
end end
@ -1801,8 +1790,8 @@ end
-- Makes snowable node below snowed. -- Makes snowable node below snowed.
function mcl_core.on_snow_construct(pos) function mcl_core.on_snow_construct(pos)
local npos = {x=pos.x, y=pos.y-1, z=pos.z} local npos = {x=pos.x, y=pos.y-1, z=pos.z}
local node = minetest.get_node(npos) local node = minetest_get_node(npos)
local def = minetest.registered_nodes[node.name] local def = minetest_registered_nodes[node.name]
if def._mcl_snowed then if def._mcl_snowed then
minetest.swap_node(npos, {name = def._mcl_snowed, param2=node.param2}) minetest.swap_node(npos, {name = def._mcl_snowed, param2=node.param2})
end end
@ -1810,13 +1799,13 @@ end
-- after_destruct -- after_destruct
-- Clears snowed dirtlike node below. -- Clears snowed dirtlike node below.
function mcl_core.after_snow_destruct(pos) function mcl_core.after_snow_destruct(pos)
local nn = minetest.get_node(pos).name local nn = minetest_get_node(pos).name
-- No-op if snow was replaced with snow -- No-op if snow was replaced with snow
if minetest.get_item_group(nn, "snow_cover") == 1 then if minetest_get_item_group(nn, "snow_cover") == 1 then
return return
end end
local npos = {x=pos.x, y=pos.y-1, z=pos.z} local npos = {x=pos.x, y=pos.y-1, z=pos.z}
local node = minetest.get_node(npos) local node = minetest_get_node(npos)
mcl_core.clear_snow_dirt(npos, node) mcl_core.clear_snow_dirt(npos, node)
end end

View File

@ -3045,8 +3045,6 @@ local function register_decorations()
octaves = 3, octaves = 3,
persist = 0.6 persist = 0.6
}, },
y_min = 4,
y_max = mcl_mapgen.overworld.max,
decoration = "mcl_core:cactus", decoration = "mcl_core:cactus",
biomes = {"Desert", biomes = {"Desert",
"Mesa","Mesa_sandlevel", "Mesa","Mesa_sandlevel",

View File

@ -670,8 +670,6 @@ local function register_mgv6_decorations()
octaves = 3, octaves = 3,
persist = 0.6 persist = 0.6
}, },
y_min = 4,
y_max = mcl_mapgen.overworld.max,
decoration = "mcl_core:cactus", decoration = "mcl_core:cactus",
height = 1, height = 1,
height_max = 3, height_max = 3,