ethereal/sealife.lua

469 lines
12 KiB
Lua
Raw Normal View History

2023-08-14 10:08:04 +03:00
local S = ethereal.translate
2016-06-09 17:08:34 +03:00
2014-11-09 22:17:41 +03:00
-- Seaweed
minetest.register_node("ethereal:seaweed", {
2016-06-09 17:08:34 +03:00
description = S("Seaweed"),
2014-11-09 22:17:41 +03:00
drawtype = "plantlike",
tiles = {"ethereal_seaweed.png"},
inventory_image = "ethereal_seaweed.png",
wield_image = "ethereal_seaweed.png",
2014-11-09 22:17:41 +03:00
paramtype = "light",
walkable = false,
climbable = true,
drowning = 1,
2015-07-04 14:22:39 +03:00
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
},
post_effect_color = {a = 64, r = 100, g = 100, b = 200},
2018-03-12 21:40:36 +03:00
groups = {food_seaweed = 1, snappy = 3, flammable = 3},
2014-11-09 22:17:41 +03:00
on_use = minetest.item_eat(1),
sounds = default.node_sound_leaves_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local pname = placer:get_player_name()
local pos = pointed_thing.above
local pos_up = {x = pos.x, y = pos.y + 1, z = pos.z}
local pos_down = {x = pos.x, y = pos.y - 1, z = pos.z}
local def_up = minetest.registered_nodes[minetest.get_node(pos_up).name] or {}
local def_down = minetest.registered_nodes[minetest.get_node(pos_down).name] or {}
if def_up.liquidtype == nil or def_up.liquidtype ~= "none" then
if minetest.is_protected(pos, pname) then
return
end
if def_down.name ~= "default:sand" then
return
end
if minetest.get_node(pos_up).name == "default:water_source" then
minetest.set_node(pos_down, {name = "ethereal:seaweed_rooted",
param2 = 16})
if not ethereal.check_creative(pname) then
itemstack:take_item()
end
end
return itemstack
end
return minetest.item_place_node(itemstack, placer, pointed_thing)
end
})
minetest.register_node("ethereal:seaweed_rooted", {
description = S("Seaweed"),
drop = "ethereal:seaweed",
drawtype = "plantlike_rooted",
tiles = {"default_sand.png"},
special_tiles = {{name = "ethereal_seaweed.png", tileable_vertical = true}},
inventory_image = "ethereal_seaweed.png",
wield_image = "ethereal_seaweed.png",
paramtype = "light",
paramtype2 = "leveled",
walkable = false,
climbable = true,
drowning = 1,
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- sand node
{-0.3, 0.5, -0.3, 0.3, 3.5, 0.3} -- seaweed
}
},
post_effect_color = {a = 64, r = 100, g = 100, b = 200},
groups = {food_seaweed = 1, snappy = 3, flammable = 3, not_in_creative_inventory = 1},
on_use = minetest.item_eat(1),
sounds = default.node_sound_leaves_defaults(),
after_dig_node = function(pos, node, metadata, digger)
minetest.set_node(pos, {name = "default:sand"})
end,
on_place = function(itemstack, placer, pointed_thing) -- do not place rooted seaweed
return itemstack
end,
on_dig = function(pos, node, digger)
local p2 = node.param2 or 16
2024-01-23 12:15:07 +03:00
local num = math.max(1, math.floor(p2 / 16))
local inv = digger and digger:get_inventory()
if not inv then return end
local stack = ItemStack("ethereal:seaweed " .. tonumber(num))
local leftover = inv:add_item("main", stack)
local count = leftover:get_count()
minetest.set_node(pos, {name = "default:sand"})
if count > 0 then
pos.y = pos.y + 1
minetest.add_item(pos, "ethereal:seaweed " .. tonumber(count))
end
end
2014-11-09 22:17:41 +03:00
})
minetest.register_lbm({
label = "[ethereal] Upgrade seaweed",
name = "ethereal:upgrade_seaweed",
nodenames = {"ethereal:seaweed"},
run_at_every_load = false,
action = function(pos, node)
local pos_up = {x = pos.x, y = pos.y + 1, z = pos.z}
local pos_down = {x = pos.x, y = pos.y - 1, z = pos.z}
local def_up = minetest.registered_nodes[minetest.get_node(pos_up).name] or {}
local def_down = minetest.registered_nodes[minetest.get_node(pos_down).name] or {}
if def_up.name == "ethereal:seaweed"
and (def_down.name == "default:sand" or def_down.name == "ethereal:sandy") then
local height = 0
while height < 14
and minetest.get_node(pos_up).name == "ethereal:seaweed" do
minetest.remove_node(pos_up)
height = height + 1
pos_up.y = pos_up.y + 1
end
minetest.remove_node(pos)
minetest.set_node(pos_down, {name = "ethereal:seaweed_rooted",
param2 = (height + 1) * 16})
end
end
2014-11-09 22:17:41 +03:00
})
-- seaweed to d.green dye
minetest.register_craft( {
output = "dye:dark_green 3",
recipe = {{"ethereal:seaweed"}}
})
2018-05-31 11:35:27 +03:00
-- agar powder
minetest.register_craftitem("ethereal:agar_powder", {
description = S("Agar Powder"),
inventory_image = "ethereal_agar_powder.png",
groups = {food_gelatin = 1, flammable = 2}
2018-05-31 11:35:27 +03:00
})
minetest.register_craft({
output = "ethereal:agar_powder 3",
recipe = {
{"group:food_seaweed", "group:food_seaweed", "group:food_seaweed"},
{"bucket:bucket_water", "bucket:bucket_water", "default:torch"},
{"bucket:bucket_water", "bucket:bucket_water", "default:torch"}
2018-05-31 11:35:27 +03:00
},
replacements = {
{"bucket:bucket_water", "bucket:bucket_empty 4"}
}
2018-05-31 11:35:27 +03:00
})
-- Corals
local coral_nodes = {}
local function register_coral(name, description, texture)
local function plantlike_on_place(itemstack, placer, pointed_thing)
local pname = placer:get_player_name()
local pos = pointed_thing.above
local pos_up = {x = pos.x, y = pos.y + 1, z = pos.z}
local pos_down = {x = pos.x, y = pos.y - 1, z = pos.z}
local def_up = minetest.registered_nodes[minetest.get_node(pos_up).name] or {}
local def_down = minetest.registered_nodes[minetest.get_node(pos_down).name] or {}
if def_up.liquidtype == nil or def_up.liquidtype ~= "none" then
if minetest.is_protected(pos, pname) then
return
end
if def_down.name ~= "default:sand" then
return
end
minetest.set_node(pos_down, {name = "ethereal:" .. name .. "_rooted"})
if not ethereal.check_creative(pname) then
itemstack:take_item()
end
return itemstack
end
return minetest.item_place_node(itemstack, placer, pointed_thing)
end
local function rooted_on_dig(pos, node, digger)
local res = minetest.node_dig(pos, node, digger)
if res == true then
minetest.set_node(pos, {name = "default:sand"})
end
return res
end
minetest.register_node("ethereal:" .. name, {
description = description,
drawtype = "plantlike",
tiles = {texture},
inventory_image = texture,
wield_image = texture,
paramtype = "light",
selection_box = {
type = "fixed",
fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, 1 / 4, 6 / 16}
},
light_source = 3,
groups = {snappy = 3},
sounds = default.node_sound_leaves_defaults(),
on_place = plantlike_on_place
})
minetest.register_node("ethereal:" .. name .. "_rooted", {
description = description,
drop = "ethereal:" .. name,
drawtype = "plantlike_rooted",
tiles = {"default_sand.png"},
special_tiles = {{name = texture, tileable_vertical = true}},
inventory_image = texture,
wield_image = texture,
paramtype = "light",
selection_box = {
type = "fixed",
fixed = {-6 / 16, 0.5, -6 / 16, 6 / 16, 1.25, 6 / 16}
},
light_source = 3,
groups = {snappy = 3, not_in_creative_inventory = 1},
sounds = default.node_sound_leaves_defaults(),
on_dig = rooted_on_dig
})
table.insert(coral_nodes, "ethereal:" .. name)
end
minetest.register_lbm({
label = "[ethereal] Upgrade corals",
name = "ethereal:upgrade_corals",
nodenames = coral_nodes,
run_at_every_load = false,
action = function(pos, node)
local pos_up = {x = pos.x, y = pos.y + 1, z = pos.z}
local pos_down = {x = pos.x, y = pos.y - 1, z = pos.z}
local def_up = minetest.registered_nodes[minetest.get_node(pos_up).name] or {}
local def_down = minetest.registered_nodes[minetest.get_node(pos_down).name] or {}
if (def_up.liquidtype == nil or def_up.liquidtype ~= "none")
2024-01-23 18:41:11 +03:00
and (def_down.name == "default:sand" or def_down.name == "ethereal:sandy") then
minetest.set_node(pos_down, {name = node.name .. "_rooted"})
minetest.remove_node(pos)
end
end
2014-11-09 22:17:41 +03:00
})
-- Blua Coral
register_coral("coral2", S("Blue Glow Coral"), "ethereal_coral_blue.png")
2014-11-09 22:17:41 +03:00
minetest.register_craft( {
output = "dye:cyan 3",
recipe = {{"ethereal:coral2"}}
2014-11-09 22:17:41 +03:00
})
2014-11-09 22:17:41 +03:00
-- Orange Coral
register_coral("coral3", S("Orange Glow Coral"), "ethereal_coral_orange.png")
2014-11-09 22:17:41 +03:00
minetest.register_craft( {
output = "dye:orange 3",
recipe = {{"ethereal:coral3"}}
2014-11-09 22:17:41 +03:00
})
2014-11-09 22:17:41 +03:00
-- Pink Coral
register_coral("coral4", S("Pink Glow Coral"), "ethereal_coral_pink.png")
2014-11-09 22:17:41 +03:00
minetest.register_craft( {
output = "dye:pink 3",
recipe = {{"ethereal:coral4"}}
2014-11-09 22:17:41 +03:00
})
2014-11-09 22:17:41 +03:00
-- Green Coral
register_coral("coral5", S("Green Glow Coral"), "ethereal_coral_green.png")
2014-11-09 22:17:41 +03:00
minetest.register_craft( {
output = "dye:green 3",
recipe = {{"ethereal:coral5"}}
2014-11-09 22:17:41 +03:00
})
-- Undersea Sand (used for growing seaweed and corals)
2014-11-09 22:17:41 +03:00
minetest.register_node("ethereal:sandy", {
2016-06-09 17:08:34 +03:00
description = S("Sandy"),
2014-11-09 22:17:41 +03:00
tiles = {"default_sand.png"},
is_ground_content = true,
2015-07-04 14:22:39 +03:00
groups = {
crumbly = 3, falling_node = 1, sand = 1, not_in_creative_inventory = 1
2015-07-04 14:22:39 +03:00
},
2014-11-09 22:17:41 +03:00
drop = "default:sand",
sounds = default.node_sound_sand_defaults()
2014-11-09 22:17:41 +03:00
})
-- randomly generate coral or seaweed and have seaweed grow up to 14 high
if ethereal.sealife == 1 then
minetest.register_abm({
label = "Grow coral/seaweed",
nodenames = {"ethereal:sandy", "ethereal:seaweed_rooted"},
neighbors = {"group:water"},
interval = 15,
chance = 10,
catch_up = false,
action = function(pos, node)
2014-11-09 22:17:41 +03:00
local sel = math.random(6)
local pos_up = {x = pos.x, y = pos.y + 1, z = pos.z}
local nod = minetest.get_node(pos_up).name
if node.name == "ethereal:seaweed_rooted" then
local height = 0
while height < 14
and minetest.get_node(pos_up).name == "default:water_source" do
height = height + 1
pos_up.y = pos_up.y + 1
end
2020-02-28 22:42:00 +03:00
if height < 3 or height > 14 then
return
end
2020-02-28 22:42:00 +03:00
minetest.set_node(pos, {name = "ethereal:seaweed_rooted",
param2 = (height - 1) * 16})
elseif nod == "default:water_source" then
if sel == 1 then
2024-01-23 18:41:11 +03:00
minetest.set_node(pos, {name = "ethereal:seaweed_rooted",
param2 = 16})
2014-11-09 22:17:41 +03:00
elseif sel == 6 then
2024-01-23 18:41:11 +03:00
minetest.set_node(pos_up, {name = "ethereal:sponge_wet"})
2014-11-09 22:17:41 +03:00
elseif sel > 1 then
2014-11-09 22:17:41 +03:00
2024-01-23 18:41:11 +03:00
minetest.set_node(pos, {name = "ethereal:coral" .. sel .. "_rooted"})
end
2014-11-09 22:17:41 +03:00
end
end
})
end
2020-02-28 22:42:00 +03:00
-- sponge nodes
2020-02-28 22:42:00 +03:00
minetest.register_node("ethereal:sponge_air", {
drawtype = "airlike",
paramtype = "light",
walkable = false,
buildable_to = true,
sunlight_propagates = true,
pointable = false,
drop = "",
groups = {not_in_creative_inventory = 1}
2020-02-28 22:42:00 +03:00
})
minetest.register_node("ethereal:sponge_wet", {
description = S("Wet sponge"),
tiles = {"ethereal_sponge_wet.png"},
groups = {crumbly = 3},
sounds = default.node_sound_sand_defaults()
})
2020-02-28 22:42:00 +03:00
minetest.register_node("ethereal:sponge", {
description = S("Sponge"),
tiles = {"ethereal_sponge.png"},
groups = {crumbly = 3},
sounds = default.node_sound_sand_defaults(),
after_place_node = function(pos, placer, itemstack, pointed_thing)
-- get player name
local name = placer:get_player_name()
-- is area protected
if minetest.is_protected(pos, name) then
return
end
-- get water nodes within range
local num = minetest.find_nodes_in_area(
{x = pos.x - 3, y = pos.y - 3, z = pos.z - 3},
2024-01-23 18:41:11 +03:00
{x = pos.x + 3, y = pos.y + 3, z = pos.z + 3}, {"group:water"})
2020-02-28 22:42:00 +03:00
-- no water
if #num == 0 then return end
-- replace water nodes with sponge air
for _, w in pairs(num) do
if not minetest.is_protected(pos, name) then
2024-01-23 18:41:11 +03:00
minetest.set_node(w, {name = "ethereal:sponge_air"})
2020-02-28 22:42:00 +03:00
end
end
-- replace dry sponge with wet sponge
2024-01-23 18:41:11 +03:00
minetest.set_node(pos, {name = "ethereal:sponge_wet"})
2020-02-28 22:42:00 +03:00
end
})
-- cook wet sponge into dry sponge
minetest.register_craft({
type = "cooking",
recipe = "ethereal:sponge_wet",
output = "ethereal:sponge",
cooktime = 3
2020-02-28 22:42:00 +03:00
})
-- use leaf decay to remove sponge air nodes
default.register_leafdecay({
trunks = {"ethereal:sponge_wet"},
leaves = {"ethereal:sponge_air"},
radius = 3
})
-- dry sponges can be used as fuel
minetest.register_craft({
type = "fuel",
recipe = "ethereal:sponge",
burntime = 5
2020-02-28 22:42:00 +03:00
})