forked from VoxeLibre/VoxeLibre
add basic API to register player globalstep
This commit is contained in:
parent
f5f6e232cc
commit
c7a144aa10
|
@ -1,3 +1,5 @@
|
|||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
mcl_util = {}
|
||||
|
||||
-- Based on minetest.rotate_and_place
|
||||
|
@ -418,3 +420,5 @@ function mcl_util.get_color(colorstr)
|
|||
return colorstr, hex
|
||||
end
|
||||
end
|
||||
|
||||
dofile(modpath.."/playerstep.lua")
|
|
@ -0,0 +1,19 @@
|
|||
local get_connected_players = minetest.get_connected_players
|
||||
|
||||
mcl_util.registered_player_globalstep = {}
|
||||
local registered_player_globalstep = mcl_util.registered_player_globalstep
|
||||
|
||||
function mcl_util.register_player_globalstep(func)
|
||||
table.insert(mcl_util.registered_player_globalstep, func)
|
||||
end
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
minetest.register_globalstep(function(dtime)
|
||||
local players = get_connected_players()
|
||||
for _,func in pairs(registered_player_globalstep) do
|
||||
for _,player in pairs(players) do
|
||||
func(player, dtime)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
|
@ -64,13 +64,11 @@ minetest.register_on_leaveplayer(function(player)
|
|||
wieldindex[name] = nil
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
mcl_util.register_player_globalstep(function(player, dtime)
|
||||
local player_name = player:get_player_name()
|
||||
local wstack = player:get_wielded_item()
|
||||
local wname = wstack:get_name()
|
||||
local windex = player:get_wield_index()
|
||||
|
||||
if dtimes[player_name] and dtimes[player_name] < dlimit then
|
||||
dtimes[player_name] = dtimes[player_name] + dtime
|
||||
if dtimes[player_name] > dlimit and huds[player_name] then
|
||||
|
@ -83,12 +81,9 @@ minetest.register_globalstep(function(dtime)
|
|||
wieldindex[player_name] = windex
|
||||
wield[player_name] = wname
|
||||
dtimes[player_name] = 0
|
||||
|
||||
if huds[player_name] then
|
||||
|
||||
local def = minetest.registered_items[wname]
|
||||
local meta = wstack:get_meta()
|
||||
|
||||
--[[ Get description. Order of preference:
|
||||
* description from metadata
|
||||
* description from item definition
|
||||
|
@ -108,6 +103,4 @@ minetest.register_globalstep(function(dtime)
|
|||
player:hud_change(huds[player_name], 'text', desc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
name = show_wielded_item
|
||||
author = 4aiman
|
||||
description = Displays the name of the wielded item.
|
||||
depends = mcl_util
|
||||
optional_depends = hudbars
|
||||
|
|
Loading…
Reference in New Issue