From cb651b36e89187d190a4e3f50c75b2a7e161e7c7 Mon Sep 17 00:00:00 2001 From: alek13 Date: Mon, 26 Feb 2024 02:26:26 +0300 Subject: [PATCH] Wooden blocks: Refactoring `lottplants`: add `planks` API. Closes #1236 --- mods/lord/Blocks/lottplants/nodes.lua | 4 ++-- mods/lord/Blocks/lottplants/planks.lua | 14 +++++++++++++- util/mt-ide-helper/definitions/ItemDefinition.lua | 2 +- util/mt-ide-helper/definitions/NodeDefinition.lua | 2 +- util/mt-ide-helper/minetest_types.lua | 6 ++++-- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/mods/lord/Blocks/lottplants/nodes.lua b/mods/lord/Blocks/lottplants/nodes.lua index 0611bf1e4..103f50eb1 100644 --- a/mods/lord/Blocks/lottplants/nodes.lua +++ b/mods/lord/Blocks/lottplants/nodes.lua @@ -1155,8 +1155,8 @@ default.register_leafdecay({ radius = 2, }) - -dofile(minetest.get_modpath(minetest.get_current_modname()) .. '/planks.lua') +--- @type lottplants.Planks_API +planks = dofile(minetest.get_modpath(minetest.get_current_modname()) .. '/planks.lua') --Lorien grass diff --git a/mods/lord/Blocks/lottplants/planks.lua b/mods/lord/Blocks/lottplants/planks.lua index 45d8e41e2..ea1e8a446 100644 --- a/mods/lord/Blocks/lottplants/planks.lua +++ b/mods/lord/Blocks/lottplants/planks.lua @@ -1,6 +1,9 @@ local S = minetest.get_translator("lottplants") -local planks = { nodes = {} } +local planks = { + --- @type table|NodeDefinition[] + nodes = {} +} --- @param node_name string technical node name (":"). local function add_existing(node_name) @@ -101,3 +104,12 @@ minetest.register_craft({ recipe = "lottplants:hardwood", burntime = 28, }) + +--- @class lottplants.Planks_API +local Planks_API = { + add_existing = add_existing, + get_nodes = function() return planks.nodes end +} + + +return Planks_API diff --git a/util/mt-ide-helper/definitions/ItemDefinition.lua b/util/mt-ide-helper/definitions/ItemDefinition.lua index 112e5576f..810f5a1ce 100644 --- a/util/mt-ide-helper/definitions/ItemDefinition.lua +++ b/util/mt-ide-helper/definitions/ItemDefinition.lua @@ -1,5 +1,5 @@ --- @class ItemDefinition -ItemDefinition = { +local ItemDefinition = { description = "", -- Can contain new lines. "\n" has to be used as new line character. -- See also: `get_description` in [`ItemStack`] diff --git a/util/mt-ide-helper/definitions/NodeDefinition.lua b/util/mt-ide-helper/definitions/NodeDefinition.lua index b71f17dba..74a086c09 100644 --- a/util/mt-ide-helper/definitions/NodeDefinition.lua +++ b/util/mt-ide-helper/definitions/NodeDefinition.lua @@ -1,5 +1,5 @@ --- @class NodeDefinition: ItemDefinition -NodeDefinition = { +local NodeDefinition = { drawtype = "normal", -- See "Node drawtypes" diff --git a/util/mt-ide-helper/minetest_types.lua b/util/mt-ide-helper/minetest_types.lua index 218df00de..877d7cdd7 100644 --- a/util/mt-ide-helper/minetest_types.lua +++ b/util/mt-ide-helper/minetest_types.lua @@ -344,6 +344,8 @@ function minetest.log(level, text) end -- Environment: +--- @param name string technical node name (":"). +--- @param node_definition NodeDefinition table with node definition properties. --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4471-L4471) function minetest.register_node(name, node_definition) end --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4472-L4472) @@ -2286,12 +2288,12 @@ minetest.env = {} --- * Map of registered items, indexed by name --- --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5838-L5839) ---- @type table +--- @type table|ItemDefinition[] minetest.registered_items = {} --- * Map of registered node definitions, indexed by name --- --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5840-L5841) ---- @type table +--- @type table|NodeDefinition[] minetest.registered_nodes = {} --- * Map of registered craft item definitions, indexed by name ---