diff --git a/autocrafter.lua b/autocrafter.lua index 7e4fabe..e731d18 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -1,7 +1,7 @@ -- Modified and adapted from pipeworks mod by VanessaE -- https://github.com/mt-mods/pipeworks -- by rnd --- Copyright (C) 2022-2024 мтест +-- Copyright (C) 2022-2025 мтест -- See README.md for license details -- Disabled timers and on/off button, now autocrafter is only activated by signal @@ -50,13 +50,6 @@ local function get_craft(pos, inventory, hash) return craft end -local function get_item_info(stack) - local name = stack:get_name() - local def = minetest.registered_items[name ~= "" and name or nil] - local description = def and def.description or S("Unknown item") - return description, name -end - local function after_recipe_change(pos, inventory) -- if we emptied the grid, there's no point in keeping it running or cached if inventory:is_empty("recipe") then @@ -67,7 +60,8 @@ local function after_recipe_change(pos, inventory) local hash = minetest.hash_node_position(pos) autocrafterCache[hash] = nil local output_item = get_craft(pos, inventory, hash).output.item - local description, name = get_item_info(output_item) + local name = output_item:get_name() + local description = basic_machines.get_item_description(name ~= "" and name or nil) minetest.get_meta(pos):set_string("infotext", S("Autocrafter: '@1' (@2)", description, name)) inventory:set_stack("output", 1, output_item) end diff --git a/common.lua b/common.lua index 91a1f56..8ce7327 100644 --- a/common.lua +++ b/common.lua @@ -1,10 +1,12 @@ -- (c) 2015-2016 rnd --- Copyright (C) 2022-2024 мтест +-- Copyright (C) 2022-2025 мтест -- See README.md for license details +local S = minetest.get_translator("basic_machines") + basic_machines = { F = minetest.formspec_escape, - S = minetest.get_translator("basic_machines"), + S = S, version = "12/31/2024 (fork)", properties = { no_clock = false, -- if true all continuously running activities (clockgen/keypad) are disabled @@ -52,6 +54,12 @@ basic_machines = { end return table.concat(player_inv) end, + -- returns the item description + get_item_description = function(name) + local def = minetest.registered_items[name] + local description = def and def.description or S("Unknown Item") + return description + end, use_default = minetest.global_exists("default"), -- require minetest_game default mod --[[ interfaces -- autocrafter @@ -106,7 +114,7 @@ basic_machines.creative = function(name) {creative = true}) end --- result: float with precision up to two digits or integer number +-- returns a float with precision up to two digits or integer number local modf = math.modf basic_machines.twodigits_float = function(number) local r @@ -127,8 +135,6 @@ else basic_machines.sound_node_machine = function(sound_table) return sound_table end end -local S = basic_machines.S - -- test: toggle machine running with clockgen/keypad repeats, useful for debugging -- i.e. seeing how machines running affect server performance minetest.register_chatcommand("clockgen", { diff --git a/constructor.lua b/constructor.lua index cc80666..8dfa767 100644 --- a/constructor.lua +++ b/constructor.lua @@ -1,5 +1,5 @@ -- rnd 2016 --- Copyright (C) 2022-2023 мтест +-- Copyright (C) 2022-2025 мтест -- See README.md for license details local F, S = basic_machines.F, basic_machines.S @@ -32,7 +32,7 @@ local function constructor_update_form(constructor, meta) meta:set_string("formspec", "formspec_version[4]size[10.45,12.35]" .. "style_type[list;spacing=0.25,0.15]" .. "textlist[0.35,0.35;3.5,1.7;craft;" .. recipes_order_translated[constructor] .. ";" .. meta:get_int("selected") .. - "]item_image[4.75,0.35;1,1;" .. item .. "]button[4.6,1.65;1.3,0.8;CRAFT;" .. F(S("CRAFT")) .. + "]item_image[4.75,0.35;1,1;" .. item .. "]button[4.6,1.65;1.3,0.8;CRAFT;" .. F(S("Craft")) .. "]list[context;recipe;6.6,0.35;3,2]" .. "label[0.35,2.85;" .. F(description) .. "]list[context;main;0.35,3.25;8,3]" .. @@ -61,7 +61,7 @@ local function constructor_process(pos, constructor, name) for _, v in ipairs(recipe) do if not inv:contains_item("main", ItemStack(v)) then - meta:set_string("infotext", S("CRAFTING: You need '@1' to craft '@2'", v, item)); return + meta:set_string("infotext", S("Crafting: You need '@1' to craft '@2'", v, item)); return end end @@ -75,8 +75,8 @@ local function constructor_process(pos, constructor, name) end if name or meta:get_string("infotext") == "" then - meta:set_string("infotext", S("CRAFTING: '@1' (@2)", - def and def.description or S("Unknown item"), item)) + meta:set_string("infotext", S("Crafting: '@1' (@2)", + def and def.description or S("Unknown Item"), item)) end end end diff --git a/grinder.lua b/grinder.lua index 0c3cd8d..752a112 100644 --- a/grinder.lua +++ b/grinder.lua @@ -1,5 +1,5 @@ -- (c) 2015-2016 rnd --- Copyright (C) 2022-2023 мтест +-- Copyright (C) 2022-2025 мтест -- See README.md for license details local F, S = basic_machines.F, basic_machines.S @@ -347,8 +347,7 @@ local function grinder_process(pos) local steps = math.floor(stack:get_count() / def[4]) -- how many steps to process inserted stack if steps < 1 then - local item_def = minetest.registered_items[src_item] - local description = item_def and item_def.description or S("Unknown item") + local description = basic_machines.get_item_description(src_item) meta:set_string("infotext", S("Recipe requires at least @1 of '@2' (@3)", def[4], description, src_item)) return end diff --git a/locale/template b/locale/template index 40739e7..3f3657f 100644 --- a/locale/template +++ b/locale/template @@ -5,7 +5,7 @@ Autocrafter: '@1' (@2)= Unconfigured autocrafter: Place items for recipe top left. To operate place required items in bottom space (src inventory) and activate with signal. Obtain crafted item from top right (dst inventory).= Unconfigured autocrafter: Unknown recipe= Autocrafter= -Unknown item= +Unknown Item= Lifetime= Energy= Bounce= @@ -28,9 +28,9 @@ Gravity= Clock Generator: Interference from nearby clock generator detected= Clock Generator (owned by @1): place machine to be activated on top= Clock Generator= -CRAFT= -CRAFTING: You need '@1' to craft '@2'= -CRAFTING: '@1' (@2)= +Craft= +Crafting: You need '@1' to craft '@2'= +Crafting: '@1' (@2)= Constructor: to operate it insert materials, select item to make and click craft button= Constructor= Automate crafting= diff --git a/machines_configuration.lua b/machines_configuration.lua index 120b809..7a1f270 100644 --- a/machines_configuration.lua +++ b/machines_configuration.lua @@ -1,5 +1,5 @@ -- (c) 2015-2016 rnd --- Copyright (C) 2022-2024 мтест +-- Copyright (C) 2022-2025 мтест -- See README.md for license details local F, S = basic_machines.F, basic_machines.S @@ -207,8 +207,7 @@ minetest.register_on_punchnode(function(pos, node, puncher) minetest.chat_send_player(name, S("MOVER: Elevator setup completed, upgrade level @1.", upgrade - 1)) else local upgrade_item = basic_machines.get_mover("revupgrades")[2] - local upgrade_def = minetest.registered_items[upgrade_item] - local description = upgrade_def and upgrade_def.description or S("Unknown item") + local description = basic_machines.get_item_description(upgrade_item) minetest.chat_send_player(name, S("MOVER: Error while attempting to make an elevator. Need at least @1 of '@2' (@3) in upgrade (1 for every 100 distance).", requirement, description, upgrade_item)) diff --git a/mover.lua b/mover.lua index eb5ec42..5fa7cff 100644 --- a/mover.lua +++ b/mover.lua @@ -4,7 +4,7 @@ -- No background processing, just two abms (clock generator and generator), no other lag causing background processing ------------------------------------------------------------------------------------------------------------------------ -- (c) 2015-2016 rnd --- Copyright (C) 2022-2024 мтест +-- Copyright (C) 2022-2025 мтест -- See README.md for license details local F, S = basic_machines.F, basic_machines.S @@ -42,7 +42,7 @@ local mover = { dig_up_table = {}, -- how hard it is to move blocks, default factor 1, - -- note: fuel cost is this multiplied by distance and divided by machine_operations.. + -- note: fuel cost is this multiplied by distance and divided by machines_operations hardness = { ["bedrock2:bedrock"] = 999999, ["bedrock:bedrock"] = 999999, @@ -722,8 +722,7 @@ minetest.register_node("basic_machines:mover", { fuel_cost = 0 else local upgrade_item = mover_revupgrades[2] - local upgrade_def = minetest.registered_items[upgrade_item] - local description = upgrade_def and upgrade_def.description or S("Unknown item") + local description = basic_machines.get_item_description(upgrade_item) meta:set_string("infotext", S("MOVER: Elevator error. Need at least @1 of '@2' (@3) in upgrade (1 for every 100 distance).", requirement, description, upgrade_item)); return diff --git a/mover_object_mode.lua b/mover_object_mode.lua index 00463de..e9a29f9 100644 --- a/mover_object_mode.lua +++ b/mover_object_mode.lua @@ -1,5 +1,5 @@ -- (c) 2015-2016 rnd --- Copyright (C) 2022-2024 мтест +-- Copyright (C) 2022-2025 мтест -- See README.md for license details local F, S = basic_machines.F, basic_machines.S @@ -37,7 +37,7 @@ local function object(pos, meta, owner, prefer, pos1, _, _, _, pos2, mreverse) if node2 then node2_name = node2.name else - minetest.load_area(pos2) + minetest.load_area(pos2) -- alternative way: minetest.get_voxel_manip():read_from_map(pos2, pos2) node2_name = minetest.get_node(pos2).name end @@ -136,13 +136,12 @@ local function object(pos, meta, owner, prefer, pos1, _, _, _, pos2, mreverse) end end -local upgrade_item = basic_machines.get_mover("revupgrades")[2] -local upgrade_def = minetest.registered_items[upgrade_item] -local description = upgrade_def and upgrade_def.description or S("Unknown item") +local name = basic_machines.get_mover("revupgrades")[2] +local description = basic_machines.get_item_description(name) basic_machines.add_mover_mode("object", F(S("Make TELEPORTER/ELEVATOR:\n This will move any object inside a sphere (with center source1 and radius defined by distance between source1/source2) to target position\n" .. " For ELEVATOR, teleport origin/destination need to be placed exactly in same coordinate line with mover, and you need to upgrade with 1 of '@1' (@2) for every 100 height difference", - description, upgrade_item)), + description, name)), F(S("object")), object ) \ No newline at end of file diff --git a/recycler.lua b/recycler.lua index 3543975..a0e2e2e 100644 --- a/recycler.lua +++ b/recycler.lua @@ -2,7 +2,7 @@ -- You can select which recipe to use when recycling -- There is a fuel cost to recycle -- rnd 2015 --- Copyright (C) 2022-2024 мтест +-- Copyright (C) 2022-2025 мтест -- See README.md for license details local F, S = basic_machines.F, basic_machines.S @@ -135,8 +135,7 @@ local function recycler_process(pos) end reqcount = reqcount or 1 - local def = minetest.registered_items[src_item] - description = def and def.description or S("Unknown item") + description = basic_machines.get_item_description(src_item) meta:set_string("node", src_item) meta:set_string("itemlist", minetest.serialize(itemlist))