-
-
Save Jordach/5a5d660fc2907f9abafd3c2d774a0a35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local player_texture = minetest.formspec_escape(weapons.get_player_texture(player)) | |
local head = "model[7,1;3,3;head_preview;player_head.x;"..player_texture..";-45,225;false;false;90,90;0]" | |
local body = "model[7,4;3,3;body_preview;player_body.x;"..player_texture..";-45,225;false;false;170,249;60]" | |
local arms_mat = player_texture .. ",rubber.png,steel_dark.png,steel_grey.png,sight_green.png" | |
local arms = "model[7,7;3,3;arms_preview;arms_boringpistol.x;"..arms_mat..";-45,225;false;false;0,179;60]" | |
return body .. arms .. head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function weapons.get_player_texture(player) | |
local path = minetest.get_modpath("weapons").."/textures/heads/" | |
local pname = player:get_player_name() | |
local x64_template = "([combine:64x64:0,0=" | |
local x16_chop = "([combine:64x16:0,0=" | |
local result | |
local player_head = "player_"..pname..".png" | |
local width, height = weapons.get_tex_size(path..player_head) | |
local skin_overlay = weapons.get_player_skin(player) | |
if skin_overlay == nil then | |
return nil | |
elseif width == nil then | |
local nhead = x16_chop .. "default_player.png" .. ")" | |
return x64_template .. ")^" .. nhead .. "^" .. skin_overlay | |
elseif height == 64 or height == 32 then | |
local nhead = x16_chop .. player_head .. ")" | |
result = x64_template .. ")^" .. nhead .. "^" .. skin_overlay | |
else | |
local nhead = x16_chop .. "default_player.png" .. ")" | |
return x64_template .. ")^" .. nhead .. "^" .. skin_overlay | |
end | |
return result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function weapons.get_tex_size(file) -- ported from a fork | |
local file = io.open(file) | |
if file then | |
file:seek("set", 16) | |
local widthstr, heightstr = file:read(4), file:read(4) | |
local width=widthstr:sub(1,1):byte()*16777216+widthstr:sub(2,2):byte()*65536+widthstr:sub(3,3):byte()*256+widthstr:sub(4,4):byte() | |
local height=heightstr:sub(1,1):byte()*16777216+heightstr:sub(2,2):byte()*65536+heightstr:sub(3,3):byte()*256+heightstr:sub(4,4):byte() | |
file:close() | |
return width, height | |
else | |
return nil, nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment