0 |
-- Overrides 3d_armor’s get_armor_formspec function, replacing the preview image |
1 |
-- with a 3d mesh of the player, where possible. |
2 |
armor.get_armor_formspec = function(self, name, listring) |
3 |
local formspec = armor.formspec.. |
4 |
"list[detached:"..name.."_armor;armor;0,0.5;2,3;]" |
5 |
if listring == true then |
6 |
formspec = formspec.."listring[current_player;main]".. |
7 |
"listring[detached:"..name.."_armor;armor]" |
8 |
end |
9 |
|
10 |
local model = player_model_fs(minetest.get_player_by_name(name), "armor_preview", 2.5, .2, 3, 4) |
11 |
if model then |
12 |
formspec = formspec:gsub("image%[.*;armor_preview%]", model) |
13 |
else |
14 |
formspec = formspec:gsub("armor_preview", armor.textures[name].preview) |
15 |
end |
16 |
|
17 |
formspec = formspec:gsub("armor_level", armor.def[name].level) |
18 |
|
19 |
for _, attr in pairs(self.attributes) do |
20 |
formspec = formspec:gsub("armor_attr_"..attr, armor.def[name][attr]) |
21 |
end |
22 |
for group, _ in pairs(self.registered_groups) do |
23 |
formspec = formspec:gsub("armor_group_"..group, |
24 |
armor.def[name].groups[group]) |
25 |
end |
26 |
return formspec |
27 |
end |
28 |
|
29 |
|
30 |
-- Creates a formspecs mesh of the player-model. |
31 |
-- Borrowed from i3 by Jean-Patrick Guerrero: |
32 |
-- https://github.com/minetest-mods/i3 |
33 |
function player_model_fs(player, name, x, y, w, h) |
34 |
local props = player:get_properties() |
35 |
if props.mesh ~= "" then |
36 |
local t = {} |
37 |
local anim = player:get_local_animation() |
38 |
|
39 |
for _, v in ipairs(props.textures) do |
40 |
table.insert(t, (v:gsub(",", "!") and v)) |
41 |
end |
42 |
local textures = table.concat(t, ","):gsub("!", ",") |
43 |
|
44 |
return string.format( |
45 |
"model[%f,%f;%f,%f;%s;%s;%s;%s;%s;%s;%s]", |
46 |
x, y, w, h, |
47 |
name, props.mesh, textures, "0,-150", "false", "false", |
48 |
type(anim) == "table" and string.format("%u,%u;30", anim.x, anim.y) or "") |
49 |
end |
50 |
return nil |
51 |
end |