1
0
mirror of https://github.com/mt-mods/plantlife_modpack.git synced 2024-11-14 14:20:40 +01:00
plantlife_modpack/poisonivy/init.lua

138 lines
3.9 KiB
Lua
Raw Normal View History

2013-01-25 05:21:57 +01:00
-- This file supplies poison ivy for the plantlife modpack
-- support for i18n
local S = minetest.get_translator("poisonivy")
2014-03-12 19:36:42 +01:00
2013-01-25 05:21:57 +01:00
local walls_list = {
"default:dirt",
"default:dirt_with_grass",
"default:stone",
"default:cobble",
"default:mossycobble",
"default:brick",
"default:tree",
"default:jungletree",
"default:stone_with_coal",
"default:stone_with_iron"
}
2013-01-25 05:21:57 +01:00
minetest.register_node('poisonivy:seedling', {
2014-03-12 19:36:42 +01:00
description = S("Poison ivy (seedling)"),
2013-01-25 05:21:57 +01:00
drawtype = 'plantlike',
waving = 1,
2015-10-23 19:08:58 +02:00
tiles = { 'poisonivy_seedling.png' },
2013-01-25 05:21:57 +01:00
inventory_image = 'poisonivy_seedling.png',
wield_image = 'poisonivy_seedling.png',
sunlight_propagates = true,
paramtype = 'light',
walkable = false,
groups = { snappy = 3, poisonivy=1, flora_block=1, attached_node=1 },
2013-01-25 05:21:57 +01:00
sounds = default.node_sound_leaves_defaults(),
buildable_to = true,
2013-01-25 05:21:57 +01:00
})
minetest.register_node('poisonivy:sproutling', {
2014-03-12 19:36:42 +01:00
description = S("Poison ivy (sproutling)"),
2013-01-25 05:21:57 +01:00
drawtype = 'plantlike',
waving = 1,
2015-10-23 19:08:58 +02:00
tiles = { 'poisonivy_sproutling.png' },
2013-01-25 05:21:57 +01:00
inventory_image = 'poisonivy_sproutling.png',
wield_image = 'poisonivy_sproutling.png',
sunlight_propagates = true,
paramtype = 'light',
walkable = false,
groups = { snappy = 3, poisonivy=1, flora_block=1, attached_node=1 },
2013-01-25 05:21:57 +01:00
sounds = default.node_sound_leaves_defaults(),
buildable_to = true,
2013-01-25 05:21:57 +01:00
})
minetest.register_node('poisonivy:climbing', {
2014-03-12 19:36:42 +01:00
description = S("Poison ivy (climbing plant)"),
2013-01-25 05:21:57 +01:00
drawtype = 'signlike',
2015-10-23 19:08:58 +02:00
tiles = { 'poisonivy_climbing.png' },
2013-01-25 05:21:57 +01:00
inventory_image = 'poisonivy_climbing.png',
wield_image = 'poisonivy_climbing.png',
sunlight_propagates = true,
paramtype = 'light',
paramtype2 = 'wallmounted',
walkable = false,
groups = { snappy = 3, poisonivy=1, flora_block=1, attached_node=1 },
2013-01-25 05:21:57 +01:00
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "wallmounted",
--wall_side = = <default>
},
buildable_to = true,
2013-01-25 05:21:57 +01:00
})
local function find_adjacent_wall(pos, verticals, randomflag)
local verts = dump(verticals)
if string.find(verts, minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z }).name) then return 3 end
if string.find(verts, minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z }).name) then return 2 end
if string.find(verts, minetest.get_node({x=pos.x , y=pos.y, z=pos.z-1}).name) then return 5 end
if string.find(verts, minetest.get_node({x=pos.x , y=pos.y, z=pos.z+1}).name) then return 4 end
return nil
end
minetest.register_abm({
nodenames = {"default:dirt_with_grass"},
interval = 1000,
chance = 20,
label = "[poisoninvy] spawn plants",
min_y = -16,
max_y = 48,
action = function(pos, node)
local p_top = {x = pos.x, y = pos.y + 1, z = pos.z}
local n_top = minetest.get_node_or_nil(p_top)
if not n_top or n_top.name ~= "air" then return end
local n_light = minetest.get_node_light(p_top)
if n_light < 7 then
return
end
2013-01-25 05:21:57 +01:00
if minetest.find_node_near(p_top, 10 + math.random(-1.5,2), {"group:poisonivy", "group:flower"}) then
return -- Nodes to avoid are nearby
end
local walldir = find_adjacent_wall(p_top, walls_list)
if walldir then
minetest.swap_node(p_top, {name = "poisonivy:climbing", param2 = walldir})
return
end
minetest.swap_node(p_top, {name = "poisonivy:seedling", param2 = 0})
end
2013-01-25 05:21:57 +01:00
})
minetest.register_abm({
nodenames = {"poisonivy:seedling"},
interval = 1000,
chance = 30,
label = "grow poisonivy",
action = function(pos, node)
local p_top = {x=pos.x, y=pos.y+1, z=pos.z}
local n_top = minetest.get_node(p_top)
if n_top.name == "air" then
minetest.swap_node(pos, {name = "poisonivy:sproutling"})
end
end
2013-01-25 05:21:57 +01:00
})
minetest.register_abm({
nodenames = {"poisonivy:climbing"},
interval = 500,
chance = 60,
label = "grow climbing poisonivy",
action = function(pos, node)
local p_top = {x=pos.x, y=pos.y+1, z=pos.z}
local n_top = minetest.get_node(p_top)
local walldir = find_adjacent_wall(p_top, walls_list)
if n_top.name == "air" and walldir then
minetest.swap_node(p_top, {name = "poisonivy:climbing", param2 = walldir})
end
end
})