1 local path = minetest.get_modpath(minetest.get_current_modname())
3 -- path for the temporary skins file
4 local temppath = minetest.get_worldpath() .. "/skins_temp.png"
6 local pngimage = dofile(path.."/png_lua/png.lua")
8 --run through all the skins on the skindex and index them all locally
9 --only try to index further than the point in the current list max
11 local http = minetest.request_http_api()
12 local id = "Lua Skins Updater"
13 -- Binary downloads are required
14 if not core.features.httpfetch_binary_data then
15 print("outdated version of MINETEST detected!")
23 print("---------------------------------------------------------------")
24 print("HTTP access is required. Please add this to your minetest.conf:")
25 print("secure.http_mods = skins")
26 print("!!Skins will not work without this!!")
27 print("---------------------------------------------------------------")
31 -- Fancy debug wrapper to download an URL
32 local function fetch_url(url, callback)
38 if result.succeeded then
40 --if result.code ~= 200 then
41 --core.log("warning", ("%s: STATUS=%i URL=%s"):format(
42 -- _ID_, result.code, url))
44 return callback(result.data)
46 core.log("warning", ("%s: Failed to download URL=%s"):format(
51 --https://gist.github.com/marceloCodget/3862929 rgb to hex
53 local function rgbToHex(rgb)
55 local hexadecimal = ""
57 for key, value in pairs(rgb) do
61 local index = math.fmod(value, 16) + 1
62 value = math.floor(value / 16)
63 hex = string.sub('0123456789ABCDEF', index, index) .. hex
66 if(string.len(hex) == 0)then
69 elseif(string.len(hex) == 1)then
73 hexadecimal = hexadecimal .. hex
81 local function file_to_texture(image)
84 --local base_texture = "[combine:"..xmax.."x"..ymax
85 local base_texture = "[combine:" .. xmax .. "x" .. ymax
86 --local base_texture2 = "[combine:"..xmax.."x"..ymax
87 for _,line in pairs(image.pixels) do
88 for _,data in pairs(line) do
89 if x <= 32 or y > 16 then
90 local hex = rgbToHex({data.R,data.G,data.B})
91 --skip transparent pixels
93 --https://github.com/GreenXenith/skinmaker/blob/master/init.lua#L57 Thanks :D
95 base_texture = base_texture .. (":%s,%s=%s"):format(x - 1, y - 1, "(p.png\\^[colorize\\:#" .. hex .. ")")
113 -- Function to fetch a range of pages
114 fetch_function = function(name)
115 fetch_url("https://raw.githubusercontent.com/"..name.."/crafter_skindex/master/skin.png", function(data)
117 local f = io.open(temppath, "wb")
121 local img = pngimage(temppath, nil, false, false)
123 local stored_texture = file_to_texture(img)
125 --print("===============================================================")
126 --print(stored_texture)
127 if stored_texture then
128 --set the player's skin
129 local player = minetest.get_player_by_name(name)
130 player:set_properties({textures = {stored_texture}})
131 local meta = player:get_meta()
132 meta:set_string("skin",stored_texture)
134 recalculate_armor(player)
139 hud_elem_type = "image", -- See HUD element types
140 -- Type of element, can be "image", "text", "statbar", or "inventory"
142 position = {x=0.5, y=0.5},
143 -- Left corner position of element
147 scale = {x = 2, y = 2},
149 text = stored_texture,
156 -- Selected item in inventory. 0 for no item selected.
159 -- Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
161 alignment = {x=0, y=0},
165 size = { x=100, y=100 },
166 -- Size of element in pixels
169 -- Z index : lower z-index HUDs are displayed behind higher z-index HUDs
180 --local img = pngimage(minetest.get_modpath("skins").."/skin_temp/temp.png", nil, false, false)
183 minetest.register_on_joinplayer(function(player)
184 local meta = player:get_meta()
185 meta:set_string("skin","player.png")
186 minetest.after(0,function()
187 fetch_function(player:get_player_name())