2015-06-29 20:55:56 +03:00
|
|
|
|
--
|
2017-05-23 06:31:07 +03:00
|
|
|
|
-- Lava vs water interactions
|
2015-06-29 20:55:56 +03:00
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
minetest.register_abm({
|
2017-05-23 06:31:07 +03:00
|
|
|
|
label = "Lava cooling",
|
|
|
|
|
nodenames = {"group:lava"},
|
2015-06-29 20:55:56 +03:00
|
|
|
|
neighbors = {"group:water"},
|
|
|
|
|
interval = 1,
|
|
|
|
|
chance = 1,
|
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2017-05-23 06:31:07 +03:00
|
|
|
|
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")
|
2015-06-29 20:55:56 +03:00
|
|
|
|
|
2017-05-23 06:31:07 +03:00
|
|
|
|
local lavatype = minetest.registered_nodes[node.name].liquidtype
|
|
|
|
|
|
|
|
|
|
for w=1, #water do
|
|
|
|
|
local waternode = minetest.get_node(water[w])
|
|
|
|
|
local watertype = minetest.registered_nodes[waternode.name].liquidtype
|
|
|
|
|
-- 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
|
|
|
|
|
minetest.set_node(water[w], {name="mcl_core:stone"})
|
|
|
|
|
minetest.sound_play("fire_extinguish_flame", {pos = water[w], gain = 0.25, max_hear_distance = 16})
|
|
|
|
|
-- Flowing lava vs water on same level: Lava turns into cobblestone
|
|
|
|
|
elseif lavatype == "flowing" and water[w].y == pos.y and (water[w].x == pos.x or water[w].z == pos.z) then
|
|
|
|
|
minetest.set_node(pos, {name="mcl_core:cobble"})
|
|
|
|
|
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16})
|
|
|
|
|
-- Still lava vs flowing water above or horizontally neighbored: Lava turns into obsidian
|
|
|
|
|
elseif lavatype == "source" and
|
|
|
|
|
((water[w].y > pos.y and water[w].x == pos.x and water[w].z == pos.z) or
|
|
|
|
|
(water[w].y == pos.y and (water[w].x == pos.x or water[w].z == pos.z))) then
|
|
|
|
|
minetest.set_node(pos, {name="mcl_core:obsidian"})
|
|
|
|
|
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16})
|
|
|
|
|
-- Flowing water above flowing lava: Lava turns into cobblestone
|
|
|
|
|
elseif watertype == "flowing" and lavatype == "flowing" and water[w].y > pos.y and water[w].x == pos.x and water[w].z == pos.z then
|
|
|
|
|
minetest.set_node(pos, {name="mcl_core:cobble"})
|
|
|
|
|
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16})
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
|
-- Papyrus and cactus growing
|
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
-- Functions
|
2017-02-11 21:03:26 +03:00
|
|
|
|
mcl_core.grow_cactus = function(pos, node)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
pos.y = pos.y-1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
local name = minetest.get_node(pos).name
|
2015-06-29 20:55:56 +03:00
|
|
|
|
if minetest.get_item_group(name, "sand") ~= 0 then
|
|
|
|
|
pos.y = pos.y+1
|
|
|
|
|
local height = 0
|
2017-02-01 01:32:56 +03:00
|
|
|
|
while minetest.get_node(pos).name == "mcl_core:cactus" and height < 4 do
|
2015-06-29 20:55:56 +03:00
|
|
|
|
height = height+1
|
|
|
|
|
pos.y = pos.y+1
|
|
|
|
|
end
|
2017-01-12 09:13:58 +03:00
|
|
|
|
if height < 3 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.set_node(pos, {name="mcl_core:cactus"})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-02-11 21:03:26 +03:00
|
|
|
|
mcl_core.grow_reeds = function(pos, node)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
pos.y = pos.y-1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
local name = minetest.get_node(pos).name
|
2017-01-12 08:54:16 +03:00
|
|
|
|
if minetest.get_node_group(name, "soil_sugarcane") ~= 0 then
|
2017-02-18 04:23:27 +03:00
|
|
|
|
if minetest.find_node_near(pos, 1, {"group:water"}) == nil and minetest.find_node_near(pos, 1, {"group:frosted_ice"}) == nil then
|
2015-06-29 20:55:56 +03:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
pos.y = pos.y+1
|
|
|
|
|
local height = 0
|
2017-02-01 01:32:56 +03:00
|
|
|
|
while minetest.get_node(pos).name == "mcl_core:reeds" and height < 3 do
|
2015-06-29 20:55:56 +03:00
|
|
|
|
height = height+1
|
|
|
|
|
pos.y = pos.y+1
|
|
|
|
|
end
|
|
|
|
|
if height < 3 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.set_node(pos, {name="mcl_core:reeds"})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- ABMs
|
2015-07-01 08:56:51 +03:00
|
|
|
|
|
2017-01-08 02:22:10 +03:00
|
|
|
|
|
|
|
|
|
local function drop_attached_node(p)
|
|
|
|
|
local nn = minetest.get_node(p).name
|
|
|
|
|
minetest.remove_node(p)
|
|
|
|
|
for _, item in pairs(minetest.get_node_drops(nn, "")) do
|
|
|
|
|
local pos = {
|
|
|
|
|
x = p.x + math.random()/2 - 0.25,
|
|
|
|
|
y = p.y + math.random()/2 - 0.25,
|
|
|
|
|
z = p.z + math.random()/2 - 0.25,
|
|
|
|
|
}
|
|
|
|
|
minetest.add_item(pos, item)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-20 06:05:58 +03:00
|
|
|
|
-- Helper function for node actions for liquid flow
|
|
|
|
|
local liquid_flow_action = function(pos, group, action)
|
|
|
|
|
local check_detach = function(pos, xp, yp, zp)
|
|
|
|
|
local p = {x=pos.x+xp, y=pos.y+yp, z=pos.z+zp}
|
|
|
|
|
local n = minetest.get_node_or_nil(p)
|
|
|
|
|
if not n then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
local d = minetest.registered_nodes[n.name]
|
|
|
|
|
--[[ Check if we want to perform the liquid action.
|
|
|
|
|
* 1: Item must be in liquid group
|
|
|
|
|
* 2a: If target node is below liquid, always succeed
|
2017-05-22 19:56:46 +03:00
|
|
|
|
* 2b: If target node is horizontal to liquid: succeed if source, otherwise check param2 for horizontal flow direction ]]
|
|
|
|
|
if (minetest.get_item_group(n.name, group) ~= 0) and
|
|
|
|
|
((yp > 0) or
|
|
|
|
|
(yp == 0 and ((d.liquidtype == "source") or (n.param2 > (8-d.liquid_range) and n.param2 < 9)))) then
|
2017-05-20 06:05:58 +03:00
|
|
|
|
action(pos)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local posses = {
|
|
|
|
|
{ x=-1, y=0, z=0 },
|
|
|
|
|
{ x=1, y=0, z=0 },
|
|
|
|
|
{ x=0, y=0, z=-1 },
|
|
|
|
|
{ x=0, y=0, z=1 },
|
|
|
|
|
{ x=0, y=1, z=0 },
|
|
|
|
|
}
|
|
|
|
|
for p=1,#posses do
|
|
|
|
|
check_detach(pos, posses[p].x, posses[p].y, posses[p].z)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Drop some nodes next to flowing water, if it would flow into the node
|
2015-07-01 08:37:51 +03:00
|
|
|
|
minetest.register_abm({
|
2017-05-20 06:05:58 +03:00
|
|
|
|
label = "Wash away dig_by_water nodes by water flow",
|
2015-07-01 08:37:51 +03:00
|
|
|
|
nodenames = {"group:dig_by_water"},
|
|
|
|
|
neighbors = {"group:water"},
|
|
|
|
|
interval = 1,
|
|
|
|
|
chance = 1,
|
2015-07-01 08:56:51 +03:00
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2017-05-20 06:05:58 +03:00
|
|
|
|
liquid_flow_action(pos, "water", function(pos)
|
|
|
|
|
drop_attached_node(pos)
|
|
|
|
|
minetest.dig_node(pos)
|
|
|
|
|
end)
|
2015-07-01 08:37:51 +03:00
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
2017-05-20 06:05:58 +03:00
|
|
|
|
-- Destroy some nodes next to flowing lava, if it would flow into the node
|
2017-05-20 05:11:14 +03:00
|
|
|
|
minetest.register_abm({
|
2017-05-20 06:05:58 +03:00
|
|
|
|
label = "Destroy destroy_by_lava_flow nodes by lava flow",
|
2017-05-20 05:11:14 +03:00
|
|
|
|
nodenames = {"group:destroy_by_lava_flow"},
|
|
|
|
|
neighbors = {"group:lava"},
|
|
|
|
|
interval = 1,
|
|
|
|
|
chance = 1,
|
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2017-05-20 06:05:58 +03:00
|
|
|
|
liquid_flow_action(pos, "lava", function(pos)
|
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
|
minetest.sound_play("builtin_item_lava", {pos = pos, gain = 0.25, max_hear_distance = 16})
|
|
|
|
|
core.check_for_falling(pos)
|
|
|
|
|
end)
|
2017-05-20 05:11:14 +03:00
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
2015-06-29 20:55:56 +03:00
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Cactus growth",
|
2017-02-01 01:32:56 +03:00
|
|
|
|
nodenames = {"mcl_core:cactus"},
|
2015-06-29 20:55:56 +03:00
|
|
|
|
neighbors = {"group:sand"},
|
|
|
|
|
interval = 25,
|
|
|
|
|
chance = 10,
|
|
|
|
|
action = function(pos)
|
2017-02-11 21:03:26 +03:00
|
|
|
|
mcl_core.grow_cactus(pos)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Sugar canes growth",
|
2017-02-01 01:32:56 +03:00
|
|
|
|
nodenames = {"mcl_core:reeds"},
|
2017-02-18 01:39:23 +03:00
|
|
|
|
neighbors = {"group:soil_sugarcane"},
|
2015-06-29 20:55:56 +03:00
|
|
|
|
interval = 25,
|
|
|
|
|
chance = 10,
|
|
|
|
|
action = function(pos)
|
2017-02-11 21:03:26 +03:00
|
|
|
|
mcl_core.grow_reeds(pos)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
|
-- Papyrus and cactus drop
|
|
|
|
|
--
|
|
|
|
|
|
2017-03-21 23:48:26 +03:00
|
|
|
|
local timber_nodenames={"mcl_core:reeds"}
|
2015-06-29 20:55:56 +03:00
|
|
|
|
|
|
|
|
|
minetest.register_on_dignode(function(pos, node)
|
|
|
|
|
local i=1
|
|
|
|
|
while timber_nodenames[i]~=nil do
|
|
|
|
|
if node.name==timber_nodenames[i] then
|
2017-01-27 15:45:21 +03:00
|
|
|
|
local np={x=pos.x, y=pos.y+1, z=pos.z}
|
2015-07-04 05:56:02 +03:00
|
|
|
|
while minetest.get_node(np).name==timber_nodenames[i] do
|
|
|
|
|
minetest.remove_node(np)
|
2017-02-18 23:51:50 +03:00
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
|
minetest.add_item(np, timber_nodenames[i])
|
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
|
np={x=np.x, y=np.y+1, z=np.z}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
i=i+1
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
2017-03-08 01:28:54 +03:00
|
|
|
|
local function air_leaf(leaftype)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
if math.random(0, 50) == 3 then
|
|
|
|
|
return {name = "air"}
|
|
|
|
|
else
|
2017-03-08 01:28:54 +03:00
|
|
|
|
return {name = leaftype}
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-02-11 21:03:26 +03:00
|
|
|
|
function mcl_core.generate_tree(pos, trunk, leaves, typearbre)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
pos.y = pos.y-1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
local nodename = minetest.get_node(pos).name
|
2015-06-29 20:55:56 +03:00
|
|
|
|
|
|
|
|
|
pos.y = pos.y+1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if not minetest.get_node_light(pos) then
|
2015-06-29 20:55:56 +03:00
|
|
|
|
return
|
|
|
|
|
end
|
2017-01-27 15:45:21 +03:00
|
|
|
|
local node
|
2015-06-29 20:55:56 +03:00
|
|
|
|
if typearbre == nil or typearbre == 1 then
|
|
|
|
|
node = {name = ""}
|
|
|
|
|
for dy=1,4 do
|
|
|
|
|
pos.y = pos.y+dy
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name ~= "air" then
|
2015-06-29 20:55:56 +03:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
pos.y = pos.y-dy
|
|
|
|
|
end
|
|
|
|
|
node = {name = trunk}
|
|
|
|
|
for dy=0,4 do
|
|
|
|
|
pos.y = pos.y+dy
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" then
|
|
|
|
|
minetest.add_node(pos, node)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.y = pos.y-dy
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
node = {name = leaves}
|
|
|
|
|
pos.y = pos.y+3
|
|
|
|
|
local rarity = 0
|
|
|
|
|
if math.random(0, 10) == 3 then
|
|
|
|
|
rarity = 1
|
|
|
|
|
end
|
|
|
|
|
for dx=-2,2 do
|
|
|
|
|
for dz=-2,2 do
|
|
|
|
|
for dy=0,3 do
|
|
|
|
|
pos.x = pos.x+dx
|
|
|
|
|
pos.y = pos.y+dy
|
|
|
|
|
pos.z = pos.z+dz
|
|
|
|
|
|
|
|
|
|
if dx == 0 and dz == 0 and dy==3 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
|
|
|
|
|
minetest.add_node(pos, node)
|
2017-03-08 01:28:54 +03:00
|
|
|
|
minetest.add_node(pos, air_leaf(leaves))
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
elseif dx == 0 and dz == 0 and dy==4 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
|
|
|
|
|
minetest.add_node(pos, node)
|
2017-03-08 01:28:54 +03:00
|
|
|
|
minetest.add_node(pos, air_leaf(leaves))
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" then
|
|
|
|
|
minetest.add_node(pos, node)
|
2017-03-08 01:28:54 +03:00
|
|
|
|
minetest.add_node(pos, air_leaf(leaves))
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
|
|
|
|
|
minetest.add_node(pos, node)
|
2017-03-08 01:28:54 +03:00
|
|
|
|
minetest.add_node(pos, air_leaf(leaves))
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x-dx
|
|
|
|
|
pos.y = pos.y-dy
|
|
|
|
|
pos.z = pos.z-dz
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif typearbre == 2 then
|
|
|
|
|
node = {name = ""}
|
|
|
|
|
|
|
|
|
|
-- can place big tree ?
|
|
|
|
|
local tree_size = math.random(15, 25)
|
|
|
|
|
for dy=1,4 do
|
|
|
|
|
pos.y = pos.y+dy
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name ~= "air" then
|
2015-06-29 20:55:56 +03:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
pos.y = pos.y-dy
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--Cheak for placing big tree
|
|
|
|
|
pos.y = pos.y-1
|
|
|
|
|
for dz=0,1 do
|
|
|
|
|
pos.z = pos.z + dz
|
|
|
|
|
--> 0
|
2017-04-01 07:51:55 +03:00
|
|
|
|
local name = minetest.get_node(pos).name
|
|
|
|
|
if name == "mcl_core:dirt_with_grass"
|
|
|
|
|
or name == "mcl_core:dirt_with_grass_snow"
|
|
|
|
|
or name == "mcl_core:dirt" then else
|
2015-06-29 20:55:56 +03:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x+1
|
|
|
|
|
--> 1
|
2017-04-01 07:51:55 +03:00
|
|
|
|
if name == "mcl_core:dirt_with_grass"
|
|
|
|
|
or name == "mcl_core:dirt_with_grass_snow"
|
|
|
|
|
or name == "mcl_core:dirt" then else
|
2015-06-29 20:55:56 +03:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x-1
|
|
|
|
|
pos.z = pos.z - dz
|
|
|
|
|
end
|
|
|
|
|
pos.y = pos.y+1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Make tree with vine
|
|
|
|
|
node = {name = trunk}
|
|
|
|
|
for dy=0,tree_size do
|
|
|
|
|
pos.y = pos.y+dy
|
|
|
|
|
|
|
|
|
|
for dz=-1,2 do
|
|
|
|
|
if dz == -1 then
|
|
|
|
|
pos.z = pos.z + dz
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.add_node(pos, {name = "mcl_core:vine", param2 = 4})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x+1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.add_node(pos, {name = "mcl_core:vine", param2 = 4})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x-1
|
|
|
|
|
pos.z = pos.z - dz
|
|
|
|
|
elseif dz == 2 then
|
|
|
|
|
pos.z = pos.z + dz
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air"then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.add_node(pos, {name = "mcl_core:vine", param2 = 5})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x+1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.add_node(pos, {name = "mcl_core:vine", param2 = 5})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x-1
|
|
|
|
|
pos.z = pos.z - dz
|
|
|
|
|
else
|
|
|
|
|
pos.z = pos.z + dz
|
|
|
|
|
pos.x = pos.x-1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.add_node(pos, {name = "mcl_core:vine", param2 = 2})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x+1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" then
|
|
|
|
|
minetest.add_node(pos, {name = trunk, param2=2})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x+1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" then
|
|
|
|
|
minetest.add_node(pos, {name = trunk, param2=2})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x+1
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.add_node(pos, {name = "mcl_core:vine", param2 = 3})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x-2
|
|
|
|
|
pos.z = pos.z - dz
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
pos.y = pos.y-dy
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- make leaves
|
|
|
|
|
node = {name = leaves}
|
|
|
|
|
pos.y = pos.y+tree_size-4
|
2017-03-08 02:13:04 +03:00
|
|
|
|
for dx=-4,4 do
|
|
|
|
|
for dz=-4,4 do
|
2015-06-29 20:55:56 +03:00
|
|
|
|
for dy=0,3 do
|
|
|
|
|
pos.x = pos.x+dx
|
|
|
|
|
pos.y = pos.y+dy
|
|
|
|
|
pos.z = pos.z+dz
|
|
|
|
|
|
|
|
|
|
if dx == 0 and dz == 0 and dy==3 then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "mcl_core:vine" and math.random(1, 2) == 1 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
minetest.add_node(pos, node)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
elseif dx == 0 and dz == 0 and dy==4 then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "mcl_core:vine" and math.random(1, 5) == 1 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
minetest.add_node(pos, node)
|
2017-03-08 01:28:54 +03:00
|
|
|
|
minetest.add_node(pos, air_leaf(leaves))
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "mcl_core:vine" then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
minetest.add_node(pos, node)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
|
2017-02-01 01:32:56 +03:00
|
|
|
|
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "mcl_core:vine" and math.random(1, 3) == 1 then
|
2015-07-04 05:56:02 +03:00
|
|
|
|
minetest.add_node(pos, node)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
else
|
2015-07-04 05:56:02 +03:00
|
|
|
|
if math.random(1, 5) == 1 and minetest.get_node(pos).name == "air" then
|
|
|
|
|
minetest.add_node(pos, node)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
pos.x = pos.x-dx
|
|
|
|
|
pos.y = pos.y-dy
|
|
|
|
|
pos.z = pos.z-dz
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-05-26 03:16:41 +03:00
|
|
|
|
elseif typearbre == 3 then
|
|
|
|
|
mcl_core.generate_spruce_tree(pos)
|
2017-05-26 03:36:25 +03:00
|
|
|
|
elseif typearbre == 4 then
|
|
|
|
|
mcl_core.grow_new_acacia_tree(pos)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-26 03:16:41 +03:00
|
|
|
|
-- BEGIN of spruce tree generation functions --
|
|
|
|
|
-- Copied from Minetest Game 0.4.15 from the pine tree (default.generate_pine_tree)
|
|
|
|
|
|
|
|
|
|
-- Pine tree (=spruce tree in MCL2) from mg mapgen mod, design by sfan5, pointy top added by paramat
|
|
|
|
|
local function add_spruce_leaves(data, vi, c_air, c_ignore, c_snow, c_spruce_leaves)
|
|
|
|
|
local node_id = data[vi]
|
|
|
|
|
if node_id == c_air or node_id == c_ignore or node_id == c_snow then
|
|
|
|
|
data[vi] = c_spruce_leaves
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function mcl_core.generate_spruce_tree(pos)
|
|
|
|
|
local x, y, z = pos.x, pos.y, pos.z
|
|
|
|
|
local maxy = y + math.random(9, 13) -- Trunk top
|
|
|
|
|
|
|
|
|
|
local c_air = minetest.get_content_id("air")
|
|
|
|
|
local c_ignore = minetest.get_content_id("ignore")
|
|
|
|
|
local c_spruce_tree = minetest.get_content_id("mcl_core:sprucetree")
|
|
|
|
|
local c_spruce_leaves = minetest.get_content_id("mcl_core:spruceleaves")
|
|
|
|
|
local c_snow = minetest.get_content_id("mcl_core:snow")
|
|
|
|
|
|
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
|
local minp, maxp = vm:read_from_map(
|
|
|
|
|
{x = x - 3, y = y, z = z - 3},
|
|
|
|
|
{x = x + 3, y = maxy + 3, z = z + 3}
|
|
|
|
|
)
|
|
|
|
|
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
|
|
|
|
local data = vm:get_data()
|
|
|
|
|
|
|
|
|
|
-- Upper branches layer
|
|
|
|
|
local dev = 3
|
|
|
|
|
for yy = maxy - 1, maxy + 1 do
|
|
|
|
|
for zz = z - dev, z + dev do
|
|
|
|
|
local vi = a:index(x - dev, yy, zz)
|
|
|
|
|
local via = a:index(x - dev, yy + 1, zz)
|
|
|
|
|
for xx = x - dev, x + dev do
|
|
|
|
|
if math.random() < 0.95 - dev * 0.05 then
|
|
|
|
|
add_spruce_leaves(data, vi, c_air, c_ignore, c_snow,
|
|
|
|
|
c_spruce_leaves)
|
|
|
|
|
end
|
|
|
|
|
vi = vi + 1
|
|
|
|
|
via = via + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
dev = dev - 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Centre top nodes
|
|
|
|
|
add_spruce_leaves(data, a:index(x, maxy + 1, z), c_air, c_ignore, c_snow,
|
|
|
|
|
c_spruce_leaves)
|
|
|
|
|
add_spruce_leaves(data, a:index(x, maxy + 2, z), c_air, c_ignore, c_snow,
|
|
|
|
|
c_spruce_leaves) -- Paramat added a pointy top node
|
|
|
|
|
|
|
|
|
|
-- Lower branches layer
|
|
|
|
|
local my = 0
|
|
|
|
|
for i = 1, 20 do -- Random 2x2 squares of leaves
|
|
|
|
|
local xi = x + math.random(-3, 2)
|
|
|
|
|
local yy = maxy + math.random(-6, -5)
|
|
|
|
|
local zi = z + math.random(-3, 2)
|
|
|
|
|
if yy > my then
|
|
|
|
|
my = yy
|
|
|
|
|
end
|
|
|
|
|
for zz = zi, zi+1 do
|
|
|
|
|
local vi = a:index(xi, yy, zz)
|
|
|
|
|
local via = a:index(xi, yy + 1, zz)
|
|
|
|
|
for xx = xi, xi + 1 do
|
|
|
|
|
add_spruce_leaves(data, vi, c_air, c_ignore, c_snow,
|
|
|
|
|
c_spruce_leaves)
|
|
|
|
|
vi = vi + 1
|
|
|
|
|
via = via + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
dev = 2
|
|
|
|
|
for yy = my + 1, my + 2 do
|
|
|
|
|
for zz = z - dev, z + dev do
|
|
|
|
|
local vi = a:index(x - dev, yy, zz)
|
|
|
|
|
local via = a:index(x - dev, yy + 1, zz)
|
|
|
|
|
for xx = x - dev, x + dev do
|
|
|
|
|
if math.random() < 0.95 - dev * 0.05 then
|
|
|
|
|
add_spruce_leaves(data, vi, c_air, c_ignore, c_snow,
|
|
|
|
|
c_spruce_leaves)
|
|
|
|
|
end
|
|
|
|
|
vi = vi + 1
|
|
|
|
|
via = via + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
dev = dev - 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Trunk
|
|
|
|
|
-- Force-place lowest trunk node to replace sapling
|
|
|
|
|
data[a:index(x, y, z)] = c_spruce_tree
|
|
|
|
|
for yy = y + 1, maxy do
|
|
|
|
|
local vi = a:index(x, yy, z)
|
|
|
|
|
local node_id = data[vi]
|
|
|
|
|
if node_id == c_air or node_id == c_ignore or
|
|
|
|
|
node_id == c_spruce_leaves or node_id == c_snow then
|
|
|
|
|
data[vi] = c_spruce_tree
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
vm:set_data(data)
|
|
|
|
|
vm:write_to_map()
|
|
|
|
|
vm:update_map()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- END of spruce tree functions --
|
|
|
|
|
|
2017-05-26 03:36:25 +03:00
|
|
|
|
-- Acacia tree grow function from Minetest Game 0.4.15
|
|
|
|
|
function mcl_core.grow_new_acacia_tree(pos)
|
|
|
|
|
local path = minetest.get_modpath("mcl_core") ..
|
|
|
|
|
"/schematics/acacia_tree_from_sapling.mts"
|
|
|
|
|
minetest.place_schematic({x = pos.x - 4, y = pos.y - 1, z = pos.z - 4}, path, "random", nil, false)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2017-05-15 01:30:49 +03:00
|
|
|
|
local grass_spread_randomizer = PseudoRandom(minetest.get_mapgen_params().seed)
|
|
|
|
|
|
2015-06-29 20:55:56 +03:00
|
|
|
|
------------------------------
|
2017-05-14 00:32:43 +03:00
|
|
|
|
-- Spread grass blocks and mycelium on neighbor dirt
|
2015-06-29 20:55:56 +03:00
|
|
|
|
------------------------------
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:30:49 +03:00
|
|
|
|
label = "Grass Block and Mycelium spread",
|
2017-02-01 01:32:56 +03:00
|
|
|
|
nodenames = {"mcl_core:dirt"},
|
2017-05-14 00:32:43 +03:00
|
|
|
|
neighbors = {"air", "mcl_core:dirt_with_grass", "mcl_core:mycelium"},
|
2015-06-29 20:55:56 +03:00
|
|
|
|
interval = 30,
|
|
|
|
|
chance = 20,
|
2017-05-14 20:49:04 +03:00
|
|
|
|
catch_up = false,
|
2015-06-29 20:55:56 +03:00
|
|
|
|
action = function(pos)
|
2017-05-14 00:32:43 +03:00
|
|
|
|
if pos == nil then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local can_change = false
|
|
|
|
|
local above = {x=pos.x, y=pos.y+1, z=pos.z}
|
|
|
|
|
local abovenode = minetest.get_node(above)
|
2017-05-14 01:42:20 +03:00
|
|
|
|
local light_self = minetest.get_node_light(above)
|
|
|
|
|
if not light_self then return end
|
|
|
|
|
--[[ Try to find a spreading dirt-type block (e.g. grass block or mycelium)
|
2017-05-15 01:30:49 +03:00
|
|
|
|
within a 3×5×3 area, with the source block being on the 2nd-topmost layer. ]]
|
|
|
|
|
local nodes = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1}, {x=pos.x+1, y=pos.y+3, z=pos.z+1}, "group:spreading_dirt_type")
|
|
|
|
|
local p2
|
|
|
|
|
-- Nothing found ? Bail out!
|
|
|
|
|
if #nodes <= 0 then
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
p2 = nodes[grass_spread_randomizer:next(1, #nodes)]
|
2017-05-14 00:32:43 +03:00
|
|
|
|
end
|
|
|
|
|
|
2017-05-14 01:42:20 +03:00
|
|
|
|
-- Found it! Now check light levels!
|
|
|
|
|
local source_above = {x=p2.x, y=p2.y+1, z=p2.z}
|
|
|
|
|
local light_source = minetest.get_node_light(source_above)
|
|
|
|
|
if not light_source then return end
|
|
|
|
|
|
|
|
|
|
if light_self >= 4 and light_source >= 9 then
|
|
|
|
|
-- All checks passed! Let's spread the grass/mycelium!
|
|
|
|
|
local n2 = minetest.get_node(p2)
|
|
|
|
|
minetest.set_node(pos, {name=n2.name})
|
2017-05-14 00:32:43 +03:00
|
|
|
|
|
2017-05-14 01:42:20 +03:00
|
|
|
|
-- If this was mycelium, uproot plant above
|
|
|
|
|
if n2.name == "mcl_core:mycelium" then
|
|
|
|
|
local tad = minetest.registered_nodes[minetest.get_node(above).name]
|
|
|
|
|
if tad.groups and tad.groups.non_mycelium_plant then
|
|
|
|
|
minetest.dig_node(above)
|
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-05-14 00:32:43 +03:00
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
|
})
|
|
|
|
|
|
2017-05-14 03:23:46 +03:00
|
|
|
|
-- Grass/mycelium death in darkness
|
|
|
|
|
minetest.register_abm({
|
|
|
|
|
label = "Grass Block / Mycelium in darkness",
|
|
|
|
|
nodenames = {"group:spreading_dirt_type"},
|
|
|
|
|
interval = 8,
|
|
|
|
|
chance = 50,
|
|
|
|
|
catch_up = false,
|
|
|
|
|
action = function(pos, node)
|
|
|
|
|
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
|
|
|
|
local name = minetest.get_node(above).name
|
|
|
|
|
local nodedef = minetest.registered_nodes[name]
|
|
|
|
|
-- Kill grass/mycelium when below opaque block or liquid
|
|
|
|
|
if name ~= "ignore" and nodedef and ((nodedef.groups and nodedef.groups.opaque) or nodedef.liquidtype ~= "none") then
|
|
|
|
|
minetest.set_node(pos, {name = "mcl_core:dirt"})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
|
2017-05-14 23:44:34 +03:00
|
|
|
|
-- 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)
|
|
|
|
|
if minetest.get_item_group(newnode.name, "solid") ~= 0 then
|
|
|
|
|
local below = {x=pos.x, y=pos.y-1, z=pos.z}
|
|
|
|
|
local belownode = minetest.get_node(below)
|
|
|
|
|
if minetest.get_item_group(belownode.name, "dirtifies_below_solid") == 1 then
|
|
|
|
|
minetest.set_node(below, {name="mcl_core:dirt"})
|
2017-05-14 23:25:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-05-14 23:44:34 +03:00
|
|
|
|
end)
|
2017-05-14 03:23:46 +03:00
|
|
|
|
|
2017-05-14 23:58:37 +03:00
|
|
|
|
minetest.register_abm({
|
|
|
|
|
label = "Turn Grass Path below solid block into Dirt",
|
|
|
|
|
nodenames = {"mcl_core:grass_path"},
|
|
|
|
|
neighbors = {"group:solid"},
|
|
|
|
|
interval = 8,
|
|
|
|
|
chance = 50,
|
|
|
|
|
action = function(pos, node)
|
|
|
|
|
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
|
|
|
|
local name = minetest.get_node(above).name
|
|
|
|
|
local nodedef = minetest.registered_nodes[name]
|
|
|
|
|
if name ~= "ignore" and nodedef and (nodedef.groups and nodedef.groups.solid) then
|
|
|
|
|
minetest.set_node(pos, {name = "mcl_core:dirt"})
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
2015-06-29 20:55:56 +03:00
|
|
|
|
--------------------------
|
|
|
|
|
-- Try generate tree ---
|
|
|
|
|
--------------------------
|
2017-03-08 01:28:54 +03:00
|
|
|
|
local treelight = 9
|
|
|
|
|
|
2017-03-08 03:54:04 +03:00
|
|
|
|
local sapling_grow_action = function(trunknode, leafnode, tree_id, soil_needed)
|
|
|
|
|
return function(pos)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
local light = minetest.get_node_light(pos)
|
2017-01-12 09:07:30 +03:00
|
|
|
|
local soilnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
2017-01-12 23:01:01 +03:00
|
|
|
|
local soiltype = minetest.get_item_group(soilnode.name, "soil_sapling")
|
2017-03-08 03:54:04 +03:00
|
|
|
|
if soiltype >= soil_needed and light and light >= treelight then
|
2017-03-08 01:28:54 +03:00
|
|
|
|
-- Increase and check growth stage
|
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
local stage = meta:get_int("stage")
|
|
|
|
|
if stage == nil then stage = 0 end
|
|
|
|
|
stage = stage + 1
|
|
|
|
|
if stage == 2 then
|
|
|
|
|
minetest.set_node(pos, {name="air"})
|
2017-03-08 03:54:04 +03:00
|
|
|
|
mcl_core.generate_tree(pos, trunknode, leafnode, tree_id)
|
2017-03-08 01:28:54 +03:00
|
|
|
|
else
|
|
|
|
|
meta:set_int("stage", stage)
|
|
|
|
|
end
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
2017-03-08 03:54:04 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-04-01 03:29:36 +03:00
|
|
|
|
-- Attempts to grow the sapling at the specified position
|
|
|
|
|
-- pos: Position
|
|
|
|
|
-- node: Node table of the node at this position, from minetest.get_node
|
|
|
|
|
-- Returns true on success and false on failure
|
|
|
|
|
mcl_core.grow_sapling = function(pos, node)
|
|
|
|
|
local grow
|
|
|
|
|
if node.name == "mcl_core:sapling" then
|
|
|
|
|
grow = sapling_grow_action("mcl_core:tree", "mcl_core:leaves", 1, 1)
|
|
|
|
|
elseif node.name == "mcl_core:darksapling" then
|
|
|
|
|
grow = sapling_grow_action("mcl_core:darktree", "mcl_core:darkleaves", 1, 2)
|
|
|
|
|
elseif node.name == "mcl_core:junglesapling" then
|
|
|
|
|
grow = sapling_grow_action("mcl_core:jungletree", "mcl_core:jungleleaves", 1, 2)
|
|
|
|
|
elseif node.name == "mcl_core:acaciasapling" then
|
2017-05-26 03:36:25 +03:00
|
|
|
|
grow = sapling_grow_action("mcl_core:acaciatree", "mcl_core:acacialeaves", 4, 2)
|
2017-04-01 03:29:36 +03:00
|
|
|
|
elseif node.name == "mcl_core:sprucesapling" then
|
2017-05-26 03:16:41 +03:00
|
|
|
|
grow = sapling_grow_action("mcl_core:sprucetree", "mcl_core:spruceleaves", 3, 1)
|
2017-04-01 03:29:36 +03:00
|
|
|
|
elseif node.name == "mcl_core:birchsapling" then
|
|
|
|
|
grow = sapling_grow_action("mcl_core:birchtree", "mcl_core:birchleaves", 1, 1)
|
|
|
|
|
end
|
|
|
|
|
if grow then
|
|
|
|
|
grow(pos)
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-03-08 04:00:17 +03:00
|
|
|
|
-- TODO: Use better tree models for everything
|
|
|
|
|
-- TODO: Support 2×2 saplings
|
|
|
|
|
|
2017-03-08 03:54:04 +03:00
|
|
|
|
-- Oak tree
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Oak tree growth",
|
2017-03-08 03:54:04 +03:00
|
|
|
|
nodenames = {"mcl_core:sapling"},
|
|
|
|
|
neighbors = {"group:soil_sapling"},
|
|
|
|
|
interval = 20,
|
|
|
|
|
chance = 1,
|
|
|
|
|
action = sapling_grow_action("mcl_core:tree", "mcl_core:leaves", 1, 1),
|
2015-06-29 20:55:56 +03:00
|
|
|
|
})
|
|
|
|
|
|
2017-03-08 04:00:17 +03:00
|
|
|
|
-- Dark oak tree
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Dark oak tree growth",
|
2017-03-08 04:00:17 +03:00
|
|
|
|
nodenames = {"mcl_core:darksapling"},
|
|
|
|
|
neighbors = {"group:soil_sapling"},
|
|
|
|
|
interval = 20,
|
|
|
|
|
chance = 1,
|
|
|
|
|
action = sapling_grow_action("mcl_core:darktree", "mcl_core:darkleaves", 1, 2),
|
|
|
|
|
})
|
|
|
|
|
|
2015-06-29 20:55:56 +03:00
|
|
|
|
-- Jungle Tree
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Jungle tree growth",
|
2017-02-01 01:32:56 +03:00
|
|
|
|
nodenames = {"mcl_core:junglesapling"},
|
2017-01-12 09:07:30 +03:00
|
|
|
|
neighbors = {"group:soil_sapling"},
|
2017-03-08 00:55:49 +03:00
|
|
|
|
interval = 20,
|
2017-03-08 01:28:54 +03:00
|
|
|
|
chance = 1,
|
2017-03-08 03:54:04 +03:00
|
|
|
|
action = sapling_grow_action("mcl_core:jungletree", "mcl_core:jungleleaves", 1, 2)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
})
|
|
|
|
|
|
2017-03-08 04:00:17 +03:00
|
|
|
|
-- Spruce tree
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Spruce tree growth",
|
2017-03-08 04:00:17 +03:00
|
|
|
|
nodenames = {"mcl_core:sprucesapling"},
|
|
|
|
|
neighbors = {"group:soil_sapling"},
|
|
|
|
|
interval = 20,
|
|
|
|
|
chance = 1,
|
|
|
|
|
action = sapling_grow_action("mcl_core:sprucetree", "mcl_core:spruceleaves", 1, 1),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
-- Birch tree
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Birch tree growth",
|
2017-03-08 04:00:17 +03:00
|
|
|
|
nodenames = {"mcl_core:birchsapling"},
|
|
|
|
|
neighbors = {"group:soil_sapling"},
|
|
|
|
|
interval = 20,
|
|
|
|
|
chance = 1,
|
|
|
|
|
action = sapling_grow_action("mcl_core:birchtree", "mcl_core:birchleaves", 1, 1),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
-- Acacia tree
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Acacia tree growth",
|
2017-03-08 04:00:17 +03:00
|
|
|
|
nodenames = {"mcl_core:acaciasapling"},
|
|
|
|
|
neighbors = {"group:soil_sapling"},
|
|
|
|
|
interval = 20,
|
|
|
|
|
chance = 1,
|
|
|
|
|
action = sapling_grow_action("mcl_core:acaciatree", "mcl_core:acacialeaves", 1, 2),
|
|
|
|
|
})
|
|
|
|
|
|
2015-06-29 20:55:56 +03:00
|
|
|
|
---------------------
|
|
|
|
|
-- Vine generating --
|
|
|
|
|
---------------------
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Vines growth",
|
2017-02-01 01:32:56 +03:00
|
|
|
|
nodenames = {"mcl_core:vine"},
|
2015-06-29 20:55:56 +03:00
|
|
|
|
interval = 80,
|
|
|
|
|
chance = 5,
|
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
|
local newpos = {x=pos.x, y=pos.y-1, z=pos.z}
|
2015-07-04 05:56:02 +03:00
|
|
|
|
local n = minetest.get_node(newpos)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
if n.name == "air" then
|
2017-01-27 15:45:21 +03:00
|
|
|
|
local walldir = node.param2
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.add_node(newpos, {name = "mcl_core:vine", param2 = walldir})
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Leaf Decay
|
|
|
|
|
|
|
|
|
|
-- To enable leaf decay for a node, add it to the "leafdecay" group.
|
|
|
|
|
--
|
|
|
|
|
-- The rating of the group determines how far from a node in the group "tree"
|
|
|
|
|
-- the node can be without decaying.
|
|
|
|
|
--
|
|
|
|
|
-- If param2 of the node is ~= 0, the node will always be preserved. Thus, if
|
|
|
|
|
-- the player places a node of that kind, you will want to set param2=1 or so.
|
|
|
|
|
--
|
|
|
|
|
-- If the node is in the leafdecay_drop group then the it will always be dropped
|
|
|
|
|
-- as an item
|
|
|
|
|
|
2017-02-01 01:32:56 +03:00
|
|
|
|
mcl_core.leafdecay_trunk_cache = {}
|
|
|
|
|
mcl_core.leafdecay_enable_cache = true
|
2015-06-29 20:55:56 +03:00
|
|
|
|
-- Spread the load of finding trunks
|
2017-02-01 01:32:56 +03:00
|
|
|
|
mcl_core.leafdecay_trunk_find_allow_accumulator = 0
|
2015-06-29 20:55:56 +03:00
|
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
|
local finds_per_second = 5000
|
2017-02-01 01:32:56 +03:00
|
|
|
|
mcl_core.leafdecay_trunk_find_allow_accumulator =
|
2015-06-29 20:55:56 +03:00
|
|
|
|
math.floor(dtime * finds_per_second)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
minetest.register_abm({
|
2017-05-15 01:45:54 +03:00
|
|
|
|
label = "Leaf decay",
|
2015-06-29 20:55:56 +03:00
|
|
|
|
nodenames = {"group:leafdecay"},
|
|
|
|
|
neighbors = {"air", "group:liquid"},
|
|
|
|
|
-- A low interval and a high inverse chance spreads the load
|
|
|
|
|
interval = 2,
|
|
|
|
|
chance = 5,
|
|
|
|
|
|
|
|
|
|
action = function(p0, node, _, _)
|
|
|
|
|
local do_preserve = false
|
|
|
|
|
local d = minetest.registered_nodes[node.name].groups.leafdecay
|
|
|
|
|
if not d or d == 0 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local n0 = minetest.get_node(p0)
|
|
|
|
|
if n0.param2 ~= 0 then
|
2017-03-08 02:25:04 +03:00
|
|
|
|
-- Prevent leafdecay for player-placed leaves.
|
|
|
|
|
-- param2 is set to 1 after it was placed by the player
|
2015-06-29 20:55:56 +03:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local p0_hash = nil
|
2017-02-01 01:32:56 +03:00
|
|
|
|
if mcl_core.leafdecay_enable_cache then
|
2015-06-29 20:55:56 +03:00
|
|
|
|
p0_hash = minetest.hash_node_position(p0)
|
2017-02-01 01:32:56 +03:00
|
|
|
|
local trunkp = mcl_core.leafdecay_trunk_cache[p0_hash]
|
2015-06-29 20:55:56 +03:00
|
|
|
|
if trunkp then
|
|
|
|
|
local n = minetest.get_node(trunkp)
|
|
|
|
|
local reg = minetest.registered_nodes[n.name]
|
|
|
|
|
-- 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
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
-- Cache is invalid
|
2017-02-01 01:32:56 +03:00
|
|
|
|
table.remove(mcl_core.leafdecay_trunk_cache, p0_hash)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-02-01 01:32:56 +03:00
|
|
|
|
if mcl_core.leafdecay_trunk_find_allow_accumulator <= 0 then
|
2015-06-29 20:55:56 +03:00
|
|
|
|
return
|
|
|
|
|
end
|
2017-02-01 01:32:56 +03:00
|
|
|
|
mcl_core.leafdecay_trunk_find_allow_accumulator =
|
|
|
|
|
mcl_core.leafdecay_trunk_find_allow_accumulator - 1
|
2015-06-29 20:55:56 +03:00
|
|
|
|
-- Assume ignore is a trunk, to make the thing work at the border of the active area
|
|
|
|
|
local p1 = minetest.find_node_near(p0, d, {"ignore", "group:tree"})
|
|
|
|
|
if p1 then
|
|
|
|
|
do_preserve = true
|
2017-02-01 01:32:56 +03:00
|
|
|
|
if mcl_core.leafdecay_enable_cache then
|
2015-06-29 20:55:56 +03:00
|
|
|
|
-- Cache the trunk
|
2017-02-01 01:32:56 +03:00
|
|
|
|
mcl_core.leafdecay_trunk_cache[p0_hash] = p1
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if not do_preserve then
|
|
|
|
|
-- Drop stuff other than the node itself
|
2015-07-04 05:56:02 +03:00
|
|
|
|
local itemstacks = minetest.get_node_drops(n0.name)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
for _, itemname in ipairs(itemstacks) do
|
|
|
|
|
if minetest.get_item_group(n0.name, "leafdecay_drop") ~= 0 or
|
|
|
|
|
itemname ~= n0.name then
|
|
|
|
|
local p_drop = {
|
|
|
|
|
x = p0.x - 0.5 + math.random(),
|
|
|
|
|
y = p0.y - 0.5 + math.random(),
|
|
|
|
|
z = p0.z - 0.5 + math.random(),
|
|
|
|
|
}
|
|
|
|
|
minetest.add_item(p_drop, itemname)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- Remove node
|
|
|
|
|
minetest.remove_node(p0)
|
2017-01-26 21:14:07 +03:00
|
|
|
|
core.check_for_falling(p0)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
------------------------
|
|
|
|
|
-- Create Color Glass --
|
|
|
|
|
------------------------
|
2017-05-15 21:42:23 +03:00
|
|
|
|
function mcl_core.add_glass(desc, recipeitem, colorgroup, color)
|
2015-06-29 20:55:56 +03:00
|
|
|
|
|
2017-02-01 01:32:56 +03:00
|
|
|
|
minetest.register_node("mcl_core:glass_"..color, {
|
2015-06-29 20:55:56 +03:00
|
|
|
|
description = desc,
|
2017-03-11 03:51:06 +03:00
|
|
|
|
_doc_items_longdesc = "Stained glass is a decorational and mostly transparent block which comes in various different colors.",
|
2015-06-29 20:55:56 +03:00
|
|
|
|
drawtype = "glasslike",
|
2017-01-05 00:36:51 +03:00
|
|
|
|
is_ground_content = false,
|
2017-01-16 15:00:20 +03:00
|
|
|
|
tiles = {"xpanes_pane_glass_"..color..".png"},
|
2017-01-04 14:50:23 +03:00
|
|
|
|
inventory_image = minetest.inventorycube("xpanes_pane_glass_"..color..".png"),
|
2015-06-29 20:55:56 +03:00
|
|
|
|
paramtype = "light",
|
2017-05-15 02:16:30 +03:00
|
|
|
|
sunlight_propagates = "true",
|
2015-06-29 20:55:56 +03:00
|
|
|
|
use_texture_alpha = true,
|
|
|
|
|
stack_max = 64,
|
2017-05-15 21:42:23 +03:00
|
|
|
|
-- TODO: Add color to groups
|
2017-03-11 07:34:58 +03:00
|
|
|
|
groups = {handy=1, glass=1, building_block=1, material_glass=1},
|
2017-02-11 20:46:23 +03:00
|
|
|
|
sounds = mcl_sounds.node_sound_glass_defaults(),
|
2015-06-29 20:55:56 +03:00
|
|
|
|
drop = "",
|
2017-02-22 17:40:22 +03:00
|
|
|
|
_mcl_blast_resistance = 1.5,
|
2017-02-24 17:56:46 +03:00
|
|
|
|
_mcl_hardness = 0.3,
|
2015-06-29 20:55:56 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2017-02-01 01:32:56 +03:00
|
|
|
|
output = 'mcl_core:glass_'..color..' 8',
|
2015-06-29 20:55:56 +03:00
|
|
|
|
recipe = {
|
2017-02-01 01:32:56 +03:00
|
|
|
|
{'mcl_core:glass','mcl_core:glass','mcl_core:glass'},
|
2017-05-15 21:42:23 +03:00
|
|
|
|
{'mcl_core:glass',recipeitem,'mcl_core:glass'},
|
2017-02-01 01:32:56 +03:00
|
|
|
|
{'mcl_core:glass','mcl_core:glass','mcl_core:glass'},
|
2015-06-29 20:55:56 +03:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|