Merge pull request #13 from bell07/masteer

move redundant code into functions. Fix warnings with Minetest 5.5
This commit is contained in:
jordan4ibanez 2022-06-23 21:36:32 -04:00 committed by GitHub
commit 53b5d1d7a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 52 deletions

View File

@ -1,2 +1,13 @@
# newhand
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

View File

@ -1,17 +1,9 @@
--print(dump(skins.list))
newhand = {}
local simple_skins = minetest.get_modpath("simple_skins") ~= nil
--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, {
function newhand.register_hand(name, texture)
minetest.register_node(name, {
description = "",
tiles = {texture..".png"},
tiles = {texture},
inventory_image = "newhand_inv.png",
on_place = function(itemstack, placer, pointed_thing)
if minetest.get_node(pointed_thing.under).name == "default:chest_locked" then
@ -24,8 +16,32 @@ if simple_skins == true then
drawtype = "mesh",
mesh = "hand.b3d",
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)
local skin = skins.skins[player:get_player_name()]
@ -35,37 +51,15 @@ if simple_skins == true then
--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
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
minetest.register_node("newhand:hand", {
description = "",
tiles = {"character.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 = "",
})
newhand.register_hand("newhand:hand", "character.png")
minetest.register_on_joinplayer(function(player)
player:get_inventory():set_stack("hand", 1, "newhand:hand")
newhand.set_hand(player, "newhand:hand")
end)
end

View File

@ -1 +1,2 @@
name = newhand
optional_depends = simple_skins