Make some manual formatting to make the code more readable
Some checks failed
build / build (pull_request) Waiting to run
build / build (push) Has been cancelled

This commit was merged in pull request #2.
This commit is contained in:
2025-12-05 11:59:55 +01:00
parent 2eddcca11c
commit e1cdc26a75
6 changed files with 40 additions and 27 deletions

View File

@@ -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"
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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,
}
)

View File

@@ -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,
}
)

View File

@@ -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", {