nalc/nalc_flowers/init.lua

104 lines
3.0 KiB
Lua
Raw Normal View History

local lilypad_def = table.copy(minetest.registered_nodes["flowers:waterlily"])
lilypad_def.description = "Lily Pad"
lilypad_def.tiles = {"flowers_lily_pad.png"}
lilypad_def.inventory_image = "flowers_lily_pad.png"
lilypad_def.wield_image = "flowers_lily_pad.png"
lilypad_def.on_place = function(itemstack, placer, pointed_thing)
2018-09-30 11:41:45 +02:00
local pos = pointed_thing.above
local node = minetest.get_node(pointed_thing.under)
local def = minetest.registered_nodes[node.name]
if def and def.on_rightclick then
return def.on_rightclick(pointed_thing.under, node, placer, itemstack,
pointed_thing)
end
if def and def.liquidtype == "source" and
minetest.get_item_group(node.name, "water") > 0 then
local player_name = placer and placer:get_player_name() or ""
2018-09-30 11:41:45 +02:00
if not minetest.is_protected(pos, player_name) then
minetest.set_node(pos, {name = "nalc_flowers:lily_pad" ..
(def.waving == 3 and "_waving" or ""),
param2 = math.random(0, 3)})
2018-09-30 11:41:45 +02:00
if not (creative and creative.is_enabled_for
and creative.is_enabled_for(player_name)) then
itemstack:take_item()
end
else
minetest.chat_send_player(player_name, "Node is protected")
minetest.record_protection_violation(pos, player_name)
end
end
return itemstack
end
local lilypad_waving_def = table.copy(lilypad_def)
lilypad_waving_def.waving = 3
lilypad_waving_def.drop = "nalc_flowers:lily_pad"
lilypad_waving_def.groups.not_in_creative_inventory = 1
minetest.register_node("nalc_flowers:lily_pad", lilypad_def)
minetest.register_node("nalc_flowers:lily_pad_waving", lilypad_waving_def)
2018-09-30 11:41:45 +02:00
local function lily_pad_spread(pos, node)
if minetest.get_node_light(pos, nil) < 9 then
return
end
local positions = minetest.find_nodes_in_area_under_air(
{x = pos.x - 1, y = pos.y-1, z = pos.z - 1},
{x = pos.x + 1, y = pos.y-1, z = pos.z + 1},
{"default:water_source"})
if #positions == 0 then return end
local pos2 = positions[math.random(#positions)]
pos2.y = pos2.y+1
if minetest.get_node_light(pos2, nil) >= 9 then
minetest.set_node(pos2, {name = node.name})
end
end
-- spawn ABM registration
minetest.register_abm({
label = "Lilypad spread",
nodenames = {"nalc_flowers:lily_pad_waving"},
neighbors = {"default:jungletree"},
interval = 600,
chance = 5,
action = function(...)
lily_pad_spread(...)
end,
})
minetest.register_decoration({
name = "nalc_flowers:lily_pad",
deco_type = "simple",
place_on = {"default:dirt"},
sidelen = 16,
noise_params = {
offset = -0.12,
scale = 0.3,
spread = {x=200, y=200, z=200},
seed = 34,
octaves = 3,
persist = 0.7
},
biomes = {"rainforest_swamp"},
y_min = 0,
y_max = 0,
decoration = "nalc_flowers:lily_pad_waving",
param2 = 0,
param2_max = 3,
place_offset_y = 1,
})
2018-09-30 11:41:45 +02:00
minetest.register_alias("flowers:lily_pad", "nalc_flowers:lily_pad")
2019-02-05 22:42:03 +01:00
minetest.register_alias("nalc:lily_pad", "nalc_flowers:lily_pad")
2018-09-30 11:41:45 +02:00
-- Correction d'alias
minetest.register_alias("mushroom:poison", "flowers:mushroom_red")
2018-09-30 11:41:45 +02:00
minetest.log("action", "[nalc_flowers] loaded.")