moved functions to external accesseable API, Add support for disabling hand
This commit is contained in:
parent
315d4910ca
commit
208e1e417a
11
README.md
11
README.md
@ -1,2 +1,13 @@
|
|||||||
# newhand
|
# newhand
|
||||||
a mod which makes the hand 3d in minetest
|
a mod which makes the hand 3d in minetest
|
||||||
|
|
||||||
|
|
||||||
|
# API
|
||||||
|
Any player skin mod can integrate the hand using this API
|
||||||
|
- newhand.register_hand(hand, texture)
|
||||||
|
- name - Hand (node) name. Should match mod:name_xyz
|
||||||
|
- texture - skin texture
|
||||||
|
|
||||||
|
- newhand.set_hand(player, hand)
|
||||||
|
- player - Player object
|
||||||
|
- hand - Hand (node) name
|
||||||
|
24
init.lua
24
init.lua
@ -1,4 +1,6 @@
|
|||||||
local function register_hand(name, texture)
|
newhand = {}
|
||||||
|
|
||||||
|
function newhand.register_hand(name, texture)
|
||||||
minetest.register_node(name, {
|
minetest.register_node(name, {
|
||||||
description = "",
|
description = "",
|
||||||
tiles = {texture},
|
tiles = {texture},
|
||||||
@ -19,13 +21,17 @@ local function register_hand(name, texture)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local oldhand = {}
|
local oldhand = {}
|
||||||
local function set_hand(player, hand)
|
|
||||||
|
function newhand.set_hand(player, hand)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if hand ~= oldhand[name] then
|
if hand ~= oldhand[name] then
|
||||||
player:get_inventory():set_size("hand", 1)
|
if hand and minetest.registered_nodes[hand] then
|
||||||
player:get_inventory():set_stack("hand", 1, hand)
|
player:get_inventory():set_size("hand", 1)
|
||||||
|
player:get_inventory():set_stack("hand", 1, hand)
|
||||||
|
else
|
||||||
|
player:get_inventory():set_size("hand", 0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
oldhand[name] = hand
|
oldhand[name] = hand
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -33,7 +39,7 @@ end
|
|||||||
if minetest.get_modpath("simple_skins") then
|
if minetest.get_modpath("simple_skins") then
|
||||||
--generate a node for every skin
|
--generate a node for every skin
|
||||||
for _,texture in pairs(skins.list) do
|
for _,texture in pairs(skins.list) do
|
||||||
register_hand("newhand:"..texture, texture..".png")
|
newhand.register_hand("newhand:"..texture, texture..".png")
|
||||||
end
|
end
|
||||||
|
|
||||||
--change the player's hand to their skin
|
--change the player's hand to their skin
|
||||||
@ -46,14 +52,14 @@ if minetest.get_modpath("simple_skins") then
|
|||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
local skin = skins.skins[player:get_player_name()]
|
local skin = skins.skins[player:get_player_name()]
|
||||||
set_hand(player, "newhand:"..skin)
|
newhand.set_hand(player, "newhand:"..skin)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--do default skin if no skin mod installed
|
--do default skin if no skin mod installed
|
||||||
else
|
else
|
||||||
register_hand("newhand:hand", "character.png")
|
newhand.register_hand("newhand:hand", "character.png")
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
set_hand(player, "newhand:hand")
|
newhand.set_hand(player, "newhand:hand")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user