From e1cdc26a75562ed92a4649dbe166d4bdfecaea7e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 5 Dec 2025 11:59:55 +0100 Subject: [PATCH] Make some manual formatting to make the code more readable --- .luacheckrc | 3 +-- chiseling_machine.lua | 19 +++++++++++++++---- default.lua | 7 +++---- functions.lua | 16 ++++++++++------ init.lua | 19 ++++++++++--------- moretrees.lua | 3 +-- 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 65423a9..2fe0274 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,4 +1,3 @@ - unused_args = false allow_defined_top = true exclude_files = {".luacheckrc"} @@ -18,6 +17,6 @@ read_globals = { -- MTG "default", "sfinv", "creative", - --depends + -- Dependencies "moretrees", "ethereal", "moreores" } diff --git a/chiseling_machine.lua b/chiseling_machine.lua index 38b3d6d..afd0555 100644 --- a/chiseling_machine.lua +++ b/chiseling_machine.lua @@ -1,5 +1,19 @@ local max_stack = tonumber(minetest.settings:get("default_stack_max")) or 99 +-- LuaFormatter off +local machine_formspec = "" .. + "size[8,9]" .. + "label[0,0;Chiseling Machine]" .. + "image[2,2;1,1;chisel.png]" .. + "list[current_name;src;2,1;1,1;]" .. + "list[current_name;dst;5,1;2,2;]" .. + "list[current_player;main;0,5;8,4;]" .. + "listring[current_name;dst]" .. + "listring[current_player;main]" .. + "listring[current_name;src]" .. + "listring[current_player;main]" +-- LuaFormatter on + minetest.register_node( "stripped_tree:chiseling_machine", { description = "Chiseladora para troncos", @@ -15,10 +29,7 @@ minetest.register_node( after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) - meta:set_string( - "formspec", - "size[8,9]label[0,0;Chiseling Machine]image[2,2;1,1;chisel.png]list[current_name;src;2,1;1,1;]list[current_name;dst;5,1;2,2;]list[current_player;main;0,5;8,4;]listring[current_name;dst]listring[current_player;main]listring[current_name;src]listring[current_player;main]" - ) + meta:set_string("formspec", machine_formspec) end, on_construct = function(pos) diff --git a/default.lua b/default.lua index 8c2888e..fb930e4 100644 --- a/default.lua +++ b/default.lua @@ -3,12 +3,12 @@ minetest.register_craftitem( ":default:tree_bark", {description = "Tree bark", inventory_image = "tree_bark.png", groups = {not_in_creative_inventory = 1}} ) --- register bark as fuel + +-- Register bark as fuel minetest.register_craft({type = "fuel", recipe = "default:tree_bark", burntime = 15}) -- Register craft for string if minetest.get_modpath("farming") then - minetest.register_craft( { output = "farming:string 4", @@ -35,7 +35,6 @@ minetest.register_craft( -- Register craft for mulch if minetest.get_modpath("bonemeal") then - minetest.register_craft( { output = "bonemeal:mulch 4", @@ -47,6 +46,7 @@ if minetest.get_modpath("bonemeal") then } ) end + -- Register stripped trees local mod_name = "default" local trunk_names = {"tree", "jungletree", "aspen_tree", "acacia_tree", "pine_tree"} @@ -56,4 +56,3 @@ stripped_tree.register_trunk(mod_name, trunk_names) -- Register axes local axe_types = {"axe_wood", "axe_stone", "axe_bronze", "axe_steel", "axe_mese", "axe_diamond"} if not stripped_tree.ENABLE_CHISEL then stripped_tree.register_axes(mod_name, axe_types) end - diff --git a/functions.lua b/functions.lua index ed1dab1..a3b6785 100644 --- a/functions.lua +++ b/functions.lua @@ -1,6 +1,9 @@ stripped_tree = {} + -- Select between chisel tool or axes. -stripped_tree.ENABLE_CHISEL = core.settings:get_bool "stripped_tree_enable_chisel" +stripped_tree.ENABLE_CHISEL = core.settings:get_bool("stripped_tree_enable_chisel") + +-- Check if we are running on a creative server local creative_mode = minetest.settings:get_bool("creative_mode") -- Function to verify that stripped tree trunk exists @@ -8,6 +11,7 @@ stripped_tree.has_stripped = function(pos) local node = minetest.get_node(pos).name or pos local mod_name, node_name = unpack(node:split(":")) local has_stripped = minetest.registered_nodes[mod_name .. ":" .. "stripped_" .. node_name] + return has_stripped end @@ -15,12 +19,14 @@ end stripped_tree.swap_node = function(pos, user, creative_mode) local old_node = minetest.get_node(pos) local stripped = mod_name .. ":" .. "stripped_" .. node_name + minetest.swap_node(pos, {name = stripped, param2 = old_node.param2}) -- itemstack:add_wear(65535 / 299) this is not useful at moment. if not creative_mode then local inv = user:get_inventory() - -- check for room in inv, if not, drop item + + -- If the player has room in their inventory for a bark, give them one; otherwise, drop the bark to the ground. if inv:room_for_item("main", "default:tree_bark") then inv:add_item("main", {name = "default:tree_bark"}) else @@ -29,10 +35,9 @@ stripped_tree.swap_node = function(pos, user, creative_mode) end return itemstack - end --- function to register nodes +-- Function to register nodes function stripped_tree.register_trunk(mod_name, trunk_names) for _, name in ipairs(trunk_names) do minetest.register_node( @@ -69,7 +74,7 @@ function stripped_tree.register_trunk(mod_name, trunk_names) end end --- function to override axes +-- Function to override axes if stripped_tree.ENABLE_CHISEL ~= true then function stripped_tree.register_axes(mod_n, axe_types) for _, axe_name in ipairs(axe_types) do @@ -89,7 +94,6 @@ if stripped_tree.ENABLE_CHISEL ~= true then if stripped_tree.has_stripped(pos) then stripped_tree.swap_node(pos, user, creative_mode) end - end, } ) diff --git a/init.lua b/init.lua index 2d25e62..d9ecf6e 100644 --- a/init.lua +++ b/init.lua @@ -1,14 +1,14 @@ --- get modpath +-- Get our own path local mpath = minetest.get_modpath("stripped_tree") --- load functions +-- Load functions dofile(mpath .. "/functions.lua") --- load default +-- Load default (AKA the Minetest game) dofile(mpath .. "/default.lua") dofile(mpath .. "/chiseling_machine.lua") --- load optional dependencies +-- Load optional dependencies if minetest.get_modpath("moretrees") then dofile(mpath .. "/moretrees.lua") end if minetest.get_modpath("ethereal") then dofile(mpath .. "/ethereal.lua") end @@ -16,7 +16,6 @@ if minetest.get_modpath("ethereal") then dofile(mpath .. "/ethereal.lua") end if minetest.get_modpath("moreores") then dofile(mpath .. "/moreores.lua") end if stripped_tree.ENABLE_CHISEL then - minetest.register_tool( "stripped_tree:chisel", { description = "Chisel for tree trunks", @@ -25,7 +24,6 @@ if stripped_tree.ENABLE_CHISEL then sound = {breaks = "default_tool_breaks"}, stack_max = 1, on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "node" then return end local pos = pointed_thing.under @@ -38,9 +36,11 @@ if stripped_tree.ENABLE_CHISEL then local node = minetest.get_node(pos).name local mod_name, node_name = unpack(node:split(":")) - -- before concatenating check for nil + + -- Before concatenating check for nil if not mod_name then return end if not node_name then return end + local has_stripped = minetest.registered_nodes[mod_name .. ":" .. "stripped_" .. node_name] if has_stripped then @@ -49,18 +49,19 @@ if stripped_tree.ENABLE_CHISEL then if not minetest.settings:get_bool("creative_mode") then local inv = user:get_inventory() - -- check for room in inv, if not, drop item + + -- Check for room in inv, if not, drop item if inv:room_for_item("main", "default:tree_bark") then inv:add_item("main", {name = "default:tree_bark"}) else minetest.add_item(pos, "default:tree_bark") end + itemstack:add_wear(65535 / 299) -- 300 uses end return itemstack end - end, } ) diff --git a/moretrees.lua b/moretrees.lua index c118c43..169e872 100644 --- a/moretrees.lua +++ b/moretrees.lua @@ -15,12 +15,11 @@ local trunk_names = { "rubber_tree_trunk", "fir_trunk", "jungletree_trunk", - } stripped_tree.register_trunk(mod_name, trunk_names) --- register tree variations using the same texture as default moretree trunks +-- Register tree variations using the same texture as default moretree trunks minetest.register_node( ":" .. mod_name .. ":stripped_date_palm_mfruit_trunk", {