1
0
Fork 0

Update + reformat based on VoxeLibre recommendations

main
Bram van den Heuvel 2024-09-04 18:07:13 +02:00
parent 2b33d45a60
commit 4d6044c4bf
1 changed files with 48 additions and 48 deletions

92
api.lua
View File

@ -45,38 +45,6 @@ local WIDTH_NAMES = {
-- Internal table that lets us define functions without directly exposing them.
local internal = {}
-- Add a droplet catcher, which is a node that allows a stalactite spike to
-- change the name using a droplet.
function internal.register_droplet_catcher(droplet, oldnodename, newnodename)
if CAULDRONS[droplet] == nil then
internal.uninitialized_droplet_error(droplet)
end
CAULDRONS[droplet][oldnodename] = newnodename
end
function internal.register_droplet_source(droplet, nodename)
if SOURCES[droplet] == nil then
internal.uninitialized_droplet_error(droplet)
end
table.insert(SOURCES[droplet], nodename)
-- If the node can emit an infinite number of droplets,
-- it can also absorb an infinite number of droplets.
internal.register_droplet_catcher(droplet, oldnodename, newnodename)
end
-- Add a droplet trickler, which is a dripstone node that allows a droplet to
-- be trickled down from the node directly above it.
-- Running this function overrides previous values.
function internal.add_droplet_trickler(droplet, oldnodename, newnodename)
if TRICKLERS[droplet] == nil then
internal.uninitialized_droplet_error(droplet)
end
TRICKLERS[droplet][oldnodename] = newnodename
end
-- Capitalize a string
function internal.capitalize(str)
return (str:gsub("^%l", string.upper))
@ -107,11 +75,7 @@ end
-- Determine whether this mod considers a node an air node.
function internal.is_air(nodename)
if nodename == "air" then
return true
else
return minetest.get_item_group(nodename, "air") ~= 0
end
return (nodename == "air") or (minetest.get_item_group(nodename, "air") ~= 0)
end
-- Create a node box for any given dripstone size.
@ -190,7 +154,7 @@ function internal.register_dripstone_flavor(flavor, def)
-- Allow dripstone nodes to trickle down droplets
for droplet, new_flavor in pairs(on_droplet_receive) do
for width = 1, 8, 1 do
internal.add_droplet_trickler(
internal.register_trickler(
droplet,
internal.size_to_name(flavor, width),
internal.size_to_name(new_flavor, width)
@ -282,17 +246,21 @@ function internal.register_dripstone_node(flavor, size, tiles, sounds, drop)
drop = {
max_items = math.floor((size + 1) / 2),
items = {
{ rarity = 1
, items = { drop }
{
rarity = 1,
items = { drop },
},
{ rarity = 2
, items = { drop }
{
rarity = 2,
items = { drop },
},
{ rarity = 4
, items = { drop }
{
rarity = 4,
items = { drop },
},
{ rarity = 4
, items = { drop }
{
rarity = 4,
items = { drop },
},
}
},
@ -357,6 +325,27 @@ function internal.register_droplet(droplet)
end
end
-- Add a droplet catcher, which is a node that allows a stalactite spike to
-- change the name using a droplet.
function internal.register_droplet_catcher(droplet, oldnodename, newnodename)
if CAULDRONS[droplet] == nil then
internal.uninitialized_droplet_error(droplet)
end
CAULDRONS[droplet][oldnodename] = newnodename
end
function internal.register_droplet_source(droplet, nodename)
if SOURCES[droplet] == nil then
internal.uninitialized_droplet_error(droplet)
end
table.insert(SOURCES[droplet], nodename)
-- If the node can emit an infinite number of droplets,
-- it can also absorb an infinite number of droplets.
internal.register_droplet_catcher(droplet, nodename, nodename)
end
function internal.register_grow_abm(oldnodename, newnodename, width)
minetest.register_abm({
nodenames = { oldnodename },
@ -400,6 +389,17 @@ function internal.register_trickle_down_abm(droplet, width, old_source, new_sour
})
end
-- Add a droplet trickler, which is a dripstone node that allows a droplet to
-- be trickled down from the node directly above it.
-- Running this function overrides previous values.
function internal.register_trickler(droplet, oldnodename, newnodename)
if TRICKLERS[droplet] == nil then
internal.uninitialized_droplet_error(droplet)
end
TRICKLERS[droplet][oldnodename] = newnodename
end
function internal.size_to_description(flavor, size)
local width_name = WIDTH_NAMES[size]