Code: Select all
minetest.register_node("ws_core:cattail", {
description = "Cattail",
drawtype = "plantlike_rooted",
waving = 1,
tiles = {"ws_cattail_bottom.png"},
special_tiles = {{name = "ws_sandy_dirt.png", tileable_vertical = true}},
inventory_image = "ws_cattail_plant.png",
paramtype = "light",
paramtype2 = "leveled",
is_ground_content = false,
groups = {cracky = 1, level = 2},
walkable = true,
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
{-0.1, 0.5, -0.1, 0.1, 2.0, 0.1}
}
},
node_dig_prediction = "ws_core:toxic_water_source",
node_placement_prediction = "ws_core:cattail_bottom",
sounds = ws_core.node_sound_metal_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local depth,sytpe,surface = ws_core.water_depth(pos,20) -- max must be specified and >12 or buoys will always be set
if surface then
local height = depth-1
pos = surface
pos.y = pos.y - height
local pos_top = surface--{x = pos.x, y = pos.y + height, z = pos.z}
local node_top = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
local def_top = minetest.registered_nodes[node_top.name]
local player_name = placer:get_player_name()
if def_top and def_top.liquidtype == "source" and height > 1 and height < 11 and minetest.get_item_group(node_top.name, "water") > 0 then
if not minetest.is_protected(pos, player_name) and not minetest.is_protected(pos_top, player_name) then
minetest.set_node(pos, {name = "ws_core:cattail_bottom",param2 = height * 2 })
local meta = minetest.get_meta(pos)
meta:set_int("cattail", height)
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
end
return itemstack
end,
on_destruct = function(pos)
local meta=minetest.get_meta(pos)
if meta then
local height = meta:get_int("buoy")
if height then
local cpos = {x=pos.x, y= pos.y + height, z=pos.z}
local object = minetest.get_objects_inside_radius(cpos, 1)
for _,obj in ipairs(object) do
local entity = obj:get_luaentity()
if entity and entity.name == "ws_core:cattail_top" then
obj:remove()
end
end
end
end
end,
})
minetest.register_node("ws_core:cattail_bottom", {
description = ("Cattail"),
drawtype = "plantlike_rooted",
waving = 1,
paramtype = "light",
tiles = {"ws_cattail_bottom.png"},
special_tiles = {{name = "ws_cattail_bottom.png", tileable_vertical = true}},
inventory_image = "ws_cattail_plant.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 = "ws_core:cattail_bottom",
node_placement_prediction = "",
sounds = ws_core.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 = "ws_core:cattail_bottom"})
end,
on_construct = function(pos)
local above = vector.new(pos)
above.y = above.y + 1
minetest.set_node(above, {name = "ws_core:cattail_top"})
end,
})
minetest.register_node("ws_core:cattail_top", {
description = ("Cattail"),
drawtype = "plantlike_rooted",
waving = 1,
paramtype = "light",
tiles = {"ws_cattail_top.png"},
special_tiles = {{name = "ws_cattail_top.png", tileable_vertical = true}},
inventory_image = "ws_cattail_plant.png",
groups = {snappy = 3, not_in_creative_inventory = 1},
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 = "ws_core:cattail_top",
node_placement_prediction = "",
sounds = ws_core.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 = "ws_core:cattail_bottom"})
end,
})
Code: Select all
minetest.register_lbm({
label = "Grow cattails in water",
name = "ws_core:cattail",
nodenames = {"ws_core:toxic_water_source"},
run_at_every_load = false,
action = function(pos, node)
if math.random(6) == 1 then
local under = vector.new(pos)
under.y = under.y - 1
local node_under = minetest.registered_nodes[minetest.get_node(under).name]
if node_under and node_under.walkable then
minetest.set_node(pos, {name = "ws_core:cattail_bottom"})
end
end
end,
})