-- IndustrialTest -- Copyright (C) 2025 mrkubax10 -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . local S=minetest.get_translator("industrialtest") -- \brief Creates hypertext table with rows -- \param rows table -- \param withTitleRow bool -- \param description (optional) string -- \returns string local function createTable(rows,withTitleRow,description) local columnWidths={} for _,row in ipairs(rows) do for i,cell in ipairs(row) do -- Add 3 here because of cell padding (2 spaces at each side of column text) and right cell separator columnWidths[i]=math.max(columnWidths[i] or 0,string.len(cell)+3) end end -- Begin with width of 1 because of left edge local tableWidth=1 for _,width in ipairs(columnWidths) do tableWidth=tableWidth+width end local horizontalEdge=string.rep("-",tableWidth).."\n" local hypertextRows={horizontalEdge} for i,row in ipairs(rows) do local hypertextRow={"|"} for o,cell in ipairs(row) do local cellWidth=string.len(cell)+3 local rightPadding=string.rep(" ",columnWidths[o]-cellWidth) table.insert(hypertextRow,string.format(" %s%s |",cell,rightPadding)) end table.insert(hypertextRow,"\n") table.insert(hypertextRows,table.concat(hypertextRow,"")) -- Insert horizontal edge if title row is present if withTitleRow and i==1 then table.insert(hypertextRows,horizontalEdge) end end table.insert(hypertextRows,horizontalEdge) return ""..table.concat(hypertextRows,"")..(description or "").."\n" end -- \brief Creates table with machine information while providing few shortcuts for common fields -- \param fields table -- \param machineName string -- \returns string local function createMachineInformationTable(fields,machineName) local fieldLabels={ inputVoltage="Input voltage level", outputVoltage="Output voltage level", recipe="Recipe type", powerCapacity="Power capacity", opPower="Power per operation", powerPerFuel="Power per fuel unit", efficiency="Default efficiency" } local rows={} for _,field in ipairs(fields) do local label=fieldLabels[field.name] or field.name table.insert(rows,{ label, field.value }) end return createTable(rows,false,string.format("Figure 1. Machine information for %s",machineName)) end local pages={ { name="introduction", title=S("Introduction"), icon=industrialtest.elementKeys.paper, content={ [[ ||Introduction|| ||IndustrialTest implements finite power functionality which can be used to perform various tasks using generators and consumers. Such features are not a new thing in Luanti, as there are older mods which do that already. This mod, however, proves to be more flexible.|| ]] } }, { name="electricalNetwork", title=S("Electrical network"), icon="industrialtest:insulated_copper_cable", content={ [[ ||Electrical network|| ||In order to attach electricity consumers to power sources (like generators, batteries, further just called generators) electrical network is used. Consumers can get connected either directly to generators or through various cables. Each generator can output certain voltage (this is actually amperage, however since this mod doesn't simulate electricity accurately, it's called voltage), the same situation is for consumers as they can only handle up to certain voltage.|| ||Figure 1 shows voltage levels present in this mod.|| ||If voltage is too high for cable it will melt without dropping anything while consumer will explode also without dropping anything and possibly destroying terrain around. Power capacity is measured in EU (Energy Units) and the voltage is EU/update.|| ||Picture 1 shows environment after consumer explosion.|| ]], createTable({ { "Voltage level", "EU/update", "Cable" }, { "LV", "600", "Tin" }, { "MV", "2400", "Copper" }, { "HV", "10200", "Gold" }, { "EV", "40800", "Iron" }, { "IV", "163800", "Glass Fibre" } },true,S("Figure 1. Voltage levels and respective cables")), [[ ||Picture 1. Environment after consumer explosion|| ]] } }, { name="cableFormer", title=S("Cable Former"), icon="industrialtest:cable_former", content={ [[ ||Cable Former|| ||Cable Former can be used to produce cables with higher material efficiency. It can, however, only produce cables from metals so for example Glass Fibre Cable can't be produced in it.|| ]], createMachineInformationTable({ { name="inputVoltage", value="LV" }, { name="recipe", value="Cable forming" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.CableFormer.capacity) }, { name="opPower", value=string.format("%d EU",industrialtest.CableFormer.opPower) }, { name="efficiency", value=tostring(1/industrialtest.CableFormer.efficiency) } },S("Cable Former")), [[ ||Picture 1. Cable Former running|| ]] } }, { name="canningMachine", title=S("Canning Machine"), icon="industrialtest:canning_machine", content={ [[ ||Canning Machine|| ||Canning Machine is used to move certain fluid from one item to another. The common usage is to refill fuel in Jetpack or Fuel Can.|| ]], createMachineInformationTable({ { name="inputVoltage", value="LV" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.CanningMachine.capacity) }, { name="opPower", value=string.format("%d EU",industrialtest.CanningMachine._opPower) }, { name="Canning completion time", value=string.format("%d seconds",industrialtest.CanningMachine._canningTime) } },S("Canning Machine")), [[ ||Picture 1. Canning Machine refilling Fuel Can with fuel from Coalfuel Cell|| ]] } }, { name="compressor", title=S("Compressor"), icon="industrialtest:compressor", content={ [[ ||Compressor|| ||Compressor as the name suggests is used to compress various materials. Mostly required to produce items for crafting other items.|| ]], createMachineInformationTable({ { name="inputVoltage", value="LV" }, { name="recipe", value="Compressing" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.Compressor.capacity) }, { name="opPower", value=string.format("%d EU",industrialtest.Compressor.opPower) }, { name="efficiency", value=tostring(1/industrialtest.Compressor.efficiency) } },S("Compressor")), [[ ||Picture 1. Compressor compressing Plantball into Compressed Plantball|| ]] } }, { name="electricFurnace", title=S("Electric Furnace"), icon="industrialtest:electric_furnace", content={ [[ ||Electric Furnace|| ||Electric Furnace like regular furnace can be used to smelt items. The difference is that Electric Furnace is slightly faster even without any upgrades and, well, it's electric so it doesn't require fuel.|| ]], createMachineInformationTable({ { name="inputVoltage", value="LV" }, { name="recipe", value="Smelting" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.ElectricFurnace.capacity) }, { name="opPower", value=string.format("%d EU",industrialtest.ElectricFurnace.opPower) }, { name="efficiency", value=tostring(1/industrialtest.ElectricFurnace.efficiency) } },S("Electric Furnace")), [[ ||Picture 1. Electric Furnace smelting Iron Dust into Iron Ingot|| ]] } }, { name="extractor", title=S("Extractor"), icon="industrialtest:extractor", content={ [[ ||Extractor|| ||Extractor is used to separate materials from within other materials, often when it's not possible by other means.|| ]], createMachineInformationTable({ { name="inputVoltage", value="LV" }, { name="recipe", value="Extracting" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.Extractor.capacity) }, { name="opPower", value=string.format("%d EU",industrialtest.Extractor.opPower) }, { name="efficiency", value=tostring(1/industrialtest.Extractor.efficiency) } },S("Extractor")), [[ ||Picture 1. Extractor extracting Rubber from Rubber Wood|| ]] } }, { name="generator", title=S("Generator"), icon="industrialtest:generator", content={ [[ ||Generator|| ||Generator produces energy from various fuels which can be used for smelting. It is the most basic way of powering electric machines and also the simplest to obtain.|| ]], createMachineInformationTable({ { name="outputVoltage", value="LV" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.Generator.capacity) }, { name="powerPerFuel", value="200 EU" } },S("Generator")), [[ ||Picture 1. Generator producing power from Coal|| ]] } }, { name="geothermalGenerator", title=S("Geothermal Generator"), icon="industrialtest:geothermal_generator", content={ [[ ||Geothermal Generator|| ||Geothermal Generator produces energy using heat from fluids like lava. Hot fluids can be transferred into Geothermal Generator for example by using Empty Cell or Empty Bucket.|| ]], createMachineInformationTable({ { name="outputVoltage", value="LV" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.GeothermalGenerator.capacity) } },S("Geothermal Generator")), [[ ||Picture 1. Geothermal Generator producing power from Lava|| ]] } }, { name="inductionFurnace", title=S("Induction Furnace"), icon="industrialtest:induction_furnace", content={ [[ ||Induction Furnace|| ||Induction Furnace like Electric Furnace uses electricity to smelt items. The difference between those is that Induction Furnace when running builds up heat internally over time. This property results in Induction Furnace smelting items faster the longer it's running. Once smelting is finished Induction Furnace begins to slowly lose heat. The heat level is indicated on the left of formspec.|| ||Furthermore Induction Furnace allows to smelt 2 different items at once increasing efficiency even more.|| ]], createMachineInformationTable({ { name="inputVoltage", value="MV" }, { name="recipe", value="Smelting" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.InductionFurnace.capacity) }, { name="opPower", value=string.format("%d EU",industrialtest.InductionFurnace._opPower) }, { name="efficiency", value=tostring(1/industrialtest.InductionFurnace._efficiency) } },S("Induction Furnace")), [[ ||Picture 1. Induction Furnace smelting Copper Dust and Iron Dust into Copper Ingot and Iron Ingot.|| ]] } }, { name="ironFurnace", title=S("Iron Furnace"), icon="industrialtest:iron_furnace", content={ [[ ||Iron Furnace|| ||Iron Furnace works in similar way to regular furnace but it smelts items faster.|| ]], createMachineInformationTable({ { name="recipe", value="Smelting" } },S("Iron Furnace")), [[ ||Picture 1. Iron Furnace smelting Iron Dust into Iron Ingot using Coal.|| ]] } }, { name="macerator", title=S("Macerator"), icon="industrialtest:macerator", content={ [[ ||Macerator|| ||Macerator allows to crush various materials into their dust form. This is particularly useful with ores where it can be used for obtaining twice as much resources in some cases.|| ]], createMachineInformationTable({ { name="inputVoltage", value="LV" }, { name="recipe", value="Macerating" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.Macerator.capacity) }, { name="opPower", value=string.format("%d EU",industrialtest.Macerator.opPower) }, { name="efficiency", value=tostring(1/industrialtest.Macerator.efficiency) } },S("Macerator")), [[ ||Picture 1. Macerator crushing Iron Lump into Iron Dust.|| ]] } }, { name="magnetizer", title=S("Magnetizer"), icon="industrialtest:magnetizer", content={ [[ ||Magnetizer|| ||Magnetizer when used together with vertical rail made of Iron Fence next to it creates small magnetic field around the fence. Such field allows for moving (as long as player wears some metal boots) upwards when jump key is pressed or downwards when sneak key is pressed. Each fence in rail adds to total power capacity that can be stored. Magnetizer automatically changes rotation to face detected fence rail.|| ]], createMachineInformationTable({ { name="inputVoltage", value="LV" }, { name="powerCapacity", value=string.format("%d EU + %d EU per fence in rail",industrialtest.Magnetizer.capacity,industrialtest.Magnetizer._capacityPerFence) }, { name="opPower", value=string.format("%d EU",industrialtest.Magnetizer._opPower) } },S("Magnetizer")), [[ ||Picture 1. Magnetizer powered by Solar Panel with fence rail next to it.|| ]] } }, { name="massFabricator", title=S("Mass Fabricator"), icon="industrialtest:mass_fabricator", content={ [[ ||Mass Fabricator|| ||Mass Fabricator can transform energy and Scrap into UU-Matter which then can be later used to produce various materials.|| ]], createMachineInformationTable({ { name="inputVoltage", value="EV" }, { name="recipe", value="Mass fabricating" }, { name="Scraps per UU-Matter", value="34" }, { name="powerCapacity", value=string.format("%d EU",industrialtest.MassFabricator.capacity) }, { name="opPower", value=string.format("%d EU",industrialtest.MassFabricator.opPower) }, { name="efficiency", value=tostring(1/industrialtest.MassFabricator.efficiency) } },S("Mass Fabricator")), [[ ||Picture 1. Mass Fabricator producing UU-Matter from Scrap.|| ]] } } } local function preprocessHypertext(content,vars) -- Find and replace strings which should be translated, this pattern matches any string that doesn't include | which is contained within || at both ends content=string.gsub(content,"||([^|]+)||",function(sourceString) return S(sourceString) end) for key,value in pairs(vars) do content=string.gsub(content,string.format("{{%s}}",key),value) end return content end local function getGuideFormspec(playerName,pageName) local formspec={ "formspec_version[4]", "size[15,10.8]", "label[0.1,0.2;"..S("IndustrialTest Guide").."]", --"scrollbaroptions[]", "scrollbar[3.6,0.4;0.5,10.3;vertical;scrollbarList;0]", "scroll_container[0.1,0.4;4,10.3;scrollbarList;vertical]" } -- Contents sidebar local PAGE_BUTTON_HEIGHT=0.7 for i,page in ipairs(pages) do table.insert(formspec,string.format("container[0,%f]",(i-1)*PAGE_BUTTON_HEIGHT)) table.insert(formspec,string.format("item_image[0,0;%f,%f;%s]",PAGE_BUTTON_HEIGHT,PAGE_BUTTON_HEIGHT,page.icon)) table.insert(formspec,string.format("button[%f,0;%f,%f;%s;%s]",PAGE_BUTTON_HEIGHT+0.05,3.45-PAGE_BUTTON_HEIGHT,PAGE_BUTTON_HEIGHT,page.name,page.title)) table.insert(formspec,"container_end[]") end table.insert(formspec,"scroll_container_end[]") -- Introduction page is shown by default pageName=(pageName or "introduction") for _,page in ipairs(pages) do if page.name==pageName then local content=preprocessHypertext(table.concat(page.content,""),{ IMAGE_WIDTH=550, ITEM_HEIGHT=16, elementKeyBucket=industrialtest.elementKeys.bucket, elementKeyCoal=industrialtest.elementKeys.coal, elementKeyCopperIngot=industrialtest.elementKeys.copperIngot, elementKeyIronIngot=industrialtest.elementKeys.ironIngot, elementKeyIronLump=industrialtest.elementKeys.ironLump, elementKeyRubber=industrialtest.elementKeys.rubber, elementKeyRubberWood=industrialtest.elementKeys.rubberWood }) table.insert(formspec,string.format("hypertext[4.2,0.4;10.7,10.3;content;%s]",content)) break end end return table.concat(formspec,"") end local function showGuide(playerName,page) minetest.show_formspec(playerName,"industrialtest:guide",getGuideFormspec(playerName,page)) return true end local function handleGuideFields(player,formname,fields) if formname~="industrialtest:guide" then return end for _,page in ipairs(pages) do if fields[page.name] then minetest.close_formspec(player:get_player_name(),formname) showGuide(player:get_player_name(),page.name) break end end end minetest.register_on_player_receive_fields(handleGuideFields) minetest.register_chatcommand("industrialtest_guide",{ description=S("Shows graphical guide for content and features provided by IndustrialTest"), func=function(playerName) showGuide(playerName) end })