Compare commits

...

9 Commits

Author SHA1 Message Date
chmodsayshello 3c19e3596a fix cape being registered twice 2023-12-23 00:05:10 +01:00
chmodsayshello b9dc2885fc fix cape rendering conflicts
The elytra and the normal cape were able to render at the same time while wearing an elytra.
2023-12-23 00:05:10 +01:00
chmodsayshello c99d8f0f1b remove test selector_func 2023-12-23 00:05:10 +01:00
chmodsayshello 9e7d4b42e6 update elytra cape instantly 2023-12-23 00:05:10 +01:00
chmodsayshello d3be07ce7e add cape api 2023-12-23 00:05:10 +01:00
chmodsayshello e54d60c8c6 remove sha1 unlocking for minetest cape 2023-12-23 00:05:10 +01:00
the-real-herowl f40c07c3cb Fix crash and trim trailing 2023-12-23 00:05:10 +01:00
chmodsayshello da147ff3d3 fix string length method call 2023-12-23 00:05:10 +01:00
chmodsayshello d73d0aaf51 resolve merge conflict 2023-12-23 00:04:49 +01:00
18 changed files with 209 additions and 59 deletions

View File

@ -227,5 +227,27 @@ minetest.register_tool("mcl_armor:elytra", {
on_place = mcl_armor.equip_on_use,
on_secondary_use = mcl_armor.equip_on_use,
_mcl_armor_element = "torso",
_mcl_armor_texture = "mcl_armor_elytra.png"
_mcl_armor_texture = function(obj, itemstack)
if obj:is_player() then
local cape = mcl_skins.player_skins[obj].cape
if cape ~= "blank.png" then
return cape:gsub("_body", "_elytra")
end
end
return "mcl_armor_elytra.png"
end,
_on_equip = function(obj, itemstack)
if not obj:is_player() then return end
local cape = mcl_skins.player_skins[obj].cape
if cape ~= "blank.png" then
local skinval = mcl_player.player_get_skin(obj)
skinval = skinval:gsub("%^" .. cape, "")
mcl_player.player_set_skin(obj, skinval)
-- this doesn't mess with the data mcl_skins has, so when mcl_skins reloads (which happens when the elytra is unequipped), the normal cape returns
end
end,
_on_unequip = function(obj, itemstack)
if not obj:is_player() then return end
mcl_skins.update_player_skin(obj)
end
})

View File

@ -129,6 +129,11 @@ function mcl_player.player_set_skin(player, texture)
update_player_textures(player)
end
function mcl_player.player_get_skin(player)
local name = player:get_player_name()
return player_textures[name][1]
end
function mcl_player.player_set_armor(player, texture)
local name = player:get_player_name()
player_textures[name][2] = texture

View File

