24,539 ARTICLES
ON THIS WIKI

Module:Grid/Crafting Square Numbers


Lua Logo.svg This is the Lua module for Template:Grid/Crafting Square Numbers. Below is the documentation for that template.

Shows a Minecraft grid number of up to 3 digits.

Syntax[edit]

{{Grid/Crafting Square Numbers|<params>}}

Parameters[edit]

  • 1: The number value.
  • 2: The link for the image. (optional)

Examples[edit]

A gray background is displayed behind the output to clarify. This background is not present when using the template. The template output is positioned relative to the rectangle's upper-left corner.

1[edit]

The number 1 is not shown, but the template is still parsed!

{{Grid/Crafting Square Numbers|1}}

gives...

GridNumbersCSS.pngGridNumbersCSS.pngGridNumbersCSS.png

1 digit[edit]

{{Grid/Crafting Square Numbers|4}}

gives...

GridNumbersCSS.pngGridNumbersCSS.pngGridNumbersCSS.png

2 digits[edit]

{{Grid/Crafting Square Numbers|64}}

gives...

GridNumbersCSS.pngGridNumbersCSS.pngGridNumbersCSS.png

3 digits[edit]

{{Grid/Crafting Square Numbers|128}}

gives...

GridNumbersCSS.pngGridNumbersCSS.pngGridNumbersCSS.png

local p = {}

local g = require("Module:Common")
local s = require("Module:Sprite")

function p.makeCraftingNumbers(amount, link)
	local pos = {11, 11, 11}
	
	if amount > 1 then
		if amount > 99 then
			pos[1] = math.floor(amount / 100)
			amount = math.mod(amount, 100)
			pos[2] = math.floor(amount / 10)
			amount = math.mod(amount, 10)
		elseif amount > 9 then
			pos[2] = math.floor(amount / 10)
			amount = math.mod(amount, 10)
		end
		pos[3] = amount
	elseif amount == 0 then
		pos[3] = 0
	end
	
	-- Value for 0 is at position 10 in the sprite sheet
	for idx = 1, 3, 1 do
		if pos[idx] == 0 then
			pos[idx] = 10
		end
	end
	
	local output = "<span>" .. s.makeSprite("GridNumbersCSS.png", pos[1] - 1, 16, 64, link) .. "</span>"
	output = output .. "<span style=\"position:absolute; left:12px;\">" .. s.makeSprite("GridNumbersCSS.png", pos[2] - 1, 16, 64, link) .. "</span>"
	output = output .. "<span style=\"position:absolute; left:24px;\">" .. s.makeSprite("GridNumbersCSS.png", pos[3] - 1, 16, 64, link) .. "</span>"

	return output
end

function p.main(frame)
	return p.makeCraftingNumbers(tonumber(frame.args[1] or 1), frame.args[2] or '')
end

return p