Add wearables API

This commit is contained in:
Signal 2025-10-10 23:46:01 -04:00
parent 9e63d7fe3a
commit 5e4d2924e4
14 changed files with 181 additions and 0 deletions

View file

@ -43,10 +43,40 @@ Player = {
e.hud = {}
e.poi = {}
e.wearing = {}
e:update_hp(p:get_hp())
e:update_inv()
return e
end,
update_inv = function(m)
m.object:set_formspec_prepend [[
bgcolor[#000;true]
background9[0,0;0,0;rgt_container_bg.png;true;16,16]
style_type[button;border=false;bgimg=rgt_button_bg.png;bgimg_middle=8,8]
listcolors[#fff0;#fff3;#0000;#444;#aaa]
]]
local fs = "\
formspec_version[10]\
size[12,10]\
"
for x = 0, 7 do
for y = 0, 3 do
fs = fs.."\
image["..(x *1.25 +1 -0.0625)..","..(y *1.25 +4.5 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
"
end
end
fs = fs.."\
list[current_player;main;1,4.5;8,4;]\
list[current_player;craft;3,0.5;3,3;]\
listring[]\
list[current_player;craftpreview;7,1;1,1;]\
"
m.object:set_inventory_formspec(fs)
end,
update_hp = function(m, hp)
if not (m.health_display and m.health_display:is_valid()) then
local pos = m.object:get_pos() or vector.zero()
@ -109,6 +139,8 @@ Player = {
wield_item = def.name
}
m.wielditem_display:set_attach(m.object, "RightArm", pos, rot)
-- Apparently this forces a resend so that properties and attachment position will sync up?
m.wielditem_display:set_pos(m.wielditem_display:get_pos())
end,
tick = function(m, dtime)
local time = minetest.get_us_time()
@ -333,6 +365,7 @@ Player = {
end,
deinit = function(m)
m.health_display:remove()
m.wielditem_display:remove()
rgt.players[m.name] = nil
end
}