Talk:Games/Minetest Game/Smelting

From Minetest
Revision as of 11:17, 26 June 2020 by >Wuzzy (Wuzzy moved page Talk:Smelting to Talk:Games/Minetest Game/Smelting: This is very MTG-specific)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Semi-automatic generation of fuel table

Since updating the fuel table is a tedious and error-prone task, I have written a Lua script to semi-automatically generate the table. Put the following code into a mod called “wikifuel”, enable it in Minetest Game with no other mods enabled and use the /wikifuel command. The mod will then output a wiki table into fuel_recipes.txt in the world directory. This wiki table can be pasted into the the article.

The wiki table you get will still need manual updates:

  • Links need to be corrected
  • Images need to be corrected
  • Replacements must be added by hand (e.g. Lava Bucket turning into Empty Bucket)
  • Groups must be added by hand
-- TODO: Add support for replacements
-- TODO: Add support for groups
-- TODO: Make item count sortable

local function do_out(playername, param)

	local outstring = ""

	outstring = 
[=[
{| class="wikitable collapsible sortable"
! scope="row" class="unsortable" |
! scope="row" | Block
! scope="row" | Burning time in seconds
! scope="row" class="unsortable" | Items smelted per fuel<ref>Assuming a smelting time of 3 seconds</ref>
! scope="row" class="unsortable" |
! scope="row" | Remainder
|-
]=]

	local fuelitems = {}
	for k,v in pairs(minetest.registered_items) do
		local f = minetest.get_craft_result({method="fuel", items = {k}})
		if f~=nil and f.time > 0 then table.insert(fuelitems, {burntime=f.time, item=k}) end
	end

	table.sort(fuelitems, function(a,b)
		return a.burntime > b.burntime
	end)

	for i=1,#fuelitems do

		local itemname = minetest.registered_items[fuelitems[i].item].description
		if itemname == nil then itemname = "UNKNOWN ITEM" end
		local burntime = fuelitems[i].burntime
		local iwhole = math.floor(burntime/3)
		local iremainder = math.fmod(burntime, 3)
		local itemcount = ""
		if iremainder == 0 then
			itemcount = tostring(iwhole)
		else
			if iwhole >= 1 then
				itemcount = tostring(iwhole)
				itemcount = itemcount .. '​'
			end
			if iremainder == 2 then
				itemcount = itemcount .. "⅔"
			elseif iremainder == 1 then
				itemcount = itemcount .. "⅓"
			end
		end

		outstring = outstring ..
		string.format(
[=[
| [[File:%s.png|link=%s|32px]]
| [[%s]]
| %d
| %s
|
| ''Nothing''
|-
]=], itemname, itemname, itemname, burntime, itemcount)


end

	outstring = outstring .. "|}\n<references/>"

	local filename = minetest.get_worldpath().."/fuel_recipes.txt"
	local file = io.open(filename, "w")
	file:write(outstring)
	file:close()
	minetest.chat_send_player(playername, "Fuel items written to: "..filename)
	minetest.log("action", "[wikifuel] Fuel items were written into file: "..filename)
end

minetest.register_chatcommand("wikifuel", {
	description = "Writes a list of all available fuels in MediaWiki syntax",
	params = "",
	privs = {server=true},
	func = do_out,
})