Add distance check to ta4 movecontroller

This commit is contained in:
Joachim Stolberg 2022-08-18 18:06:55 +02:00
parent 22495ad741
commit ede42eefbd
2 changed files with 10 additions and 9 deletions

View File

@ -75,14 +75,15 @@ function flylib.distance(v)
return math.abs(v.x) + math.abs(v.y) + math.abs(v.z)
end
function flylib.to_vector(s)
function flylib.to_vector(s, max_dist)
local x,y,z = unpack(string.split(s, ","))
x = tonumber(x) or 0
y = tonumber(y) or 0
z = tonumber(z) or 0
if x and y and z then
return {
x=tonumber(x) or 0,
y=tonumber(y) or 0,
z=tonumber(z) or 0,
}
if not max_dist or (math.abs(x) + math.abs(y) + math.abs(z)) <= max_dist then
return {x = x, y = y, z = z}
end
end
end

View File

@ -22,7 +22,7 @@ local MP = minetest.get_modpath("techage")
local fly = dofile(MP .. "/basis/fly_lib.lua")
local mark = dofile(MP .. "/basis/mark_lib.lua")
local MAX_DIST = 100
local MAX_DIST = 200
local MAX_BLOCKS = 16
local WRENCH_MENU = {
@ -183,7 +183,7 @@ minetest.register_node("techage:ta4_movecontroller", {
if fly.to_vector(fields.path or "", MAX_DIST) then
meta:set_string("path", fields.path)
end
local line = fly.to_vector(meta:get_string("path"))
local line = fly.to_vector(meta:get_string("path"), MAX_DIST)
if line then
nvm.running = true
fly.move_to(pos, line)
@ -240,7 +240,7 @@ techage.register_node({"techage:ta4_movecontroller"}, {
nvm.running = true
return fly.move_to_other_pos(pos, nvm.moveBA == false)
elseif move_xyz and topic == "move2" then
local line = fly.to_vector(payload)
local line = fly.to_vector(payload, MAX_DIST)
if line then
nvm.running = true
nvm.controller_mode = true