2021-05-29 14:12:33 +00:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
|
|
|
local mod_doc = minetest.get_modpath("doc")
|
2019-12-17 18:52:19 +00:00
|
|
|
|
2019-12-17 19:39:58 +00:00
|
|
|
-- List of supported surfaces for seagrass
|
|
|
|
local surfaces = {
|
|
|
|
{ "dirt", "mcl_core:dirt" },
|
2019-12-17 20:24:57 +00:00
|
|
|
{ "sand", "mcl_core:sand", 1 },
|
|
|
|
{ "redsand", "mcl_core:redsand", 1 },
|
|
|
|
{ "gravel", "mcl_core:gravel", 1 },
|
2019-12-17 19:39:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 18:52:19 +00:00
|
|
|
local function seagrass_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 node_above = minetest.get_node(pos_above)
|
|
|
|
local def_under = minetest.registered_nodes[node_under.name]
|
|
|
|
local def_above = minetest.registered_nodes[node_above.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 pos_under.y >= pos_above.y then
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Placement rules:
|
|
|
|
-- Seagrass can only be placed on top of dirt inside water
|
|
|
|
local g_above_water = minetest.get_item_group(node_above.name, "water")
|
|
|
|
if not (g_above_water ~= 0 and def_above.liquidtype == "source") then
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2023-01-12 19:22:36 +00:00
|
|
|
if mcl_util.check_area_protection(pos_under, pos_above, placer) then
|
2019-12-17 18:52:19 +00:00
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2019-12-17 20:43:30 +00:00
|
|
|
-- Select a seagrass node
|
2019-12-17 19:39:58 +00:00
|
|
|
if node_under.name == "mcl_core:dirt" then
|
|
|
|
node_under.name = "mcl_ocean:seagrass_dirt"
|
2019-12-17 20:43:30 +00:00
|
|
|
elseif node_under.name == "mcl_core:sand" then
|
|
|
|
node_under.name = "mcl_ocean:seagrass_sand"
|
|
|
|
elseif node_under.name == "mcl_core:redsand" then
|
|
|
|
node_under.name = "mcl_ocean:seagrass_redsand"
|
|
|
|
elseif node_under.name == "mcl_core:gravel" then
|
|
|
|
node_under.name = "mcl_ocean:seagrass_gravel"
|
2019-12-17 19:39:58 +00:00
|
|
|
else
|
2019-12-17 18:52:19 +00:00
|
|
|
return itemstack
|
|
|
|
end
|
2019-12-17 21:43:35 +00:00
|
|
|
node_under.param2 = minetest.registered_items[node_under.name].place_param2 or 3
|
2019-12-17 18:52:19 +00:00
|
|
|
if node_under.param2 < 8 and math.random(1,2) == 1 then
|
|
|
|
-- Random horizontal displacement
|
|
|
|
node_under.param2 = node_under.param2 + 8
|
|
|
|
end
|
2019-12-17 20:43:30 +00:00
|
|
|
local def_node = minetest.registered_items[node_under.name]
|
|
|
|
if def_node.sounds then
|
2020-04-06 22:55:45 +00:00
|
|
|
minetest.sound_play(def_node.sounds.place, { gain = 0.5, pos = pos_under }, true)
|
2019-12-17 20:43:30 +00:00
|
|
|
end
|
2019-12-17 18:52:19 +00:00
|
|
|
minetest.set_node(pos_under, node_under)
|
2020-07-10 14:08:40 +00:00
|
|
|
if not minetest.is_creative_enabled(player_name) then
|
2019-12-17 18:52:19 +00:00
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2019-12-17 19:39:58 +00:00
|
|
|
minetest.register_craftitem("mcl_ocean:seagrass", {
|
2019-12-17 18:52:19 +00:00
|
|
|
description = S("Seagrass"),
|
2020-03-08 02:18:47 +00:00
|
|
|
_tt_help = S("Grows in water on dirt, sand, gravel"),
|
2019-12-18 02:42:18 +00:00
|
|
|
_doc_items_create_entry = false,
|
2022-12-08 17:37:14 +00:00
|
|
|
inventory_image = "mcl_ocean_seagrass_item.png",
|
|
|
|
wield_image = "mcl_ocean_seagrass_item.png",
|
2019-12-17 18:52:19 +00:00
|
|
|
on_place = seagrass_on_place,
|
Add `compostability` to node definition group.
* mcl_cake/init.lua (cake);
* mcl_core/craftitems.lua (apple);
* mcl_core/nodes_base.lua (dirt with grass);
* mcl_core/nodes_cactuscane.lua (cactus, sugarcane);
* mcl_core/nodes_climb.lua (vines);
* mcl_core/nodes_trees.lua (leaves, saplings);
* mcl_dye/init.lua (cocoa beans);
* mcl_farming/beetroot.lua (beetroot, & seeds);
* mcl_farming/carrots.lua (carrot);
* mcl_farming/melon.lua (melon, & slice, & seeds);
* mcl_farming/potatoes.lua (potato, baked potato);
* mcl_farming/pumpkin.lua (pumpkin, carved &, & seeds, & pie);
* mcl_farming/wheat.lua (wheat, cookie, bread, hay block);
* mcl_flowers/init.lua (flowers, ferns, grass, & tall variants);
* mcl_mushrooms/small.lua (red and brown mushrooms);
* mcl_mushrooms/huge.lua (red and brown huge mushrooms);
* mcl_nether/init.lua (nether wart block);
* mcl_nether/nether_wart.lua (nether wart);
* mcl_ocean/kelp.lua (kelp, dried &, & block);
* mcl_ocean/sea_pickle.lua (sea pickle);
* mcl_ocean/seagrass.lua (seagrass).
2022-03-29 10:54:51 +00:00
|
|
|
groups = {deco_block = 1, compostability = 30},
|
2019-12-17 18:52:19 +00:00
|
|
|
})
|
2019-12-17 19:39:58 +00:00
|
|
|
|
|
|
|
-- Seagrass nodes: seagrass on a surface node
|
|
|
|
|
|
|
|
for s=1, #surfaces do
|
|
|
|
local def = minetest.registered_nodes[surfaces[s][2]]
|
2019-12-17 20:24:57 +00:00
|
|
|
local alt
|
|
|
|
if surfaces[s][3] == 1 then
|
|
|
|
alt = surfaces[s][2]
|
|
|
|
end
|
2019-12-17 20:43:30 +00:00
|
|
|
local sounds = table.copy(def.sounds)
|
|
|
|
local leaf_sounds = mcl_sounds.node_sound_leaves_defaults()
|
|
|
|
sounds.dig = leaf_sounds.dig
|
|
|
|
sounds.dug = leaf_sounds.dug
|
|
|
|
sounds.place = leaf_sounds.place
|
2020-03-08 02:18:47 +00:00
|
|
|
local doc_longdesc, doc_img, desc
|
2019-12-18 02:42:18 +00:00
|
|
|
if surfaces[s][1] == "dirt" then
|
2019-12-18 03:28:47 +00:00
|
|
|
doc_longdesc = S("Seagrass grows inside water on top of dirt, sand or gravel.")
|
2019-12-18 02:42:18 +00:00
|
|
|
desc = S("Seagrass")
|
|
|
|
doc_create = true
|
2022-12-08 17:37:14 +00:00
|
|
|
doc_img = "mcl_ocean_seagrass_item.png"
|
2019-12-18 02:42:18 +00:00
|
|
|
else
|
|
|
|
doc_create = false
|
|
|
|
end
|
2019-12-17 19:39:58 +00:00
|
|
|
minetest.register_node("mcl_ocean:seagrass_"..surfaces[s][1], {
|
2019-12-18 02:42:18 +00:00
|
|
|
_doc_items_entry_name = desc,
|
|
|
|
_doc_items_longdesc = doc_longdesc,
|
|
|
|
_doc_items_create_entry = doc_create,
|
2021-05-22 21:12:33 +00:00
|
|
|
_doc_items_image = doc_img,
|
2019-12-17 19:39:58 +00:00
|
|
|
drawtype = "plantlike_rooted",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "meshoptions",
|
2023-02-19 08:21:39 +00:00
|
|
|
param2 = 3,
|
2019-12-17 19:39:58 +00:00
|
|
|
tiles = def.tiles,
|
|
|
|
special_tiles = {
|
|
|
|
{
|
|
|
|
image = "mcl_ocean_seagrass.png",
|
|
|
|
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length=1.0},
|
|
|
|
}
|
|
|
|
},
|
2022-12-08 17:37:14 +00:00
|
|
|
inventory_image = "mcl_ocean_seagrass_item.png",
|
|
|
|
wield_image = "mcl_ocean_seagrass_item.png",
|
2019-12-17 19:39:58 +00:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
|
|
|
{ -0.5, 0.5, -0.5, 0.5, 1.3, 0.5 },
|
|
|
|
},
|
|
|
|
},
|
2019-12-18 02:42:18 +00:00
|
|
|
groups = { handy = 1, shearsy = 1, deco_block = 1, plant = 1, seagrass = 1, falling_node = surfaces[s][3], not_in_creative_inventory = 1 },
|
2019-12-17 20:43:30 +00:00
|
|
|
sounds = sounds,
|
2019-12-17 19:39:58 +00:00
|
|
|
node_dig_prediction = surfaces[s][2],
|
2019-12-17 20:24:57 +00:00
|
|
|
after_dig_node = function(pos)
|
|
|
|
minetest.set_node(pos, {name=surfaces[s][2]})
|
2019-12-17 19:39:58 +00:00
|
|
|
end,
|
|
|
|
drop = "",
|
2019-12-17 20:24:57 +00:00
|
|
|
_mcl_falling_node_alternative = alt,
|
2019-12-18 02:10:49 +00:00
|
|
|
_mcl_shears_drop = { "mcl_ocean:seagrass" },
|
2019-12-17 19:39:58 +00:00
|
|
|
_mcl_hardness = 0,
|
|
|
|
_mcl_blast_resistance = 0,
|
|
|
|
})
|
2019-12-18 11:43:17 +00:00
|
|
|
if mod_doc and surfaces[s][1] ~= "dirt" then
|
2019-12-18 02:42:18 +00:00
|
|
|
doc.add_entry_alias("nodes", "mcl_ocean:seagrass_dirt", "nodes", "mcl_ocean:seagrass_"..surfaces[s][1])
|
|
|
|
end
|
2019-12-17 19:39:58 +00:00
|
|
|
end
|
2019-12-18 02:42:18 +00:00
|
|
|
|
2019-12-18 11:43:17 +00:00
|
|
|
if mod_doc then
|
|
|
|
doc.add_entry_alias("nodes", "mcl_ocean:seagrass_dirt", "craftitems", "mcl_ocean:seagrass")
|
|
|
|
end
|
2023-02-19 08:21:39 +00:00
|
|
|
|
|
|
|
minetest.register_lbm({
|
|
|
|
label = "Fix incorrect seagrass",
|
|
|
|
name = "mcl_ocean:fix_incorrect_seagrass",
|
|
|
|
nodenames = {"group:seagrass"},
|
|
|
|
run_at_every_load = false,
|
|
|
|
action = function(pos, node)
|
|
|
|
if node.param2 ~= 3 then
|
|
|
|
node.param2 = 3
|
|
|
|
minetest.set_node(pos, node)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_on_generated(function(minp, maxp, blockseed)
|
|
|
|
local seagrass = minetest.find_nodes_in_area(minp, maxp, {"group:seagrass"})
|
|
|
|
for _, sgpos in pairs(seagrass) do
|
|
|
|
local sgnode = minetest.get_node(sgpos)
|
|
|
|
if sgnode.param2 ~= 3 then
|
|
|
|
sgnode.param2 = 3
|
|
|
|
minetest.set_node(sgpos, sgnode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|