2021-06-28 22:10:28 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2024-10-14 18:44:58 -04:00
|
|
|
local core, math, nc
|
|
|
|
= core, math, nc
|
2021-12-15 07:22:05 -05:00
|
|
|
local math_random
|
|
|
|
= math.random
|
2021-06-28 22:10:28 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2024-10-14 18:44:58 -04:00
|
|
|
local modname = core.get_current_modname()
|
2021-06-28 22:10:28 -04:00
|
|
|
|
|
|
|
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
|
2022-02-27 21:25:40 -05:00
|
|
|
local sedgename = modname .. ":sedge_" .. i
|
|
|
|
allsedges[sedgename] = i
|
|
|
|
allsedges[i] = sedgename
|
2021-12-03 22:41:39 -05:00
|
|
|
local h = (i == 5) and (3/4) or (i / 8)
|
2024-10-14 18:44:58 -04:00
|
|
|
core.register_node(sedgename, {
|
2021-06-28 22:10:28 -04:00
|
|
|
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,
|
2023-11-01 18:55:48 -04:00
|
|
|
peat_grindable_item = 1,
|
|
|
|
optic_opaque = i == 5 and 1 or nil,
|
2021-06-28 22:10:28 -04:00
|
|
|
},
|
2024-10-14 18:44:58 -04:00
|
|
|
sounds = nc.sounds("nc_terrain_grassy"),
|
|
|
|
selection_box = nc.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,
|
2022-02-27 21:25:40 -05:00
|
|
|
after_place_node = function(pos)
|
2024-10-14 18:44:58 -04:00
|
|
|
local node = core.get_node(pos)
|
2022-02-27 21:25:40 -05:00
|
|
|
if node.name ~= sedgename then return end
|
2023-01-01 12:49:48 -05:00
|
|
|
local r = math_random(1, 15)
|
|
|
|
if r >= 8 then
|
2022-02-27 21:25:40 -05:00
|
|
|
node.name = modname .. ":sedge_1"
|
2021-12-15 07:22:05 -05:00
|
|
|
elseif r >= 4 then
|
2023-01-01 12:49:48 -05:00
|
|
|
node.name = modname .. ":sedge_2"
|
2021-12-15 07:22:05 -05:00
|
|
|
elseif r >= 2 then
|
2023-01-01 12:49:48 -05:00
|
|
|
node.name = modname .. ":sedge_3"
|
2021-12-15 07:22:05 -05:00
|
|
|
else
|
2023-01-01 12:49:48 -05:00
|
|
|
node.name = modname .. ":sedge_4"
|
2021-12-15 07:22:05 -05:00
|
|
|
end
|
2022-02-27 21:25:40 -05:00
|
|
|
if node.name == sedgename then return end
|
2024-10-14 18:44:58 -04:00
|
|
|
nc.set_node_check(pos, node)
|
2023-12-02 14:27:00 -05:00
|
|
|
end,
|
|
|
|
mapcolor = {r = 80, g = 106, b = 50, a = 128},
|
2021-06-28 22:10:28 -04:00
|
|
|
})
|
|
|
|
|
2024-10-14 18:44:58 -04:00
|
|
|
core.register_decoration({
|
2021-06-28 22:10:28 -04:00
|
|
|
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
|
|
|
|
|
2024-10-14 18:44:58 -04:00
|
|
|
nc.register_on_nodeupdate({
|
Selective register_on_nodeupdate API
The old API simply registered functions, which listened for all
events and received all parameters. This was inefficient because:
- Not all calls actually used the "node" parameter, so if we don't
need it, and the event that triggers the notification doesn't
provide one, we used to have to do a get_node for it.
- A lot of things that can change a node in the world can't
actually cause certain things to change. For example,
remove_node can never cause a cookable node to be in a position
for a recipe check (and making plain air cookable would not
be sane).
Allowing us to selectively ignore certain events, and to indicate
that we aren't using the "node" param so the API doesn't need to go
out of its way to provide it, should make a lot of things more
efficient.
The biggest problems we were seeing were when a lot of liquids were
transforming due to "pumhell" deep underground, where pumice
freezing and melting causes constant reflows of pumwater. This is
an intentional game mechanic to make those areas dangerous to
explore or try to develop without taming them, but the only notify
callback we really need to trigger is the optic revalidation one,
which should just be checking for indexed beams to reevaluate and
finding none in most cases. We were seeing a ton of lag when in
these areas, leading to the hypothesis that it's all the other
unnecessary checks that causes this slowdown.
2024-09-05 07:15:28 -04:00
|
|
|
ignore = {
|
|
|
|
stack_set = true,
|
|
|
|
add_node = true,
|
|
|
|
place_node = true,
|
|
|
|
add_node_level = true,
|
|
|
|
liquid_transformed = true,
|
|
|
|
},
|
|
|
|
getnode = true,
|
|
|
|
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}
|
2024-10-14 18:44:58 -04:00
|
|
|
node = core.get_node(above)
|
|
|
|
if allsedges[node.name] then return core.remove_node(above) end
|
Selective register_on_nodeupdate API
The old API simply registered functions, which listened for all
events and received all parameters. This was inefficient because:
- Not all calls actually used the "node" parameter, so if we don't
need it, and the event that triggers the notification doesn't
provide one, we used to have to do a get_node for it.
- A lot of things that can change a node in the world can't
actually cause certain things to change. For example,
remove_node can never cause a cookable node to be in a position
for a recipe check (and making plain air cookable would not
be sane).
Allowing us to selectively ignore certain events, and to indicate
that we aren't using the "node" param so the API doesn't need to go
out of its way to provide it, should make a lot of things more
efficient.
The biggest problems we were seeing were when a lot of liquids were
transforming due to "pumhell" deep underground, where pumice
freezing and melting causes constant reflows of pumwater. This is
an intentional game mechanic to make those areas dangerous to
explore or try to develop without taming them, but the only notify
callback we really need to trigger is the optic revalidation one,
which should just be checking for indexed beams to reevaluate and
finding none in most cases. We were seeing a ton of lag when in
these areas, leading to the hypothesis that it's all the other
unnecessary checks that causes this slowdown.
2024-09-05 07:15:28 -04:00
|
|
|
end
|
|
|
|
})
|
2021-06-28 22:10:28 -04:00
|
|
|
|
2024-10-14 18:44:58 -04:00
|
|
|
core.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}
|
2024-10-14 18:44:58 -04:00
|
|
|
local bnode = core.get_node_or_nil(below)
|
2021-06-28 22:10:28 -04:00
|
|
|
if not bnode then return end
|
2021-12-26 09:13:09 -05:00
|
|
|
if bnode.name ~= grassname
|
2024-10-14 18:44:58 -04:00
|
|
|
or not nc.can_grass_grow_under(pos) then
|
|
|
|
return core.remove_node(pos)
|
2021-06-28 22:10:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local lv = allsedges[node.name]
|
|
|
|
local grow = lv and allsedges[lv + 1]
|
|
|
|
if grow then
|
2024-10-14 18:44:58 -04:00
|
|
|
if #nc.find_nodes_around(pos, "group:moist", {2, 1, 2}) < 1
|
2024-09-10 20:47:43 +00:00
|
|
|
then return end
|
|
|
|
|
2024-10-14 18:44:58 -04:00
|
|
|
nc.set_loud(pos, {name = grow, param2 = 2})
|
|
|
|
return nc.witness(pos, "sedge growth")
|
2021-06-28 22:10:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
2022-01-15 12:03:28 -05:00
|
|
|
|
2024-10-14 18:44:58 -04:00
|
|
|
nc.register_on_peat_compost(function(pos)
|
2022-01-15 12:03:28 -05:00
|
|
|
if math_random(1, 10) ~= 1 then return end
|
|
|
|
|
2024-10-14 18:44:58 -04:00
|
|
|
if core.get_node(pos).name ~= grassname then return end
|
2022-01-15 12:03:28 -05:00
|
|
|
|
|
|
|
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
2024-10-14 18:44:58 -04:00
|
|
|
if not (nc.air_equivalent(above)
|
|
|
|
and nc.can_grass_grow_under(above)
|
|
|
|
and #nc.find_nodes_around(above, "group:moist", {2, 1, 2}) > 0)
|
2022-01-15 12:03:28 -05:00
|
|
|
then return end
|
|
|
|
|
2024-10-14 18:44:58 -04:00
|
|
|
nc.set_loud(above, {name = modname .. ":sedge_1", param2 = 2})
|
2022-01-15 12:03:28 -05:00
|
|
|
end)
|