mirror of
https://github.com/minetest-mods/3d_armor.git
synced 2024-12-27 03:00:40 +01:00
Improve API for third party mods (#21)
* Add `armor:update_skin(player_name)` function (useful for skin mods) * Add option to prevent physics override (useful for Techage Jetpack mod) * Add documentation
This commit is contained in:
parent
3f1a952afb
commit
7436fcdffe
@ -172,6 +172,10 @@ armor:unequip(player, armor_name)
|
||||
|
||||
Unequip the armor, adding the itemstack to the main inventory.
|
||||
|
||||
armor:update_skin(player_name)
|
||||
|
||||
Triggers a skin update with the same action as if a field with `skins_set` was submitted.
|
||||
|
||||
Item Callbacks:
|
||||
|
||||
on_equip = func(player, index, stack)
|
||||
@ -201,3 +205,8 @@ armor:register_on_update(function(player)
|
||||
print(player:get_player_name().." armor updated!")
|
||||
end)
|
||||
|
||||
|
||||
Note:
|
||||
|
||||
The player physics modifications won't be applied via `set_physics_override` if `player_physics_locked` is set to 1
|
||||
in the respective player's meta.
|
||||
|
@ -315,8 +315,11 @@ armor.set_player_armor = function(self, player)
|
||||
})
|
||||
pova.do_override(player)
|
||||
else
|
||||
local player_physics_locked = player:get_meta():get_int("player_physics_locked")
|
||||
if player_physics_locked == nil or player_physics_locked == 0 then
|
||||
player:set_physics_override(physics)
|
||||
end
|
||||
end
|
||||
self.textures[name].armor = texture
|
||||
self.textures[name].preview = preview
|
||||
self.def[name].level = self.def[name].groups.fleshy or 0
|
||||
@ -490,6 +493,16 @@ armor.get_player_skin = function(self, name)
|
||||
return armor.default_skin..".png"
|
||||
end
|
||||
|
||||
armor.update_skin = function(self, name)
|
||||
minetest.after(0, function()
|
||||
local pplayer = minetest.get_player_by_name(name)
|
||||
if pplayer then
|
||||
self.textures[name].skin = self:get_player_skin(name)
|
||||
self:set_player_armor(pplayer)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
armor.add_preview = function(self, preview)
|
||||
skin_previews[preview] = true
|
||||
end
|
||||
|
@ -295,14 +295,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local player_name = player:get_player_name()
|
||||
for field, _ in pairs(fields) do
|
||||
if string.find(field, "skins_set") then
|
||||
minetest.after(0, function()
|
||||
local pplayer = minetest.get_player_by_name(player_name)
|
||||
if player then
|
||||
local skin = armor:get_player_skin(name)
|
||||
armor.textures[name].skin = skin
|
||||
armor:set_player_armor(pplayer)
|
||||
end
|
||||
end)
|
||||
armor:update_skin(player_name)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user