water_life/flora/corals.lua
2022-07-10 13:19:00 +02:00

130 lines
3.6 KiB
Lua

local function coral_on_place(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" or not placer then
return itemstack
end
local player_name = placer:get_player_name()
local pos_under = pointed_thing.under
local pos_above = pointed_thing.above
local node_under = minetest.get_node(pos_under)
local def_under = minetest.registered_nodes[node_under.name]
if def_under and def_under.on_rightclick and not placer:get_player_control().sneak then
return def_under.on_rightclick(pos_under, node_under,
placer, itemstack, pointed_thing) or itemstack
end
if node_under.name ~= "default:coral_skeleton" or
minetest.get_node(pos_above).name ~= "default:water_source" then
return itemstack
end
if minetest.is_protected(pos_under, player_name) or
minetest.is_protected(pos_above, player_name) then
minetest.log("action", player_name
.. " tried to place " .. itemstack:get_name()
.. " at protected position "
.. minetest.pos_to_string(pos_under))
minetest.record_protection_violation(pos_under, player_name)
return itemstack
end
node_under.name = itemstack:get_name()
minetest.set_node(pos_under, node_under)
if not (creative and creative.is_enabled_for(player_name)) then
itemstack:take_item()
end
return itemstack
end
-- NODES
minetest.register_node("water_life:coralmagenta", {
description = "Magenta Coral",
drawtype = "plantlike_rooted",
waving = 1,
paramtype = "light",
tiles = {"default_coral_skeleton.png"},
special_tiles = {{name = "water_life_coralmagenta.png", tileable_vertical = true}},
inventory_image = "water_life_coralmagenta.png",
groups = {snappy = 3},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
{-4/16, 0.5, -4/16, 4/16, 1.5, 4/16},
},
},
node_dig_prediction = "default:coral_skeleton",
node_placement_prediction = "",
sounds = default.node_sound_stone_defaults({
dig = {name = "default_dig_snappy", gain = 0.2},
dug = {name = "default_grass_footstep", gain = 0.25},
}),
on_place = coral_on_place,
after_destruct = function(pos, oldnode)
minetest.set_node(pos, {name = "default:coral_skeleton"})
end,
})
minetest.register_node("water_life:coralskyblue", {
description = "Skyblue Coral",
drawtype = "plantlike_rooted",
waving = 1,
paramtype = "light",
tiles = {"default_coral_skeleton.png"},
special_tiles = {{name = "water_life_coralskyblue.png", tileable_vertical = true}},
inventory_image = "water_life_coralskyblue.png",
groups = {snappy = 3},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
{-4/16, 0.5, -4/16, 4/16, 1.5, 4/16},
},
},
node_dig_prediction = "default:coral_skeleton",
node_placement_prediction = "",
sounds = default.node_sound_stone_defaults({
dig = {name = "default_dig_snappy", gain = 0.2},
dug = {name = "default_grass_footstep", gain = 0.25},
}),
on_place = coral_on_place,
after_destruct = function(pos, oldnode)
minetest.set_node(pos, {name = "default:coral_skeleton"})
end,
})
minetest.register_decoration({
name = ":default:corals",
deco_type = "simple",
place_on = {"default:sand"},
place_offset_y = -1,
sidelen = 4,
noise_params = {
offset = -4,
scale = 4,
spread = {x = 50, y = 50, z = 50},
seed = 7013,
octaves = 3,
persist = 0.7,
},
biomes = {
"desert_ocean",
"savanna_ocean",
"rainforest_ocean",
},
y_max = -2,
y_min = -8,
flags = "force_placement",
decoration = {
"default:coral_green", "default:coral_pink",
"default:coral_cyan", "default:coral_brown",
"default:coral_orange", "default:coral_skeleton",
"water_life:coralmagenta", "water_life:coralskyblue"
},
})