diff --git a/mods/PLAYER/mcl_meshhand/README.md b/mods/PLAYER/mcl_meshhand/README.md new file mode 100644 index 000000000..2c796ff32 --- /dev/null +++ b/mods/PLAYER/mcl_meshhand/README.md @@ -0,0 +1,9 @@ +Mesh hand mod for MineClone 2. + +This mod uses a better-looking mesh for the wieldhand and applies the player skin texture to it. + +== Credits == +Based on 3D Hand [newhand] mod by jordan4ibanez. +https://forum.minetest.net/viewtopic.php?t=16435 + +License: CC0 diff --git a/mods/PLAYER/mcl_meshhand/depends.txt b/mods/PLAYER/mcl_meshhand/depends.txt new file mode 100644 index 000000000..f8be59ba7 --- /dev/null +++ b/mods/PLAYER/mcl_meshhand/depends.txt @@ -0,0 +1 @@ +mcl_skins? diff --git a/mods/PLAYER/mcl_meshhand/description.txt b/mods/PLAYER/mcl_meshhand/description.txt new file mode 100644 index 000000000..7a4daae59 --- /dev/null +++ b/mods/PLAYER/mcl_meshhand/description.txt @@ -0,0 +1 @@ +Applies the player skin texture to the hand. diff --git a/mods/PLAYER/mcl_meshhand/init.lua b/mods/PLAYER/mcl_meshhand/init.lua new file mode 100644 index 000000000..1e318a5b5 --- /dev/null +++ b/mods/PLAYER/mcl_meshhand/init.lua @@ -0,0 +1,47 @@ +local has_mcl_skins = minetest.get_modpath("mcl_skins") ~= nil + +-- mcl_skins is enabled +if has_mcl_skins == true then + --generate a node for every skin + for _,texture in pairs(mcl_skins.list) do + minetest.register_node("mcl_meshhand:"..texture, { + description = "", + tiles = {texture..".png"}, + inventory_image = "blank.png", + visual_scale = 1, + wield_scale = {x=1,y=1,z=1}, + paramtype = "light", + drawtype = "mesh", + mesh = "mcl_meshhand.b3d", + node_placement_prediction = "", + }) + end + --change the player's hand to their skin + minetest.register_on_joinplayer(function(player) + local skin = mcl_skins.skins[player:get_player_name()] + player:get_inventory():set_stack("hand", 1, "mcl_meshhand:"..skin) + end) + + mcl_skins.register_on_set_skin(function(player, skin) + local name = player:get_player_name() + player:get_inventory():set_stack("hand", 1, "mcl_meshhand:"..skin) + end) + +--do default skin if no skin mod installed +else + minetest.register_node("mcl_meshhand:hand", { + description = "", + tiles = {"character.png"}, + inventory_image = "blank.png", + visual_scale = 1, + wield_scale = {x=1,y=1,z=1}, + paramtype = "light", + drawtype = "mesh", + mesh = "mcl_meshhand.b3d", + node_placement_prediction = "", + }) + + minetest.register_on_joinplayer(function(player) + player:get_inventory():set_stack("hand", 1, "mcl_meshhand:hand") + end) +end diff --git a/mods/PLAYER/mcl_meshhand/mod.conf b/mods/PLAYER/mcl_meshhand/mod.conf new file mode 100644 index 000000000..6b57f4a49 --- /dev/null +++ b/mods/PLAYER/mcl_meshhand/mod.conf @@ -0,0 +1 @@ +name = mcl_meshhand diff --git a/mods/PLAYER/mcl_meshhand/models/mcl_meshhand.b3d b/mods/PLAYER/mcl_meshhand/models/mcl_meshhand.b3d new file mode 100644 index 000000000..a38124c60 Binary files /dev/null and b/mods/PLAYER/mcl_meshhand/models/mcl_meshhand.b3d differ diff --git a/mods/PLAYER/mcl_meshhand/models/mcl_meshhand.blend b/mods/PLAYER/mcl_meshhand/models/mcl_meshhand.blend new file mode 100644 index 000000000..495e74eb5 Binary files /dev/null and b/mods/PLAYER/mcl_meshhand/models/mcl_meshhand.blend differ diff --git a/mods/PLAYER/mcl_skins/init.lua b/mods/PLAYER/mcl_skins/init.lua index a822218d2..c24ce4a4c 100644 --- a/mods/PLAYER/mcl_skins/init.lua +++ b/mods/PLAYER/mcl_skins/init.lua @@ -1,7 +1,7 @@ -- Skins for MineClone 2 mcl_skins = { - skins = {}, previews = {}, meta = {}, + skins = {}, list = {}, previews = {}, meta = {}, modpath = minetest.get_modpath("mcl_skins"), skin_count = 0, -- counter of _custom_ skins (all skins except character.png) } @@ -14,6 +14,8 @@ local S, NS = dofile(mcl_skins.modpath .. "/intllib.lua") -- load skin list and metadata local id, f, data, skin = 1 +mcl_skins.list[0] = "character" + while true do skin = "character_" .. id @@ -23,11 +25,13 @@ while true do -- escape loop if not found and remove last entry if not f then + mcl_skins.list[id] = nil id = id - 1 break end f:close() + table.insert(mcl_skins.list, skin) -- does metadata exist for that skin file ? f = io.open(mcl_skins.modpath .. "/meta/" .. skin .. ".txt") @@ -52,7 +56,7 @@ mcl_skins.set_player_skin = function(player, skin_id) return false end local playername = player:get_player_name() - local skin, preview + local skin, skin_file, preview if skin_id == nil or type(skin_id) ~= "number" or skin_id < 0 or skin_id > mcl_skins.skin_count then return false elseif skin_id == 0 then @@ -62,17 +66,21 @@ mcl_skins.set_player_skin = function(player, skin_id) skin = "character_" .. tostring(skin_id) preview = "player_" .. tostring(skin_id) end + skin_file = skin .. ".png" mcl_skins.skins[playername] = skin mcl_skins.previews[playername] = preview player:set_attribute("mcl_skins:skin_id", tostring(skin_id)) mcl_skins.update_player_skin(player) if minetest.get_modpath("3d_armor") then - armor.textures[playername].skin = skin .. ".png" + armor.textures[playername].skin = skin_file armor:update_player_visuals(player) end if minetest.get_modpath("mcl_inventory") then mcl_inventory.update_inventory_formspec(player) end + for i=1, #mcl_skins.registered_on_set_skins do + mcl_skins.registered_on_set_skins[i](player, skin) + end minetest.log("action", "[mcl_skins] Player skin for "..playername.." set to skin #"..skin_id) return true end @@ -108,6 +116,12 @@ minetest.register_on_joinplayer(function(player) end end) +mcl_skins.registered_on_set_skins = {} + +mcl_skins.register_on_set_skin = function(func) + table.insert(mcl_skins.registered_on_set_skins, func) +end + -- command to set player skin (usually for custom skins) minetest.register_chatcommand("setskin", { params = "[] ",