forked from VoxeLibre/VoxeLibre
Added API support for positions of parts of player in mcl_playerinfo
This commit is contained in:
parent
0609d6fb23
commit
6898aa919c
|
@ -552,14 +552,12 @@ end
|
|||
|
||||
local function do_breath_tick(player, dtime)
|
||||
-- don't use default breath
|
||||
|
||||
minetest.set_node({x=0, y=100, z=0}, {name="mcl_core:lava_flowing", param2=math.random(0,7)})
|
||||
player:set_breath(player:get_properties().breath_max)
|
||||
|
||||
local breath_max = hb.settings.breath_max
|
||||
local player_name = player:get_player_name()
|
||||
local node_head = mcl_playerinfo[player_name].node_head
|
||||
minetest.debug(mcl_playerinfo[player_name].node_head,
|
||||
mcl_playerinfo[player_name].ndef_head.param2 and
|
||||
bit.band(mcl_playerinfo[player_name].ndef_head.param2, 7))
|
||||
local in_water = mcl_player.is_head_in_water(player)
|
||||
local current_breath = hb.get_breath(player)
|
||||
|
||||
|
|
|
@ -3,11 +3,32 @@ local table = table
|
|||
-- Player state for public API
|
||||
mcl_playerinfo = {}
|
||||
|
||||
local function get_playerpart_pos(part, player_pos, collisionbox, eye_height)
|
||||
--<part> can be "head", "head_top", "stand", "stand_below", "feet"
|
||||
local part_pos = table.copy(player_pos)
|
||||
if part == "head" then
|
||||
part_pos.y = part_pos.y + eye_height
|
||||
elseif part == "head_top" then
|
||||
part_pos.y = part_pos.y + collisionbox[5]
|
||||
elseif part == "stand" then
|
||||
-- small amount below bottom of hitbox
|
||||
part_pos.y = part_pos.y + collisionbox[2] - 0.05
|
||||
elseif part == "stand_below" then
|
||||
-- node below stood node
|
||||
part_pos.y = part_pos.y + collisionbox[2] - 1.05
|
||||
elseif part == "feet" then
|
||||
-- small amount above bottom of hitbox
|
||||
part_pos.y = part_pos.y + collisionbox[2] + 0.05
|
||||
end
|
||||
return part_pos
|
||||
end
|
||||
|
||||
mcl_playerinfo.get_playerpart_pos = get_playerpart_pos
|
||||
|
||||
|
||||
-- Get node but use fallback for nil or unknown
|
||||
local function node_ok(pos, fallback)
|
||||
|
||||
fallback = fallback or {name="air", param1=0, param2=0}
|
||||
|
||||
fallback = fallback or {name="air", param2=0, param1=0}
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
|
||||
if not node then
|
||||
|
@ -23,29 +44,33 @@ end
|
|||
|
||||
local time = 0
|
||||
|
||||
local function get_player_nodes(player_pos)
|
||||
local infotable = {}
|
||||
local work_pos = table.copy(player_pos)
|
||||
local function get_player_nodes(player)
|
||||
local player_pos = player:get_pos()
|
||||
local collisionbox = player:get_properties().collisionbox
|
||||
local eye_height = player:get_properties().eye_height
|
||||
|
||||
-- what is around me?
|
||||
work_pos.y = work_pos.y - 0.1 -- standing on
|
||||
infotable.ndef_stand = node_ok(work_pos)
|
||||
infotable.node_stand = infotable.ndef_stand.name
|
||||
local infotable = {
|
||||
player_pos = player_pos,
|
||||
collisionbox = collisionbox,
|
||||
eye_height = eye_height,
|
||||
}
|
||||
|
||||
infotable.ndef_stand_below = node_ok({x=work_pos.x, y=work_pos.y-1, z=work_pos.z})
|
||||
infotable.node_stand_below = infotable.ndef_stand_below.name
|
||||
local part_pos
|
||||
|
||||
work_pos.y = work_pos.y + 1.5 -- head level
|
||||
infotable.ndef_head = node_ok(work_pos)
|
||||
infotable.node_head = infotable.ndef_head.name
|
||||
work_pos.y = work_pos.y + 0.5 -- top of head level, at collision box height
|
||||
infotable.ndef_head_top = node_ok(work_pos)
|
||||
infotable.node_head_top = infotable.ndef_head_top.name
|
||||
work_pos.y = work_pos.y - 0.5
|
||||
part_pos = get_playerpart_pos("stand", player_pos, collisionbox, eye_height)
|
||||
infotable.node_stand = node_ok(part_pos).name
|
||||
|
||||
work_pos.y = work_pos.y - 1.2 -- feet level
|
||||
infotable.ndef_feet = node_ok(work_pos)
|
||||
infotable.node_feet = infotable.ndef_feet.name
|
||||
part_pos = get_playerpart_pos("head", player_pos, collisionbox, eye_height)
|
||||
infotable.node_head = node_ok(part_pos).name
|
||||
|
||||
part_pos = get_playerpart_pos("head_top", player_pos, collisionbox, eye_height)
|
||||
infotable.node_head_top = node_ok(part_pos).name
|
||||
|
||||
part_pos = get_playerpart_pos("feet", player_pos, collisionbox, eye_height)
|
||||
infotable.node_feet = node_ok(part_pos).name
|
||||
|
||||
part_pos = get_playerpart_pos("stand_below", player_pos, collisionbox, eye_height)
|
||||
infotable.node_stand_below = node_ok(part_pos).name
|
||||
|
||||
return infotable
|
||||
end
|
||||
|
@ -63,16 +88,11 @@ minetest.register_globalstep(function(dtime)
|
|||
-- FIXME: Make sure a regular check interval applies
|
||||
time = 0
|
||||
|
||||
-- check players
|
||||
-- get cbox, eye height, pos and relevant nodes around each player
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
-- who am I?
|
||||
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- where am I?
|
||||
local pos = player:get_pos()
|
||||
|
||||
-- what is around me?
|
||||
mcl_playerinfo[name] = get_player_nodes(pos)
|
||||
mcl_playerinfo[name] = get_player_nodes(player)
|
||||
end
|
||||
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue