autofly: add transport api

This commit is contained in:
cora 2021-02-09 05:54:31 +01:00 committed by Schmappie Eldress
parent 45a0a33ba1
commit 4b1330c8c3
3 changed files with 65 additions and 16 deletions

View File

@ -186,10 +186,16 @@ function autofly.set_hud_info(text)
return true
end
function autofly.display(pos)
autofly.set_hud_wp(autofly.last_coords, autofly.last_name)
return true
end
function autofly.display_waypoint(name)
local pos=autofly.get_waypoint(name)
local pos=name
if type(name) ~= 'table' then pos=autofly.get_waypoint(name) end
autofly.last_name = name
autofly.last_coords = pos
autofly.set_hud_info(name)
@ -1204,6 +1210,7 @@ function autofly.autotp(tpname)
local txt = v:get_item_textures()
if ( txt:find('mcl_boats_texture')) then
boat_found=true
minetest.display_chat_message("boat found. entering and tping to "..minetest.pos_to_string(autofly.get_waypoint('AUTOTP')))
autofly.aim(vector.add(v:get_pos(),{x=0,y=-1.5,z=0}))
minetest.after("0.2",function()
minetest.interact("place") end)
@ -1213,10 +1220,16 @@ function autofly.autotp(tpname)
return true
end
end
if not boat_found then minetest.after("5.0",function() autofly.autotp(tpname) end) return end
if not boat_found then
minetest.display_chat_message("no boat found. trying again in 5.")
minetest.after("5.0",function() autofly.autotp(tpname) end)
return end
--minetest.sound_play({name = "default_alert", gain = 3.0})
--autofly.delete_waypoint('AUTOTP')
end
autofly.register_transport('Fly',function(pos,name) autofly.goto_waypoint(name) end)
autofly.register_transport('Warp',function(pos,name) autofly.warp(name) end)
autofly.register_transport('w+e',function(pos,name) autofly.warpae(name) end)
function autofly.axissnap()
if not minetest.settings:get_bool('afly_snap') then return end
@ -1246,9 +1259,23 @@ minetest.register_on_death(function()
end
end)
local function get_dimension(pos)
if pos.y > -65 then return "overworld"
elseif pos.y > -8000 then return "void"
elseif pos.y > -27000 then return "end"
elseif pos.y >29000 then return "void"
elseif pos.y >31000 then return "nether"
else return "void"
end
end
function autofly.warp(name)
local pos=vector.add(autofly.get_waypoint(name),{x=0,y=150,z=0})
local pos=autofly.get_waypoint(name)
if pos then
if pos.y > -64 then
pos=vector.add(pos,{x=0,y=150,z=0})
end
if get_dimension(pos) == "void" then return false end
minetest.localplayer:set_pos(pos)
return true
end

View File

@ -14,26 +14,35 @@ local stprefix="autofly-".. info['address'] .. '-'
autofly = {}
wps={}
autofly.registered_transports={}
local tspeed = 20 -- speed in blocks per second
local speed=0;
local ltime=0
function autofly.register_transport(name,func)
table.insert(autofly.registered_transports,{name=name,func=func})
end
function autofly.display_formspec()
local formspec = 'size[5.25,9]' ..
'label[0,0;Waypoint list]' ..
'button_exit[0,7.5;1,0.5;display;Show]' ..
'button[2.625,7.5;1.3,0.5;rename;Rename]' ..
'button[3.9375,7.5;1.3,0.5;delete;Delete]' ..
'button_exit[0,8.5;1,0.5;goto;Fly]' ..
'button_exit[0.8.0,8.5;1,0.5;itp;warp]' ..
'button_exit[1.6,8.5;1,0.5;autotp;w+e]' ..
'button_exit[2.4,8.5;1,0.5;itp;itp]' ..
'button_exit[3.2,8.5;1,0.5;jitp;jitp]'
'button[3.9375,7.5;1.3,0.5;delete;Delete]'
-- 'button_exit[0,8.5;1,0.5;goto;Fly]' ..
-- 'button_exit[0.8.0,8.5;1,0.5;itp;warp]' ..
-- 'button_exit[1.6,8.5;1,0.5;autotp;w+e]' ..
-- 'button_exit[2.4,8.5;1,0.5;itp;itp]' ..
-- 'button_exit[3.2,8.5;1,0.5;jitp;jitp]'
-- Iterate over all the waypoints
if emicor then
formspec=formspec..'button_exit[4.0,8.5;1,0.5;stp;stp]'
local sp=0
for k,v in pairs(autofly.registered_transports) do
formspec=formspec..'button_exit['..sp..',8.5;1,0.5;'..v.name..';'..v.name..']'
sp=sp+0.8
end
-- if emicor then
-- formspec=formspec..'button_exit[4.0,8.5;1,0.5;stp;stp]'
-- end
formspec=formspec..'textlist[0,0.75;5,6;marker;'
local selected = 1
formspec_list = {}
@ -92,6 +101,13 @@ minetest.register_on_formspec_input(function(formname, fields)
end
if name then
for k,v in pairs(autofly.registered_transports) do
if fields[v.name] then
if not v.func(autofly.get_waypoint(name),name) then
minetest.display_chat_message('Error with '..v.name)
end
end
end
if fields.display then
if not autofly.display_waypoint(name) then
minetest.display_chat_message('Error displaying waypoint!')
@ -108,10 +124,6 @@ minetest.register_on_formspec_input(function(formname, fields)
if not autofly.autotp(name) then
minetest.display_chat_message('warpandexit error')
end
elseif fields.stp then
if (emicor and emicor.stp(autofly.get_waypoint(name))) then
minetest.display_chat_message('stp error')
end
elseif fields.itp then
if incremental_tp then
incremetal_tp.tp(autofly.get_waypoint(name))

View File

@ -34,12 +34,17 @@ end
local function tpstep(target, time, second, variance,sfunc)
local pos = minetest.localplayer:get_pos()
local vec = vector.subtract(target, pos)
minetest.settings:set_bool("free_move",true)
if math.abs(vec.x) + math.abs(vec.y) + math.abs(vec.z) < 1 then
minetest.localplayer:set_pos(target)
incremental_tp.tpactive=false
minetest.display_chat_message("Arrived at " .. minetest.pos_to_string(target))
if sfunc then sfunc(target) end
if sfunc then
minetest.after(time, function()
sfunc(target)
end)
end
return
end
@ -68,9 +73,14 @@ function incremental_tp.tp(target, time, variance)
end
function incremental_tp.tpafter(target,time,variance,sfunc)
incremental_tp.tpactive=true
tpstep(target,time,1,variance,sfunc)
end
if autofly then autofly.register_transport('itp',function(pos,name) incremental_tp.tp(pos,1) end) end
if autofly then autofly.register_transport('jitp',function(pos,name) incremental_tp.tp(pos,0.5,0.4) end) end
minetest.register_chatcommand("itp", {
description = "Teleport to destination with fixed increments.",
params = "<destination>",