2021-06-28 22:10:28 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2021-12-15 07:22:05 -05:00
|
|
|
local math, minetest, nodecore
|
|
|
|
= math, minetest, nodecore
|
|
|
|
local math_random
|
|
|
|
= math.random
|
2021-06-28 22:10:28 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
|
|
|
local grassname = "nc_terrain:dirt_with_grass"
|
|
|
|
|
|
|
|
local sedge1 = modname .. ":sedge_1"
|
|
|
|
local droprates = {
|
|
|
|
{{items = {sedge1}, rarity = 16}},
|
|
|
|
{{items = {sedge1}, rarity = 8}},
|
|
|
|
{{items = {sedge1}, rarity = 4}},
|
2021-12-13 23:28:26 -05:00
|
|
|
{{items = {sedge1}, rarity = 2}},
|
2021-11-27 13:36:08 -05:00
|
|
|
{
|
2021-12-13 23:28:26 -05:00
|
|
|
{items = {sedge1 .. " 2"}, rarity = 2},
|
2021-11-27 13:45:42 -05:00
|
|
|
{items = {sedge1}, rarity = 1}
|
2021-11-27 13:36:08 -05:00
|
|
|
}
|
2021-06-28 22:10:28 -04:00
|
|
|
}
|
|
|
|
|
2021-07-01 18:34:53 -04:00
|
|
|
local tilebase = modname .. "_sedge_color.png^(nc_terrain_grass_top.png^[mask:"
|
|
|
|
.. modname .. "_grass_mask.png)"
|
|
|
|
|
2021-06-28 22:10:28 -04:00
|
|
|
local allsedges = {}
|
|
|
|
for i = 1, 5 do
|
|
|
|
allsedges[modname .. ":sedge_" .. i] = i
|
|
|
|
allsedges[i] = modname .. ":sedge_" .. i
|
2021-12-03 22:41:39 -05:00
|
|
|
local h = (i == 5) and (3/4) or (i / 8)
|
2021-06-28 22:10:28 -04:00
|
|
|
minetest.register_node(modname .. ":sedge_" .. i, {
|
|
|
|
description = "Sedge",
|
|
|
|
drawtype = "plantlike",
|
|
|
|
waving = 1,
|
|
|
|
inventory_image = modname .. "_sedge_item.png",
|
|
|
|
wield_image = modname .. "_sedge_item.png",
|
|
|
|
tiles = {
|
|
|
|
tilebase .. "^[mask:" .. modname
|
|
|
|
.. "_sedge_mask" .. i .. ".png"
|
|
|
|
},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "meshoptions",
|
|
|
|
place_param2 = 2,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
floodable = true,
|
|
|
|
groups = {
|
|
|
|
snappy = 1,
|
|
|
|
flora = 1,
|
2021-11-21 00:48:14 -05:00
|
|
|
flora_sedges = i,
|
2021-09-06 10:17:39 -04:00
|
|
|
flora_dry = 1,
|
2021-06-28 22:10:28 -04:00
|
|
|
flammable = 3,
|
2021-12-16 20:47:13 -05:00
|
|
|
attached_node = 1,
|
|
|
|
peat_grindable_item = 1
|
2021-06-28 22:10:28 -04:00
|
|
|
},
|
2021-11-27 15:48:27 -05:00
|
|
|
sounds = nodecore.sounds("nc_terrain_grassy"),
|
2021-06-28 22:10:28 -04:00
|
|
|
selection_box = nodecore.fixedbox(
|
2021-12-03 22:41:39 -05:00
|
|
|
{-3/8, -1/2, -3/8, 3/8, -1/2 + h, 3/8}
|
2021-06-28 22:10:28 -04:00
|
|
|
),
|
|
|
|
stack_family = modname .. ":sedge_1",
|
2021-11-27 13:45:42 -05:00
|
|
|
drop = {max_items = 1, items = droprates[i]},
|
2021-12-15 07:22:05 -05:00
|
|
|
destroy_on_dig = 20,
|
|
|
|
on_place = function(stack, ...)
|
|
|
|
local old = stack:get_name()
|
|
|
|
local r = math_random(1, 31)
|
|
|
|
if r >= 16 then
|
|
|
|
stack:set_name(modname .. ":sedge_1")
|
|
|
|
elseif r >= 8 then
|
|
|
|
stack:set_name(modname .. ":sedge_2")
|
|
|
|
elseif r >= 4 then
|
|
|
|
stack:set_name(modname .. ":sedge_3")
|
|
|
|
elseif r >= 2 then
|
|
|
|
stack:set_name(modname .. ":sedge_4")
|
|
|
|
else
|
|
|
|
stack:set_name(modname .. ":sedge_5")
|
|
|
|
end
|
|
|
|
stack = minetest.item_place(stack, ...)
|
|
|
|
if not stack:is_empty() then
|
|
|
|
stack:set_name(old)
|
|
|
|
end
|
|
|
|
return stack
|
|
|
|
end
|
2021-06-28 22:10:28 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_decoration({
|
|
|
|
name = modname .. ":sedge_" .. i,
|
|
|
|
deco_type = "simple",
|
|
|
|
place_on = {grassname},
|
|
|
|
sidelen = 1,
|
|
|
|
noise_params = {
|
|
|
|
offset = -0.05,
|
|
|
|
scale = 0.1,
|
|
|
|
spread = {x = 100, y = 100, z = 100},
|
|
|
|
seed = 1572,
|
|
|
|
octaves = 3,
|
|
|
|
persist = 0.7
|
|
|
|
},
|
|
|
|
decoration = {modname .. ":sedge_" .. i},
|
|
|
|
param2 = 2,
|
|
|
|
})
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
nodecore.register_on_nodeupdate(function(pos, node)
|
|
|
|
if node.name == "nc_terrain:dirt_with_grass" then return end
|
|
|
|
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
|
|
|
node = minetest.get_node(above)
|
|
|
|
if allsedges[node.name] then return minetest.remove_node(above) end
|
|
|
|
end)
|
|
|
|
|
2021-07-10 11:09:44 -04:00
|
|
|
minetest.register_abm({
|
2021-06-28 22:10:28 -04:00
|
|
|
label = "sedge growth/death",
|
|
|
|
interval = 2,
|
|
|
|
chance = 250,
|
2021-12-18 11:28:14 -05:00
|
|
|
arealoaded = 1,
|
2021-06-28 22:10:28 -04:00
|
|
|
nodenames = {"group:flora_sedges"},
|
|
|
|
action = function(pos, node)
|
|
|
|
local below = {x = pos.x, y = pos.y - 1, z = pos.z}
|
|
|
|
local bnode = minetest.get_node_or_nil(below)
|
|
|
|
if not bnode then return end
|
2021-12-26 09:13:09 -05:00
|
|
|
if bnode.name ~= grassname
|
|
|
|
or not nodecore.can_grass_grow_under(pos) then
|
2021-06-28 22:10:28 -04:00
|
|
|
return minetest.remove_node(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
if #nodecore.find_nodes_around(pos, "group:moist", {2, 1, 2}) < 1
|
|
|
|
then return end
|
|
|
|
|
|
|
|
local lv = allsedges[node.name]
|
|
|
|
local grow = lv and allsedges[lv + 1]
|
|
|
|
if grow then
|
2021-07-05 11:34:33 -04:00
|
|
|
nodecore.set_loud(pos, {name = grow, param2 = 2})
|
|
|
|
return nodecore.witness(pos, "sedge growth")
|
2021-06-28 22:10:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|