Merge pull request #13 from bell07/masteer
move redundant code into functions. Fix warnings with Minetest 5.5
This commit is contained in:
commit
53b5d1d7a8
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
|
||||||
|
98
init.lua
98
init.lua
@ -1,56 +1,9 @@
|
|||||||
--print(dump(skins.list))
|
newhand = {}
|
||||||
|
|
||||||
local simple_skins = minetest.get_modpath("simple_skins") ~= nil
|
function newhand.register_hand(name, texture)
|
||||||
|
minetest.register_node(name, {
|
||||||
|
|
||||||
|
|
||||||
--simple skins is enabled
|
|
||||||
if simple_skins == true then
|
|
||||||
newhand_oldskin = {}
|
|
||||||
--generate a node for every skin
|
|
||||||
for _,texture in pairs(skins.list) do
|
|
||||||
minetest.register_node("newhand:"..texture, {
|
|
||||||
description = "",
|
|
||||||
tiles = {texture..".png"},
|
|
||||||
inventory_image = "newhand_inv.png",
|
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
|
||||||
if minetest.get_node(pointed_thing.under).name == "default:chest_locked" then
|
|
||||||
minetest.item_place(itemstack, placer, pointed_thing, param2)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
visual_scale = 1,
|
|
||||||
wield_scale = {x=1,y=1,z=1},
|
|
||||||
paramtype = "light",
|
|
||||||
drawtype = "mesh",
|
|
||||||
mesh = "hand.b3d",
|
|
||||||
node_placement_prediction = "",
|
|
||||||
})
|
|
||||||
end
|
|
||||||
--change the player's hand to their skin
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
|
||||||
local skin = skins.skins[player:get_player_name()]
|
|
||||||
player:get_inventory():set_stack("hand", 1, "newhand:"..skin)
|
|
||||||
end)
|
|
||||||
|
|
||||||
--check to update the skin
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local skin = skins.skins[name]
|
|
||||||
|
|
||||||
if skin ~= newhand_oldskin[name] then
|
|
||||||
player:get_inventory():set_stack("hand", 1, "newhand:"..skin)
|
|
||||||
end
|
|
||||||
|
|
||||||
newhand_oldskin[name] = skin
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
--do default skin if no skin mod installed
|
|
||||||
else
|
|
||||||
minetest.register_node("newhand:hand", {
|
|
||||||
description = "",
|
description = "",
|
||||||
tiles = {"character.png"},
|
tiles = {texture},
|
||||||
inventory_image = "newhand_inv.png",
|
inventory_image = "newhand_inv.png",
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
if minetest.get_node(pointed_thing.under).name == "default:chest_locked" then
|
if minetest.get_node(pointed_thing.under).name == "default:chest_locked" then
|
||||||
@ -63,9 +16,50 @@ else
|
|||||||
drawtype = "mesh",
|
drawtype = "mesh",
|
||||||
mesh = "hand.b3d",
|
mesh = "hand.b3d",
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
|
use_texture_alpha = "clip"
|
||||||
})
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local oldhand = {}
|
||||||
|
|
||||||
|
function newhand.set_hand(player, hand)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if hand ~= oldhand[name] then
|
||||||
|
if hand and minetest.registered_nodes[hand] then
|
||||||
|
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
|
||||||
|
oldhand[name] = hand
|
||||||
|
end
|
||||||
|
|
||||||
|
--simple skins is enabled
|
||||||
|
if minetest.get_modpath("simple_skins") then
|
||||||
|
--generate a node for every skin
|
||||||
|
for _,texture in pairs(skins.list) do
|
||||||
|
newhand.register_hand("newhand:"..texture, texture..".png")
|
||||||
|
end
|
||||||
|
|
||||||
|
--change the player's hand to their skin
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
player:get_inventory():set_stack("hand", 1, "newhand:hand")
|
local skin = skins.skins[player:get_player_name()]
|
||||||
|
player:get_inventory():set_stack("hand", 1, "newhand:"..skin)
|
||||||
|
end)
|
||||||
|
|
||||||
|
--check to update the skin
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
local skin = skins.skins[player:get_player_name()]
|
||||||
|
newhand.set_hand(player, "newhand:"..skin)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
--do default skin if no skin mod installed
|
||||||
|
else
|
||||||
|
newhand.register_hand("newhand:hand", "character.png")
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
newhand.set_hand(player, "newhand:hand")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user