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

96
api.lua
View File

@ -45,38 +45,6 @@ local WIDTH_NAMES = {
-- Internal table that lets us define functions without directly exposing them. -- Internal table that lets us define functions without directly exposing them.
local internal = {} 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 -- Capitalize a string
function internal.capitalize(str) function internal.capitalize(str)
return (str:gsub("^%l", string.upper)) return (str:gsub("^%l", string.upper))
@ -107,11 +75,7 @@ end
-- Determine whether this mod considers a node an air node. -- Determine whether this mod considers a node an air node.
function internal.is_air(nodename) function internal.is_air(nodename)
if nodename == "air" then return (nodename == "air") or (minetest.get_item_group(nodename, "air") ~= 0)
return true
else
return minetest.get_item_group(nodename, "air") ~= 0
end
end end
-- Create a node box for any given dripstone size. -- 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 -- Allow dripstone nodes to trickle down droplets
for droplet, new_flavor in pairs(on_droplet_receive) do for droplet, new_flavor in pairs(on_droplet_receive) do
for width = 1, 8, 1 do for width = 1, 8, 1 do
internal.add_droplet_trickler( internal.register_trickler(
droplet, droplet,
internal.size_to_name(flavor, width), internal.size_to_name(flavor, width),
internal.size_to_name(new_flavor, width) internal.size_to_name(new_flavor, width)
@ -274,25 +238,29 @@ function internal.register_dripstone_node(flavor, size, tiles, sounds, drop)
description = internal.size_to_description(flavor, size), description = internal.size_to_description(flavor, size),
tiles = tiles, tiles = tiles,
groups = { groups = {
pickaxey=2, pickaxey = 2,
material_stone=1, material_stone = 1,
fall_damage_add_percent = math.max(4 - size, 0) / 4 * 100 fall_damage_add_percent = math.max(4 - size, 0) / 4 * 100
}, },
is_ground_content = true, is_ground_content = true,
drop = { drop = {
max_items = math.floor((size + 1) / 2), max_items = math.floor((size + 1) / 2),
items = { 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
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) function internal.register_grow_abm(oldnodename, newnodename, width)
minetest.register_abm({ minetest.register_abm({
nodenames = { oldnodename }, nodenames = { oldnodename },
@ -400,6 +389,17 @@ function internal.register_trickle_down_abm(droplet, width, old_source, new_sour
}) })
end 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) function internal.size_to_description(flavor, size)
local width_name = WIDTH_NAMES[size] local width_name = WIDTH_NAMES[size]