1
0
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:
Thomas--S 2020-10-12 07:47:57 +02:00 committed by GitHub
parent 3f1a952afb
commit 7436fcdffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 9 deletions

View File

@ -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.

View File

@ -315,7 +315,10 @@ armor.set_player_armor = function(self, player)
})
pova.do_override(player)
else
player:set_physics_override(physics)
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
@ -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

View File

@ -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)