From 2eddcca11c74751bc0059bad5c881828217291be Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 6 Dec 2025 10:58:24 +0100 Subject: [PATCH 1/2] Reformat all files with LuaFormatter --- .lua-format | 33 +++++++++++++ chiseling_machine.lua | 108 +++++++++++++++++++++++------------------ default.lua | 101 ++++++++++++++++++-------------------- ethereal.lua | 15 ++---- functions.lua | 110 +++++++++++++++++++++++------------------- init.lua | 103 ++++++++++++++++++--------------------- moreores.lua | 11 ++--- moretrees.lua | 110 ++++++++++++++++++++++-------------------- 8 files changed, 315 insertions(+), 276 deletions(-) create mode 100644 .lua-format diff --git a/.lua-format b/.lua-format new file mode 100644 index 0000000..8361b9b --- /dev/null +++ b/.lua-format @@ -0,0 +1,33 @@ +column_limit: 120 +indent_width: 4 +use_tab: false +tab_width: 4 +continuation_indent_width: 4 +spaces_before_call: 1 +keep_simple_control_block_one_line: true +keep_simple_function_one_line: true +align_args: true +break_after_functioncall_lp: true +break_before_functioncall_rp: true +spaces_inside_functioncall_parens: false +spaces_inside_functiondef_parens: false +align_parameter: true +chop_down_parameter: false +break_after_functiondef_lp: true +break_before_functiondef_rp: true +align_table_field: true +break_after_table_lb: true +break_before_table_rb: true +chop_down_table: true +chop_down_kv_table: true +table_sep: "," +extra_sep_at_table_end: true +column_table_limit: 0 +column_table_limit_kv: 0 +spaces_inside_table_braces: false +break_after_operator: true +double_quote_to_single_quote: false +single_quote_to_double_quote: true +spaces_around_equals_in_field: true +line_breaks_after_function_body: 1 +line_separator: input diff --git a/chiseling_machine.lua b/chiseling_machine.lua index 6be3d08..38b3d6d 100644 --- a/chiseling_machine.lua +++ b/chiseling_machine.lua @@ -1,56 +1,70 @@ local max_stack = tonumber(minetest.settings:get("default_stack_max")) or 99 -minetest.register_node("stripped_tree:chiseling_machine", { - description = "Chiseladora para troncos", - tiles = {"chiseling_machine.png", "chiseling_machine.png", "chiseling_machine_side.png", "chiseling_machine_side.png","chiseling_machine_side.png", "chiseling_machine_side.png"}, - groups = {cracky = 1}, +minetest.register_node( + "stripped_tree:chiseling_machine", { + description = "Chiseladora para troncos", + tiles = { + "chiseling_machine.png", + "chiseling_machine.png", + "chiseling_machine_side.png", + "chiseling_machine_side.png", + "chiseling_machine_side.png", + "chiseling_machine_side.png", + }, + groups = {cracky = 1}, - 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]") - end, + 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]" + ) + end, - on_construct = function(pos) - local inv = minetest.get_meta(pos):get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 2) - minetest.get_node_timer(pos):start(1.0) - end, + on_construct = function(pos) + local inv = minetest.get_meta(pos):get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 2) + minetest.get_node_timer(pos):start(1.0) + end, - on_metadata_inventory_put = function(pos, listname, index, stack, player) - local inv = minetest.get_meta(pos):get_inventory() - local src_stack = inv:get_stack("src", 1) - local dst_stack = inv:get_stack("dst", 1) - if listname == "src" and not src_stack:is_empty() then - local src_name = src_stack:get_name() - local src_count = src_stack:get_count() - local mod_name, node_name = unpack(src_name:split(":")) - local stripped_name = mod_name .. ":stripped_" .. node_name - local has_stripped = minetest.registered_nodes[stripped_name] - local dst_count = dst_stack:get_count() - if has_stripped and dst_count < max_stack then - inv:add_item("dst", stripped_name .. " " .. src_count) - inv:add_item("dst", "default:tree_bark " .. src_count) - inv:remove_item("src", src_stack) + on_metadata_inventory_put = function(pos, listname, index, stack, player) + local inv = minetest.get_meta(pos):get_inventory() + local src_stack = inv:get_stack("src", 1) + local dst_stack = inv:get_stack("dst", 1) + if listname == "src" and not src_stack:is_empty() then + local src_name = src_stack:get_name() + local src_count = src_stack:get_count() + local mod_name, node_name = unpack(src_name:split(":")) + local stripped_name = mod_name .. ":stripped_" .. node_name + local has_stripped = minetest.registered_nodes[stripped_name] + local dst_count = dst_stack:get_count() + if has_stripped and dst_count < max_stack then + inv:add_item("dst", stripped_name .. " " .. src_count) + inv:add_item("dst", "default:tree_bark " .. src_count) + inv:remove_item("src", src_stack) + end end - end - end, + end, - on_receive_fields = function(pos, formname, fields, sender) - if fields.quit then return end - print(fields.x) - end, + on_receive_fields = function(pos, formname, fields, sender) + if fields.quit then return end + print(fields.x) + end, - allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - return count - end -}) + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + return count + end, + } +) -minetest.register_craft({ - output = "stripped_tree:chiseling_machine", - recipe = { - {"group:wood","default:diamond","group:wood"}, - {"group:wood","stripped_tree:chisel","group:wood"}, - {"group:wood", "group:wood","group:wood"}, - }, -}) +minetest.register_craft( + { + output = "stripped_tree:chiseling_machine", + recipe = { + {"group:wood", "default:diamond", "group:wood"}, + {"group:wood", "stripped_tree:chisel", "group:wood"}, + {"group:wood", "group:wood", "group:wood"}, + }, + } +) diff --git a/default.lua b/default.lua index 806189a..8c2888e 100644 --- a/default.lua +++ b/default.lua @@ -1,68 +1,59 @@ ---Register tree bark -minetest.register_craftitem(":default:tree_bark", { - description = "Tree bark", - inventory_image = "tree_bark.png", - groups = {not_in_creative_inventory = 1} -}) ---register bark as fuel -minetest.register_craft({ - type = "fuel", - recipe = "default:tree_bark", - burntime = 15, -}) +-- Register tree bark +minetest.register_craftitem( + ":default:tree_bark", + {description = "Tree bark", inventory_image = "tree_bark.png", groups = {not_in_creative_inventory = 1}} +) +-- register bark as fuel +minetest.register_craft({type = "fuel", recipe = "default:tree_bark", burntime = 15}) ---Register craft for string +-- Register craft for string if minetest.get_modpath("farming") then - minetest.register_craft({ - output = "farming:string 4", - recipe = {{"default:tree_bark","default:tree_bark","default:tree_bark"}, - {"default:tree_bark","default:tree_bark","default:tree_bark"}, - {"default:tree_bark","default:tree_bark","default:tree_bark"}} - }) + minetest.register_craft( + { + output = "farming:string 4", + recipe = { + {"default:tree_bark", "default:tree_bark", "default:tree_bark"}, + {"default:tree_bark", "default:tree_bark", "default:tree_bark"}, + {"default:tree_bark", "default:tree_bark", "default:tree_bark"}, + }, + } + ) end ---Register craft for paper -minetest.register_craft({ - output = "default:paper 8", - recipe = {{"default:tree_bark","default:tree_bark","default:tree_bark"}, - {"default:tree_bark","bucket:bucket_water","default:tree_bark"}, - {"default:tree_bark","default:tree_bark","default:tree_bark"}} -}) +-- Register craft for paper +minetest.register_craft( + { + output = "default:paper 8", + recipe = { + {"default:tree_bark", "default:tree_bark", "default:tree_bark"}, + {"default:tree_bark", "bucket:bucket_water", "default:tree_bark"}, + {"default:tree_bark", "default:tree_bark", "default:tree_bark"}, + }, + } +) ---Register craft for mulch +-- Register craft for mulch if minetest.get_modpath("bonemeal") then - minetest.register_craft({ - output = "bonemeal:mulch 4", - recipe = {{"default:tree_bark","default:tree_bark","default:tree_bark"}, - {"default:tree_bark","default:tree_bark","default:tree_bark"}, - {"","",""}} - }) + minetest.register_craft( + { + output = "bonemeal:mulch 4", + recipe = { + {"default:tree_bark", "default:tree_bark", "default:tree_bark"}, + {"default:tree_bark", "default:tree_bark", "default:tree_bark"}, + {"", "", ""}, + }, + } + ) end ---Register stripped trees +-- Register stripped trees local mod_name = "default" -local trunk_names = { - "tree", - "jungletree", - "aspen_tree", - "acacia_tree", - "pine_tree", -} +local trunk_names = {"tree", "jungletree", "aspen_tree", "acacia_tree", "pine_tree"} -stripped_tree.register_trunk(mod_name,trunk_names) +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 +-- 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/ethereal.lua b/ethereal.lua index 29c7f5b..2a582a0 100644 --- a/ethereal.lua +++ b/ethereal.lua @@ -1,4 +1,4 @@ ---Register stripped trees +-- Register stripped trees local mod_name = "ethereal" local trunk_names = { "banana_trunk", @@ -12,13 +12,8 @@ local trunk_names = { "palm_trunk", } -stripped_tree.register_trunk(mod_name,trunk_names) +stripped_tree.register_trunk(mod_name, trunk_names) - ---Register axes -local axe_types = { -"axe_crystal", -} -if not stripped_tree.ENABLE_CHISEL then -stripped_tree.register_axes(mod_name,axe_types) -end +-- Register axes +local axe_types = {"axe_crystal"} +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 2f0e133..ed1dab1 100644 --- a/functions.lua +++ b/functions.lua @@ -1,28 +1,28 @@ stripped_tree = {} ---Select between chisel tool or axes. -stripped_tree.ENABLE_CHISEL = core.settings:get_bool"stripped_tree_enable_chisel" +-- Select between chisel tool or axes. +stripped_tree.ENABLE_CHISEL = core.settings:get_bool "stripped_tree_enable_chisel" local creative_mode = minetest.settings:get_bool("creative_mode") ---Function to verify that stripped tree trunk exists +-- Function to verify that stripped tree trunk exists 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] + local has_stripped = minetest.registered_nodes[mod_name .. ":" .. "stripped_" .. node_name] return has_stripped end ---Function to swap nodes -stripped_tree.swap_node = function(pos,user,creative_mode) +-- Function to swap nodes +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. + 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 + -- 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"}) + inv:add_item("main", {name = "default:tree_bark"}) else minetest.add_item(pos, "default:tree_bark") end @@ -32,55 +32,67 @@ stripped_tree.swap_node = function(pos,user,creative_mode) end ---function to register nodes -function stripped_tree.register_trunk(mod_name,trunk_names) +-- function to register nodes +function stripped_tree.register_trunk(mod_name, trunk_names) for _, name in ipairs(trunk_names) do - minetest.register_node(":"..mod_name..":stripped_" .. name, { - description = "Stripped "..name, - tiles = { - "stripped_"..mod_name.."_"..name.."_top.png", - "stripped_"..mod_name.."_"..name.."_top.png", - "stripped_"..mod_name.."_"..name..".png" - }, - groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, - sounds = default.node_sound_wood_defaults(), - paramtype2 = "facedir", - on_place = minetest.rotate_node, - }) + minetest.register_node( + ":" .. mod_name .. ":stripped_" .. name, { + description = "Stripped " .. name, + tiles = { + "stripped_" .. mod_name .. "_" .. name .. "_top.png", + "stripped_" .. mod_name .. "_" .. name .. "_top.png", + "stripped_" .. mod_name .. "_" .. name .. ".png", + }, + groups = { + tree = 1, + choppy = 2, + oddly_breakable_by_hand = 1, + flammable = 2, + not_in_creative_inventory = 1, + }, + sounds = default.node_sound_wood_defaults(), + paramtype2 = "facedir", + on_place = minetest.rotate_node, + } + ) - minetest.register_craft({ - output = mod_name..":"..name, - recipe = {{"","default:tree_bark",""}, - {"default:tree_bark",mod_name..":stripped_" .. name,"default:tree_bark"}, - {"","default:tree_bark",""}} - }) + minetest.register_craft( + { + output = mod_name .. ":" .. name, + recipe = { + {"", "default:tree_bark", ""}, + {"default:tree_bark", mod_name .. ":stripped_" .. name, "default:tree_bark"}, + {"", "default:tree_bark", ""}, + }, + } + ) 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) + function stripped_tree.register_axes(mod_n, axe_types) for _, axe_name in ipairs(axe_types) do - minetest.override_item(mod_n..":" .. axe_name, { - on_place = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "node" then - return - end + minetest.override_item( + mod_n .. ":" .. axe_name, { + on_place = function(itemstack, user, pointed_thing) + if pointed_thing.type ~= "node" then return end - local pos = pointed_thing.under - local pname = user:get_player_name() + local pos = pointed_thing.under + local pname = user:get_player_name() - if minetest.is_protected(pos, pname) then - minetest.record_protection_violation(pos, pname) - return - end + if minetest.is_protected(pos, pname) then + minetest.record_protection_violation(pos, pname) + return + end - if stripped_tree.has_stripped(pos) then - stripped_tree.swap_node(pos,user,creative_mode) - end + if stripped_tree.has_stripped(pos) then + stripped_tree.swap_node(pos, user, creative_mode) + end - end, - }) + end, + } + ) end end end diff --git a/init.lua b/init.lua index aa5f675..2d25e62 100644 --- a/init.lua +++ b/init.lua @@ -1,83 +1,74 @@ - - - -- get modpath local mpath = minetest.get_modpath("stripped_tree") -- load functions dofile(mpath .. "/functions.lua") ---load default +-- load default dofile(mpath .. "/default.lua") dofile(mpath .. "/chiseling_machine.lua") ---load optional dependencies -if minetest.get_modpath("moretrees") then - dofile(mpath .. "/moretrees.lua") -end +-- 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 +if minetest.get_modpath("ethereal") then dofile(mpath .. "/ethereal.lua") end -if minetest.get_modpath("moreores") then - dofile(mpath .. "/moreores.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", - inventory_image = "chisel.png", - wield_image = "chisel.png", - sound = {breaks = "default_tool_breaks"}, - stack_max = 1, - on_use = function(itemstack, user, pointed_thing) + minetest.register_tool( + "stripped_tree:chisel", { + description = "Chisel for tree trunks", + inventory_image = "chisel.png", + wield_image = "chisel.png", + sound = {breaks = "default_tool_breaks"}, + stack_max = 1, + on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "node" then - return - end + if pointed_thing.type ~= "node" then return end - local pos = pointed_thing.under - local pname = user:get_player_name() + local pos = pointed_thing.under + local pname = user:get_player_name() - if minetest.is_protected(pos, pname) then - minetest.record_protection_violation(pos, pname) - return - end + if minetest.is_protected(pos, pname) then + minetest.record_protection_violation(pos, pname) + return + end - local node = minetest.get_node(pos).name - local mod_name, node_name = unpack(node:split(":")) + local node = minetest.get_node(pos).name + local mod_name, node_name = unpack(node:split(":")) -- 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] + local has_stripped = minetest.registered_nodes[mod_name .. ":" .. "stripped_" .. node_name] - if has_stripped then - local stripped = mod_name..":".."stripped_"..node_name - minetest.swap_node(pos,{name=stripped}) + if has_stripped then + local stripped = mod_name .. ":" .. "stripped_" .. node_name + minetest.swap_node(pos, {name = stripped}) - if not minetest.settings:get_bool("creative_mode") then - local inv = user:get_inventory() - --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 + if not minetest.settings:get_bool("creative_mode") then + local inv = user:get_inventory() + -- 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 - return itemstack - end + end, + } + ) - end, - }) - - minetest.register_craft({ - output = "stripped_tree:chisel", - recipe = {{"","default:steel_ingot",""}, - {"","screwdriver:screwdriver",""}, - {"","",""}} - }) + minetest.register_craft( + { + output = "stripped_tree:chisel", + recipe = {{"", "default:steel_ingot", ""}, {"", "screwdriver:screwdriver", ""}, {"", "", ""}}, + } + ) end diff --git a/moreores.lua b/moreores.lua index 80c74bf..20e8f2b 100644 --- a/moreores.lua +++ b/moreores.lua @@ -1,9 +1,4 @@ ---Register axes -local axe_types = { - "axe_mithril", - "axe_silver", -} +-- Register axes +local axe_types = {"axe_mithril", "axe_silver"} -if not stripped_tree.ENABLE_CHISEL then -stripped_tree.register_axes("moreores",axe_types) -end +if not stripped_tree.ENABLE_CHISEL then stripped_tree.register_axes("moreores", axe_types) end diff --git a/moretrees.lua b/moretrees.lua index 4c1501f..c118c43 100644 --- a/moretrees.lua +++ b/moretrees.lua @@ -1,4 +1,4 @@ ---Register stripped trees +-- Register stripped trees local mod_name = "moretrees" local trunk_names = { "beech_trunk", @@ -18,58 +18,66 @@ local trunk_names = { } -stripped_tree.register_trunk(mod_name,trunk_names) +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", { - description = "Stripped date_palm_fruit_trunk", - tiles = { - "stripped_"..mod_name.."_date_palm_trunk_top.png", - "stripped_"..mod_name.."_date_palm_trunk_top.png", - "stripped_"..mod_name.."_date_palm_trunk.png" - }, - groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, - sounds = default.node_sound_wood_defaults(), - paramtype2 = "facedir", - on_place = minetest.rotate_node, -}) +minetest.register_node( + ":" .. mod_name .. ":stripped_date_palm_mfruit_trunk", { + description = "Stripped date_palm_fruit_trunk", + tiles = { + "stripped_" .. mod_name .. "_date_palm_trunk_top.png", + "stripped_" .. mod_name .. "_date_palm_trunk_top.png", + "stripped_" .. mod_name .. "_date_palm_trunk.png", + }, + groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, + sounds = default.node_sound_wood_defaults(), + paramtype2 = "facedir", + on_place = minetest.rotate_node, + } +) -minetest.register_node(":"..mod_name..":stripped_date_palm_ffruit_trunk", { - description = "Stripped date_palm_fruit_trunk", - tiles = { - "stripped_"..mod_name.."_date_palm_trunk_top.png", - "stripped_"..mod_name.."_date_palm_trunk_top.png", - "stripped_"..mod_name.."_date_palm_trunk.png" - }, - groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, - sounds = default.node_sound_wood_defaults(), - paramtype2 = "facedir", - on_place = minetest.rotate_node, -}) +minetest.register_node( + ":" .. mod_name .. ":stripped_date_palm_ffruit_trunk", { + description = "Stripped date_palm_fruit_trunk", + tiles = { + "stripped_" .. mod_name .. "_date_palm_trunk_top.png", + "stripped_" .. mod_name .. "_date_palm_trunk_top.png", + "stripped_" .. mod_name .. "_date_palm_trunk.png", + }, + groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, + sounds = default.node_sound_wood_defaults(), + paramtype2 = "facedir", + on_place = minetest.rotate_node, + } +) -minetest.register_node(":"..mod_name..":stripped_date_palm_fruit_trunk", { - description = "Stripped date_palm_fruit_trunk", - tiles = { - "stripped_"..mod_name.."_date_palm_trunk_top.png", - "stripped_"..mod_name.."_date_palm_trunk_top.png", - "stripped_"..mod_name.."_date_palm_trunk.png" - }, - groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, - sounds = default.node_sound_wood_defaults(), - paramtype2 = "facedir", - on_place = minetest.rotate_node, -}) +minetest.register_node( + ":" .. mod_name .. ":stripped_date_palm_fruit_trunk", { + description = "Stripped date_palm_fruit_trunk", + tiles = { + "stripped_" .. mod_name .. "_date_palm_trunk_top.png", + "stripped_" .. mod_name .. "_date_palm_trunk_top.png", + "stripped_" .. mod_name .. "_date_palm_trunk.png", + }, + groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, + sounds = default.node_sound_wood_defaults(), + paramtype2 = "facedir", + on_place = minetest.rotate_node, + } +) -minetest.register_node(":"..mod_name..":stripped_rubber_tree_trunk_empty", { - description = "Stripped date_palm_fruit_trunk", - tiles = { - "stripped_"..mod_name.."_rubber_tree_trunk_top.png", - "stripped_"..mod_name.."_rubber_tree_trunk_top.png", - "stripped_"..mod_name.."_rubber_tree_trunk.png" - }, - groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, - sounds = default.node_sound_wood_defaults(), - paramtype2 = "facedir", - on_place = minetest.rotate_node, -}) +minetest.register_node( + ":" .. mod_name .. ":stripped_rubber_tree_trunk_empty", { + description = "Stripped date_palm_fruit_trunk", + tiles = { + "stripped_" .. mod_name .. "_rubber_tree_trunk_top.png", + "stripped_" .. mod_name .. "_rubber_tree_trunk_top.png", + "stripped_" .. mod_name .. "_rubber_tree_trunk.png", + }, + groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1}, + sounds = default.node_sound_wood_defaults(), + paramtype2 = "facedir", + on_place = minetest.rotate_node, + } +) -- 2.49.1 From e1cdc26a75562ed92a4649dbe166d4bdfecaea7e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 5 Dec 2025 11:59:55 +0100 Subject: [PATCH 2/2] 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", { -- 2.49.1