Add is_valid_pos to builtin
This commit is contained in:
parent
8dcf7df205
commit
5b424fd67b
@ -102,6 +102,17 @@ function core.get_player_radius_area(player_name, radius)
|
||||
return p1, p2
|
||||
end
|
||||
|
||||
function core.is_valid_pos(pos)
|
||||
if pos then
|
||||
for _, v in pairs({"x", "y", "z"}) do
|
||||
if not pos[v] or pos[v] < -32000 or pos[v] > 32000 then
|
||||
return
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function core.hash_node_position(pos)
|
||||
return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768
|
||||
end
|
||||
|
@ -22,17 +22,6 @@ minetest.register_on_joinplayer(function(player)
|
||||
end
|
||||
end)
|
||||
|
||||
local function valid_pos(pos)
|
||||
if pos then
|
||||
for _, v in pairs({"x", "y", "z"}) do
|
||||
if not pos[v] or pos[v] < -32000 or pos[v] > 32000 then
|
||||
return
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function clean()
|
||||
local players = minetest.get_connected_players()
|
||||
for i = 1, #players do
|
||||
@ -43,7 +32,7 @@ local function clean()
|
||||
for y = -height, height do
|
||||
for z = -radius, radius do
|
||||
local pos_scan = vector.new(pos.x + x, pos.y + y, pos.z + z)
|
||||
if not valid_pos(pos_scan) then
|
||||
if not minetest.is_valid_pos(pos_scan) then
|
||||
return
|
||||
end
|
||||
--local hash = minetest.hash_node_position(pos_scan)
|
||||
|
@ -2,20 +2,9 @@ local age = 0.5 --How old an item has to be before collecting
|
||||
local radius_magnet = 2 --Radius of item magnet
|
||||
local player_collect_height = 1.3 --Added to their pos y value
|
||||
|
||||
local function valid_pos(pos)
|
||||
if pos then
|
||||
for _, v in pairs({"x", "y", "z"}) do
|
||||
if not pos[v] or pos[v] < -32000 or pos[v] > 32000 then
|
||||
return
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function collect_items(player)
|
||||
local pos = player:get_pos()
|
||||
if not valid_pos(pos) then
|
||||
if not minetest.is_valid_pos(pos) then
|
||||
return
|
||||
end
|
||||
local col_pos = vector.add(pos, {x=0, y=player_collect_height, z=0})
|
||||
|
Loading…
x
Reference in New Issue
Block a user