@ -5,8 +5,8 @@ local EDIT_SKIN_KEY = -1 -- The key used for edit skin in the mcl_skins.simple_s
mcl_skins = {
simple_skins = {},
texture_to_simple_skin = {},
item_names = {"base", "footwear", "eye", "mouth", "bottom", "top", "hair", "headwear"},
tab_names = {"skin", "template", "base", "headwear", "hair", "eye", "mouth", "top", "arm", "bottom", "footwear"},
item_names = {"base", "footwear", "eye", "mouth", "bottom", "top", "hair", "headwear", "cape"},
tab_names = {"skin", "template", "base", "headwear", "hair", "eye", "mouth", "top", "arm", "bottom", "footwear", "cape"},
tab_descriptions = {
template = S("Templates"),
arm = S("Arm size"),
@ -19,11 +19,13 @@ mcl_skins = {
hair = S("Hairs"),
headwear = S("Headwears"),
skin = S("Skins"),
cape = S("Capes")
},
cape = {},
template1 = {}, -- Stores edit skin values for template1
template2 = {}, -- Stores edit skin values for template2
base = {}, -- List of base textures
-- Base color is separate to keep the number of junk nodes registered in check
base_color = {0xffeeb592, 0xffb47a57, 0xff8d471d},
color = {
@ -59,15 +61,29 @@ mcl_skins = {
function mcl_skins.register_item(item)
assert(mcl_skins[item.type], "Skin item type " .. item.type .. " does not exist.")
if item.type == "cape" then
local func = item.selector_func
if type(func) == "string" then
func = loadstring(func)()
end
table.insert(mcl_skins.cape, {name=item.name, selector_func=func, mask=item.mask})
mcl_skins.masks[item.name] = item.mask
return
end
local texture = item.texture or "blank.png"
if item.template1 then
mcl_skins.template1[item.type] = texture
end
if item.template2 then
mcl_skins.template2[item.type] = texture
end
table.insert(mcl_skins[item.type], texture)
mcl_skins.masks[texture] = item.mask
mcl_skins.preview_rotations[texture] = item.preview_rotation
@ -143,11 +159,19 @@ function mcl_skins.update_player_skin(player)
if not player then
return
end
local skin = mcl_skins.player_skins[player]
mcl_player.player_set_skin(player, mcl_skins.compile_skin(skin))
local skin = mcl_skins.player_skins[player]
local skinval = mcl_skins.compile_skin(skin)
if player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" then
skinval = skinval:gsub("%^" .. skin.cape, "")
-- don't render the "normal" cape on players while wearing the elytra.
-- this is NOT used when the player puts an elytra on, see register.lua in mcl_armor for that.
-- this is used when a player joins or changes something regarding their skin.
end
mcl_player.player_set_skin(player, skinval)
local slim_arms
if skin.simple_skins_id then
slim_arms = mcl_skins.texture_to_simple_skin[skin.simple_skins_id].slim_arms
@ -203,6 +227,8 @@ end)
local function calculate_page_count(tab)
if tab == "skin" then
return math.ceil((#mcl_skins.simple_skins + 2) / 8)
elseif tab == "cape" then
return math.ceil(#mcl_skins.cape / 5)
elseif mcl_skins[tab] then
return math.ceil(#mcl_skins[tab] / 16)
end
@ -213,29 +239,29 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
local formspec_data = mcl_skins.player_formspecs[player]
local skin = mcl_skins.player_skins[player]
formspec_data.active_tab = active_tab
local page_count = calculate_page_count(active_tab)
if page_num < 1 then page_num = 1 end
if page_num > page_count then page_num = page_count end
formspec_data.page_num = page_num
local formspec = "formspec_version[3]size[14.2,11]"
for i, tab in pairs(mcl_skins.tab_names) do
if tab == active_tab then
formspec = formspec ..
"style[" .. tab .. ";bgcolor=green]"
end
local y = 0.3 + (i - 1) * 0.8
formspec = formspec ..
"style[" .. tab .. ";content_offset=16,0]" ..
"button[0.3," .. y .. ";4,0.8;" .. tab .. ";" .. mcl_skins.tab_descriptions[tab] .. "]" ..
"image[0.4," .. y + 0.1 .. ";0.6,0.6;mcl_skins_icons.png^[verticalframe:11:" .. i - 1 .. "]"
"image[0.4," .. y + 0.1 .. ";0.6,0.6;mcl_skins_icons.png^[verticalframe:12:" .. i - 1 .. "]"
if skin.simple_skins_id then break end
end
local slim_arms
if skin.simple_skins_id then
slim_arms = mcl_skins.texture_to_simple_skin[skin.simple_skins_id].slim_arms
@ -249,6 +275,9 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
mcl_skins.compile_skin(skin) ..
",blank.png,blank.png;0,180;false;true;0,0]"
local cape_tab = active_tab == "cape"
if active_tab == "skin" then
local page_start = (page_num - 1) * 8 - 1
local page_end = math.min(page_start + 8 - 1, #mcl_skins.simple_skins)
@ -264,21 +293,21 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
}
simple_skins_id = simple_skins_id or
mcl_skins.simple_skins[EDIT_SKIN_KEY].texture
for i = page_start, page_end do
local skin = mcl_skins.simple_skins[i]
local j = i - page_start - 1
local mesh = skin.slim_arms and "mcl_armor_character_female.b3d" or
"mcl_armor_character.b3d"
local x = 4.5 + (j + 1) % 4 * 1.6
local y = 0.3 + math.floor((j + 1) / 4) * 3.1
formspec = formspec ..
"model[" .. x .. "," .. y .. ";1.5,3;player_mesh;" .. mesh .. ";" ..
skin.texture ..
",blank.png,blank.png;0,180;false;true;0,0]"
if simple_skins_id == skin.texture then
formspec = formspec ..
"style[" .. i ..
@ -288,7 +317,7 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
formspec = formspec ..
"button[" .. x .. "," .. y .. ";1.5,3;" .. i .. ";]"
end
if page_start == EDIT_SKIN_KEY then
formspec = formspec .. "image[4.85,1;0.8,0.8;mcl_skins_button.png]"
end
@ -303,16 +332,47 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
"model[7.5,2;2,3;player_mesh;mcl_armor_character_female.b3d;" ..
mcl_skins.compile_skin(mcl_skins.template2) ..
",blank.png,blank.png;0,180;false;true;0,0]" ..
"button[7.5,5.2;2,0.8;template2;" .. S("Select") .. "]"
elseif cape_tab then
local possize = {{"6,2;1,2", "5.5,4.2;2,0.8"}, {"9,2;1,2","8.5,4.2;2,0.8"}, {"6,7;1,2","5.5,9.2;2,0.8"}, {"9,7;1,2","8.5,9.2;2,0.8"},{"12,7;1,2","11.5,9.2;2,0.8"}}
local slot_start = 1
local slot_end = #mcl_skins.cape % (page_num * 5)
if slot_end == 0 then slot_end = 5 end
if page_num == 1 then
formspec = formspec ..
"label[6,3;" .. S("(None)") .. "]"..
"button[5.5,4.2;2,0.8;nocape;" .. S("Select") .. "]"
slot_start = 2
end
for slot = slot_start, slot_end do
local cape = mcl_skins.cape[((page_num -1) * 5) + slot]
local pos = possize[slot]
local show = true
if type(cape.selector_func) == "function" then
show = cape.selector_func(player)
end
if not show then
slot = slot - 1
else
formspec = formspec ..
"image[" .. possize[slot][1] .. ";" .. cape.name ..".png]"..
"button[" .. possize[slot][2] .. ";" .. cape.name ..";" .. S("Select") .. "]"
end
end
elseif mcl_skins[active_tab] then
formspec = formspec ..
"style_type[button;bgcolor=#00000000]"
local textures = mcl_skins[active_tab]
local page_start = (page_num - 1) * 16 + 1
local page_end = math.min(page_start + 16 - 1, #textures)
for j = page_start, page_end do
local i = j - page_start + 1
local texture = textures[j]
@ -323,21 +383,21 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
preview = preview .. "^(" .. mask .. "^[colorize:" .. color .. ":alpha)"
end
preview = preview .. "^" .. texture
local mesh = "mcl_skins_head.obj"
if active_tab == "top" then
mesh = "mcl_skins_top.obj"
elseif active_tab == "bottom" or active_tab == "footwear" then
mesh = "mcl_skins_bottom.obj"
end
local rot_x = -10
local rot_y = 20
if mcl_skins.preview_rotations[texture] then
rot_x = mcl_skins.preview_rotations[texture].x
rot_y = mcl_skins.preview_rotations[texture].y
end
i = i - 1
local x = 4.5 + i % 4 * 1.6
local y = 0.3 + math.floor(i / 4) * 1.6
@ -346,7 +406,7 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
";1.5,1.5;" .. mesh .. ";" .. mesh .. ";" ..
preview ..
";" .. rot_x .. "," .. rot_y .. ";false;false;0,0]"
if skin[active_tab] == texture then
formspec = formspec ..
"style[" .. texture ..
@ -365,11 +425,11 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
"button[" .. x .. ",0.3;1,1;arm;]"
end
if skin[active_tab .. "_color"] then
local colors = mcl_skins.color
if active_tab == "base" then colors = mcl_skins.base_color end
local tab_color = active_tab .. "_color"
local selected_color = skin[tab_color]
for i, colorspec in pairs(colors) do
@ -381,7 +441,7 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
"image_button[" .. x .. "," .. y ..
";0.8,0.8;blank.png^[noalpha^[colorize:" ..
color .. ":alpha;" .. colorspec .. ";]"
if selected_color == colorspec then
formspec = formspec ..
"style[" .. color ..
@ -389,9 +449,9 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
"bgimg_pressed=mcl_skins_select_overlay.png]" ..
"button[" .. x .. "," .. y .. ";0.8,0.8;" .. color .. ";]"
end
end
if not (active_tab == "base") then
-- Bitwise Operations !?!?!
local red = math.floor(selected_color / 0x10000) - 0xff00
@ -400,39 +460,54 @@ function mcl_skins.show_formspec(player, active_tab, page_num)
formspec = formspec ..
"container[10.2,8]" ..
"scrollbaroptions[min=0;max=255;smallstep=20]" ..
"box[0.4,0;2.49,0.38;red]" ..
"label[0.2,0.2;-]" ..
"scrollbar[0.4,0;2.5,0.4;horizontal;red;" .. red .."]" ..
"label[2.9,0.2;+]" ..
"box[0.4,0.6;2.49,0.38;green]" ..
"label[0.2,0.8;-]" ..
"scrollbar[0.4,0.6;2.5,0.4;horizontal;green;" .. green .."]" ..
"label[2.9,0.8;+]" ..
"box[0.4,1.2;2.49,0.38;blue]" ..
"label[0.2,1.4;-]" ..
"scrollbar[0.4,1.2;2.5,0.4;horizontal;blue;" .. blue .. "]" ..
"label[2.9,1.4;+]" ..
"container_end[]"
end
end
if page_num > 1 then
formspec = formspec ..
"image_button[4.5,6.7;1,1;mcl_skins_arrow.png^[transformFX;previous_page;]"
if cape_tab then
formspec = formspec ..
"image_button[4.5,0.7;1,1;mcl_skins_arrow.png^[transformFX;previous_page;]"
else
formspec = formspec ..
"image_button[4.5,6.7;1,1;mcl_skins_arrow.png^[transformFX;previous_page;]"
end
end
if page_num < page_count then
formspec = formspec ..
"image_button[9.8,6.7;1,1;mcl_skins_arrow.png;next_page;]"
if cape_tab then
formspec = formspec ..
"image_button[9.8,0.7;1,1;mcl_skins_arrow.png;next_page;]"
else
formspec = formspec ..
"image_button[9.8,6.7;1,1;mcl_skins_arrow.png;next_page;]"
end
end
if page_count > 1 then
formspec = formspec ..
"label[7.3,7.2;" .. page_num .. " / " .. page_count .. "]"
if cape_tab then
formspec = formspec ..
"label[7.3,1.2;" .. page_num .. " / " .. page_count .. "]"
else
formspec = formspec ..
"label[7.3,7.2;" .. page_num .. " / " .. page_count .. "]"
end
end
local player_name = player:get_player_name()
@ -456,7 +531,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
formspec_data.form_send_job:cancel()
formspec_data.form_send_job = nil
end
if fields.quit then
mcl_skins.save(player)
return true
@ -472,18 +547,33 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mcl_skins.update_player_skin(player)
mcl_skins.show_formspec(player, active_tab, page_num)
return true
elseif fields.nocape then
mcl_skins.player_skins[player].cape = "blank.png"
mcl_skins.update_player_skin(player)
mcl_armor.update(player) --update elytra cape
return true
elseif active_tab == "cape" then
for cape_index = ((page_num - 1) * 5) + 1, math.min(#mcl_skins.cape, page_num * 5) do
local cape = mcl_skins.cape[cape_index]
if fields[cape.name] then
mcl_skins.player_skins[player].cape = cape.mask -- the actual overlay image
mcl_skins.update_player_skin(player)
mcl_armor.update(player) --update elytra cape
return true
end
end
end
for i, tab in pairs(mcl_skins.tab_names) do
if fields[tab] then
mcl_skins.show_formspec(player, tab, 1)
return true
end
end
local skin = mcl_skins.player_skins[player]
if not skin then return true end
if fields.next_page then
page_num = page_num + 1
mcl_skins.show_formspec(player, active_tab, page_num)
@ -493,7 +583,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mcl_skins.show_formspec(player, active_tab, page_num)
return true
end
if active_tab == "arm" then
if fields.thick_arms then
skin.slim_arms = false
@ -504,7 +594,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mcl_skins.show_formspec(player, active_tab, page_num)
return true
end
if
skin[active_tab .. "_color"] and (
fields.red and fields.red:find("^CHG") or
@ -518,7 +608,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
red = tonumber(red) or 0
green = tonumber(green) or 0
blue = tonumber(blue) or 0
local color = 0xff000000 + red * 0x10000 + green * 0x100 + blue
if color >= 0 and color <= 0xffffffff then
-- We delay resedning the form because otherwise it will break dragging scrollbars
@ -533,7 +623,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return true
end
end
local field
for f, value in pairs(fields) do
if value == "" then
@ -541,7 +631,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
break
end
end
if field and active_tab == "skin" then
local index = tonumber(field)
index = index and math.floor(index) or 0
@ -556,7 +646,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
return true
end
-- See if field is a texture
if
field and mcl_skins[active_tab] and
@ -567,7 +657,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mcl_skins.show_formspec(player, active_tab, page_num)
return true
end
-- See if field is a color
local number = tonumber(field)
if number and skin[active_tab .. "_color"] then
@ -591,7 +681,7 @@ local function init()
local json, error = minetest.parse_json(data)
assert(json, error)
f:close()
for _, item in pairs(json) do
mcl_skins.register_item(item)
end
@ -600,12 +690,14 @@ local function init()
mcl_skins.template1.top_color = 0xff993535
mcl_skins.template1.bottom_color = 0xff644939
mcl_skins.template1.slim_arms = false
mcl_skins.template1.cape = "blank.png"
mcl_skins.template2.base_color = mcl_skins.base_color[1]
mcl_skins.template2.hair_color = 0xff715d57
mcl_skins.template2.top_color = 0xff346840
mcl_skins.template2.bottom_color = 0xff383532
mcl_skins.template2.slim_arms = true
mcl_skins.template2.cape = "blank.png"
mcl_skins.register_simple_skin({
index = 0,
@ -619,3 +711,9 @@ local function init()
end
init()
if not minetest.settings:get_bool("mcl_keepInventory", false) then
minetest.register_on_respawnplayer(function(player)
mcl_skins.update_player_skin(player) -- ensures players have their cape again after dying with an elytra
end)
end

View File

@ -263,5 +263,29 @@
"mask": "mcl_skins_base_1_mask.png",
"template1": true,
"template2": true
},
{
"type": "cape",
"name": "mtcape",
"mask": "mtcape_body.png",
"selector_func" : null
},
{
"type": "cape",
"name": "slimecape",
"mask": "slimecape_body.png",
"selector_func" : null
},
{
"type": "cape",
"name": "ghastcape",
"mask": "ghastcape_body.png",
"selector_func" : null
},
{
"type": "cape",
"name": "mclcape",
"mask": "mclcape_body.png",
"selector_func" : null
}
]

View File

@ -10,5 +10,6 @@ Bottoms=
Tops=
Hairs=
Headwears=
Open skin configuration screen.=
Open skin configuration screen.=
Select=
Capes=

BIN
textures/ghastcape.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
textures/ghastcape_body.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 420 B

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
textures/mclcape.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

BIN
textures/mclcape_body.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

BIN
textures/mclcape_elytra.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
textures/mtcape.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
textures/mtcape_body.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

BIN
textures/mtcape_elytra.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
textures/slimecape.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

BIN
textures/slimecape_body.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB