1
0
Fork 0

Merge pull request 'Fix invisibility potion when changing skin' (#2661) from potions into master

Reviewed-on: MineClone2/MineClone2#2661
Reviewed-by: cora <cora@noreply.git.minetest.land>
This commit is contained in:
cora 2022-09-15 19:50:33 +00:00
commit 103cde2db4
9 changed files with 89 additions and 72 deletions

View File

@ -189,9 +189,10 @@ minetest.register_on_joinplayer(function(player)
return_fields(player, "enchanting_lapis") return_fields(player, "enchanting_lapis")
end) end)
dofile(minetest.get_modpath(minetest.get_current_modname()).."/creative.lua") dofile(minetest.get_modpath(minetest.get_current_modname()).."/creative.lua")
mcl_player.register_on_visual_change(mcl_inventory.update_inventory_formspec)
local mt_is_creative_enabled = minetest.is_creative_enabled local mt_is_creative_enabled = minetest.is_creative_enabled
function minetest.is_creative_enabled(name) function minetest.is_creative_enabled(name)

View File

@ -1,5 +1,5 @@
name = mcl_inventory name = mcl_inventory
author = BlockMen author = BlockMen
description = Adds the player inventory and creative inventory. description = Adds the player inventory and creative inventory.
depends = mcl_init, mcl_formspec, mcl_enchanting depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_player
optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide, mcl_player optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide

View File

@ -405,11 +405,11 @@ function mcl_potions._reset_player_effects(player, set_hud)
mcl_weather.skycolor.update_sky_color({player}) mcl_weather.skycolor.update_sky_color({player})
mcl_potions._clear_cached_player_data(player)
if set_hud ~= false then if set_hud ~= false then
potions_set_hud(player) potions_set_hud(player)
end end
mcl_potions._clear_cached_player_data(player)
end end
function mcl_potions._save_player_effects(player) function mcl_potions._save_player_effects(player)
@ -561,45 +561,24 @@ function mcl_potions.is_obj_hit(self, pos)
end end
function mcl_potions.make_invisible(player, toggle) function mcl_potions.make_invisible(obj_ref, hide)
if obj_ref:is_player() then
if not player then if hide then
return false mcl_player.player_set_visibility(obj_ref, false)
obj_ref:set_nametag_attributes({ color = { a = 0 } })
else
mcl_player.player_set_visibility(obj_ref, true)
obj_ref:set_nametag_attributes({ color = { r = 255, g = 255, b = 255, a = 255 } })
end
else
if hide then
local luaentity = obj_ref:get_luaentity()
EF.invisible[obj_ref].old_size = luaentity.visual_size
obj_ref:set_properties({ visual_size = { x = 0, y = 0 } })
else
obj_ref:set_properties({ visual_size = EF.invisible[obj_ref].old_size })
end
end end
local is_player = player:is_player()
local entity = player:get_luaentity()
--local playername = player:get_player_name()
local skin_file
if toggle then -- hide player
skin_file = "mobs_mc_empty.png"
if entity then
EF.invisible[player].old_size = entity.visual_size
elseif not is_player then -- if not a player or entity, do nothing
return
end
if is_player then
mcl_player.player_set_skin(player, skin_file)
elseif not is_player then
player:set_properties({visual_size = {x = 0, y = 0}})
end
player:set_nametag_attributes({color = {a = 0}})
elseif EF.invisible[player] then -- show player
if is_player then
mcl_skins.update_player_skin(player)
elseif not is_player then
player:set_properties({visual_size = EF.invisible[player].old_size})
end
player:set_nametag_attributes({color = {r = 255, g = 255, b = 255, a = 255}})
end
end end

View File

@ -48,7 +48,7 @@ end
if mcl_skins_enabled then if mcl_skins_enabled then
-- Change the player's hand to their skin -- Change the player's hand to their skin
mcl_skins.register_on_set_skin(function(player) mcl_player.register_on_visual_change(function(player)
local node_id = mcl_skins.get_node_id_by_player(player) local node_id = mcl_skins.get_node_id_by_player(player)
player:get_inventory():set_stack("hand", 1, "mcl_meshhand:" .. node_id) player:get_inventory():set_stack("hand", 1, "mcl_meshhand:" .. node_id)
end) end)

View File

@ -1,6 +1,5 @@
name = mcl_meshhand name = mcl_meshhand
author = jordan4ibanez author = jordan4ibanez
description = Applies the player skin texture to the hand. description = Applies the player skin texture to the hand.
depends = mcl_tools depends = mcl_tools, mcl_player
optional_depends = mcl_skins optional_depends = mcl_skins

View File

@ -1,3 +1,5 @@
local sf = string.format
-- Minetest 0.4 mod: player -- Minetest 0.4 mod: player
-- See README.txt for licensing and other information. -- See README.txt for licensing and other information.
mcl_player = {} mcl_player = {}
@ -53,17 +55,55 @@ local player_model = {}
local player_textures = {} local player_textures = {}
local player_anim = {} local player_anim = {}
local player_sneak = {} local player_sneak = {}
local player_visible = {}
mcl_player.player_attached = {} mcl_player.player_attached = {}
function mcl_player.player_get_animation(player) function mcl_player.player_get_animation(player)
local name = player:get_player_name() local name = player:get_player_name()
local textures = player_textures[name]
if not player_visible[name] then
textures = table.copy(textures)
textures[1] = "blank.png"
end
return { return {
model = player_model[name], model = player_model[name],
textures = player_textures[name], textures = textures,
animation = player_anim[name], animation = player_anim[name],
visibility = player_visibility[name]
} }
end end
local registered_on_visual_change = {}
function mcl_player.register_on_visual_change(func)
table.insert(registered_on_visual_change, func)
end
local function update_player_textures(player)
local name = player:get_player_name()
local textures = player_textures[name]
if not player_visible[name] then
textures = table.copy(textures)
textures[1] = "blank.png"
end
player:set_properties({ textures = textures })
-- Delay calling the callbacks because mods (including mcl_player)
-- need to fully initialize player data from minetest.register_on_joinplayer
-- before callbacks run
minetest.after(0.1, function()
if player:is_player() then
for i, func in ipairs(registered_on_visual_change) do
func(player)
end
end
end)
end
-- Called when a player's appearance needs to be updated -- Called when a player's appearance needs to be updated
function mcl_player.player_set_model(player, model_name) function mcl_player.player_set_model(player, model_name)
local name = player:get_player_name() local name = player:get_player_name()
@ -74,11 +114,11 @@ function mcl_player.player_set_model(player, model_name)
end end
player:set_properties({ player:set_properties({
mesh = model_name, mesh = model_name,
textures = player_textures[name] or model.textures,
visual = "mesh", visual = "mesh",
visual_size = model.visual_size or {x=1, y=1}, visual_size = model.visual_size or {x=1, y=1},
damage_texture_modifier = "^[colorize:red:130", damage_texture_modifier = "^[colorize:red:130",
}) })
update_player_textures(player)
mcl_player.player_set_animation(player, "stand") mcl_player.player_set_animation(player, "stand")
else else
player:set_properties({ player:set_properties({
@ -89,25 +129,36 @@ function mcl_player.player_set_model(player, model_name)
player_model[name] = model_name player_model[name] = model_name
end end
local function set_texture(player, index, texture) function mcl_player.player_set_visibility(player, visible)
local textures = player_textures[player:get_player_name()] local name = player:get_player_name()
textures[index] = texture if player_visible[name] == visible then return end
player:set_properties({textures = textures}) player_visible[name] = visible
update_player_textures(player)
end end
function mcl_player.player_set_skin(player, texture) function mcl_player.player_set_skin(player, texture)
set_texture(player, 1, texture) local name = player:get_player_name()
player_textures[name][1] = texture
update_player_textures(player)
end end
function mcl_player.player_set_armor(player, texture) function mcl_player.player_set_armor(player, texture)
set_texture(player, 2, texture) local name = player:get_player_name()
player_textures[name][2] = texture
update_player_textures(player)
end end
function mcl_player.get_player_formspec_model(player, x, y, w, h, fsname) function mcl_player.get_player_formspec_model(player, x, y, w, h, fsname)
local name = player:get_player_name() local name = player:get_player_name()
local model = player_model[name] local model = player_model[name]
local anim = models[model].animations[player_anim[name]] local anim = models[model].animations[player_anim[name]]
return "model["..x..","..y..";"..w..","..h..";"..fsname..";"..model..";"..table.concat(player_textures[name], ",")..";0,".. 180 ..";false;false;"..anim.x..","..anim.y.."]" local textures = player_textures[name]
if not player_visible[name] then
textures = table.copy(textures)
textures[1] = "blank.png"
end
return sf("model[%s,%s;%s,%s;%s;%s;%s;0,180;false;false;%s,%s]", x, y, w, h, fsname, model,
table.concat(textures, ","), anim.x, anim.y)
end end
function mcl_player.player_set_animation(player, anim_name, speed) function mcl_player.player_set_animation(player, anim_name, speed)
@ -128,6 +179,7 @@ end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
mcl_player.player_attached[name] = false mcl_player.player_attached[name] = false
player_visible[name] = true
mcl_player.player_set_model(player, "character.b3d") mcl_player.player_set_model(player, "character.b3d")
player_textures[name] = {"character.png", "blank.png", "blank.png"} player_textures[name] = {"character.png", "blank.png", "blank.png"}
--player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30) --player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
@ -139,6 +191,8 @@ minetest.register_on_leaveplayer(function(player)
player_model[name] = nil player_model[name] = nil
player_anim[name] = nil player_anim[name] = nil
player_textures[name] = nil player_textures[name] = nil
player_sneak[name] = nil
player_visible[name] = nil
end) end)
-- Localize for better performance. -- Localize for better performance.

View File

@ -44,10 +44,6 @@ Can be one of: "arm", "base", "footwear", "eye", "mouth", "bottom", "top", "hair
`page_num` The page number to display of there are multiple pages of items. `page_num` The page number to display of there are multiple pages of items.
This parameter is optional. Must be a number. If it is not a valid page number the closest page number will be shown. This parameter is optional. Must be a number. If it is not a valid page number the closest page number will be shown.
### `mcl_skins.register_on_set_skin(func)`
Register a function to be called whenever a player skin changes.
The function will be given a player ObjectRef as a parameter.
### `mcl_skins.get_skin_list()` ### `mcl_skins.get_skin_list()`
This function is used by mods that want a list of skins to register nodes that use the player skin as a texture. This function is used by mods that want a list of skins to register nodes that use the player skin as a texture.
Returns an array of tables containing information about each skin. Returns an array of tables containing information about each skin.

View File

@ -127,12 +127,6 @@ function mcl_skins.update_player_skin(player)
end end
local model = slim_arms and "mcl_armor_character_female.b3d" or "mcl_armor_character.b3d" local model = slim_arms and "mcl_armor_character_female.b3d" or "mcl_armor_character.b3d"
mcl_player.player_set_model(player, model) mcl_player.player_set_model(player, model)
mcl_inventory.update_inventory_formspec(player)
for i=1, #mcl_skins.registered_on_set_skins do
mcl_skins.registered_on_set_skins[i](player)
end
end end
-- Load player skin on join -- Load player skin on join
@ -170,12 +164,6 @@ minetest.register_on_leaveplayer(function(player)
mcl_skins.players[player] = nil mcl_skins.players[player] = nil
end) end)
mcl_skins.registered_on_set_skins = {}
function mcl_skins.register_on_set_skin(func)
table.insert(mcl_skins.registered_on_set_skins, func)
end
function mcl_skins.show_formspec(player, active_tab, page_num) function mcl_skins.show_formspec(player, active_tab, page_num)
local skin = mcl_skins.players[player] local skin = mcl_skins.players[player]
local default = #mcl_skins.simple_skins > 0 and "skin" or "template" local default = #mcl_skins.simple_skins > 0 and "skin" or "template"

View File

@ -1,4 +1,4 @@
name = mcl_skins name = mcl_skins
author = MrRar author = MrRar
description = Advanced player skin customization. description = Advanced player skin customization.
depends = mcl_player,mcl_inventory depends = mcl_player