Split mcl_playerplus to mcl_playerinfo for the node info
This commit is contained in:
parent
5ef42f27ec
commit
705dae46a0
11 changed files with 172 additions and 72 deletions
15
mods/PLAYER/mcl_playerinfo/README.md
Normal file
15
mods/PLAYER/mcl_playerinfo/README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# PlayerInfo mod for MineClone 2
|
||||
|
||||
This is a helper mod for other mod to query the nodes around the player.
|
||||
|
||||
Every half second the mod checks which node the player is standing on, which
|
||||
node is at foot and head level and stores inside a global table to be used by mods:
|
||||
|
||||
- `mcl_playerinfo[name].node_stand`
|
||||
- `mcl_playerinfo[name].node_stand_below`
|
||||
- `mcl_playerinfo[name].node_foot`
|
||||
- `mcl_playerinfo[name].node_head`
|
||||
|
||||
## License
|
||||
MIT License
|
||||
|
7
mods/PLAYER/mcl_playerinfo/depends.txt
Normal file
7
mods/PLAYER/mcl_playerinfo/depends.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
mcl_init
|
||||
mcl_util
|
||||
mcl_core
|
||||
mcl_particles
|
||||
mcl_hunger
|
||||
mcl_death_messages
|
||||
3d_armor?
|
91
mods/PLAYER/mcl_playerinfo/init.lua
Normal file
91
mods/PLAYER/mcl_playerinfo/init.lua
Normal file
|
@ -0,0 +1,91 @@
|
|||
-- Player state for public API
|
||||
mcl_playerinfo = {}
|
||||
|
||||
-- Get node but use fallback for nil or unknown
|
||||
local function node_ok(pos, fallback)
|
||||
|
||||
fallback = fallback or "air"
|
||||
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
|
||||
if not node then
|
||||
return fallback
|
||||
end
|
||||
|
||||
if minetest.registered_nodes[node.name] then
|
||||
return node.name
|
||||
end
|
||||
|
||||
return fallback
|
||||
end
|
||||
|
||||
local time = 0
|
||||
|
||||
local get_player_nodes = function(player_pos)
|
||||
local work_pos = table.copy(player_pos)
|
||||
|
||||
-- what is around me?
|
||||
work_pos.y = work_pos.y - 0.1 -- standing on
|
||||
local node_stand = node_ok(work_pos)
|
||||
local node_stand_below = node_ok({x=work_pos.x, y=work_pos.y-1, z=work_pos.z})
|
||||
|
||||
work_pos.y = work_pos.y + 1.5 -- head level
|
||||
local node_head = node_ok(work_pos)
|
||||
|
||||
work_pos.y = work_pos.y - 1.2 -- feet level
|
||||
local node_feet = node_ok(work_pos)
|
||||
|
||||
return node_stand, node_stand_below, node_head, node_feet
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
|
||||
time = time + dtime
|
||||
|
||||
-- Run the rest of the code every 0.5 seconds
|
||||
if time < 0.5 then
|
||||
return
|
||||
end
|
||||
|
||||
-- reset time for next check
|
||||
-- FIXME: Make sure a regular check interval applies
|
||||
time = 0
|
||||
|
||||
-- check players
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
-- who am I?
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- where am I?
|
||||
local pos = player:getpos()
|
||||
|
||||
-- what is around me?
|
||||
local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos)
|
||||
mcl_playerinfo[name].node_stand = node_stand
|
||||
mcl_playerinfo[name].node_stand_below = node_stand_below
|
||||
mcl_playerinfo[name].node_head = node_head
|
||||
mcl_playerinfo[name].node_feet = node_feet
|
||||
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
-- set to blank on join (for 3rd party mods)
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
mcl_playerinfo[name] = {
|
||||
node_head = "",
|
||||
node_feet = "",
|
||||
node_stand = "",
|
||||
node_stand_below = "",
|
||||
}
|
||||
|
||||
end)
|
||||
|
||||
-- clear when player leaves
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
mcl_playerinfo[name] = nil
|
||||
end)
|
21
mods/PLAYER/mcl_playerinfo/license.txt
Normal file
21
mods/PLAYER/mcl_playerinfo/license.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 TenPlus1
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
1
mods/PLAYER/mcl_playerinfo/mod.conf
Normal file
1
mods/PLAYER/mcl_playerinfo/mod.conf
Normal file
|
@ -0,0 +1 @@
|
|||
name = mcl_playerinfo
|
Loading…
Add table
Add a link
Reference in a new issue